| 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 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame^] | 1475 | /* PLOGI failed Don't print the vport to vport rjts */ |
| 1476 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1477 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1478 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1479 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1480 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1481 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", |
| 1482 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1483 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1484 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1485 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1486 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1487 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1488 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1489 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1490 | } else { |
| 1491 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1492 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1493 | cmdiocb->context2)->list.next, |
| 1494 | struct lpfc_dmabuf, list); |
| 1495 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1496 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1497 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1498 | } |
| 1499 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1500 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1501 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1502 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1503 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1504 | if (vport->num_disc_nodes == 0) { |
| 1505 | spin_lock_irq(shost->host_lock); |
| 1506 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1507 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1508 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1509 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1510 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1511 | } |
| 1512 | } |
| 1513 | |
| 1514 | out: |
| 1515 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1516 | return; |
| 1517 | } |
| 1518 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1519 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1520 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1521 | * @vport: pointer to a host virtual N_Port data structure. |
| 1522 | * @did: destination port identifier. |
| 1523 | * @retry: number of retries to the command IOCB. |
| 1524 | * |
| 1525 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1526 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1527 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1528 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1529 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1530 | * |
| 1531 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1532 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1533 | * will be stored into the context1 field of the IOCB for the completion |
| 1534 | * callback function to the PLOGI ELS command. |
| 1535 | * |
| 1536 | * Return code |
| 1537 | * 0 - Successfully issued a plogi for @vport |
| 1538 | * 1 - failed to issue a plogi for @vport |
| 1539 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1540 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1541 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1542 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1543 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1544 | struct serv_parm *sp; |
| 1545 | IOCB_t *icmd; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1546 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1547 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1548 | struct lpfc_sli *psli; |
| 1549 | uint8_t *pcmd; |
| 1550 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1551 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1552 | |
| 1553 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1554 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1555 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1556 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1557 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1558 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1559 | /* 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] | 1560 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1561 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1562 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1563 | if (!elsiocb) |
| 1564 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1565 | |
| 1566 | icmd = &elsiocb->iocb; |
| 1567 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1568 | |
| 1569 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1570 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1571 | pcmd += sizeof(uint32_t); |
| 1572 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1573 | sp = (struct serv_parm *) pcmd; |
| 1574 | |
| 1575 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1576 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1577 | |
| 1578 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1579 | sp->cmn.fcphHigh = FC_PH3; |
| 1580 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1581 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1582 | "Issue PLOGI: did:x%x", |
| 1583 | did, 0, 0); |
| 1584 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1585 | phba->fc_stat.elsXmitPLOGI++; |
| 1586 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1587 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1588 | |
| 1589 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1590 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1591 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1592 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1593 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1594 | } |
| 1595 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1596 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1597 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1598 | * @phba: pointer to lpfc hba data structure. |
| 1599 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1600 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1601 | * |
| 1602 | * This routine is the completion callback function for a Process Login |
| 1603 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 1604 | * status. If there is error status reported, PRLI retry shall be attempted |
| 1605 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 1606 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 1607 | * ndlp to mark the PRLI completion. |
| 1608 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1609 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1610 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1611 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1612 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1613 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1614 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1615 | IOCB_t *irsp; |
| 1616 | struct lpfc_sli *psli; |
| 1617 | struct lpfc_nodelist *ndlp; |
| 1618 | |
| 1619 | psli = &phba->sli; |
| 1620 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1621 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1622 | |
| 1623 | irsp = &(rspiocb->iocb); |
| 1624 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1625 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1626 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1627 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1628 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1629 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1630 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 1631 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1632 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1633 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1634 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1635 | "0103 PRLI completes to NPort x%x " |
| 1636 | "Data: x%x x%x x%x x%x\n", |
| 1637 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1638 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1639 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1640 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1641 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1642 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1643 | goto out; |
| 1644 | |
| 1645 | if (irsp->ulpStatus) { |
| 1646 | /* Check for retry */ |
| 1647 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1648 | /* ELS command is being retried */ |
| 1649 | goto out; |
| 1650 | } |
| 1651 | /* PRLI failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1652 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1653 | "2754 PRLI failure DID:%06X Status:x%x/x%x\n", |
| 1654 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1655 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1656 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1657 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1658 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1659 | else |
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); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1662 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1663 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1664 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1665 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1666 | out: |
| 1667 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1668 | return; |
| 1669 | } |
| 1670 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1671 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1672 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1673 | * @vport: pointer to a host virtual N_Port data structure. |
| 1674 | * @ndlp: pointer to a node-list data structure. |
| 1675 | * @retry: number of retries to the command IOCB. |
| 1676 | * |
| 1677 | * This routine issues a Process Login (PRLI) ELS command for the |
| 1678 | * @vport. The PRLI service parameters are set up in the payload of the |
| 1679 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 1680 | * is put to the IOCB completion callback func field before invoking the |
| 1681 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 1682 | * |
| 1683 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1684 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1685 | * will be stored into the context1 field of the IOCB for the completion |
| 1686 | * callback function to the PRLI ELS command. |
| 1687 | * |
| 1688 | * Return code |
| 1689 | * 0 - successfully issued prli iocb command for @vport |
| 1690 | * 1 - failed to issue prli iocb command for @vport |
| 1691 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1692 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1693 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1694 | uint8_t retry) |
| 1695 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1696 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1697 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1698 | PRLI *npr; |
| 1699 | IOCB_t *icmd; |
| 1700 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1701 | uint8_t *pcmd; |
| 1702 | uint16_t cmdsize; |
| 1703 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1704 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1705 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1706 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1707 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1708 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1709 | |
| 1710 | icmd = &elsiocb->iocb; |
| 1711 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1712 | |
| 1713 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1714 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1715 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1716 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1717 | |
| 1718 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 1719 | npr = (PRLI *) pcmd; |
| 1720 | /* |
| 1721 | * If our firmware version is 3.20 or later, |
| 1722 | * set the following bits for FC-TAPE support. |
| 1723 | */ |
| 1724 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 1725 | npr->ConfmComplAllowed = 1; |
| 1726 | npr->Retry = 1; |
| 1727 | npr->TaskRetryIdReq = 1; |
| 1728 | } |
| 1729 | npr->estabImagePair = 1; |
| 1730 | npr->readXferRdyDis = 1; |
| 1731 | |
| 1732 | /* For FCP support */ |
| 1733 | npr->prliType = PRLI_FCP_TYPE; |
| 1734 | npr->initiatorFunc = 1; |
| 1735 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1736 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1737 | "Issue PRLI: did:x%x", |
| 1738 | ndlp->nlp_DID, 0, 0); |
| 1739 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1740 | phba->fc_stat.elsXmitPRLI++; |
| 1741 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1742 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1743 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1744 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1745 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 1746 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1747 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1748 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1749 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1750 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1751 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1752 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1753 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1754 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1755 | } |
| 1756 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1757 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1758 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1759 | * @vport: pointer to a host virtual N_Port data structure. |
| 1760 | * |
| 1761 | * This routine performs Registration State Change Notification (RSCN) |
| 1762 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 1763 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 1764 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 1765 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 1766 | * invoked to check and handle possible more RSCN came in during the period |
| 1767 | * of processing the current ones. |
| 1768 | **/ |
| 1769 | static void |
| 1770 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 1771 | { |
| 1772 | lpfc_can_disctmo(vport); |
| 1773 | |
| 1774 | /* RSCN discovery */ |
| 1775 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 1776 | if (vport->fc_npr_cnt) |
| 1777 | if (lpfc_els_disc_plogi(vport)) |
| 1778 | return; |
| 1779 | |
| 1780 | lpfc_end_rscn(vport); |
| 1781 | } |
| 1782 | |
| 1783 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1784 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1785 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 1786 | * |
| 1787 | * This function is called when the final ADISC is completed during discovery. |
| 1788 | * This function handles clearing link attention or issuing reg_vpi depending |
| 1789 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 1790 | * discovery. |
| 1791 | * This function is called with no locks held. |
| 1792 | **/ |
| 1793 | static void |
| 1794 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 1795 | { |
| 1796 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1797 | struct lpfc_hba *phba = vport->phba; |
| 1798 | |
| 1799 | /* |
| 1800 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 1801 | * and continue discovery. |
| 1802 | */ |
| 1803 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1804 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 1805 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1806 | lpfc_issue_reg_vpi(phba, vport); |
| 1807 | return; |
| 1808 | } |
| 1809 | /* |
| 1810 | * For SLI2, we need to set port_state to READY |
| 1811 | * and continue discovery. |
| 1812 | */ |
| 1813 | if (vport->port_state < LPFC_VPORT_READY) { |
| 1814 | /* If we get here, there is nothing to ADISC */ |
| 1815 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1816 | lpfc_issue_clear_la(phba, vport); |
| 1817 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 1818 | vport->num_disc_nodes = 0; |
| 1819 | /* go thru NPR list, issue ELS PLOGIs */ |
| 1820 | if (vport->fc_npr_cnt) |
| 1821 | lpfc_els_disc_plogi(vport); |
| 1822 | if (!vport->num_disc_nodes) { |
| 1823 | spin_lock_irq(shost->host_lock); |
| 1824 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1825 | spin_unlock_irq(shost->host_lock); |
| 1826 | lpfc_can_disctmo(vport); |
| 1827 | lpfc_end_rscn(vport); |
| 1828 | } |
| 1829 | } |
| 1830 | vport->port_state = LPFC_VPORT_READY; |
| 1831 | } else |
| 1832 | lpfc_rscn_disc(vport); |
| 1833 | } |
| 1834 | |
| 1835 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1836 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1837 | * @vport: pointer to a host virtual N_Port data structure. |
| 1838 | * |
| 1839 | * This routine determines whether there are more ndlps on a @vport |
| 1840 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 1841 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 1842 | * remaining nodes which need to have ADISC sent. |
| 1843 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1844 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1845 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1846 | { |
| 1847 | int sentadisc; |
| 1848 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1849 | if (vport->num_disc_nodes) |
| 1850 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1851 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1852 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1853 | "0210 Continue discovery with %d ADISCs to go " |
| 1854 | "Data: x%x x%x x%x\n", |
| 1855 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 1856 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1857 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1858 | if (vport->fc_flag & FC_NLP_MORE) { |
| 1859 | lpfc_set_disctmo(vport); |
| 1860 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 1861 | sentadisc = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1862 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1863 | if (!vport->num_disc_nodes) |
| 1864 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1865 | return; |
| 1866 | } |
| 1867 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1868 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1869 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1870 | * @phba: pointer to lpfc hba data structure. |
| 1871 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1872 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1873 | * |
| 1874 | * This routine is the completion function for issuing the Address Discover |
| 1875 | * (ADISC) command. It first checks to see whether link went down during |
| 1876 | * the discovery process. If so, the node will be marked as node port |
| 1877 | * recovery for issuing discover IOCB by the link attention handler and |
| 1878 | * exit. Otherwise, the response status is checked. If error was reported |
| 1879 | * in the response status, the ADISC command shall be retried by invoking |
| 1880 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 1881 | * the response status, the state machine is invoked to set transition |
| 1882 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 1883 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1884 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1885 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1886 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1887 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1888 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1889 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1890 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1891 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1892 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1893 | |
| 1894 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1895 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1896 | |
| 1897 | irsp = &(rspiocb->iocb); |
| 1898 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1899 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1900 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1901 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 1902 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1903 | ndlp->nlp_DID); |
| 1904 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1905 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1906 | * is being used during discovery. |
| 1907 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1908 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1909 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1910 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1911 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1912 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1913 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1914 | "0104 ADISC completes to NPort x%x " |
| 1915 | "Data: x%x x%x x%x x%x x%x\n", |
| 1916 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1917 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1918 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1919 | if (lpfc_els_chk_latt(vport)) { |
| 1920 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1921 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1922 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1923 | goto out; |
| 1924 | } |
| 1925 | |
| 1926 | if (irsp->ulpStatus) { |
| 1927 | /* Check for retry */ |
| 1928 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1929 | /* ELS command is being retried */ |
| 1930 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1931 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1932 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1933 | spin_unlock_irq(shost->host_lock); |
| 1934 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1935 | } |
| 1936 | goto out; |
| 1937 | } |
| 1938 | /* ADISC failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1939 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1940 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", |
| 1941 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1942 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1943 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1944 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1945 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1946 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1947 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1948 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1949 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1950 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1951 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1952 | /* Check to see if there are more ADISCs to be sent */ |
| 1953 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1954 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1955 | out: |
| 1956 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1957 | return; |
| 1958 | } |
| 1959 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1960 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1961 | * 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] | 1962 | * @vport: pointer to a virtual N_Port data structure. |
| 1963 | * @ndlp: pointer to a node-list data structure. |
| 1964 | * @retry: number of retries to the command IOCB. |
| 1965 | * |
| 1966 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 1967 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 1968 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 1969 | * to issue the ADISC ELS command. |
| 1970 | * |
| 1971 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1972 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1973 | * will be stored into the context1 field of the IOCB for the completion |
| 1974 | * callback function to the ADISC ELS command. |
| 1975 | * |
| 1976 | * Return code |
| 1977 | * 0 - successfully issued adisc |
| 1978 | * 1 - failed to issue adisc |
| 1979 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1980 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1981 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1982 | uint8_t retry) |
| 1983 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1984 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1985 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1986 | ADISC *ap; |
| 1987 | IOCB_t *icmd; |
| 1988 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1989 | uint8_t *pcmd; |
| 1990 | uint16_t cmdsize; |
| 1991 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1992 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1993 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1994 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1995 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1996 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1997 | |
| 1998 | icmd = &elsiocb->iocb; |
| 1999 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2000 | |
| 2001 | /* For ADISC request, remainder of payload is service parameters */ |
| 2002 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2003 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2004 | |
| 2005 | /* Fill in ADISC payload */ |
| 2006 | ap = (ADISC *) pcmd; |
| 2007 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2008 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2009 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2010 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2011 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2012 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2013 | "Issue ADISC: did:x%x", |
| 2014 | ndlp->nlp_DID, 0, 0); |
| 2015 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2016 | phba->fc_stat.elsXmitADISC++; |
| 2017 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2018 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2019 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2020 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2021 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2022 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2023 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2024 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2025 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2026 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2027 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2028 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2029 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2030 | } |
| 2031 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2032 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2033 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2034 | * @phba: pointer to lpfc hba data structure. |
| 2035 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2036 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2037 | * |
| 2038 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 2039 | * command. If no error status was reported from the LOGO response, the |
| 2040 | * state machine of the associated ndlp shall be invoked for transition with |
| 2041 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 2042 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 2043 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2044 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2045 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2046 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2047 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2048 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2049 | struct lpfc_vport *vport = ndlp->vport; |
| 2050 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2051 | IOCB_t *irsp; |
| 2052 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2053 | |
| 2054 | psli = &phba->sli; |
| 2055 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2056 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2057 | |
| 2058 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2059 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2060 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2061 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2062 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2063 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2064 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 2065 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2066 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2067 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2068 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2069 | "0105 LOGO completes to NPort x%x " |
| 2070 | "Data: x%x x%x x%x x%x\n", |
| 2071 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2072 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2073 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2074 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2075 | goto out; |
| 2076 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2077 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 2078 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 2079 | * which should abort all outstanding IOs. |
| 2080 | */ |
| 2081 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2082 | NLP_EVT_DEVICE_RM); |
| 2083 | goto out; |
| 2084 | } |
| 2085 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2086 | if (irsp->ulpStatus) { |
| 2087 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2088 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2089 | /* ELS command is being retried */ |
| 2090 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2091 | /* LOGO failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2092 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2093 | "2756 LOGO failure DID:%06X Status:x%x/x%x\n", |
| 2094 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2095 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2096 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2097 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2098 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2099 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2100 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2101 | NLP_EVT_CMPL_LOGO); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2102 | } else |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2103 | /* Good status, call state machine. |
| 2104 | * This will unregister the rpi if needed. |
| 2105 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2106 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2107 | NLP_EVT_CMPL_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2108 | out: |
| 2109 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2110 | return; |
| 2111 | } |
| 2112 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2113 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2114 | * 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] | 2115 | * @vport: pointer to a virtual N_Port data structure. |
| 2116 | * @ndlp: pointer to a node-list data structure. |
| 2117 | * @retry: number of retries to the command IOCB. |
| 2118 | * |
| 2119 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2120 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2121 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2122 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2123 | * |
| 2124 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2125 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2126 | * will be stored into the context1 field of the IOCB for the completion |
| 2127 | * callback function to the LOGO ELS command. |
| 2128 | * |
| 2129 | * Return code |
| 2130 | * 0 - successfully issued logo |
| 2131 | * 1 - failed to issue logo |
| 2132 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2133 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2134 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2135 | uint8_t retry) |
| 2136 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2137 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2138 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2139 | IOCB_t *icmd; |
| 2140 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2141 | uint8_t *pcmd; |
| 2142 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2143 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2144 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2145 | spin_lock_irq(shost->host_lock); |
| 2146 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2147 | spin_unlock_irq(shost->host_lock); |
| 2148 | return 0; |
| 2149 | } |
| 2150 | spin_unlock_irq(shost->host_lock); |
| 2151 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2152 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2153 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2154 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2155 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2156 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2157 | |
| 2158 | icmd = &elsiocb->iocb; |
| 2159 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2160 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2161 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2162 | |
| 2163 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2164 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2165 | pcmd += sizeof(uint32_t); |
| 2166 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2167 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2168 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2169 | "Issue LOGO: did:x%x", |
| 2170 | ndlp->nlp_DID, 0, 0); |
| 2171 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2172 | phba->fc_stat.elsXmitLOGO++; |
| 2173 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2174 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2175 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2176 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2177 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2178 | |
| 2179 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2180 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2181 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2182 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2183 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2184 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2185 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2186 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2187 | } |
| 2188 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2189 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2190 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2191 | * @phba: pointer to lpfc hba data structure. |
| 2192 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2193 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2194 | * |
| 2195 | * This routine is a generic completion callback function for ELS commands. |
| 2196 | * Specifically, it is the callback function which does not need to perform |
| 2197 | * any command specific operations. It is currently used by the ELS command |
| 2198 | * issuing routines for the ELS State Change Request (SCR), |
| 2199 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 2200 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2201 | * certain debug loggings, this callback function simply invokes the |
| 2202 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2203 | * discovery process. |
| 2204 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2205 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2206 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2207 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2208 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2209 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2210 | IOCB_t *irsp; |
| 2211 | |
| 2212 | irsp = &rspiocb->iocb; |
| 2213 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2214 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2215 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2216 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2217 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2218 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2219 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2220 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2221 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2222 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2223 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2224 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2225 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2226 | return; |
| 2227 | } |
| 2228 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2229 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2230 | * 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] | 2231 | * @vport: pointer to a host virtual N_Port data structure. |
| 2232 | * @nportid: N_Port identifier to the remote node. |
| 2233 | * @retry: number of retries to the command IOCB. |
| 2234 | * |
| 2235 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2236 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2237 | * first search the @vport node list to find the matching ndlp. If no such |
| 2238 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2239 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2240 | * routine is invoked to send the SCR IOCB. |
| 2241 | * |
| 2242 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2243 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2244 | * will be stored into the context1 field of the IOCB for the completion |
| 2245 | * callback function to the SCR ELS command. |
| 2246 | * |
| 2247 | * Return code |
| 2248 | * 0 - Successfully issued scr command |
| 2249 | * 1 - Failed to issue scr command |
| 2250 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2251 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2252 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2253 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2254 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2255 | IOCB_t *icmd; |
| 2256 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2257 | struct lpfc_sli *psli; |
| 2258 | uint8_t *pcmd; |
| 2259 | uint16_t cmdsize; |
| 2260 | struct lpfc_nodelist *ndlp; |
| 2261 | |
| 2262 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2263 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2264 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2265 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2266 | if (!ndlp) { |
| 2267 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2268 | if (!ndlp) |
| 2269 | return 1; |
| 2270 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2271 | lpfc_enqueue_node(vport, ndlp); |
| 2272 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2273 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2274 | if (!ndlp) |
| 2275 | return 1; |
| 2276 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2277 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2278 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2279 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2280 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2281 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2282 | /* This will trigger the release of the node just |
| 2283 | * allocated |
| 2284 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2285 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2286 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2287 | } |
| 2288 | |
| 2289 | icmd = &elsiocb->iocb; |
| 2290 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2291 | |
| 2292 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2293 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2294 | |
| 2295 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2296 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2297 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2298 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2299 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2300 | "Issue SCR: did:x%x", |
| 2301 | ndlp->nlp_DID, 0, 0); |
| 2302 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2303 | phba->fc_stat.elsXmitSCR++; |
| 2304 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2305 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2306 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2307 | /* The additional lpfc_nlp_put will cause the following |
| 2308 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2309 | * the node. |
| 2310 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2311 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2312 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2313 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2314 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2315 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2316 | * trigger the release of node. |
| 2317 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2318 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2319 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2320 | } |
| 2321 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2322 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2323 | * 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] | 2324 | * @vport: pointer to a host virtual N_Port data structure. |
| 2325 | * @nportid: N_Port identifier to the remote node. |
| 2326 | * @retry: number of retries to the command IOCB. |
| 2327 | * |
| 2328 | * This routine issues a Fibre Channel Address Resolution Response |
| 2329 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2330 | * is passed into the function. It first search the @vport node list to find |
| 2331 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2332 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2333 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2334 | * |
| 2335 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2336 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2337 | * will be stored into the context1 field of the IOCB for the completion |
| 2338 | * callback function to the PARPR ELS command. |
| 2339 | * |
| 2340 | * Return code |
| 2341 | * 0 - Successfully issued farpr command |
| 2342 | * 1 - Failed to issue farpr command |
| 2343 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2344 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2345 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2346 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2347 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2348 | IOCB_t *icmd; |
| 2349 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2350 | struct lpfc_sli *psli; |
| 2351 | FARP *fp; |
| 2352 | uint8_t *pcmd; |
| 2353 | uint32_t *lp; |
| 2354 | uint16_t cmdsize; |
| 2355 | struct lpfc_nodelist *ondlp; |
| 2356 | struct lpfc_nodelist *ndlp; |
| 2357 | |
| 2358 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2359 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2360 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2361 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2362 | if (!ndlp) { |
| 2363 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2364 | if (!ndlp) |
| 2365 | return 1; |
| 2366 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2367 | lpfc_enqueue_node(vport, ndlp); |
| 2368 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2369 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2370 | if (!ndlp) |
| 2371 | return 1; |
| 2372 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2373 | |
| 2374 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2375 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2376 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2377 | /* This will trigger the release of the node just |
| 2378 | * allocated |
| 2379 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2380 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2381 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2382 | } |
| 2383 | |
| 2384 | icmd = &elsiocb->iocb; |
| 2385 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2386 | |
| 2387 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2388 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2389 | |
| 2390 | /* Fill in FARPR payload */ |
| 2391 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2392 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2393 | lp = (uint32_t *) pcmd; |
| 2394 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2395 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2396 | fp->Rflags = 0; |
| 2397 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2398 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2399 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2400 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2401 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2402 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2403 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2404 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2405 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2406 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2407 | } |
| 2408 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2409 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2410 | "Issue FARPR: did:x%x", |
| 2411 | ndlp->nlp_DID, 0, 0); |
| 2412 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2413 | phba->fc_stat.elsXmitFARPR++; |
| 2414 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2415 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2416 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2417 | /* The additional lpfc_nlp_put will cause the following |
| 2418 | * lpfc_els_free_iocb routine to trigger the release of |
| 2419 | * the node. |
| 2420 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2421 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2422 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2423 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2424 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2425 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2426 | * trigger the release of the node. |
| 2427 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2428 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2429 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2430 | } |
| 2431 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2432 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2433 | * 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] | 2434 | * @vport: pointer to a host virtual N_Port data structure. |
| 2435 | * @nlp: pointer to a node-list data structure. |
| 2436 | * |
| 2437 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2438 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2439 | * removes the ELS retry event if it presents. In addition, if the |
| 2440 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2441 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2442 | * ADISC. |
| 2443 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2444 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2445 | 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] | 2446 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2447 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2448 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2449 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2450 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2451 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2452 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2453 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2454 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2455 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2456 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2457 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2458 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2459 | /* Decrement nlp reference count held for the delayed retry */ |
| 2460 | evtp = &nlp->els_retry_evt; |
| 2461 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2462 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2463 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2464 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2465 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2466 | spin_unlock_irq(shost->host_lock); |
| 2467 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2468 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2469 | /* Check if there are more ADISCs to be sent */ |
| 2470 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2471 | } else { |
| 2472 | /* Check if there are more PLOGIs to be sent */ |
| 2473 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2474 | if (vport->num_disc_nodes == 0) { |
| 2475 | spin_lock_irq(shost->host_lock); |
| 2476 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2477 | spin_unlock_irq(shost->host_lock); |
| 2478 | lpfc_can_disctmo(vport); |
| 2479 | lpfc_end_rscn(vport); |
| 2480 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2481 | } |
| 2482 | } |
| 2483 | } |
| 2484 | return; |
| 2485 | } |
| 2486 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2487 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2488 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2489 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2490 | * |
| 2491 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2492 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2493 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2494 | * adds the delayed events to the HBA work list and invokes the |
| 2495 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2496 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2497 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2498 | * reference to ndlp will still be available when the worker thread gets |
| 2499 | * to the event associated with the ndlp. |
| 2500 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2501 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2502 | lpfc_els_retry_delay(unsigned long ptr) |
| 2503 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2504 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2505 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2506 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2507 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2508 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2509 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2510 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2511 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2512 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2513 | return; |
| 2514 | } |
| 2515 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2516 | /* We need to hold the node by incrementing the reference |
| 2517 | * count until the queued work is done |
| 2518 | */ |
| 2519 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2520 | if (evtp->evt_arg1) { |
| 2521 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2522 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2523 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2524 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2525 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2526 | return; |
| 2527 | } |
| 2528 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2529 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2530 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2531 | * @ndlp: pointer to a node-list data structure. |
| 2532 | * |
| 2533 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 2534 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 2535 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 2536 | * function according to the delayed ELS command to retry the command. |
| 2537 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2538 | void |
| 2539 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 2540 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2541 | struct lpfc_vport *vport = ndlp->vport; |
| 2542 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2543 | uint32_t cmd, did, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2544 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2545 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2546 | did = ndlp->nlp_DID; |
| 2547 | cmd = ndlp->nlp_last_elscmd; |
| 2548 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2549 | |
| 2550 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2551 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2552 | return; |
| 2553 | } |
| 2554 | |
| 2555 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2556 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 2557 | /* |
| 2558 | * If a discovery event readded nlp_delayfunc after timer |
| 2559 | * firing and before processing the timer, cancel the |
| 2560 | * nlp_delayfunc. |
| 2561 | */ |
| 2562 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2563 | retry = ndlp->nlp_retry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 2564 | ndlp->nlp_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2565 | |
| 2566 | switch (cmd) { |
| 2567 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2568 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2569 | break; |
| 2570 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2571 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2572 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2573 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2574 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2575 | break; |
| 2576 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2577 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2578 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2579 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2580 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2581 | break; |
| 2582 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2583 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2584 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2585 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2586 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2587 | break; |
| 2588 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2589 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2590 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2591 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2592 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2593 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2594 | case ELS_CMD_FDISC: |
| 2595 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
| 2596 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2597 | } |
| 2598 | return; |
| 2599 | } |
| 2600 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2601 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2602 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2603 | * @phba: pointer to lpfc hba data structure. |
| 2604 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2605 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2606 | * |
| 2607 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 2608 | * failed. The following ELS IOCBs use this function for retrying the command |
| 2609 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 2610 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 2611 | * returned error status, it makes the decision whether a retry shall be |
| 2612 | * issued for the command, and whether a retry shall be made immediately or |
| 2613 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 2614 | * is called to retry the command. In the later case, the ELS command shall |
| 2615 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 2616 | * ndlp for the delayed command issusing. |
| 2617 | * |
| 2618 | * Return code |
| 2619 | * 0 - No retry of els command is made |
| 2620 | * 1 - Immediate or delayed retry of els command is made |
| 2621 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2622 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2623 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2624 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2625 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2626 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2627 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2628 | IOCB_t *irsp = &rspiocb->iocb; |
| 2629 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2630 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2631 | uint32_t *elscmd; |
| 2632 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2633 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2634 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2635 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2636 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2637 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2638 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2639 | /* Note: context2 may be 0 for internal driver abort |
| 2640 | * of delays ELS command. |
| 2641 | */ |
| 2642 | |
| 2643 | if (pcmd && pcmd->virt) { |
| 2644 | elscmd = (uint32_t *) (pcmd->virt); |
| 2645 | cmd = *elscmd++; |
| 2646 | } |
| 2647 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2648 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2649 | did = ndlp->nlp_DID; |
| 2650 | else { |
| 2651 | /* We should only hit this case for retrying PLOGI */ |
| 2652 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2653 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2654 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 2655 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2656 | return 1; |
| 2657 | } |
| 2658 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2659 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2660 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 2661 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 2662 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2663 | switch (irsp->ulpStatus) { |
| 2664 | case IOSTAT_FCP_RSP_ERROR: |
| 2665 | case IOSTAT_REMOTE_STOP: |
| 2666 | break; |
| 2667 | |
| 2668 | case IOSTAT_LOCAL_REJECT: |
| 2669 | switch ((irsp->un.ulpWord[4] & 0xff)) { |
| 2670 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2671 | if (cmd == ELS_CMD_FLOGI) { |
| 2672 | if (PCI_DEVICE_ID_HORNET == |
| 2673 | phba->pcidev->device) { |
| 2674 | phba->fc_topology = TOPOLOGY_LOOP; |
| 2675 | phba->pport->fc_myDID = 0; |
| 2676 | phba->alpa_map[0] = 0; |
| 2677 | phba->alpa_map[1] = 0; |
| 2678 | } |
| 2679 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2680 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2681 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2682 | retry = 1; |
| 2683 | break; |
| 2684 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2685 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2686 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2687 | "0124 Retry illegal cmd x%x " |
| 2688 | "retry:x%x delay:x%x\n", |
| 2689 | cmd, cmdiocb->retry, delay); |
| 2690 | retry = 1; |
| 2691 | /* All command's retry policy */ |
| 2692 | maxretry = 8; |
| 2693 | if (cmdiocb->retry > 2) |
| 2694 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2695 | break; |
| 2696 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2697 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2698 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2699 | retry = 1; |
| 2700 | if (cmdiocb->retry > 100) |
| 2701 | delay = 100; |
| 2702 | maxretry = 250; |
| 2703 | break; |
| 2704 | |
| 2705 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2706 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2707 | retry = 1; |
| 2708 | break; |
| 2709 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2710 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2711 | case IOERR_INVALID_RPI: |
| 2712 | retry = 1; |
| 2713 | break; |
| 2714 | } |
| 2715 | break; |
| 2716 | |
| 2717 | case IOSTAT_NPORT_RJT: |
| 2718 | case IOSTAT_FABRIC_RJT: |
| 2719 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 2720 | retry = 1; |
| 2721 | break; |
| 2722 | } |
| 2723 | break; |
| 2724 | |
| 2725 | case IOSTAT_NPORT_BSY: |
| 2726 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2727 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2728 | retry = 1; |
| 2729 | break; |
| 2730 | |
| 2731 | case IOSTAT_LS_RJT: |
| 2732 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 2733 | /* Added for Vendor specifc support |
| 2734 | * Just keep retrying for these Rsn / Exp codes |
| 2735 | */ |
| 2736 | switch (stat.un.b.lsRjtRsnCode) { |
| 2737 | case LSRJT_UNABLE_TPC: |
| 2738 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2739 | LSEXP_CMD_IN_PROGRESS) { |
| 2740 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2741 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2742 | maxretry = 48; |
| 2743 | } |
| 2744 | retry = 1; |
| 2745 | break; |
| 2746 | } |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 2747 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2748 | LSEXP_CANT_GIVE_DATA) { |
| 2749 | if (cmd == ELS_CMD_PLOGI) { |
| 2750 | delay = 1000; |
| 2751 | maxretry = 48; |
| 2752 | } |
| 2753 | retry = 1; |
| 2754 | break; |
| 2755 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2756 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2757 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2758 | maxretry = lpfc_max_els_tries + 1; |
| 2759 | retry = 1; |
| 2760 | break; |
| 2761 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2762 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2763 | (cmd == ELS_CMD_FDISC) && |
| 2764 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2765 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2766 | "0125 FDISC Failed (x%x). " |
| 2767 | "Fabric out of resources\n", |
| 2768 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2769 | lpfc_vport_set_state(vport, |
| 2770 | FC_VPORT_NO_FABRIC_RSCS); |
| 2771 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2772 | break; |
| 2773 | |
| 2774 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2775 | if ((cmd == ELS_CMD_PLOGI) || |
| 2776 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2777 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2778 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2779 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2780 | /* FDISC retry policy */ |
| 2781 | maxretry = 48; |
| 2782 | if (cmdiocb->retry >= 32) |
| 2783 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2784 | } |
| 2785 | retry = 1; |
| 2786 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2787 | |
| 2788 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2789 | /* There are some cases where switches return this |
| 2790 | * error when they are not ready and should be returning |
| 2791 | * Logical Busy. We should delay every time. |
| 2792 | */ |
| 2793 | if (cmd == ELS_CMD_FDISC && |
| 2794 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 2795 | maxretry = 3; |
| 2796 | delay = 1000; |
| 2797 | retry = 1; |
| 2798 | break; |
| 2799 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2800 | case LSRJT_PROTOCOL_ERR: |
| 2801 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2802 | (cmd == ELS_CMD_FDISC) && |
| 2803 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 2804 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 2805 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2806 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2807 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2808 | "Fabric Detected Bad WWN\n", |
| 2809 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2810 | lpfc_vport_set_state(vport, |
| 2811 | FC_VPORT_FABRIC_REJ_WWN); |
| 2812 | } |
| 2813 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2814 | } |
| 2815 | break; |
| 2816 | |
| 2817 | case IOSTAT_INTERMED_RSP: |
| 2818 | case IOSTAT_BA_RJT: |
| 2819 | break; |
| 2820 | |
| 2821 | default: |
| 2822 | break; |
| 2823 | } |
| 2824 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2825 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2826 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2827 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2828 | if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 2829 | (phba->fc_topology != TOPOLOGY_LOOP) && |
| 2830 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2831 | /* FLOGI retry policy */ |
| 2832 | retry = 1; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2833 | /* retry forever */ |
| 2834 | maxretry = 0; |
| 2835 | if (cmdiocb->retry >= 100) |
| 2836 | delay = 5000; |
| 2837 | else if (cmdiocb->retry >= 32) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2838 | delay = 1000; |
| 2839 | } |
| 2840 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2841 | cmdiocb->retry++; |
| 2842 | if (maxretry && (cmdiocb->retry >= maxretry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2843 | phba->fc_stat.elsRetryExceeded++; |
| 2844 | retry = 0; |
| 2845 | } |
| 2846 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2847 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 2848 | retry = 0; |
| 2849 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2850 | if (retry) { |
| 2851 | |
| 2852 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2853 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2854 | "0107 Retry ELS command x%x to remote " |
| 2855 | "NPORT x%x Data: x%x x%x\n", |
| 2856 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2857 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2858 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 2859 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 2860 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { |
| 2861 | /* Don't reset timer for no resources */ |
| 2862 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2863 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2864 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2865 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2866 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2867 | } |
| 2868 | |
| 2869 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2870 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2871 | phba->fc_stat.elsDelayRetry++; |
| 2872 | ndlp->nlp_retry = cmdiocb->retry; |
| 2873 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2874 | /* delay is specified in milliseconds */ |
| 2875 | mod_timer(&ndlp->nlp_delayfunc, |
| 2876 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2877 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2878 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2879 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2880 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2881 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2882 | if (cmd == ELS_CMD_PRLI) |
| 2883 | lpfc_nlp_set_state(vport, ndlp, |
| 2884 | NLP_STE_REG_LOGIN_ISSUE); |
| 2885 | else |
| 2886 | lpfc_nlp_set_state(vport, ndlp, |
| 2887 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2888 | ndlp->nlp_last_elscmd = cmd; |
| 2889 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2890 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2891 | } |
| 2892 | switch (cmd) { |
| 2893 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2894 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2895 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2896 | case ELS_CMD_FDISC: |
| 2897 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 2898 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2899 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2900 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2901 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2902 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2903 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2904 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2905 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2906 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2907 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2908 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2909 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 2910 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2911 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2912 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2913 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2914 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 2915 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2916 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2917 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2918 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2919 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 2920 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2921 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2922 | } |
| 2923 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2924 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2925 | if (logerr) { |
| 2926 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2927 | "0137 No retry ELS command x%x to remote " |
| 2928 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 2929 | cmd, did, irsp->ulpStatus, |
| 2930 | irsp->un.ulpWord[4]); |
| 2931 | } |
| 2932 | else { |
| 2933 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2934 | "0108 No retry ELS command x%x to remote " |
| 2935 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 2936 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 2937 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2938 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2939 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2940 | } |
| 2941 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2942 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2943 | * 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] | 2944 | * @phba: pointer to lpfc hba data structure. |
| 2945 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 2946 | * |
| 2947 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 2948 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 2949 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 2950 | * response of the command IOCB. If so, it will be released before releasing |
| 2951 | * the lpfc DMA buffer associated with the IOCB itself. |
| 2952 | * |
| 2953 | * Return code |
| 2954 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2955 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2956 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2957 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 2958 | { |
| 2959 | struct lpfc_dmabuf *buf_ptr; |
| 2960 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2961 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2962 | if (!list_empty(&buf_ptr1->list)) { |
| 2963 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 2964 | struct lpfc_dmabuf, |
| 2965 | list); |
| 2966 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2967 | kfree(buf_ptr); |
| 2968 | } |
| 2969 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 2970 | kfree(buf_ptr1); |
| 2971 | return 0; |
| 2972 | } |
| 2973 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2974 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2975 | * 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] | 2976 | * @phba: pointer to lpfc hba data structure. |
| 2977 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 2978 | * |
| 2979 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 2980 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 2981 | * pool. |
| 2982 | * |
| 2983 | * Return code |
| 2984 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2985 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2986 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2987 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 2988 | { |
| 2989 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2990 | kfree(buf_ptr); |
| 2991 | return 0; |
| 2992 | } |
| 2993 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2994 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2995 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2996 | * @phba: pointer to lpfc hba data structure. |
| 2997 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 2998 | * |
| 2999 | * This routine frees a command IOCB and its associated resources. The |
| 3000 | * command IOCB data structure contains the reference to various associated |
| 3001 | * resources, these fields must be set to NULL if the associated reference |
| 3002 | * not present: |
| 3003 | * context1 - reference to ndlp |
| 3004 | * context2 - reference to cmd |
| 3005 | * context2->next - reference to rsp |
| 3006 | * context3 - reference to bpl |
| 3007 | * |
| 3008 | * It first properly decrements the reference count held on ndlp for the |
| 3009 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 3010 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 3011 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 3012 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 3013 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 3014 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 3015 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 3016 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 3017 | * |
| 3018 | * Return code |
| 3019 | * 0 - Success (currently, always return 0) |
| 3020 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3021 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3022 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3023 | { |
| 3024 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3025 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3026 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3027 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 3028 | if (ndlp) { |
| 3029 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 3030 | lpfc_nlp_put(ndlp); |
| 3031 | |
| 3032 | /* If the ndlp is not being used by another discovery |
| 3033 | * thread, free it. |
| 3034 | */ |
| 3035 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3036 | /* If ndlp is being used by another discovery |
| 3037 | * thread, just clear NLP_DEFER_RM |
| 3038 | */ |
| 3039 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 3040 | } |
| 3041 | } |
| 3042 | else |
| 3043 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3044 | elsiocb->context1 = NULL; |
| 3045 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3046 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 3047 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3048 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 3049 | /* Firmware could still be in progress of DMAing |
| 3050 | * payload, so don't free data buffer till after |
| 3051 | * a hbeat. |
| 3052 | */ |
| 3053 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 3054 | buf_ptr = elsiocb->context2; |
| 3055 | elsiocb->context2 = NULL; |
| 3056 | if (buf_ptr) { |
| 3057 | buf_ptr1 = NULL; |
| 3058 | spin_lock_irq(&phba->hbalock); |
| 3059 | if (!list_empty(&buf_ptr->list)) { |
| 3060 | list_remove_head(&buf_ptr->list, |
| 3061 | buf_ptr1, struct lpfc_dmabuf, |
| 3062 | list); |
| 3063 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 3064 | list_add_tail(&buf_ptr1->list, |
| 3065 | &phba->elsbuf); |
| 3066 | phba->elsbuf_cnt++; |
| 3067 | } |
| 3068 | INIT_LIST_HEAD(&buf_ptr->list); |
| 3069 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 3070 | phba->elsbuf_cnt++; |
| 3071 | spin_unlock_irq(&phba->hbalock); |
| 3072 | } |
| 3073 | } else { |
| 3074 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 3075 | lpfc_els_free_data(phba, buf_ptr1); |
| 3076 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3077 | } |
| 3078 | |
| 3079 | if (elsiocb->context3) { |
| 3080 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3081 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3082 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3083 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3084 | return 0; |
| 3085 | } |
| 3086 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3087 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3088 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3089 | * @phba: pointer to lpfc hba data structure. |
| 3090 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3091 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3092 | * |
| 3093 | * This routine is the completion callback function to the Logout (LOGO) |
| 3094 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 3095 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 3096 | * release the ndlp if it has the last reference remaining (reference count |
| 3097 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 3098 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 3099 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 3100 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 3101 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 3102 | * IOCB data structure. |
| 3103 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3104 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3105 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3106 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3107 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3108 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3109 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3110 | IOCB_t *irsp; |
| 3111 | |
| 3112 | irsp = &rspiocb->iocb; |
| 3113 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3114 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 3115 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3116 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3117 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3118 | "0109 ACC to LOGO completes to NPort x%x " |
| 3119 | "Data: x%x x%x x%x\n", |
| 3120 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3121 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3122 | |
| 3123 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 3124 | /* NPort Recovery mode or node is just allocated */ |
| 3125 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3126 | /* If the ndlp is being used by another discovery |
| 3127 | * thread, just unregister the RPI. |
| 3128 | */ |
| 3129 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3130 | } else { |
| 3131 | /* Indicate the node has already released, should |
| 3132 | * not reference to it from within lpfc_els_free_iocb. |
| 3133 | */ |
| 3134 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3135 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3136 | } |
| 3137 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3138 | return; |
| 3139 | } |
| 3140 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3141 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3142 | * 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] | 3143 | * @phba: pointer to lpfc hba data structure. |
| 3144 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 3145 | * |
| 3146 | * This routine is the completion callback function for unregister default |
| 3147 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 3148 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 3149 | * decrements the ndlp reference count held for this completion callback |
| 3150 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 3151 | * whether there is only one reference left on the ndlp. If so, it will |
| 3152 | * perform one more decrement and trigger the release of the ndlp. |
| 3153 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3154 | void |
| 3155 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3156 | { |
| 3157 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3158 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3159 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3160 | /* |
| 3161 | * This routine is used to register and unregister in previous SLI |
| 3162 | * modes. |
| 3163 | */ |
| 3164 | if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) && |
| 3165 | (phba->sli_rev == LPFC_SLI_REV4)) |
| 3166 | lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi); |
| 3167 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3168 | pmb->context1 = NULL; |
| 3169 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3170 | kfree(mp); |
| 3171 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3172 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3173 | lpfc_nlp_put(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3174 | /* This is the end of the default RPI cleanup logic for this |
| 3175 | * ndlp. If no other discovery threads are using this ndlp. |
| 3176 | * we should free all resources associated with it. |
| 3177 | */ |
| 3178 | lpfc_nlp_not_used(ndlp); |
| 3179 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3180 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3181 | return; |
| 3182 | } |
| 3183 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3184 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3185 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3186 | * @phba: pointer to lpfc hba data structure. |
| 3187 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3188 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3189 | * |
| 3190 | * This routine is the completion callback function for ELS Response IOCB |
| 3191 | * command. In normal case, this callback function just properly sets the |
| 3192 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 3193 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 3194 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 3195 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 3196 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 3197 | * routine shall be invoked trying to release the ndlp if no other threads |
| 3198 | * are currently referring it. |
| 3199 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3200 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3201 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3202 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3203 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3204 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3205 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 3206 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3207 | IOCB_t *irsp; |
| 3208 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3209 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3210 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3211 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3212 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3213 | irsp = &rspiocb->iocb; |
| 3214 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3215 | if (cmdiocb->context_un.mbox) |
| 3216 | mbox = cmdiocb->context_un.mbox; |
| 3217 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3218 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 3219 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 3220 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3221 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3222 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3223 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3224 | /* A LS_RJT associated with Default RPI cleanup has its own |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 3225 | * separate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3226 | */ |
| 3227 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 3228 | ls_rjt = 1; |
| 3229 | } |
| 3230 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3231 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3232 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3233 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3234 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3235 | if (mp) { |
| 3236 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3237 | kfree(mp); |
| 3238 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3239 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3240 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3241 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3242 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3243 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3244 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3245 | /* Indicate the node has already released, |
| 3246 | * should not reference to it from within |
| 3247 | * the routine lpfc_els_free_iocb. |
| 3248 | */ |
| 3249 | cmdiocb->context1 = NULL; |
| 3250 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3251 | goto out; |
| 3252 | } |
| 3253 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3254 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3255 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3256 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3257 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3258 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3259 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3260 | "0110 ELS response tag x%x completes " |
| 3261 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3262 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3263 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3264 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3265 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3266 | if (mbox) { |
| 3267 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3268 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3269 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3270 | /* Increment reference count to ndlp to hold the |
| 3271 | * reference to ndlp for the callback function. |
| 3272 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3273 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3274 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3275 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3276 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3277 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3278 | } |
| 3279 | else { |
| 3280 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3281 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3282 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3283 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3284 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3285 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3286 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3287 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3288 | else |
| 3289 | /* Decrement the ndlp reference count we |
| 3290 | * set for this failed mailbox command. |
| 3291 | */ |
| 3292 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3293 | |
| 3294 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3295 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3296 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3297 | "Data: x%x x%x x%x\n", |
| 3298 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3299 | ndlp->nlp_rpi); |
| 3300 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3301 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3302 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3303 | /* Indicate node has already been released, |
| 3304 | * should not reference to it from within |
| 3305 | * the routine lpfc_els_free_iocb. |
| 3306 | */ |
| 3307 | cmdiocb->context1 = NULL; |
| 3308 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3309 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3310 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3311 | if (!lpfc_error_lost_link(irsp) && |
| 3312 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3313 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3314 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3315 | /* Indicate node has already been |
| 3316 | * released, should not reference |
| 3317 | * to it from within the routine |
| 3318 | * lpfc_els_free_iocb. |
| 3319 | */ |
| 3320 | cmdiocb->context1 = NULL; |
| 3321 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3322 | } |
| 3323 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3324 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3325 | if (mp) { |
| 3326 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3327 | kfree(mp); |
| 3328 | } |
| 3329 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3330 | } |
| 3331 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3332 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3333 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3334 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3335 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3336 | |
| 3337 | /* If the node is not being used by another discovery thread, |
| 3338 | * and we are sending a reject, we are done with it. |
| 3339 | * Release driver reference count here and free associated |
| 3340 | * resources. |
| 3341 | */ |
| 3342 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3343 | if (lpfc_nlp_not_used(ndlp)) |
| 3344 | /* Indicate node has already been released, |
| 3345 | * should not reference to it from within |
| 3346 | * the routine lpfc_els_free_iocb. |
| 3347 | */ |
| 3348 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3349 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3350 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3351 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3352 | return; |
| 3353 | } |
| 3354 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3355 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3356 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3357 | * @vport: pointer to a host virtual N_Port data structure. |
| 3358 | * @flag: the els command code to be accepted. |
| 3359 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3360 | * @ndlp: pointer to a node-list data structure. |
| 3361 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3362 | * |
| 3363 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3364 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3365 | * specific ACC response command to be issued and invokes the |
| 3366 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3367 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3368 | * field of the IOCB for the completion callback function to issue the |
| 3369 | * mailbox command to the HBA later when callback is invoked. |
| 3370 | * |
| 3371 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3372 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3373 | * will be stored into the context1 field of the IOCB for the completion |
| 3374 | * callback function to the corresponding response ELS IOCB command. |
| 3375 | * |
| 3376 | * Return code |
| 3377 | * 0 - Successfully issued acc response |
| 3378 | * 1 - Failed to issue acc response |
| 3379 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3380 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3381 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3382 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3383 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3384 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3385 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3386 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3387 | IOCB_t *icmd; |
| 3388 | IOCB_t *oldcmd; |
| 3389 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3390 | struct lpfc_sli *psli; |
| 3391 | uint8_t *pcmd; |
| 3392 | uint16_t cmdsize; |
| 3393 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3394 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3395 | |
| 3396 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3397 | oldcmd = &oldiocb->iocb; |
| 3398 | |
| 3399 | switch (flag) { |
| 3400 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3401 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3402 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3403 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3404 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3405 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3406 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3407 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3408 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3409 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3410 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3411 | icmd = &elsiocb->iocb; |
| 3412 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3413 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3414 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3415 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3416 | |
| 3417 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3418 | "Issue ACC: did:x%x flg:x%x", |
| 3419 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3420 | break; |
| 3421 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3422 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3423 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3424 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3425 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3426 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3427 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3428 | icmd = &elsiocb->iocb; |
| 3429 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3430 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3431 | |
| 3432 | if (mbox) |
| 3433 | elsiocb->context_un.mbox = mbox; |
| 3434 | |
| 3435 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3436 | pcmd += sizeof(uint32_t); |
| 3437 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3438 | |
| 3439 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3440 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 3441 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3442 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3443 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3444 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3445 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3446 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3447 | if (!elsiocb) |
| 3448 | return 1; |
| 3449 | |
| 3450 | icmd = &elsiocb->iocb; |
| 3451 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3452 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3453 | |
| 3454 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3455 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3456 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 3457 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 3458 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3459 | |
| 3460 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3461 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 3462 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3463 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3464 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3465 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3466 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3467 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3468 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3469 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
| 3470 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", |
| 3471 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3472 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3473 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3474 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3475 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3476 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3477 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3478 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 3479 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3480 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3481 | } |
| 3482 | |
| 3483 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3484 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3485 | if (rc == IOCB_ERROR) { |
| 3486 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3487 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3488 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3489 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3490 | } |
| 3491 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3492 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3493 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3494 | * @vport: pointer to a virtual N_Port data structure. |
| 3495 | * @rejectError: |
| 3496 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3497 | * @ndlp: pointer to a node-list data structure. |
| 3498 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3499 | * |
| 3500 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 3501 | * command. If a @mbox pointer is passed in, it will be put into the |
| 3502 | * context_un.mbox field of the IOCB for the completion callback function |
| 3503 | * to issue to the HBA later. |
| 3504 | * |
| 3505 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3506 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3507 | * will be stored into the context1 field of the IOCB for the completion |
| 3508 | * callback function to the reject response ELS IOCB command. |
| 3509 | * |
| 3510 | * Return code |
| 3511 | * 0 - Successfully issued reject response |
| 3512 | * 1 - Failed to issue reject response |
| 3513 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3514 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3515 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3516 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 3517 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3518 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3519 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3520 | IOCB_t *icmd; |
| 3521 | IOCB_t *oldcmd; |
| 3522 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3523 | struct lpfc_sli *psli; |
| 3524 | uint8_t *pcmd; |
| 3525 | uint16_t cmdsize; |
| 3526 | int rc; |
| 3527 | |
| 3528 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3529 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3530 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3531 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3532 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3533 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3534 | |
| 3535 | icmd = &elsiocb->iocb; |
| 3536 | oldcmd = &oldiocb->iocb; |
| 3537 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3538 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3539 | |
| 3540 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3541 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3542 | *((uint32_t *) (pcmd)) = rejectError; |
| 3543 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3544 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3545 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3546 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3547 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3548 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3549 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 3550 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 3551 | "rpi x%x\n", |
| 3552 | rejectError, elsiocb->iotag, |
| 3553 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 3554 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3555 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3556 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 3557 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 3558 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3559 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3560 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3561 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3562 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3563 | if (rc == IOCB_ERROR) { |
| 3564 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3565 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3566 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3567 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3568 | } |
| 3569 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3570 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3571 | * 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] | 3572 | * @vport: pointer to a virtual N_Port data structure. |
| 3573 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3574 | * @ndlp: pointer to a node-list data structure. |
| 3575 | * |
| 3576 | * This routine prepares and issues an Accept (ACC) response to Address |
| 3577 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 3578 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3579 | * |
| 3580 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3581 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3582 | * will be stored into the context1 field of the IOCB for the completion |
| 3583 | * callback function to the ADISC Accept response ELS IOCB command. |
| 3584 | * |
| 3585 | * Return code |
| 3586 | * 0 - Successfully issued acc adisc response |
| 3587 | * 1 - Failed to issue adisc acc response |
| 3588 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3589 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3590 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 3591 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3592 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3593 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3594 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3595 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3596 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3597 | uint8_t *pcmd; |
| 3598 | uint16_t cmdsize; |
| 3599 | int rc; |
| 3600 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3601 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3602 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3603 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3604 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3605 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3606 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3607 | icmd = &elsiocb->iocb; |
| 3608 | oldcmd = &oldiocb->iocb; |
| 3609 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3610 | |
| 3611 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3612 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3613 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 3614 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 3615 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3616 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3617 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3618 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3619 | |
| 3620 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3621 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3622 | |
| 3623 | ap = (ADISC *) (pcmd); |
| 3624 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3625 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3626 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3627 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3628 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3629 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3630 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 3631 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3632 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3633 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3634 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3635 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3636 | if (rc == IOCB_ERROR) { |
| 3637 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3638 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3639 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3640 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3641 | } |
| 3642 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3643 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3644 | * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3645 | * @vport: pointer to a virtual N_Port data structure. |
| 3646 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3647 | * @ndlp: pointer to a node-list data structure. |
| 3648 | * |
| 3649 | * This routine prepares and issues an Accept (ACC) response to Process |
| 3650 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 3651 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3652 | * |
| 3653 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3654 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3655 | * will be stored into the context1 field of the IOCB for the completion |
| 3656 | * callback function to the PRLI Accept response ELS IOCB command. |
| 3657 | * |
| 3658 | * Return code |
| 3659 | * 0 - Successfully issued acc prli response |
| 3660 | * 1 - Failed to issue acc prli response |
| 3661 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3662 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3663 | lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3664 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3665 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3666 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3667 | PRLI *npr; |
| 3668 | lpfc_vpd_t *vpd; |
| 3669 | IOCB_t *icmd; |
| 3670 | IOCB_t *oldcmd; |
| 3671 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3672 | struct lpfc_sli *psli; |
| 3673 | uint8_t *pcmd; |
| 3674 | uint16_t cmdsize; |
| 3675 | int rc; |
| 3676 | |
| 3677 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3678 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3679 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3680 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3681 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3682 | if (!elsiocb) |
| 3683 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3684 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3685 | icmd = &elsiocb->iocb; |
| 3686 | oldcmd = &oldiocb->iocb; |
| 3687 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3688 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3689 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3690 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 3691 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 3692 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3693 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3694 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3695 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3696 | |
| 3697 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3698 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3699 | |
| 3700 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3701 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3702 | |
| 3703 | npr = (PRLI *) pcmd; |
| 3704 | vpd = &phba->vpd; |
| 3705 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3706 | * If the remote port is a target and our firmware version is 3.20 or |
| 3707 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3708 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3709 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 3710 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3711 | npr->ConfmComplAllowed = 1; |
| 3712 | npr->Retry = 1; |
| 3713 | npr->TaskRetryIdReq = 1; |
| 3714 | } |
| 3715 | |
| 3716 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 3717 | npr->estabImagePair = 1; |
| 3718 | npr->readXferRdyDis = 1; |
| 3719 | npr->ConfmComplAllowed = 1; |
| 3720 | |
| 3721 | npr->prliType = PRLI_FCP_TYPE; |
| 3722 | npr->initiatorFunc = 1; |
| 3723 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3724 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3725 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 3726 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3727 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3728 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3729 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3730 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3731 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3732 | if (rc == IOCB_ERROR) { |
| 3733 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3734 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3735 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3736 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3737 | } |
| 3738 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3739 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3740 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3741 | * @vport: pointer to a virtual N_Port data structure. |
| 3742 | * @format: rnid command format. |
| 3743 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3744 | * @ndlp: pointer to a node-list data structure. |
| 3745 | * |
| 3746 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 3747 | * (ACC) response. It constructs the RNID ACC response command according to |
| 3748 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 3749 | * issue the response. Note that this command does not need to hold the ndlp |
| 3750 | * reference count for the callback. So, the ndlp reference count taken by |
| 3751 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 3752 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 3753 | * there is no ndlp reference available. |
| 3754 | * |
| 3755 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3756 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3757 | * will be stored into the context1 field of the IOCB for the completion |
| 3758 | * callback function. However, for the RNID Accept Response ELS command, |
| 3759 | * this is undone later by this routine after the IOCB is allocated. |
| 3760 | * |
| 3761 | * Return code |
| 3762 | * 0 - Successfully issued acc rnid response |
| 3763 | * 1 - Failed to issue acc rnid response |
| 3764 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3765 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3766 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3767 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3768 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3769 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3770 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3771 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3772 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3773 | struct lpfc_sli *psli; |
| 3774 | uint8_t *pcmd; |
| 3775 | uint16_t cmdsize; |
| 3776 | int rc; |
| 3777 | |
| 3778 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3779 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 3780 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3781 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3782 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3783 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3784 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3785 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3786 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3787 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3788 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3789 | icmd = &elsiocb->iocb; |
| 3790 | oldcmd = &oldiocb->iocb; |
| 3791 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3792 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3793 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3794 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 3795 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3796 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3797 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3798 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3799 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3800 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3801 | rn = (RNID *) (pcmd); |
| 3802 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3803 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 3804 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3805 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3806 | switch (format) { |
| 3807 | case 0: |
| 3808 | rn->SpecificLen = 0; |
| 3809 | break; |
| 3810 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3811 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3812 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3813 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3814 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 3815 | rn->un.topologyDisc.physPort = 0; |
| 3816 | rn->un.topologyDisc.attachedNodes = 0; |
| 3817 | break; |
| 3818 | default: |
| 3819 | rn->CommonLen = 0; |
| 3820 | rn->SpecificLen = 0; |
| 3821 | break; |
| 3822 | } |
| 3823 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3824 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3825 | "Issue ACC RNID: did:x%x flg:x%x", |
| 3826 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3827 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3828 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3829 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3830 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3831 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 3832 | * it could be freed */ |
| 3833 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3834 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3835 | if (rc == IOCB_ERROR) { |
| 3836 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3837 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3838 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3839 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3840 | } |
| 3841 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3842 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3843 | * 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] | 3844 | * @vport: pointer to a host virtual N_Port data structure. |
| 3845 | * |
| 3846 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 3847 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 3848 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 3849 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 3850 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 3851 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 3852 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 3853 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 3854 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 3855 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 3856 | * no more ADISC need to be sent. |
| 3857 | * |
| 3858 | * Return code |
| 3859 | * The number of N_Ports with adisc issued. |
| 3860 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3861 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3862 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3863 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3864 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3865 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3866 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3867 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3868 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3869 | 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] | 3870 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3871 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3872 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3873 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3874 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3875 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3876 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3877 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3878 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3879 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 3880 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3881 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3882 | vport->num_disc_nodes++; |
| 3883 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3884 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3885 | spin_lock_irq(shost->host_lock); |
| 3886 | vport->fc_flag |= FC_NLP_MORE; |
| 3887 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3888 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3889 | } |
| 3890 | } |
| 3891 | } |
| 3892 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3893 | spin_lock_irq(shost->host_lock); |
| 3894 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3895 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3896 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3897 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3898 | } |
| 3899 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3900 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3901 | * 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] | 3902 | * @vport: pointer to a host virtual N_Port data structure. |
| 3903 | * |
| 3904 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 3905 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 3906 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 3907 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 3908 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 3909 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 3910 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 3911 | * later pick up. On the other hand, after walking through all the ndlps with |
| 3912 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 3913 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 3914 | * PLOGI need to be sent. |
| 3915 | * |
| 3916 | * Return code |
| 3917 | * The number of N_Ports with plogi issued. |
| 3918 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3919 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3920 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3921 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3922 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3923 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3924 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3925 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3926 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 3927 | 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] | 3928 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3929 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3930 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3931 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3932 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 3933 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 3934 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3935 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 3936 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3937 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3938 | vport->num_disc_nodes++; |
| 3939 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3940 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3941 | spin_lock_irq(shost->host_lock); |
| 3942 | vport->fc_flag |= FC_NLP_MORE; |
| 3943 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3944 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3945 | } |
| 3946 | } |
| 3947 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3948 | if (sentplogi) { |
| 3949 | lpfc_set_disctmo(vport); |
| 3950 | } |
| 3951 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3952 | spin_lock_irq(shost->host_lock); |
| 3953 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3954 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3955 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3956 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3957 | } |
| 3958 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3959 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3960 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3961 | * @vport: pointer to a host virtual N_Port data structure. |
| 3962 | * |
| 3963 | * This routine cleans up any Registration State Change Notification |
| 3964 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 3965 | * @vport together with the host_lock is used to prevent multiple thread |
| 3966 | * trying to access the RSCN array on a same @vport at the same time. |
| 3967 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3968 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3969 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3970 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3971 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3972 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3973 | int i; |
| 3974 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3975 | spin_lock_irq(shost->host_lock); |
| 3976 | if (vport->fc_rscn_flush) { |
| 3977 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3978 | spin_unlock_irq(shost->host_lock); |
| 3979 | return; |
| 3980 | } |
| 3981 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 3982 | vport->fc_rscn_flush = 1; |
| 3983 | spin_unlock_irq(shost->host_lock); |
| 3984 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3985 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3986 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3987 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3988 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3989 | spin_lock_irq(shost->host_lock); |
| 3990 | vport->fc_rscn_id_cnt = 0; |
| 3991 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 3992 | spin_unlock_irq(shost->host_lock); |
| 3993 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3994 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 3995 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3996 | } |
| 3997 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3998 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3999 | * lpfc_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] | 4000 | * @vport: pointer to a host virtual N_Port data structure. |
| 4001 | * @did: remote destination port identifier. |
| 4002 | * |
| 4003 | * This routine checks whether there is any pending Registration State |
| 4004 | * Configuration Notification (RSCN) to a @did on @vport. |
| 4005 | * |
| 4006 | * Return code |
| 4007 | * None zero - The @did matched with a pending rscn |
| 4008 | * 0 - not able to match @did with a pending rscn |
| 4009 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4010 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4011 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4012 | { |
| 4013 | D_ID ns_did; |
| 4014 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4015 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4016 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4017 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4018 | |
| 4019 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4020 | |
| 4021 | /* Never match fabric nodes for RSCNs */ |
| 4022 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4023 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4024 | |
| 4025 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4026 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4027 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4028 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4029 | spin_lock_irq(shost->host_lock); |
| 4030 | if (vport->fc_rscn_flush) { |
| 4031 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4032 | spin_unlock_irq(shost->host_lock); |
| 4033 | return 0; |
| 4034 | } |
| 4035 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4036 | vport->fc_rscn_flush = 1; |
| 4037 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4038 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4039 | lp = vport->fc_rscn_id_list[i]->virt; |
| 4040 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4041 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4042 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4043 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 4044 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4045 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 4046 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4047 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4048 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 4049 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4050 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4051 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4052 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4053 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4054 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
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_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4058 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4059 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4060 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4061 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4062 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4063 | } |
| 4064 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4065 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4066 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4067 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4068 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4069 | return_did_out: |
| 4070 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4071 | vport->fc_rscn_flush = 0; |
| 4072 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4073 | } |
| 4074 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4075 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4076 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4077 | * @vport: pointer to a host virtual N_Port data structure. |
| 4078 | * |
| 4079 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 4080 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 4081 | * State Change Notification). |
| 4082 | * |
| 4083 | * Return code |
| 4084 | * 0 - Successful (currently alway return 0) |
| 4085 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4086 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4087 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4088 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4089 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4090 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4091 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4092 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4093 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4094 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 4095 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4096 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4097 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4098 | NLP_EVT_DEVICE_RECOVERY); |
| 4099 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4100 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4101 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4102 | } |
| 4103 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4104 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4105 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4106 | * @vport: pointer to a host virtual N_Port data structure. |
| 4107 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4108 | * |
| 4109 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 4110 | * applications. |
| 4111 | */ |
| 4112 | static void |
| 4113 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 4114 | struct lpfc_iocbq *cmdiocb) |
| 4115 | { |
| 4116 | struct lpfc_dmabuf *pcmd; |
| 4117 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4118 | uint32_t *payload_ptr; |
| 4119 | uint32_t payload_len; |
| 4120 | struct lpfc_rscn_event_header *rscn_event_data; |
| 4121 | |
| 4122 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4123 | payload_ptr = (uint32_t *) pcmd->virt; |
| 4124 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 4125 | |
| 4126 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 4127 | payload_len, GFP_KERNEL); |
| 4128 | if (!rscn_event_data) { |
| 4129 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4130 | "0147 Failed to allocate memory for RSCN event\n"); |
| 4131 | return; |
| 4132 | } |
| 4133 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 4134 | rscn_event_data->payload_length = payload_len; |
| 4135 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 4136 | payload_len); |
| 4137 | |
| 4138 | fc_host_post_vendor_event(shost, |
| 4139 | fc_get_event_number(), |
| 4140 | sizeof(struct lpfc_els_event_header) + payload_len, |
| 4141 | (char *)rscn_event_data, |
| 4142 | LPFC_NL_VENDOR_ID); |
| 4143 | |
| 4144 | kfree(rscn_event_data); |
| 4145 | } |
| 4146 | |
| 4147 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4148 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4149 | * @vport: pointer to a host virtual N_Port data structure. |
| 4150 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4151 | * @ndlp: pointer to a node-list data structure. |
| 4152 | * |
| 4153 | * This routine processes an unsolicited RSCN (Registration State Change |
| 4154 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 4155 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 4156 | * discover state machine is about to begin discovery, it just accepts the |
| 4157 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 4158 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 4159 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 4160 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 4161 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 4162 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 4163 | * routine is invoked to handle the RSCN event. |
| 4164 | * |
| 4165 | * Return code |
| 4166 | * 0 - Just sent the acc response |
| 4167 | * 1 - Sent the acc response and waited for name server completion |
| 4168 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4169 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4170 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4171 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4172 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4173 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4174 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4175 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4176 | uint32_t *lp, *datap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4177 | IOCB_t *icmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4178 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4179 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4180 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4181 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4182 | |
| 4183 | icmd = &cmdiocb->iocb; |
| 4184 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4185 | lp = (uint32_t *) pcmd->virt; |
| 4186 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4187 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4188 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4189 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4190 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4191 | "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] | 4192 | vport->fc_flag, payload_len, *lp, |
| 4193 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4194 | |
| 4195 | /* Send an RSCN event to the management application */ |
| 4196 | lpfc_send_rscn_event(vport, cmdiocb); |
| 4197 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4198 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4199 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4200 | FCH_EVT_RSCN, lp[i]); |
| 4201 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4202 | /* If we are about to begin discovery, just ACC the RSCN. |
| 4203 | * Discovery processing will satisfy it. |
| 4204 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4205 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4206 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4207 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 4208 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4209 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4210 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4211 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4212 | } |
| 4213 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4214 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 4215 | * just ACC and ignore it. |
| 4216 | */ |
| 4217 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4218 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4219 | i = payload_len; |
| 4220 | datap = lp; |
| 4221 | while (i > 0) { |
| 4222 | nportid = *datap++; |
| 4223 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 4224 | i -= sizeof(uint32_t); |
| 4225 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4226 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 4227 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4228 | } |
| 4229 | if (rscn_id == hba_id) { |
| 4230 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4231 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4232 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4233 | "Data: x%x x%x x%x x%x\n", |
| 4234 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4235 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4236 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4237 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 4238 | ndlp->nlp_DID, vport->port_state, |
| 4239 | ndlp->nlp_flag); |
| 4240 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4241 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4242 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4243 | return 0; |
| 4244 | } |
| 4245 | } |
| 4246 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4247 | spin_lock_irq(shost->host_lock); |
| 4248 | if (vport->fc_rscn_flush) { |
| 4249 | /* Another thread is walking fc_rscn_id_list on this vport */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4250 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 4251 | spin_unlock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4252 | /* Send back ACC */ |
| 4253 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4254 | return 0; |
| 4255 | } |
| 4256 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4257 | vport->fc_rscn_flush = 1; |
| 4258 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4259 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4260 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4261 | /* If we are already processing an RSCN, save the received |
| 4262 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 4263 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4264 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4265 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4266 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 4267 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4268 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4269 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4270 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 4271 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4272 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4273 | vport->fc_flag |= FC_RSCN_MODE; |
| 4274 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4275 | if (rscn_cnt) { |
| 4276 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 4277 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 4278 | } |
| 4279 | if ((rscn_cnt) && |
| 4280 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 4281 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4282 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4283 | memcpy(((uint8_t *)cmd) + length, lp, |
| 4284 | payload_len); |
| 4285 | } else { |
| 4286 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 4287 | vport->fc_rscn_id_cnt++; |
| 4288 | /* If we zero, cmdiocb->context2, the calling |
| 4289 | * routine will not try to free it. |
| 4290 | */ |
| 4291 | cmdiocb->context2 = NULL; |
| 4292 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4293 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4294 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4295 | "0235 Deferred RSCN " |
| 4296 | "Data: x%x x%x x%x\n", |
| 4297 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4298 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4299 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4300 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 4301 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4302 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4303 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4304 | "0234 ReDiscovery RSCN " |
| 4305 | "Data: x%x x%x x%x\n", |
| 4306 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4307 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4308 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4309 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4310 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4311 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4312 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4313 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4314 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4315 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4316 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4317 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4318 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4319 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4320 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4321 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 4322 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4323 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4324 | spin_lock_irq(shost->host_lock); |
| 4325 | vport->fc_flag |= FC_RSCN_MODE; |
| 4326 | spin_unlock_irq(shost->host_lock); |
| 4327 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4328 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4329 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4330 | /* |
| 4331 | * If we zero, cmdiocb->context2, the calling routine will |
| 4332 | * not try to free it. |
| 4333 | */ |
| 4334 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4335 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4336 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4337 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4338 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4339 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4340 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4341 | } |
| 4342 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4343 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4344 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4345 | * @vport: pointer to a host virtual N_Port data structure. |
| 4346 | * |
| 4347 | * This routine handles the Registration State Configuration Notification |
| 4348 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 4349 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 4350 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 4351 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 4352 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 4353 | * RSCN activities with the @vport. |
| 4354 | * |
| 4355 | * Return code |
| 4356 | * 0 - Cleaned up rscn on the @vport |
| 4357 | * 1 - Wait for plogi to name server before proceed |
| 4358 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4359 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4360 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4361 | { |
| 4362 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4363 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4364 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4365 | /* Ignore RSCN if the port is being torn down. */ |
| 4366 | if (vport->load_flag & FC_UNLOADING) { |
| 4367 | lpfc_els_flush_rscn(vport); |
| 4368 | return 0; |
| 4369 | } |
| 4370 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4371 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4372 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4373 | |
| 4374 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4375 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4376 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 4377 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 4378 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4379 | |
| 4380 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4381 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4382 | vport->num_disc_nodes = 0; |
| 4383 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4384 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4385 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 4386 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4387 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4388 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4389 | /* Wait for NameServer query cmpl before we can |
| 4390 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4391 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4392 | } else { |
| 4393 | /* If login to NameServer does not exist, issue one */ |
| 4394 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4395 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4396 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4397 | /* Wait for NameServer login cmpl before we can |
| 4398 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4399 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4400 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4401 | if (ndlp) { |
| 4402 | ndlp = lpfc_enable_node(vport, ndlp, |
| 4403 | NLP_STE_PLOGI_ISSUE); |
| 4404 | if (!ndlp) { |
| 4405 | lpfc_els_flush_rscn(vport); |
| 4406 | return 0; |
| 4407 | } |
| 4408 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4409 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4410 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4411 | if (!ndlp) { |
| 4412 | lpfc_els_flush_rscn(vport); |
| 4413 | return 0; |
| 4414 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4415 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4416 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4417 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4418 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4419 | ndlp->nlp_type |= NLP_FABRIC; |
| 4420 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 4421 | /* Wait for NameServer login cmpl before we can |
| 4422 | * continue |
| 4423 | */ |
| 4424 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4425 | } |
| 4426 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4427 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4428 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4429 | } |
| 4430 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4431 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4432 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4433 | * @vport: pointer to a host virtual N_Port data structure. |
| 4434 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4435 | * @ndlp: pointer to a node-list data structure. |
| 4436 | * |
| 4437 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 4438 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 4439 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 4440 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 4441 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 4442 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 4443 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 4444 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 4445 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 4446 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 4447 | * higher priority (as the winning port) and will initiate PLOGI and |
| 4448 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 4449 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 4450 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 4451 | * |
| 4452 | * Return code |
| 4453 | * 0 - Successfully processed the unsolicited flogi |
| 4454 | * 1 - Failed to process the unsolicited flogi |
| 4455 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4456 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4457 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4458 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4459 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4460 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4461 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4462 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4463 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 4464 | IOCB_t *icmd = &cmdiocb->iocb; |
| 4465 | struct serv_parm *sp; |
| 4466 | LPFC_MBOXQ_t *mbox; |
| 4467 | struct ls_rjt stat; |
| 4468 | uint32_t cmd, did; |
| 4469 | int rc; |
| 4470 | |
| 4471 | cmd = *lp++; |
| 4472 | sp = (struct serv_parm *) lp; |
| 4473 | |
| 4474 | /* FLOGI received */ |
| 4475 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4476 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4477 | |
| 4478 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 4479 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 4480 | did = icmd->un.elsreq64.remoteID; |
| 4481 | |
| 4482 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 4483 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4484 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4485 | "0113 An FLOGI ELS command x%x was " |
| 4486 | "received from DID x%x in Loop Mode\n", |
| 4487 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4488 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4489 | } |
| 4490 | |
| 4491 | did = Fabric_DID; |
| 4492 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 4493 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4494 | /* For a FLOGI we accept, then if our portname is greater |
| 4495 | * then the remote portname we initiate Nport login. |
| 4496 | */ |
| 4497 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4498 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4499 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4500 | |
| 4501 | if (!rc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4502 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4503 | if (!mbox) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4504 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4505 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4506 | lpfc_linkdown(phba); |
| 4507 | lpfc_init_link(phba, mbox, |
| 4508 | phba->cfg_topology, |
| 4509 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4510 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4511 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4512 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4513 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4514 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4515 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4516 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4517 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4518 | return 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4519 | } else if (rc > 0) { /* greater than */ |
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_PLOGI; |
| 4522 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4523 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4524 | spin_lock_irq(shost->host_lock); |
| 4525 | vport->fc_flag |= FC_PT2PT; |
| 4526 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 4527 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4528 | } else { |
| 4529 | /* Reject this request because invalid parameters */ |
| 4530 | stat.un.b.lsRjtRsvd0 = 0; |
| 4531 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4532 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 4533 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4534 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4535 | NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4536 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4537 | } |
| 4538 | |
| 4539 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4540 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4541 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4542 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4543 | } |
| 4544 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4545 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4546 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4547 | * @vport: pointer to a host virtual N_Port data structure. |
| 4548 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4549 | * @ndlp: pointer to a node-list data structure. |
| 4550 | * |
| 4551 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 4552 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 4553 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 4554 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 4555 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 4556 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 4557 | * |
| 4558 | * Return code |
| 4559 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 4560 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4561 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4562 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4563 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4564 | { |
| 4565 | struct lpfc_dmabuf *pcmd; |
| 4566 | uint32_t *lp; |
| 4567 | IOCB_t *icmd; |
| 4568 | RNID *rn; |
| 4569 | struct ls_rjt stat; |
| 4570 | uint32_t cmd, did; |
| 4571 | |
| 4572 | icmd = &cmdiocb->iocb; |
| 4573 | did = icmd->un.elsreq64.remoteID; |
| 4574 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4575 | lp = (uint32_t *) pcmd->virt; |
| 4576 | |
| 4577 | cmd = *lp++; |
| 4578 | rn = (RNID *) lp; |
| 4579 | |
| 4580 | /* RNID received */ |
| 4581 | |
| 4582 | switch (rn->Format) { |
| 4583 | case 0: |
| 4584 | case RNID_TOPOLOGY_DISC: |
| 4585 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4586 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4587 | break; |
| 4588 | default: |
| 4589 | /* Reject this request because format not supported */ |
| 4590 | stat.un.b.lsRjtRsvd0 = 0; |
| 4591 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4592 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4593 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4594 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4595 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4596 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4597 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4598 | } |
| 4599 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4600 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4601 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4602 | * @vport: pointer to a host virtual N_Port data structure. |
| 4603 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4604 | * @ndlp: pointer to a node-list data structure. |
| 4605 | * |
| 4606 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 4607 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 4608 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 4609 | * |
| 4610 | * Return code |
| 4611 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 4612 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4613 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4614 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4615 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4616 | { |
| 4617 | struct ls_rjt stat; |
| 4618 | |
| 4619 | /* For now, unconditionally reject this command */ |
| 4620 | stat.un.b.lsRjtRsvd0 = 0; |
| 4621 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4622 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4623 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4624 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4625 | return 0; |
| 4626 | } |
| 4627 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4628 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4629 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb |
| 4630 | * @vport: pointer to a host virtual N_Port data structure. |
| 4631 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4632 | * @ndlp: pointer to a node-list data structure. |
| 4633 | * |
| 4634 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB |
| 4635 | * received as an ELS unsolicited event. A request to RRQ shall only |
| 4636 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder |
| 4637 | * Nx_Port N_Port_ID of the target Exchange is the same as the |
| 4638 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is |
| 4639 | * not accepted, an LS_RJT with reason code "Unable to perform |
| 4640 | * command request" and reason code explanation "Invalid Originator |
| 4641 | * S_ID" shall be returned. For now, we just unconditionally accept |
| 4642 | * RRQ from the target. |
| 4643 | **/ |
| 4644 | static void |
| 4645 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4646 | struct lpfc_nodelist *ndlp) |
| 4647 | { |
| 4648 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| 4649 | } |
| 4650 | |
| 4651 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4652 | * 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] | 4653 | * @phba: pointer to lpfc hba data structure. |
| 4654 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4655 | * |
| 4656 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 4657 | * mailbox command. This callback function is to actually send the Accept |
| 4658 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 4659 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 4660 | * mailbox command, constructs the RPS response with the link statistics |
| 4661 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 4662 | * response to the RPS. |
| 4663 | * |
| 4664 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4665 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4666 | * will be stored into the context1 field of the IOCB for the completion |
| 4667 | * callback function to the RPS Accept Response ELS IOCB command. |
| 4668 | * |
| 4669 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4670 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4671 | 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] | 4672 | { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4673 | MAILBOX_t *mb; |
| 4674 | IOCB_t *icmd; |
| 4675 | RPS_RSP *rps_rsp; |
| 4676 | uint8_t *pcmd; |
| 4677 | struct lpfc_iocbq *elsiocb; |
| 4678 | struct lpfc_nodelist *ndlp; |
| 4679 | uint16_t xri, status; |
| 4680 | uint32_t cmdsize; |
| 4681 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4682 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4683 | |
| 4684 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4685 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 4686 | pmb->context1 = NULL; |
| 4687 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4688 | |
| 4689 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4690 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4691 | return; |
| 4692 | } |
| 4693 | |
| 4694 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4695 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4696 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 4697 | lpfc_max_els_tries, ndlp, |
| 4698 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4699 | |
| 4700 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4701 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4702 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4703 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4704 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4705 | |
| 4706 | icmd = &elsiocb->iocb; |
| 4707 | icmd->ulpContext = xri; |
| 4708 | |
| 4709 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4710 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4711 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4712 | rps_rsp = (RPS_RSP *)pcmd; |
| 4713 | |
| 4714 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| 4715 | status = 0x10; |
| 4716 | else |
| 4717 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4718 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4719 | status |= 0x4; |
| 4720 | |
| 4721 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4722 | rps_rsp->portStatus = cpu_to_be16(status); |
| 4723 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 4724 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 4725 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 4726 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 4727 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 4728 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4729 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4730 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 4731 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 4732 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4733 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4734 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4735 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4736 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4737 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4738 | 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] | 4739 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4740 | return; |
| 4741 | } |
| 4742 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4743 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4744 | * lpfc_els_rcv_rps - Process an unsolicited rps iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4745 | * @vport: pointer to a host virtual N_Port data structure. |
| 4746 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4747 | * @ndlp: pointer to a node-list data structure. |
| 4748 | * |
| 4749 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 4750 | * ELS unsolicited event. It first checks the remote port state. If the |
| 4751 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 4752 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 4753 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 4754 | * for reading the HBA link statistics. It is for the callback function, |
| 4755 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 4756 | * to actually sending out RPS Accept (ACC) response. |
| 4757 | * |
| 4758 | * Return codes |
| 4759 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 4760 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4761 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4762 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4763 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4764 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4765 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4766 | uint32_t *lp; |
| 4767 | uint8_t flag; |
| 4768 | LPFC_MBOXQ_t *mbox; |
| 4769 | struct lpfc_dmabuf *pcmd; |
| 4770 | RPS *rps; |
| 4771 | struct ls_rjt stat; |
| 4772 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4773 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4774 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 4775 | /* reject the unsolicited RPS request and done with it */ |
| 4776 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4777 | |
| 4778 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4779 | lp = (uint32_t *) pcmd->virt; |
| 4780 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 4781 | rps = (RPS *) lp; |
| 4782 | |
| 4783 | if ((flag == 0) || |
| 4784 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4785 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4786 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4787 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4788 | printk("Fix me....\n"); |
| 4789 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4790 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 4791 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4792 | lpfc_read_lnk_stat(phba, mbox); |
| 4793 | mbox->context1 = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4794 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4795 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4796 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4797 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4798 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4799 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4800 | /* Mbox completion will send ELS Response */ |
| 4801 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4802 | /* Decrement reference count used for the failed mbox |
| 4803 | * command. |
| 4804 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4805 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4806 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4807 | } |
| 4808 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4809 | |
| 4810 | reject_out: |
| 4811 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4812 | stat.un.b.lsRjtRsvd0 = 0; |
| 4813 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4814 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4815 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4816 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4817 | return 0; |
| 4818 | } |
| 4819 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4820 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4821 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4822 | * @vport: pointer to a host virtual N_Port data structure. |
| 4823 | * @cmdsize: size of the ELS command. |
| 4824 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4825 | * @ndlp: pointer to a node-list data structure. |
| 4826 | * |
| 4827 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 4828 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 4829 | * |
| 4830 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4831 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4832 | * will be stored into the context1 field of the IOCB for the completion |
| 4833 | * callback function to the RPL Accept Response ELS command. |
| 4834 | * |
| 4835 | * Return code |
| 4836 | * 0 - Successfully issued ACC RPL ELS command |
| 4837 | * 1 - Failed to issue ACC RPL ELS command |
| 4838 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4839 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4840 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 4841 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4842 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4843 | struct lpfc_hba *phba = vport->phba; |
| 4844 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4845 | RPL_RSP rpl_rsp; |
| 4846 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4847 | uint8_t *pcmd; |
| 4848 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4849 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4850 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4851 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4852 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4853 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4854 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4855 | icmd = &elsiocb->iocb; |
| 4856 | oldcmd = &oldiocb->iocb; |
| 4857 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 4858 | |
| 4859 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4860 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4861 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4862 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 4863 | pcmd += sizeof(uint16_t); |
| 4864 | |
| 4865 | /* Setup the RPL ACC payload */ |
| 4866 | rpl_rsp.listLen = be32_to_cpu(1); |
| 4867 | rpl_rsp.index = 0; |
| 4868 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4869 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 4870 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4871 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4872 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4873 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4874 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4875 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 4876 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 4877 | "rpi x%x\n", |
| 4878 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4879 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4880 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4881 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4882 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4883 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 4884 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4885 | lpfc_els_free_iocb(phba, elsiocb); |
| 4886 | return 1; |
| 4887 | } |
| 4888 | return 0; |
| 4889 | } |
| 4890 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4891 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4892 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4893 | * @vport: pointer to a host virtual N_Port data structure. |
| 4894 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4895 | * @ndlp: pointer to a node-list data structure. |
| 4896 | * |
| 4897 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 4898 | * unsolicited event. It first checks the remote port state. If the remote |
| 4899 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 4900 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 4901 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 4902 | * to accept the RPL. |
| 4903 | * |
| 4904 | * Return code |
| 4905 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 4906 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4907 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4908 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4909 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4910 | { |
| 4911 | struct lpfc_dmabuf *pcmd; |
| 4912 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4913 | uint32_t maxsize; |
| 4914 | uint16_t cmdsize; |
| 4915 | RPL *rpl; |
| 4916 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4917 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4918 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 4919 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4920 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4921 | stat.un.b.lsRjtRsvd0 = 0; |
| 4922 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4923 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4924 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4925 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4926 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4927 | /* rejected the unsolicited RPL request and done with it */ |
| 4928 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4929 | } |
| 4930 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4931 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4932 | lp = (uint32_t *) pcmd->virt; |
| 4933 | rpl = (RPL *) (lp + 1); |
| 4934 | |
| 4935 | maxsize = be32_to_cpu(rpl->maxsize); |
| 4936 | |
| 4937 | /* We support only one port */ |
| 4938 | if ((rpl->index == 0) && |
| 4939 | ((maxsize == 0) || |
| 4940 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 4941 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4942 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4943 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 4944 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4945 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4946 | |
| 4947 | return 0; |
| 4948 | } |
| 4949 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4950 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4951 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4952 | * @vport: pointer to a virtual N_Port data structure. |
| 4953 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4954 | * @ndlp: pointer to a node-list data structure. |
| 4955 | * |
| 4956 | * This routine processes Fibre Channel Address Resolution Protocol |
| 4957 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 4958 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 4959 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 4960 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 4961 | * remote PortName is compared against the FC PortName stored in the @vport |
| 4962 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 4963 | * compared against the FC NodeName stored in the @vport data structure. |
| 4964 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 4965 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 4966 | * invoked to send out FARP Response to the remote node. Before sending the |
| 4967 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 4968 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 4969 | * routine is invoked to log into the remote port first. |
| 4970 | * |
| 4971 | * Return code |
| 4972 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 4973 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4974 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4975 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4976 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4977 | { |
| 4978 | struct lpfc_dmabuf *pcmd; |
| 4979 | uint32_t *lp; |
| 4980 | IOCB_t *icmd; |
| 4981 | FARP *fp; |
| 4982 | uint32_t cmd, cnt, did; |
| 4983 | |
| 4984 | icmd = &cmdiocb->iocb; |
| 4985 | did = icmd->un.elsreq64.remoteID; |
| 4986 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4987 | lp = (uint32_t *) pcmd->virt; |
| 4988 | |
| 4989 | cmd = *lp++; |
| 4990 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4991 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4992 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4993 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4994 | /* We will only support match on WWPN or WWNN */ |
| 4995 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4996 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4997 | } |
| 4998 | |
| 4999 | cnt = 0; |
| 5000 | /* If this FARP command is searching for my portname */ |
| 5001 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5002 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5003 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5004 | cnt = 1; |
| 5005 | } |
| 5006 | |
| 5007 | /* If this FARP command is searching for my nodename */ |
| 5008 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5009 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5010 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5011 | cnt = 1; |
| 5012 | } |
| 5013 | |
| 5014 | if (cnt) { |
| 5015 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 5016 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 5017 | /* Log back into the node before sending the FARP. */ |
| 5018 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5019 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5020 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 5021 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5022 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5023 | } |
| 5024 | |
| 5025 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5026 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 5027 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5028 | } |
| 5029 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5030 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5031 | } |
| 5032 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5033 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5034 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5035 | * @vport: pointer to a host virtual N_Port data structure. |
| 5036 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5037 | * @ndlp: pointer to a node-list data structure. |
| 5038 | * |
| 5039 | * This routine processes Fibre Channel Address Resolution Protocol |
| 5040 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 5041 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 5042 | * the FARP response request. |
| 5043 | * |
| 5044 | * Return code |
| 5045 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 5046 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5047 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5048 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5049 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5050 | { |
| 5051 | struct lpfc_dmabuf *pcmd; |
| 5052 | uint32_t *lp; |
| 5053 | IOCB_t *icmd; |
| 5054 | uint32_t cmd, did; |
| 5055 | |
| 5056 | icmd = &cmdiocb->iocb; |
| 5057 | did = icmd->un.elsreq64.remoteID; |
| 5058 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5059 | lp = (uint32_t *) pcmd->virt; |
| 5060 | |
| 5061 | cmd = *lp++; |
| 5062 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5063 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5064 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5065 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5066 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5067 | |
| 5068 | return 0; |
| 5069 | } |
| 5070 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5071 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5072 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5073 | * @vport: pointer to a host virtual N_Port data structure. |
| 5074 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5075 | * @fan_ndlp: pointer to a node-list data structure. |
| 5076 | * |
| 5077 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 5078 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 5079 | * only be processed on a physical port (i.e., the @vport represents the |
| 5080 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 5081 | * compared against those in the phba data structure. If any of those is |
| 5082 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 5083 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 5084 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 5085 | * is invoked to register login to the fabric. |
| 5086 | * |
| 5087 | * Return code |
| 5088 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 5089 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5090 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5091 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5092 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5093 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5094 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5095 | uint32_t *lp; |
| 5096 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5097 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5098 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 5099 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 5100 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5101 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5102 | if ((vport == phba->pport) && |
| 5103 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5104 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5105 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5106 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5107 | sizeof(struct lpfc_name)))) { |
| 5108 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5109 | lpfc_initial_flogi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5110 | } else { |
| 5111 | /* FAN verified - skip FLOGI */ |
| 5112 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5113 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5114 | lpfc_issue_fabric_reglogin(vport); |
| 5115 | else |
| 5116 | lpfc_issue_reg_vfi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5117 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5118 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5119 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5120 | } |
| 5121 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5122 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5123 | * lpfc_els_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5124 | * @ptr: holder for the timer function associated data. |
| 5125 | * |
| 5126 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 5127 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 5128 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 5129 | * up the worker thread. It is for the worker thread to invoke the routine |
| 5130 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 5131 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5132 | void |
| 5133 | lpfc_els_timeout(unsigned long ptr) |
| 5134 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5135 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 5136 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5137 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5138 | unsigned long iflag; |
| 5139 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5140 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5141 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
| 5142 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5143 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5144 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5145 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5146 | if (!tmo_posted) |
| 5147 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5148 | return; |
| 5149 | } |
| 5150 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame^] | 5151 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5152 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5153 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5154 | * @vport: pointer to a virtual N_Port data structure. |
| 5155 | * |
| 5156 | * This routine is the actual handler function that processes an ELS timeout |
| 5157 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 5158 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 5159 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5160 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5161 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5162 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5163 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5164 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5165 | struct lpfc_sli_ring *pring; |
| 5166 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5167 | IOCB_t *cmd = NULL; |
| 5168 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5169 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5170 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5171 | uint32_t remote_ID = 0xffffffff; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame^] | 5172 | LIST_HEAD(txcmplq_completions); |
| 5173 | LIST_HEAD(abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5174 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame^] | 5175 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5176 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 5177 | |
| 5178 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5179 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame^] | 5180 | spin_lock_irq(&phba->hbalock); |
| 5181 | list_splice_init(&pring->txcmplq, &txcmplq_completions); |
| 5182 | spin_unlock_irq(&phba->hbalock); |
| 5183 | |
| 5184 | list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5185 | cmd = &piocb->iocb; |
| 5186 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5187 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 5188 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 5189 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5190 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5191 | |
| 5192 | if (piocb->vport != vport) |
| 5193 | continue; |
| 5194 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5195 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5196 | if (pcmd) |
| 5197 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5198 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5199 | if (els_command == ELS_CMD_FARP || |
| 5200 | els_command == ELS_CMD_FARPR || |
| 5201 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5202 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5203 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5204 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5205 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5206 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5207 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5208 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5209 | continue; |
| 5210 | } |
| 5211 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5212 | remote_ID = 0xffffffff; |
| 5213 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5214 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5215 | else { |
| 5216 | struct lpfc_nodelist *ndlp; |
| 5217 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5218 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5219 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5220 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame^] | 5221 | list_add_tail(&piocb->dlist, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5222 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame^] | 5223 | spin_lock_irq(&phba->hbalock); |
| 5224 | list_splice(&txcmplq_completions, &pring->txcmplq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5225 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 5226 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame^] | 5227 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
| 5228 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5229 | "0127 ELS timeout Data: x%x x%x x%x " |
| 5230 | "x%x\n", els_command, |
| 5231 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
| 5232 | spin_lock_irq(&phba->hbalock); |
| 5233 | list_del_init(&piocb->dlist); |
| 5234 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5235 | spin_unlock_irq(&phba->hbalock); |
| 5236 | } |
| 5237 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5238 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
| 5239 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5240 | } |
| 5241 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5242 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5243 | * 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] | 5244 | * @vport: pointer to a host virtual N_Port data structure. |
| 5245 | * |
| 5246 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5247 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 5248 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5249 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5250 | * the IOCBs with a non-NULL completion callback function, the callback |
| 5251 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5252 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 5253 | * callback function, the IOCB will simply be released. Finally, it walks |
| 5254 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 5255 | * completion queue IOCB that is associated with the @vport and is not |
| 5256 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 5257 | * part of the discovery state machine) out to HBA by invoking the |
| 5258 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 5259 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 5260 | * the IOCBs are aborted when this function returns. |
| 5261 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5262 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5263 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5264 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5265 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5266 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5267 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5268 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5269 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5270 | |
| 5271 | lpfc_fabric_abort_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5272 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5273 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5274 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5275 | cmd = &piocb->iocb; |
| 5276 | |
| 5277 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5278 | continue; |
| 5279 | } |
| 5280 | |
| 5281 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5282 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5283 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5284 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5285 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5286 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5287 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5288 | if (piocb->vport != vport) |
| 5289 | continue; |
| 5290 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5291 | list_move_tail(&piocb->list, &completions); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5292 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5293 | } |
| 5294 | |
| 5295 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5296 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5297 | continue; |
| 5298 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5299 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5300 | if (piocb->vport != vport) |
| 5301 | continue; |
| 5302 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5303 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5304 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5305 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5306 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5307 | /* Cancell all the IOCBs from the completions list */ |
| 5308 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5309 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5310 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5311 | return; |
| 5312 | } |
| 5313 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5314 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5315 | * 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] | 5316 | * @phba: pointer to lpfc hba data structure. |
| 5317 | * |
| 5318 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5319 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 5320 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5321 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5322 | * the IOCBs with the completion callback function associated, the callback |
| 5323 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5324 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 5325 | * callback function associated, the IOCB will simply be released. Finally, |
| 5326 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 5327 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 5328 | * management plane IOCBs that are not part of the discovery state machine) |
| 5329 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5330 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5331 | void |
| 5332 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 5333 | { |
| 5334 | LIST_HEAD(completions); |
| 5335 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 5336 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5337 | IOCB_t *cmd = NULL; |
| 5338 | |
| 5339 | lpfc_fabric_abort_hba(phba); |
| 5340 | spin_lock_irq(&phba->hbalock); |
| 5341 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5342 | cmd = &piocb->iocb; |
| 5343 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5344 | continue; |
| 5345 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
| 5346 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5347 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5348 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5349 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| 5350 | continue; |
| 5351 | list_move_tail(&piocb->list, &completions); |
| 5352 | pring->txq_cnt--; |
| 5353 | } |
| 5354 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5355 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5356 | continue; |
| 5357 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5358 | } |
| 5359 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5360 | |
| 5361 | /* Cancel all the IOCBs from the completions list */ |
| 5362 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5363 | IOERR_SLI_ABORTED); |
| 5364 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5365 | return; |
| 5366 | } |
| 5367 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5368 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5369 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5370 | * @phba: Pointer to hba context object. |
| 5371 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 5372 | * @rspiocbp: Pointer to response iocb which reported error. |
| 5373 | * |
| 5374 | * This function sends an event when there is an ELS command |
| 5375 | * failure. |
| 5376 | **/ |
| 5377 | void |
| 5378 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 5379 | struct lpfc_iocbq *cmdiocbp, |
| 5380 | struct lpfc_iocbq *rspiocbp) |
| 5381 | { |
| 5382 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 5383 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5384 | struct lpfc_lsrjt_event lsrjt_event; |
| 5385 | struct lpfc_fabric_event_header fabric_event; |
| 5386 | struct ls_rjt stat; |
| 5387 | struct lpfc_nodelist *ndlp; |
| 5388 | uint32_t *pcmd; |
| 5389 | |
| 5390 | ndlp = cmdiocbp->context1; |
| 5391 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 5392 | return; |
| 5393 | |
| 5394 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 5395 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 5396 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 5397 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 5398 | sizeof(struct lpfc_name)); |
| 5399 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 5400 | sizeof(struct lpfc_name)); |
| 5401 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 5402 | cmdiocbp->context2)->virt); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 5403 | lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5404 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 5405 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 5406 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 5407 | fc_host_post_vendor_event(shost, |
| 5408 | fc_get_event_number(), |
| 5409 | sizeof(lsrjt_event), |
| 5410 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5411 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5412 | return; |
| 5413 | } |
| 5414 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 5415 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 5416 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 5417 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 5418 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 5419 | else |
| 5420 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 5421 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 5422 | sizeof(struct lpfc_name)); |
| 5423 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 5424 | sizeof(struct lpfc_name)); |
| 5425 | fc_host_post_vendor_event(shost, |
| 5426 | fc_get_event_number(), |
| 5427 | sizeof(fabric_event), |
| 5428 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5429 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5430 | return; |
| 5431 | } |
| 5432 | |
| 5433 | } |
| 5434 | |
| 5435 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5436 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5437 | * @vport: Pointer to vport object. |
| 5438 | * @ndlp: Pointer FC node object. |
| 5439 | * @cmd: ELS command code. |
| 5440 | * |
| 5441 | * This function posts an event when there is an incoming |
| 5442 | * unsolicited ELS command. |
| 5443 | **/ |
| 5444 | static void |
| 5445 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 5446 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5447 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5448 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5449 | struct lpfc_els_event_header *els_data = NULL; |
| 5450 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5451 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5452 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5453 | if (*payload == ELS_CMD_LOGO) { |
| 5454 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 5455 | if (!logo_data) { |
| 5456 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5457 | "0148 Failed to allocate memory " |
| 5458 | "for LOGO event\n"); |
| 5459 | return; |
| 5460 | } |
| 5461 | els_data = &logo_data->header; |
| 5462 | } else { |
| 5463 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 5464 | GFP_KERNEL); |
| 5465 | if (!els_data) { |
| 5466 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5467 | "0149 Failed to allocate memory " |
| 5468 | "for ELS event\n"); |
| 5469 | return; |
| 5470 | } |
| 5471 | } |
| 5472 | els_data->event_type = FC_REG_ELS_EVENT; |
| 5473 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5474 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5475 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5476 | break; |
| 5477 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5478 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5479 | break; |
| 5480 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5481 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 5482 | break; |
| 5483 | case ELS_CMD_LOGO: |
| 5484 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 5485 | /* Copy the WWPN in the LOGO payload */ |
| 5486 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 5487 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5488 | break; |
| 5489 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 5490 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5491 | return; |
| 5492 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5493 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 5494 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 5495 | if (*payload == ELS_CMD_LOGO) { |
| 5496 | fc_host_post_vendor_event(shost, |
| 5497 | fc_get_event_number(), |
| 5498 | sizeof(struct lpfc_logo_event), |
| 5499 | (char *)logo_data, |
| 5500 | LPFC_NL_VENDOR_ID); |
| 5501 | kfree(logo_data); |
| 5502 | } else { |
| 5503 | fc_host_post_vendor_event(shost, |
| 5504 | fc_get_event_number(), |
| 5505 | sizeof(struct lpfc_els_event_header), |
| 5506 | (char *)els_data, |
| 5507 | LPFC_NL_VENDOR_ID); |
| 5508 | kfree(els_data); |
| 5509 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5510 | |
| 5511 | return; |
| 5512 | } |
| 5513 | |
| 5514 | |
| 5515 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5516 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5517 | * @phba: pointer to lpfc hba data structure. |
| 5518 | * @pring: pointer to a SLI ring. |
| 5519 | * @vport: pointer to a host virtual N_Port data structure. |
| 5520 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 5521 | * |
| 5522 | * This routine is used for processing the IOCB associated with a unsolicited |
| 5523 | * event. It first determines whether there is an existing ndlp that matches |
| 5524 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 5525 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 5526 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 5527 | * of the discovery state machine. |
| 5528 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5529 | static void |
| 5530 | 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] | 5531 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5532 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5533 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5534 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5535 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5536 | uint32_t *payload; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5537 | uint32_t cmd, did, newnode, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5538 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5539 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5540 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5541 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5542 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5543 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5544 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 5545 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5546 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5547 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5548 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5549 | did = icmd->un.rcvels.remoteID; |
| 5550 | if (icmd->ulpStatus) { |
| 5551 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5552 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 5553 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5554 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5555 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5556 | |
| 5557 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5558 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5559 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5560 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 5561 | /* Ignore traffic received during vport shutdown. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5562 | if (vport->load_flag & FC_UNLOADING) |
| 5563 | goto dropit; |
| 5564 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5565 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5566 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5567 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5568 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5569 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5570 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5571 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5572 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5573 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5574 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5575 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5576 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5577 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5578 | ndlp = lpfc_enable_node(vport, ndlp, |
| 5579 | NLP_STE_UNUSED_NODE); |
| 5580 | if (!ndlp) |
| 5581 | goto dropit; |
| 5582 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5583 | newnode = 1; |
| 5584 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 5585 | ndlp->nlp_type |= NLP_FABRIC; |
| 5586 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 5587 | /* This is similar to the new node path */ |
| 5588 | ndlp = lpfc_nlp_get(ndlp); |
| 5589 | if (!ndlp) |
| 5590 | goto dropit; |
| 5591 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5592 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5593 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5594 | |
| 5595 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5596 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5597 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5598 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5599 | |
| 5600 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 5601 | cmd &= ELS_CMD_MASK; |
| 5602 | } |
| 5603 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5604 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5605 | "0112 ELS command x%x received from NPORT x%x " |
| 5606 | "Data: x%x\n", cmd, did, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5607 | switch (cmd) { |
| 5608 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5609 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5610 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 5611 | did, vport->port_state, ndlp->nlp_flag); |
| 5612 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5613 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5614 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
| 5615 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5616 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5617 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5618 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 5619 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 5620 | rjt_err = LSRJT_UNABLE_TPC; |
| 5621 | break; |
| 5622 | } |
| 5623 | /* We get here, and drop thru, if we are PT2PT with |
| 5624 | * another NPort and the other side has initiated |
| 5625 | * the PLOGI before responding to our FLOGI. |
| 5626 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5627 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5628 | |
| 5629 | shost = lpfc_shost_from_vport(vport); |
| 5630 | spin_lock_irq(shost->host_lock); |
| 5631 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 5632 | spin_unlock_irq(shost->host_lock); |
| 5633 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5634 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5635 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5636 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5637 | break; |
| 5638 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5639 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5640 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 5641 | did, vport->port_state, ndlp->nlp_flag); |
| 5642 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5643 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5644 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5645 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5646 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5647 | break; |
| 5648 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5649 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5650 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 5651 | did, vport->port_state, ndlp->nlp_flag); |
| 5652 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5653 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5654 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5655 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5656 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5657 | break; |
| 5658 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5659 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5660 | break; |
| 5661 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5662 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5663 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 5664 | did, vport->port_state, ndlp->nlp_flag); |
| 5665 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5666 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5667 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5668 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5669 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5670 | break; |
| 5671 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5672 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5673 | break; |
| 5674 | case ELS_CMD_RSCN: |
| 5675 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5676 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5677 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5678 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5679 | break; |
| 5680 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5681 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5682 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 5683 | did, vport->port_state, ndlp->nlp_flag); |
| 5684 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5685 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5686 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5687 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5688 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5689 | break; |
| 5690 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5691 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5692 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5693 | break; |
| 5694 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5695 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5696 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 5697 | did, vport->port_state, ndlp->nlp_flag); |
| 5698 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5699 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5700 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5701 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5702 | break; |
| 5703 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5704 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5705 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5706 | break; |
| 5707 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5708 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5709 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 5710 | did, vport->port_state, ndlp->nlp_flag); |
| 5711 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5712 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5713 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5714 | break; |
| 5715 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5716 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5717 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 5718 | did, vport->port_state, ndlp->nlp_flag); |
| 5719 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5720 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5721 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5722 | break; |
| 5723 | case ELS_CMD_FAN: |
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 FAN: did:x%x/ste:x%x flg:x%x", |
| 5726 | did, vport->port_state, ndlp->nlp_flag); |
| 5727 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5728 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5729 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5730 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5731 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5732 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5733 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 5734 | did, vport->port_state, ndlp->nlp_flag); |
| 5735 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5736 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5737 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5738 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5739 | break; |
| 5740 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5741 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5742 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5743 | case ELS_CMD_LIRR: |
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 LIRR: 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.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5749 | lpfc_els_rcv_lirr(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; |
| 5753 | case ELS_CMD_RPS: |
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 RPS: did:x%x/ste:x%x flg:x%x", |
| 5756 | did, vport->port_state, ndlp->nlp_flag); |
| 5757 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5758 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5759 | lpfc_els_rcv_rps(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); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5762 | break; |
| 5763 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5764 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5765 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 5766 | did, vport->port_state, ndlp->nlp_flag); |
| 5767 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5768 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5769 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5770 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5771 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5772 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5773 | case ELS_CMD_RNID: |
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 RNID: did:x%x/ste:x%x flg:x%x", |
| 5776 | did, vport->port_state, ndlp->nlp_flag); |
| 5777 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5778 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5779 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5780 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5781 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5782 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 5783 | case ELS_CMD_RRQ: |
| 5784 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5785 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", |
| 5786 | did, vport->port_state, ndlp->nlp_flag); |
| 5787 | |
| 5788 | phba->fc_stat.elsRcvRRQ++; |
| 5789 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); |
| 5790 | if (newnode) |
| 5791 | lpfc_nlp_put(ndlp); |
| 5792 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5793 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5794 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5795 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 5796 | cmd, did, vport->port_state); |
| 5797 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5798 | /* Unsupported ELS command, reject */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5799 | rjt_err = LSRJT_INVALID_CMD; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5800 | |
| 5801 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5802 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5803 | "0115 Unknown ELS command x%x " |
| 5804 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5805 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5806 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5807 | break; |
| 5808 | } |
| 5809 | |
| 5810 | /* check if need to LS_RJT received ELS cmd */ |
| 5811 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5812 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5813 | stat.un.b.lsRjtRsnCode = rjt_err; |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 5814 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5815 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 5816 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5817 | } |
| 5818 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5819 | lpfc_nlp_put(elsiocb->context1); |
| 5820 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5821 | return; |
| 5822 | |
| 5823 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5824 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5825 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5826 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5827 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5828 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5829 | phba->fc_stat.elsRcvDrop++; |
| 5830 | } |
| 5831 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5832 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5833 | * 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] | 5834 | * @phba: pointer to lpfc hba data structure. |
| 5835 | * @vpi: host virtual N_Port identifier. |
| 5836 | * |
| 5837 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 5838 | * @vpi. The function walks the HBA's vport list and returns the address |
| 5839 | * of the vport with the matching @vpi. |
| 5840 | * |
| 5841 | * Return code |
| 5842 | * NULL - No vport with the matching @vpi found |
| 5843 | * Otherwise - Address to the vport with the matching @vpi. |
| 5844 | **/ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5845 | struct lpfc_vport * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5846 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 5847 | { |
| 5848 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5849 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5850 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5851 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5852 | list_for_each_entry(vport, &phba->port_list, listentry) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5853 | if (vport->vpi == vpi) { |
| 5854 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5855 | return vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5856 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5857 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5858 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5859 | return NULL; |
| 5860 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5861 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5862 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5863 | * 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] | 5864 | * @phba: pointer to lpfc hba data structure. |
| 5865 | * @pring: pointer to a SLI ring. |
| 5866 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 5867 | * |
| 5868 | * This routine is used to process an unsolicited event received from a SLI |
| 5869 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 5870 | * associated with the unsolicited event is done by invoking the routine |
| 5871 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 5872 | * SLI ring on which the unsolicited event was received. |
| 5873 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5874 | void |
| 5875 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 5876 | struct lpfc_iocbq *elsiocb) |
| 5877 | { |
| 5878 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5879 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5880 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5881 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 5882 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5883 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5884 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5885 | elsiocb->context2 = NULL; |
| 5886 | elsiocb->context3 = NULL; |
| 5887 | |
| 5888 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 5889 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 5890 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 5891 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5892 | phba->fc_stat.NoRcvBuf++; |
| 5893 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5894 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5895 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5896 | return; |
| 5897 | } |
| 5898 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5899 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 5900 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 5901 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 5902 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 5903 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5904 | else |
| 5905 | vport = lpfc_find_vport_by_vpid(phba, |
| 5906 | icmd->unsli3.rcvsli3.vpi - phba->vpi_base); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5907 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5908 | /* If there are no BDEs associated |
| 5909 | * with this IOCB, there is nothing to do. |
| 5910 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5911 | if (icmd->ulpBdeCount == 0) |
| 5912 | return; |
| 5913 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5914 | /* type of ELS cmd is first 32bit word |
| 5915 | * in packet |
| 5916 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5917 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5918 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5919 | } else { |
| 5920 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 5921 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5922 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 5923 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5924 | } |
| 5925 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5926 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 5927 | /* |
| 5928 | * The different unsolicited event handlers would tell us |
| 5929 | * if they are done with "mp" by setting context2 to NULL. |
| 5930 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5931 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5932 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 5933 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5934 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5935 | |
| 5936 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5937 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5938 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5939 | elsiocb->context2 = bdeBuf2; |
| 5940 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5941 | /* free mp if we are done with it */ |
| 5942 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5943 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 5944 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5945 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5946 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5947 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5948 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5949 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5950 | * 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] | 5951 | * @phba: pointer to lpfc hba data structure. |
| 5952 | * @vport: pointer to a virtual N_Port data structure. |
| 5953 | * |
| 5954 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 5955 | * State Change Request (SCR) for a @vport. This routine will create an |
| 5956 | * ndlp for the Name Server associated to the @vport if such node does |
| 5957 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 5958 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 5959 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 5960 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 5961 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5962 | void |
| 5963 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 5964 | { |
| 5965 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
| 5966 | |
| 5967 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 5968 | if (!ndlp) { |
| 5969 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 5970 | if (!ndlp) { |
| 5971 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5972 | lpfc_disc_start(vport); |
| 5973 | return; |
| 5974 | } |
| 5975 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5976 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5977 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5978 | return; |
| 5979 | } |
| 5980 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5981 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5982 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 5983 | if (!ndlp) { |
| 5984 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5985 | lpfc_disc_start(vport); |
| 5986 | return; |
| 5987 | } |
| 5988 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5989 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5990 | "0348 NameServer login: node freed\n"); |
| 5991 | return; |
| 5992 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5993 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5994 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5995 | |
| 5996 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 5997 | |
| 5998 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 5999 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6000 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6001 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6002 | return; |
| 6003 | } |
| 6004 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6005 | if (vport->cfg_fdmi_on) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6006 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 6007 | GFP_KERNEL); |
| 6008 | if (ndlp_fdmi) { |
| 6009 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 6010 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6011 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
| 6012 | NLP_STE_PLOGI_ISSUE); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6013 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, |
| 6014 | 0); |
| 6015 | } |
| 6016 | } |
| 6017 | return; |
| 6018 | } |
| 6019 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6020 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6021 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6022 | * @phba: pointer to lpfc hba data structure. |
| 6023 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 6024 | * |
| 6025 | * This routine is the completion callback function to register new vport |
| 6026 | * mailbox command. If the new vport mailbox command completes successfully, |
| 6027 | * the fabric registration login shall be performed on physical port (the |
| 6028 | * new vport created is actually a physical port, with VPI 0) or the port |
| 6029 | * login to Name Server for State Change Request (SCR) will be performed |
| 6030 | * on virtual port (real virtual port, with VPI greater than 0). |
| 6031 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6032 | static void |
| 6033 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6034 | { |
| 6035 | struct lpfc_vport *vport = pmb->vport; |
| 6036 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6037 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6038 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6039 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6040 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6041 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6042 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6043 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6044 | |
| 6045 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6046 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6047 | "0915 Register VPI failed: 0x%x\n", |
| 6048 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6049 | |
| 6050 | switch (mb->mbxStatus) { |
| 6051 | case 0x11: /* unsupported feature */ |
| 6052 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6053 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6054 | /* giving up on vport registration */ |
| 6055 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6056 | spin_lock_irq(shost->host_lock); |
| 6057 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 6058 | spin_unlock_irq(shost->host_lock); |
| 6059 | lpfc_can_disctmo(vport); |
| 6060 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6061 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
| 6062 | case 0x20: |
| 6063 | spin_lock_irq(shost->host_lock); |
| 6064 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 6065 | spin_unlock_irq(shost->host_lock); |
| 6066 | lpfc_init_vpi(phba, pmb, vport->vpi); |
| 6067 | pmb->vport = vport; |
| 6068 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 6069 | rc = lpfc_sli_issue_mbox(phba, pmb, |
| 6070 | MBX_NOWAIT); |
| 6071 | if (rc == MBX_NOT_FINISHED) { |
| 6072 | lpfc_printf_vlog(vport, |
| 6073 | KERN_ERR, LOG_MBOX, |
| 6074 | "2732 Failed to issue INIT_VPI" |
| 6075 | " mailbox command\n"); |
| 6076 | } else { |
| 6077 | lpfc_nlp_put(ndlp); |
| 6078 | return; |
| 6079 | } |
| 6080 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6081 | default: |
| 6082 | /* Try to recover from this error */ |
| 6083 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6084 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6085 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6086 | spin_unlock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6087 | if (vport->port_type == LPFC_PHYSICAL_PORT |
| 6088 | && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6089 | lpfc_initial_flogi(vport); |
| 6090 | else |
| 6091 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6092 | break; |
| 6093 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6094 | } else { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6095 | spin_lock_irq(shost->host_lock); |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 6096 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6097 | spin_unlock_irq(shost->host_lock); |
| 6098 | if (vport == phba->pport) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6099 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 6100 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6101 | else { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6102 | /* |
| 6103 | * If the physical port is instantiated using |
| 6104 | * FDISC, do not start vport discovery. |
| 6105 | */ |
| 6106 | if (vport->port_state != LPFC_FDISC) |
| 6107 | lpfc_start_fdiscs(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6108 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6109 | } |
| 6110 | } else |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6111 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6112 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6113 | |
| 6114 | /* Now, we decrement the ndlp reference count held for this |
| 6115 | * callback function |
| 6116 | */ |
| 6117 | lpfc_nlp_put(ndlp); |
| 6118 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6119 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6120 | return; |
| 6121 | } |
| 6122 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6123 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6124 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6125 | * @phba: pointer to lpfc hba data structure. |
| 6126 | * @vport: pointer to a host virtual N_Port data structure. |
| 6127 | * @ndlp: pointer to a node-list data structure. |
| 6128 | * |
| 6129 | * This routine registers the @vport as a new virtual port with a HBA. |
| 6130 | * It is done through a registering vpi mailbox command. |
| 6131 | **/ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6132 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6133 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 6134 | struct lpfc_nodelist *ndlp) |
| 6135 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6136 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6137 | LPFC_MBOXQ_t *mbox; |
| 6138 | |
| 6139 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6140 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6141 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6142 | mbox->vport = vport; |
| 6143 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 6144 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 6145 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6146 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6147 | /* mailbox command not success, decrement ndlp |
| 6148 | * reference count for this command |
| 6149 | */ |
| 6150 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6151 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6152 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6153 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6154 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6155 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6156 | } |
| 6157 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6158 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6159 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6160 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6161 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6162 | return; |
| 6163 | |
| 6164 | mbox_err_exit: |
| 6165 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6166 | spin_lock_irq(shost->host_lock); |
| 6167 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 6168 | spin_unlock_irq(shost->host_lock); |
| 6169 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6170 | } |
| 6171 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6172 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6173 | * 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] | 6174 | * @phba: pointer to lpfc hba data structure. |
| 6175 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6176 | * This routine cancels the retry delay timers to all the vports. |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6177 | **/ |
| 6178 | void |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6179 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6180 | { |
| 6181 | struct lpfc_vport **vports; |
| 6182 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6183 | uint32_t link_state; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6184 | int i; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6185 | |
| 6186 | /* Treat this failure as linkdown for all vports */ |
| 6187 | link_state = phba->link_state; |
| 6188 | lpfc_linkdown(phba); |
| 6189 | phba->link_state = link_state; |
| 6190 | |
| 6191 | vports = lpfc_create_vport_work_array(phba); |
| 6192 | |
| 6193 | if (vports) { |
| 6194 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 6195 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 6196 | if (ndlp) |
| 6197 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
| 6198 | lpfc_els_flush_cmd(vports[i]); |
| 6199 | } |
| 6200 | lpfc_destroy_vport_work_array(phba, vports); |
| 6201 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6202 | } |
| 6203 | |
| 6204 | /** |
| 6205 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. |
| 6206 | * @phba: pointer to lpfc hba data structure. |
| 6207 | * |
| 6208 | * This routine abort all pending discovery commands and |
| 6209 | * start a timer to retry FLOGI for the physical port |
| 6210 | * discovery. |
| 6211 | **/ |
| 6212 | void |
| 6213 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) |
| 6214 | { |
| 6215 | struct lpfc_nodelist *ndlp; |
| 6216 | struct Scsi_Host *shost; |
| 6217 | |
| 6218 | /* Cancel the all vports retry delay retry timers */ |
| 6219 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6220 | |
| 6221 | /* If fabric require FLOGI, then re-instantiate physical login */ |
| 6222 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 6223 | if (!ndlp) |
| 6224 | return; |
| 6225 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6226 | shost = lpfc_shost_from_vport(phba->pport); |
| 6227 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); |
| 6228 | spin_lock_irq(shost->host_lock); |
| 6229 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 6230 | spin_unlock_irq(shost->host_lock); |
| 6231 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; |
| 6232 | phba->pport->port_state = LPFC_FLOGI; |
| 6233 | return; |
| 6234 | } |
| 6235 | |
| 6236 | /** |
| 6237 | * lpfc_fabric_login_reqd - Check if FLOGI required. |
| 6238 | * @phba: pointer to lpfc hba data structure. |
| 6239 | * @cmdiocb: pointer to FDISC command iocb. |
| 6240 | * @rspiocb: pointer to FDISC response iocb. |
| 6241 | * |
| 6242 | * This routine checks if a FLOGI is reguired for FDISC |
| 6243 | * to succeed. |
| 6244 | **/ |
| 6245 | static int |
| 6246 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, |
| 6247 | struct lpfc_iocbq *cmdiocb, |
| 6248 | struct lpfc_iocbq *rspiocb) |
| 6249 | { |
| 6250 | |
| 6251 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || |
| 6252 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) |
| 6253 | return 0; |
| 6254 | else |
| 6255 | return 1; |
| 6256 | } |
| 6257 | |
| 6258 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6259 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6260 | * @phba: pointer to lpfc hba data structure. |
| 6261 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6262 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6263 | * |
| 6264 | * This routine is the completion callback function to a Fabric Discover |
| 6265 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 6266 | * single threaded, each FDISC completion callback function will reset |
| 6267 | * the discovery timer for all vports such that the timers will not get |
| 6268 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 6269 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 6270 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 6271 | * assigned to the vport has been changed with the completion of the FDISC |
| 6272 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 6273 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 6274 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 6275 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 6276 | * Server for State Change Request (SCR). |
| 6277 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6278 | static void |
| 6279 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6280 | struct lpfc_iocbq *rspiocb) |
| 6281 | { |
| 6282 | struct lpfc_vport *vport = cmdiocb->vport; |
| 6283 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6284 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 6285 | struct lpfc_nodelist *np; |
| 6286 | struct lpfc_nodelist *next_np; |
| 6287 | IOCB_t *irsp = &rspiocb->iocb; |
| 6288 | struct lpfc_iocbq *piocb; |
| 6289 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6290 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6291 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 6292 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 6293 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6294 | /* Since all FDISCs are being single threaded, we |
| 6295 | * must reset the discovery timer for ALL vports |
| 6296 | * waiting to send FDISC when one completes. |
| 6297 | */ |
| 6298 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 6299 | lpfc_set_disctmo(piocb->vport); |
| 6300 | } |
| 6301 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6302 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6303 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 6304 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 6305 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6306 | if (irsp->ulpStatus) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6307 | |
| 6308 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { |
| 6309 | lpfc_retry_pport_discovery(phba); |
| 6310 | goto out; |
| 6311 | } |
| 6312 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6313 | /* Check for retry */ |
| 6314 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 6315 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6316 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6317 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6318 | "0126 FDISC failed. (%d/%d)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6319 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6320 | goto fdisc_failed; |
| 6321 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6322 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6323 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6324 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6325 | vport->fc_flag |= FC_FABRIC; |
| 6326 | if (vport->phba->fc_topology == TOPOLOGY_LOOP) |
| 6327 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 6328 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6329 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6330 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 6331 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
| 6332 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 6333 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 6334 | /* If our NportID changed, we need to ensure all |
| 6335 | * remaining NPORTs get unreg_login'ed so we can |
| 6336 | * issue unreg_vpi. |
| 6337 | */ |
| 6338 | list_for_each_entry_safe(np, next_np, |
| 6339 | &vport->fc_nodes, nlp_listp) { |
| 6340 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 6341 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 6342 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 6343 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6344 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6345 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6346 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6347 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6348 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 6349 | lpfc_cleanup_pending_mbox(vport); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6350 | lpfc_mbx_unreg_vpi(vport); |
| 6351 | spin_lock_irq(shost->host_lock); |
| 6352 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 6353 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6354 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6355 | else |
| 6356 | vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6357 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6358 | } |
| 6359 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6360 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
| 6361 | lpfc_issue_init_vpi(vport); |
| 6362 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6363 | lpfc_register_new_vport(phba, vport, ndlp); |
| 6364 | else |
| 6365 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6366 | goto out; |
| 6367 | fdisc_failed: |
| 6368 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6369 | /* Cancel discovery timer */ |
| 6370 | lpfc_can_disctmo(vport); |
| 6371 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6372 | out: |
| 6373 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6374 | } |
| 6375 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6376 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6377 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6378 | * @vport: pointer to a virtual N_Port data structure. |
| 6379 | * @ndlp: pointer to a node-list data structure. |
| 6380 | * @retry: number of retries to the command IOCB. |
| 6381 | * |
| 6382 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 6383 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 6384 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 6385 | * IOCB will be sent off HBA at any given time. |
| 6386 | * |
| 6387 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6388 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6389 | * will be stored into the context1 field of the IOCB for the completion |
| 6390 | * callback function to the FDISC ELS command. |
| 6391 | * |
| 6392 | * Return code |
| 6393 | * 0 - Successfully issued fdisc iocb command |
| 6394 | * 1 - Failed to issue fdisc iocb command |
| 6395 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6396 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6397 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 6398 | uint8_t retry) |
| 6399 | { |
| 6400 | struct lpfc_hba *phba = vport->phba; |
| 6401 | IOCB_t *icmd; |
| 6402 | struct lpfc_iocbq *elsiocb; |
| 6403 | struct serv_parm *sp; |
| 6404 | uint8_t *pcmd; |
| 6405 | uint16_t cmdsize; |
| 6406 | int did = ndlp->nlp_DID; |
| 6407 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6408 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6409 | vport->port_state = LPFC_FDISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6410 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 6411 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 6412 | ELS_CMD_FDISC); |
| 6413 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6414 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6415 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6416 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6417 | return 1; |
| 6418 | } |
| 6419 | |
| 6420 | icmd = &elsiocb->iocb; |
| 6421 | icmd->un.elsreq64.myID = 0; |
| 6422 | icmd->un.elsreq64.fl = 1; |
| 6423 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6424 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 6425 | /* FDISC needs to be 1 for WQE VPI */ |
| 6426 | elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1; |
| 6427 | elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ; |
| 6428 | /* Set the ulpContext to the vpi */ |
| 6429 | elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base; |
| 6430 | } else { |
| 6431 | /* For FDISC, Let FDISC rsp set the NPortID for this VPI */ |
| 6432 | icmd->ulpCt_h = 1; |
| 6433 | icmd->ulpCt_l = 0; |
| 6434 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6435 | |
| 6436 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6437 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 6438 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 6439 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 6440 | sp = (struct serv_parm *) pcmd; |
| 6441 | /* Setup CSPs accordingly for Fabric */ |
| 6442 | sp->cmn.e_d_tov = 0; |
| 6443 | sp->cmn.w2.r_a_tov = 0; |
| 6444 | sp->cls1.classValid = 0; |
| 6445 | sp->cls2.seqDelivery = 1; |
| 6446 | sp->cls3.seqDelivery = 1; |
| 6447 | |
| 6448 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 6449 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 6450 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 6451 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 6452 | memcpy(pcmd, &vport->fc_portname, 8); |
| 6453 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6454 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6455 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 6456 | |
| 6457 | lpfc_set_disctmo(vport); |
| 6458 | |
| 6459 | phba->fc_stat.elsXmitFDISC++; |
| 6460 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 6461 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6462 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6463 | "Issue FDISC: did:x%x", |
| 6464 | did, 0, 0); |
| 6465 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6466 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 6467 | if (rc == IOCB_ERROR) { |
| 6468 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6469 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6470 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6471 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6472 | return 1; |
| 6473 | } |
| 6474 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6475 | return 0; |
| 6476 | } |
| 6477 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6478 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6479 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6480 | * @phba: pointer to lpfc hba data structure. |
| 6481 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6482 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6483 | * |
| 6484 | * This routine is the completion callback function to the issuing of a LOGO |
| 6485 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 6486 | * reference count held on ndlp for this completion function, indicating that |
| 6487 | * the reference to the ndlp is no long needed. Note that the |
| 6488 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 6489 | * callback function and an additional explicit ndlp reference decrementation |
| 6490 | * will trigger the actual release of the ndlp. |
| 6491 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6492 | static void |
| 6493 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6494 | struct lpfc_iocbq *rspiocb) |
| 6495 | { |
| 6496 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6497 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6498 | struct lpfc_nodelist *ndlp; |
| 6499 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6500 | |
| 6501 | irsp = &rspiocb->iocb; |
| 6502 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6503 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 6504 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6505 | |
| 6506 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6507 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6508 | |
| 6509 | /* Trigger the release of the ndlp after logo */ |
| 6510 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6511 | } |
| 6512 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6513 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6514 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6515 | * @vport: pointer to a virtual N_Port data structure. |
| 6516 | * @ndlp: pointer to a node-list data structure. |
| 6517 | * |
| 6518 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 6519 | * |
| 6520 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6521 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6522 | * will be stored into the context1 field of the IOCB for the completion |
| 6523 | * callback function to the LOGO ELS command. |
| 6524 | * |
| 6525 | * Return codes |
| 6526 | * 0 - Successfully issued logo off the @vport |
| 6527 | * 1 - Failed to issue logo off the @vport |
| 6528 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6529 | int |
| 6530 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 6531 | { |
| 6532 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6533 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6534 | IOCB_t *icmd; |
| 6535 | struct lpfc_iocbq *elsiocb; |
| 6536 | uint8_t *pcmd; |
| 6537 | uint16_t cmdsize; |
| 6538 | |
| 6539 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 6540 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 6541 | ELS_CMD_LOGO); |
| 6542 | if (!elsiocb) |
| 6543 | return 1; |
| 6544 | |
| 6545 | icmd = &elsiocb->iocb; |
| 6546 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6547 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 6548 | pcmd += sizeof(uint32_t); |
| 6549 | |
| 6550 | /* Fill in LOGO payload */ |
| 6551 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 6552 | pcmd += sizeof(uint32_t); |
| 6553 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 6554 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6555 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6556 | "Issue LOGO npiv did:x%x flg:x%x", |
| 6557 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 6558 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6559 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 6560 | spin_lock_irq(shost->host_lock); |
| 6561 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 6562 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6563 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 6564 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6565 | spin_lock_irq(shost->host_lock); |
| 6566 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 6567 | spin_unlock_irq(shost->host_lock); |
| 6568 | lpfc_els_free_iocb(phba, elsiocb); |
| 6569 | return 1; |
| 6570 | } |
| 6571 | return 0; |
| 6572 | } |
| 6573 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6574 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6575 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6576 | * @ptr: holder for the timer function associated data. |
| 6577 | * |
| 6578 | * This routine is invoked by the fabric iocb block timer after |
| 6579 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 6580 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 6581 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 6582 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 6583 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 6584 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6585 | void |
| 6586 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 6587 | { |
| 6588 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 6589 | unsigned long iflags; |
| 6590 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6591 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6592 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 6593 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 6594 | if (!tmo_posted) |
| 6595 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 6596 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 6597 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6598 | if (!tmo_posted) |
| 6599 | lpfc_worker_wake_up(phba); |
| 6600 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6601 | } |
| 6602 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6603 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6604 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6605 | * @phba: pointer to lpfc hba data structure. |
| 6606 | * |
| 6607 | * This routine issues one fabric iocb from the driver internal list to |
| 6608 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 6609 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 6610 | * remove one pending fabric iocb from the driver internal list and invokes |
| 6611 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 6612 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6613 | static void |
| 6614 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 6615 | { |
| 6616 | struct lpfc_iocbq *iocb; |
| 6617 | unsigned long iflags; |
| 6618 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6619 | IOCB_t *cmd; |
| 6620 | |
| 6621 | repeat: |
| 6622 | iocb = NULL; |
| 6623 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6624 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6625 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 6626 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 6627 | list); |
| 6628 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6629 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6630 | atomic_inc(&phba->fabric_iocb_count); |
| 6631 | } |
| 6632 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6633 | if (iocb) { |
| 6634 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6635 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6636 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6637 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6638 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6639 | "Fabric sched1: ste:x%x", |
| 6640 | iocb->vport->port_state, 0, 0); |
| 6641 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6642 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6643 | |
| 6644 | if (ret == IOCB_ERROR) { |
| 6645 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6646 | iocb->fabric_iocb_cmpl = NULL; |
| 6647 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6648 | cmd = &iocb->iocb; |
| 6649 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6650 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6651 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 6652 | |
| 6653 | atomic_dec(&phba->fabric_iocb_count); |
| 6654 | goto repeat; |
| 6655 | } |
| 6656 | } |
| 6657 | |
| 6658 | return; |
| 6659 | } |
| 6660 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6661 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6662 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6663 | * @phba: pointer to lpfc hba data structure. |
| 6664 | * |
| 6665 | * This routine unblocks the issuing fabric iocb command. The function |
| 6666 | * will clear the fabric iocb block bit and then invoke the routine |
| 6667 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 6668 | * from the driver internal fabric iocb list. |
| 6669 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6670 | void |
| 6671 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 6672 | { |
| 6673 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6674 | |
| 6675 | lpfc_resume_fabric_iocbs(phba); |
| 6676 | return; |
| 6677 | } |
| 6678 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6679 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6680 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6681 | * @phba: pointer to lpfc hba data structure. |
| 6682 | * |
| 6683 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 6684 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 6685 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 6686 | * fabric iocb will be issued out of the HBA. |
| 6687 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6688 | static void |
| 6689 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 6690 | { |
| 6691 | int blocked; |
| 6692 | |
| 6693 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6694 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6695 | if (!blocked) |
| 6696 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); |
| 6697 | |
| 6698 | return; |
| 6699 | } |
| 6700 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6701 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6702 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6703 | * @phba: pointer to lpfc hba data structure. |
| 6704 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6705 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6706 | * |
| 6707 | * This routine is the callback function that is put to the fabric iocb's |
| 6708 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 6709 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 6710 | * function first restores and invokes the original iocb's callback function |
| 6711 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 6712 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 6713 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6714 | static void |
| 6715 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6716 | struct lpfc_iocbq *rspiocb) |
| 6717 | { |
| 6718 | struct ls_rjt stat; |
| 6719 | |
| 6720 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 6721 | BUG(); |
| 6722 | |
| 6723 | switch (rspiocb->iocb.ulpStatus) { |
| 6724 | case IOSTAT_NPORT_RJT: |
| 6725 | case IOSTAT_FABRIC_RJT: |
| 6726 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 6727 | lpfc_block_fabric_iocbs(phba); |
| 6728 | } |
| 6729 | break; |
| 6730 | |
| 6731 | case IOSTAT_NPORT_BSY: |
| 6732 | case IOSTAT_FABRIC_BSY: |
| 6733 | lpfc_block_fabric_iocbs(phba); |
| 6734 | break; |
| 6735 | |
| 6736 | case IOSTAT_LS_RJT: |
| 6737 | stat.un.lsRjtError = |
| 6738 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 6739 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 6740 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 6741 | lpfc_block_fabric_iocbs(phba); |
| 6742 | break; |
| 6743 | } |
| 6744 | |
| 6745 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 6746 | BUG(); |
| 6747 | |
| 6748 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 6749 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 6750 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6751 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 6752 | |
| 6753 | atomic_dec(&phba->fabric_iocb_count); |
| 6754 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6755 | /* Post any pending iocbs to HBA */ |
| 6756 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6757 | } |
| 6758 | } |
| 6759 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6760 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6761 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6762 | * @phba: pointer to lpfc hba data structure. |
| 6763 | * @iocb: pointer to lpfc command iocb data structure. |
| 6764 | * |
| 6765 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 6766 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 6767 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 6768 | * any given time. As such, this function will first check to see whether there |
| 6769 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 6770 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 6771 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 6772 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 6773 | * |
| 6774 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 6775 | * order. The problem is caused by the construction of the "ready" boolen does |
| 6776 | * not include the condition that the internal fabric IOCB list is empty. As |
| 6777 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 6778 | * ahead of the fabric IOCBs in the internal list. |
| 6779 | * |
| 6780 | * Return code |
| 6781 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 6782 | * IOCB_ERROR - failed to issue fabric iocb |
| 6783 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6784 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6785 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 6786 | { |
| 6787 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6788 | int ready; |
| 6789 | int ret; |
| 6790 | |
| 6791 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 6792 | BUG(); |
| 6793 | |
| 6794 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6795 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 6796 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6797 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6798 | if (ready) |
| 6799 | /* Increment fabric iocb count to hold the position */ |
| 6800 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6801 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6802 | if (ready) { |
| 6803 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6804 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6805 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6806 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6807 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6808 | "Fabric sched2: ste:x%x", |
| 6809 | iocb->vport->port_state, 0, 0); |
| 6810 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6811 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6812 | |
| 6813 | if (ret == IOCB_ERROR) { |
| 6814 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6815 | iocb->fabric_iocb_cmpl = NULL; |
| 6816 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6817 | atomic_dec(&phba->fabric_iocb_count); |
| 6818 | } |
| 6819 | } else { |
| 6820 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6821 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 6822 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6823 | ret = IOCB_SUCCESS; |
| 6824 | } |
| 6825 | return ret; |
| 6826 | } |
| 6827 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6828 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6829 | * 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] | 6830 | * @vport: pointer to a virtual N_Port data structure. |
| 6831 | * |
| 6832 | * This routine aborts all the IOCBs associated with a @vport from the |
| 6833 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6834 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6835 | * list, removes each IOCB associated with the @vport off the list, set the |
| 6836 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6837 | * associated with the IOCB. |
| 6838 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6839 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6840 | { |
| 6841 | LIST_HEAD(completions); |
| 6842 | struct lpfc_hba *phba = vport->phba; |
| 6843 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6844 | |
| 6845 | spin_lock_irq(&phba->hbalock); |
| 6846 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6847 | list) { |
| 6848 | |
| 6849 | if (piocb->vport != vport) |
| 6850 | continue; |
| 6851 | |
| 6852 | list_move_tail(&piocb->list, &completions); |
| 6853 | } |
| 6854 | spin_unlock_irq(&phba->hbalock); |
| 6855 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6856 | /* Cancel all the IOCBs from the completions list */ |
| 6857 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6858 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6859 | } |
| 6860 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6861 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6862 | * 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] | 6863 | * @ndlp: pointer to a node-list data structure. |
| 6864 | * |
| 6865 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 6866 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6867 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6868 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 6869 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6870 | * associated with the IOCB. |
| 6871 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6872 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 6873 | { |
| 6874 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6875 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6876 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6877 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6878 | |
| 6879 | spin_lock_irq(&phba->hbalock); |
| 6880 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6881 | list) { |
| 6882 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 6883 | |
| 6884 | list_move_tail(&piocb->list, &completions); |
| 6885 | } |
| 6886 | } |
| 6887 | spin_unlock_irq(&phba->hbalock); |
| 6888 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6889 | /* Cancel all the IOCBs from the completions list */ |
| 6890 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6891 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6892 | } |
| 6893 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6894 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6895 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6896 | * @phba: pointer to lpfc hba data structure. |
| 6897 | * |
| 6898 | * This routine aborts all the IOCBs currently on the driver internal |
| 6899 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 6900 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 6901 | * list, removes IOCBs off the list, set the status feild to |
| 6902 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 6903 | * the IOCB. |
| 6904 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6905 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 6906 | { |
| 6907 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6908 | |
| 6909 | spin_lock_irq(&phba->hbalock); |
| 6910 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 6911 | spin_unlock_irq(&phba->hbalock); |
| 6912 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6913 | /* Cancel all the IOCBs from the completions list */ |
| 6914 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6915 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6916 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6917 | |
| 6918 | /** |
| 6919 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 6920 | * @phba: pointer to lpfc hba data structure. |
| 6921 | * @axri: pointer to the els xri abort wcqe structure. |
| 6922 | * |
| 6923 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 6924 | * ELS aborted xri. |
| 6925 | **/ |
| 6926 | void |
| 6927 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 6928 | struct sli4_wcqe_xri_aborted *axri) |
| 6929 | { |
| 6930 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
| 6931 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 6932 | unsigned long iflag = 0; |
| 6933 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 6934 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 6935 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6936 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 6937 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 6938 | if (sglq_entry->sli4_xritag == xri) { |
| 6939 | list_del(&sglq_entry->list); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6940 | list_add_tail(&sglq_entry->list, |
| 6941 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 6942 | sglq_entry->state = SGL_FREED; |
| 6943 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6944 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 6945 | return; |
| 6946 | } |
| 6947 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 6948 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 6949 | sglq_entry = __lpfc_get_active_sglq(phba, xri); |
| 6950 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { |
| 6951 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 6952 | return; |
| 6953 | } |
| 6954 | sglq_entry->state = SGL_XRI_ABORTED; |
| 6955 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 6956 | return; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6957 | } |