| 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 | } |
| 587 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 588 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 589 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 590 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 591 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 592 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 593 | /* |
| 594 | * If VPI is unreged, driver need to do INIT_VPI |
| 595 | * before re-registering |
| 596 | */ |
| 597 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 598 | spin_lock_irq(shost->host_lock); |
| 599 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 600 | spin_unlock_irq(shost->host_lock); |
| 601 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 602 | } |
| 603 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 604 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 605 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
| 606 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 607 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 608 | lpfc_register_new_vport(phba, vport, ndlp); |
| 609 | else |
| 610 | lpfc_issue_fabric_reglogin(vport); |
| 611 | } else { |
| 612 | ndlp->nlp_type |= NLP_FABRIC; |
| 613 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 614 | if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) && |
| 615 | (vport->vpi_state & LPFC_VPI_REGISTERED)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 616 | lpfc_start_fdiscs(phba); |
| 617 | lpfc_do_scr_ns_plogi(phba, vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 618 | } else if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 619 | lpfc_issue_init_vpi(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 620 | else |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 621 | lpfc_issue_reg_vfi(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 622 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 623 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 624 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 625 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 626 | * 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] | 627 | * @vport: pointer to a host virtual N_Port data structure. |
| 628 | * @ndlp: pointer to a node-list data structure. |
| 629 | * @sp: pointer to service parameter data structure. |
| 630 | * |
| 631 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 632 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 633 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 634 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 635 | * the received N_Port Name lexicographically, this node shall assign local |
| 636 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 637 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 638 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 639 | * N_Port IDs. |
| 640 | * |
| 641 | * Return code |
| 642 | * 0 - Success |
| 643 | * -ENXIO - Fail |
| 644 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 645 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 646 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 647 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 648 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 649 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 650 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 651 | LPFC_MBOXQ_t *mbox; |
| 652 | int rc; |
| 653 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 654 | spin_lock_irq(shost->host_lock); |
| 655 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 656 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 657 | |
| 658 | phba->fc_edtov = FF_DEF_EDTOV; |
| 659 | phba->fc_ratov = FF_DEF_RATOV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 660 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 661 | sizeof(vport->fc_portname)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 662 | if (rc >= 0) { |
| 663 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 664 | spin_lock_irq(shost->host_lock); |
| 665 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 666 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 667 | |
| 668 | /* |
| 669 | * N_Port ID cannot be 0, set our to LocalID the other |
| 670 | * side will be RemoteID. |
| 671 | */ |
| 672 | |
| 673 | /* not equal */ |
| 674 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 675 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 676 | |
| 677 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 678 | if (!mbox) |
| 679 | goto fail; |
| 680 | |
| 681 | lpfc_config_link(phba, mbox); |
| 682 | |
| 683 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 684 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 685 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 686 | if (rc == MBX_NOT_FINISHED) { |
| 687 | mempool_free(mbox, phba->mbox_mem_pool); |
| 688 | goto fail; |
| 689 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 690 | /* Decrement ndlp reference count indicating that ndlp can be |
| 691 | * safely released when other references to it are done. |
| 692 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 693 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 694 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 695 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 696 | if (!ndlp) { |
| 697 | /* |
| 698 | * Cannot find existing Fabric ndlp, so allocate a |
| 699 | * new one |
| 700 | */ |
| 701 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 702 | if (!ndlp) |
| 703 | goto fail; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 704 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 705 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 706 | ndlp = lpfc_enable_node(vport, ndlp, |
| 707 | NLP_STE_UNUSED_NODE); |
| 708 | if(!ndlp) |
| 709 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 713 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 714 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 715 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 716 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 717 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 718 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 719 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 720 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 721 | } else |
| 722 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 723 | * count indicating that ndlp can be released when other |
| 724 | * references to it are done. |
| 725 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 726 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 727 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 728 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 729 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 730 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 731 | spin_lock_irq(shost->host_lock); |
| 732 | vport->fc_flag |= FC_PT2PT; |
| 733 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 734 | |
| 735 | /* Start discovery - this should just do CLEAR_LA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 736 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 737 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 738 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 739 | return -ENXIO; |
| 740 | } |
| 741 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 742 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 743 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 744 | * @phba: pointer to lpfc hba data structure. |
| 745 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 746 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 747 | * |
| 748 | * This routine is the top-level completion callback function for issuing |
| 749 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 750 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 751 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 752 | * returning 1), the command IOCB will be released and function returned. |
| 753 | * If the retry attempt has been given up (possibly reach the maximum |
| 754 | * number of retries), one additional decrement of ndlp reference shall be |
| 755 | * invoked before going out after releasing the command IOCB. This will |
| 756 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 757 | * invoke one decrement of ndlp reference count). If no error reported in |
| 758 | * the IOCB status, the command Port ID field is used to determine whether |
| 759 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 760 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 761 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 762 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 763 | * specific topology completion conditions. |
| 764 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 765 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 766 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 767 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 768 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 769 | struct lpfc_vport *vport = cmdiocb->vport; |
| 770 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 771 | IOCB_t *irsp = &rspiocb->iocb; |
| 772 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 773 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 774 | struct serv_parm *sp; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 775 | uint16_t fcf_index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 776 | int rc; |
| 777 | |
| 778 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 779 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 780 | /* One additional decrement on node reference count to |
| 781 | * trigger the release of the node |
| 782 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 783 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 784 | goto out; |
| 785 | } |
| 786 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 787 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 788 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 789 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 790 | vport->port_state); |
| 791 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 792 | if (irsp->ulpStatus) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 793 | /* |
| 794 | * In case of FIP mode, perform round robin FCF failover |
| 795 | * due to new FCF discovery |
| 796 | */ |
| 797 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && |
| 798 | (phba->fcf.fcf_flag & FCF_DISCOVERY)) { |
| 799 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
| 800 | "2611 FLOGI failed on registered " |
| 801 | "FCF record fcf_index:%d, trying " |
| 802 | "to perform round robin failover\n", |
| 803 | phba->fcf.current_rec.fcf_indx); |
| 804 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
| 805 | if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) { |
| 806 | /* |
| 807 | * Exhausted the eligible FCF record list, |
| 808 | * fail through to retry FLOGI on current |
| 809 | * FCF record. |
| 810 | */ |
| 811 | lpfc_printf_log(phba, KERN_WARNING, |
| 812 | LOG_FIP | LOG_ELS, |
| 813 | "2760 FLOGI exhausted FCF " |
| 814 | "round robin failover list, " |
| 815 | "retry FLOGI on the current " |
| 816 | "registered FCF index:%d\n", |
| 817 | phba->fcf.current_rec.fcf_indx); |
| 818 | spin_lock_irq(&phba->hbalock); |
| 819 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
| 820 | spin_unlock_irq(&phba->hbalock); |
| 821 | } else { |
| 822 | rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, |
| 823 | fcf_index); |
| 824 | if (rc) { |
| 825 | lpfc_printf_log(phba, KERN_WARNING, |
| 826 | LOG_FIP | LOG_ELS, |
| 827 | "2761 FLOGI round " |
| 828 | "robin FCF failover " |
| 829 | "read FCF failed " |
| 830 | "rc:x%x, fcf_index:" |
| 831 | "%d\n", rc, |
| 832 | phba->fcf.current_rec.fcf_indx); |
| 833 | spin_lock_irq(&phba->hbalock); |
| 834 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
| 835 | spin_unlock_irq(&phba->hbalock); |
| 836 | } else |
| 837 | goto out; |
| 838 | } |
| 839 | } |
| 840 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 841 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 842 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 843 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 844 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 845 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 846 | spin_lock_irq(shost->host_lock); |
| 847 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 848 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 849 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 850 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 851 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 852 | * alpa map would take too long otherwise. |
| 853 | */ |
| 854 | if (phba->alpa_map[0] == 0) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 855 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | /* FLOGI failure */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 859 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 860 | "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 861 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 862 | irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 863 | goto flogifail; |
| 864 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 865 | spin_lock_irq(shost->host_lock); |
| 866 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame^] | 867 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 868 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 869 | |
| 870 | /* |
| 871 | * The FLogI succeeded. Sync the data for the CPU before |
| 872 | * accessing it. |
| 873 | */ |
| 874 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 875 | |
| 876 | sp = prsp->virt + sizeof(uint32_t); |
| 877 | |
| 878 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 879 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 880 | "0101 FLOGI completes successfully " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 881 | "Data: x%x x%x x%x x%x\n", |
| 882 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
| 883 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 884 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 885 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 886 | /* |
| 887 | * If Common Service Parameters indicate Nport |
| 888 | * we are point to point, if Fport we are Fabric. |
| 889 | */ |
| 890 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 891 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 892 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 893 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 894 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 895 | if (!rc) { |
| 896 | /* Mark the FCF discovery process done */ |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 897 | if (phba->hba_flag & HBA_FIP_SUPPORT) |
| 898 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | |
| 899 | LOG_ELS, |
| 900 | "2769 FLOGI successful on FCF " |
| 901 | "record: current_fcf_index:" |
| 902 | "x%x, terminate FCF round " |
| 903 | "robin failover process\n", |
| 904 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 905 | spin_lock_irq(&phba->hbalock); |
| 906 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
| 907 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 908 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 909 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | flogifail: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 913 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 914 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 915 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 916 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 917 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 918 | |
| 919 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 920 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 921 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 922 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && |
| 923 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) && |
| 924 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 925 | /* If FLOGI failed enable link interrupt. */ |
| 926 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 927 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 928 | out: |
| 929 | lpfc_els_free_iocb(phba, cmdiocb); |
| 930 | } |
| 931 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 932 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 933 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 934 | * @vport: pointer to a host virtual N_Port data structure. |
| 935 | * @ndlp: pointer to a node-list data structure. |
| 936 | * @retry: number of retries to the command IOCB. |
| 937 | * |
| 938 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 939 | * for a @vport. The initiator service parameters are put into the payload |
| 940 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 941 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 942 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 943 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 944 | * |
| 945 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 946 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 947 | * will be stored into the context1 field of the IOCB for the completion |
| 948 | * callback function to the FLOGI ELS command. |
| 949 | * |
| 950 | * Return code |
| 951 | * 0 - successfully issued flogi iocb for @vport |
| 952 | * 1 - failed to issue flogi iocb for @vport |
| 953 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 954 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 955 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 956 | uint8_t retry) |
| 957 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 958 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 959 | struct serv_parm *sp; |
| 960 | IOCB_t *icmd; |
| 961 | struct lpfc_iocbq *elsiocb; |
| 962 | struct lpfc_sli_ring *pring; |
| 963 | uint8_t *pcmd; |
| 964 | uint16_t cmdsize; |
| 965 | uint32_t tmo; |
| 966 | int rc; |
| 967 | |
| 968 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 969 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 970 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 971 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 972 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 973 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 974 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 975 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 976 | |
| 977 | icmd = &elsiocb->iocb; |
| 978 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 979 | |
| 980 | /* For FLOGI request, remainder of payload is service parameters */ |
| 981 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 982 | pcmd += sizeof(uint32_t); |
| 983 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 984 | sp = (struct serv_parm *) pcmd; |
| 985 | |
| 986 | /* Setup CSPs accordingly for Fabric */ |
| 987 | sp->cmn.e_d_tov = 0; |
| 988 | sp->cmn.w2.r_a_tov = 0; |
| 989 | sp->cls1.classValid = 0; |
| 990 | sp->cls2.seqDelivery = 1; |
| 991 | sp->cls3.seqDelivery = 1; |
| 992 | if (sp->cmn.fcphLow < FC_PH3) |
| 993 | sp->cmn.fcphLow = FC_PH3; |
| 994 | if (sp->cmn.fcphHigh < FC_PH3) |
| 995 | sp->cmn.fcphHigh = FC_PH3; |
| 996 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 997 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 998 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 999 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 1000 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 1001 | /* Set the fcfi to the fcfi we registered with */ |
| 1002 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 1003 | } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1004 | sp->cmn.request_multiple_Nport = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1005 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 1006 | icmd->ulpCt_h = 1; |
| 1007 | icmd->ulpCt_l = 0; |
| 1008 | } |
| 1009 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1010 | if (phba->fc_topology != TOPOLOGY_LOOP) { |
| 1011 | icmd->un.elsreq64.myID = 0; |
| 1012 | icmd->un.elsreq64.fl = 1; |
| 1013 | } |
| 1014 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1015 | tmo = phba->fc_ratov; |
| 1016 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1017 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1018 | phba->fc_ratov = tmo; |
| 1019 | |
| 1020 | phba->fc_stat.elsXmitFLOGI++; |
| 1021 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1022 | |
| 1023 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1024 | "Issue FLOGI: opt:x%x", |
| 1025 | phba->sli3_options, 0, 0); |
| 1026 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1027 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1028 | if (rc == IOCB_ERROR) { |
| 1029 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1030 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1031 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1032 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1033 | } |
| 1034 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1035 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1036 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1037 | * @phba: pointer to lpfc hba data structure. |
| 1038 | * |
| 1039 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 1040 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 1041 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 1042 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 1043 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 1044 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 1045 | * |
| 1046 | * Return code |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 1047 | * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1048 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1049 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1050 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1051 | { |
| 1052 | struct lpfc_sli_ring *pring; |
| 1053 | struct lpfc_iocbq *iocb, *next_iocb; |
| 1054 | struct lpfc_nodelist *ndlp; |
| 1055 | IOCB_t *icmd; |
| 1056 | |
| 1057 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 1058 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1059 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 1060 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1061 | |
| 1062 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 1063 | |
| 1064 | /* |
| 1065 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 1066 | * searching for. |
| 1067 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1068 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1069 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 1070 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1071 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR && |
| 1072 | icmd->un.elsreq64.bdl.ulpIoTag32) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1073 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1074 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 1075 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1076 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1077 | } |
| 1078 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1079 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1080 | |
| 1081 | return 0; |
| 1082 | } |
| 1083 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1084 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1085 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1086 | * @vport: pointer to a host virtual N_Port data structure. |
| 1087 | * |
| 1088 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 1089 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1090 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1091 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1092 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 1093 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 1094 | * @vport. |
| 1095 | * |
| 1096 | * Return code |
| 1097 | * 0 - failed to issue initial flogi for @vport |
| 1098 | * 1 - successfully issued initial flogi for @vport |
| 1099 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1100 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1101 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1102 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1103 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1104 | struct lpfc_nodelist *ndlp; |
| 1105 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1106 | vport->port_state = LPFC_FLOGI; |
| 1107 | lpfc_set_disctmo(vport); |
| 1108 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1109 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1110 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1111 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1112 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1113 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1114 | if (!ndlp) |
| 1115 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1116 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1117 | /* Set the node type */ |
| 1118 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1119 | /* Put ndlp onto node list */ |
| 1120 | lpfc_enqueue_node(vport, ndlp); |
| 1121 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1122 | /* re-setup ndlp without removing from node list */ |
| 1123 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1124 | if (!ndlp) |
| 1125 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1126 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1127 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1128 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1129 | /* This decrement of reference count to node shall kick off |
| 1130 | * the release of the node. |
| 1131 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1132 | lpfc_nlp_put(ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1133 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1134 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1135 | } |
| 1136 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1137 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1138 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1139 | * @vport: pointer to a host virtual N_Port data structure. |
| 1140 | * |
| 1141 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 1142 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1143 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1144 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1145 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 1146 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 1147 | * @vport. |
| 1148 | * |
| 1149 | * Return code |
| 1150 | * 0 - failed to issue initial fdisc for @vport |
| 1151 | * 1 - successfully issued initial fdisc for @vport |
| 1152 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1153 | int |
| 1154 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 1155 | { |
| 1156 | struct lpfc_hba *phba = vport->phba; |
| 1157 | struct lpfc_nodelist *ndlp; |
| 1158 | |
| 1159 | /* First look for the Fabric ndlp */ |
| 1160 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1161 | if (!ndlp) { |
| 1162 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 1163 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1164 | if (!ndlp) |
| 1165 | return 0; |
| 1166 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1167 | /* Put ndlp onto node list */ |
| 1168 | lpfc_enqueue_node(vport, ndlp); |
| 1169 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1170 | /* re-setup ndlp without removing from node list */ |
| 1171 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1172 | if (!ndlp) |
| 1173 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1174 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1175 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1176 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1177 | /* decrement node reference count to trigger the release of |
| 1178 | * the node. |
| 1179 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1180 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1181 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1182 | } |
| 1183 | return 1; |
| 1184 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1185 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1186 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1187 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1188 | * @vport: pointer to a host virtual N_Port data structure. |
| 1189 | * |
| 1190 | * This routine checks whether there are more remaining Port Logins |
| 1191 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1192 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1193 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1194 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1195 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1196 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1197 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1198 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1199 | { |
| 1200 | int sentplogi; |
| 1201 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1202 | if (vport->num_disc_nodes) |
| 1203 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1204 | |
| 1205 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1206 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1207 | "0232 Continue discovery with %d PLOGIs to go " |
| 1208 | "Data: x%x x%x x%x\n", |
| 1209 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1210 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1211 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1212 | if (vport->fc_flag & FC_NLP_MORE) |
| 1213 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 1214 | sentplogi = lpfc_els_disc_plogi(vport); |
| 1215 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1216 | return; |
| 1217 | } |
| 1218 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1219 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1220 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1221 | * @phba: pointer to lpfc hba data structure. |
| 1222 | * @prsp: pointer to response IOCB payload. |
| 1223 | * @ndlp: pointer to a node-list data structure. |
| 1224 | * |
| 1225 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1226 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1227 | * The following cases are considered N_Port confirmed: |
| 1228 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1229 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1230 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1231 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1232 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1233 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1234 | * on that node to release the RPI associated with the node; 2) if there is |
| 1235 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1236 | * into, a new node shall be allocated (or activated). In either case, the |
| 1237 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1238 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1239 | * its pointer returned as the confirmed node. |
| 1240 | * |
| 1241 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1242 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1243 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1244 | * into an inactive state on the vport node list and the vport node list |
| 1245 | * management algorithm does not allow two node with a same DID. |
| 1246 | * |
| 1247 | * Return code |
| 1248 | * pointer to the PLOGI N_Port @ndlp |
| 1249 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1250 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1251 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1252 | struct lpfc_nodelist *ndlp) |
| 1253 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1254 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1255 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1256 | struct lpfc_rport_data *rdata; |
| 1257 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1258 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1259 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1260 | uint32_t rc, keepDID = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1261 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1262 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1263 | * by WWPN. Just return the ndlp that was given to us. |
| 1264 | */ |
| 1265 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1266 | return ndlp; |
| 1267 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1268 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1269 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1270 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1271 | /* 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] | 1272 | * we have for that ndlp. If not, we have some work to do. |
| 1273 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1274 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1275 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1276 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1277 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1278 | |
| 1279 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1280 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1281 | sizeof(struct lpfc_name)); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1282 | if (!rc) |
| 1283 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1284 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
| 1285 | if (!new_ndlp) |
| 1286 | return ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1287 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1288 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1289 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1290 | sizeof(struct lpfc_name)); |
| 1291 | if (!rc) |
| 1292 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1293 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1294 | NLP_STE_UNUSED_NODE); |
| 1295 | if (!new_ndlp) |
| 1296 | return ndlp; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1297 | keepDID = new_ndlp->nlp_DID; |
| 1298 | } else |
| 1299 | keepDID = new_ndlp->nlp_DID; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1300 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1301 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1302 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1303 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1304 | |
| 1305 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) |
| 1306 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 1307 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 1308 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1309 | /* 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] | 1310 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1311 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1312 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1313 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1314 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1315 | * to put ndlp on UNUSED list and try to free it. |
| 1316 | */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1317 | |
| 1318 | /* Fix up the rport accordingly */ |
| 1319 | rport = ndlp->rport; |
| 1320 | if (rport) { |
| 1321 | rdata = rport->dd_data; |
| 1322 | if (rdata->pnode == ndlp) { |
| 1323 | lpfc_nlp_put(ndlp); |
| 1324 | ndlp->rport = NULL; |
| 1325 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1326 | new_ndlp->rport = rport; |
| 1327 | } |
| 1328 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1329 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1330 | /* We shall actually free the ndlp with both nlp_DID and |
| 1331 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1332 | * nodelist never to be used. |
| 1333 | */ |
| 1334 | if (ndlp->nlp_DID == 0) { |
| 1335 | spin_lock_irq(&phba->ndlp_lock); |
| 1336 | NLP_SET_FREE_REQ(ndlp); |
| 1337 | spin_unlock_irq(&phba->ndlp_lock); |
| 1338 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1339 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1340 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1341 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1342 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1343 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1344 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1345 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1346 | /* Two ndlps cannot have the same did */ |
| 1347 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1348 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1349 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1350 | return new_ndlp; |
| 1351 | } |
| 1352 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1353 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1354 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1355 | * @vport: pointer to a host virtual N_Port data structure. |
| 1356 | * |
| 1357 | * This routine checks whether more Registration State Change |
| 1358 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1359 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1360 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1361 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1362 | * handling the RSCNs. |
| 1363 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1364 | void |
| 1365 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1366 | { |
| 1367 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1368 | |
| 1369 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1370 | /* |
| 1371 | * Check to see if more RSCNs came in while we were |
| 1372 | * processing this one. |
| 1373 | */ |
| 1374 | if (vport->fc_rscn_id_cnt || |
| 1375 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1376 | lpfc_els_handle_rscn(vport); |
| 1377 | else { |
| 1378 | spin_lock_irq(shost->host_lock); |
| 1379 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1380 | spin_unlock_irq(shost->host_lock); |
| 1381 | } |
| 1382 | } |
| 1383 | } |
| 1384 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1385 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1386 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1387 | * @phba: pointer to lpfc hba data structure. |
| 1388 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1389 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1390 | * |
| 1391 | * This routine is the completion callback function for issuing the Port |
| 1392 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1393 | * ndlp on the vport node list that matches the remote node ID from the |
| 1394 | * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply |
| 1395 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1396 | * checked for error conditons. If there is error status reported, PLOGI |
| 1397 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1398 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1399 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1400 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1401 | * there are additional N_Port nodes with the vport that need to perform |
| 1402 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1403 | * PLOGIs. |
| 1404 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1405 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1406 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1407 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1408 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1409 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1410 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1411 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1412 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1413 | struct lpfc_dmabuf *prsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1414 | int disc, rc, did, type; |
| 1415 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1416 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1417 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1418 | |
| 1419 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1420 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1421 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1422 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1423 | irsp->un.elsreq64.remoteID); |
| 1424 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1425 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1426 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1427 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1428 | "0136 PLOGI completes to NPort x%x " |
| 1429 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1430 | irsp->un.elsreq64.remoteID, |
| 1431 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1432 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1433 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1434 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1435 | |
| 1436 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1437 | * is being used during discovery. |
| 1438 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1439 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1440 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1441 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1442 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1443 | rc = 0; |
| 1444 | |
| 1445 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1446 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1447 | "0102 PLOGI completes to NPort x%x " |
| 1448 | "Data: x%x x%x x%x x%x x%x\n", |
| 1449 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1450 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1451 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1452 | if (lpfc_els_chk_latt(vport)) { |
| 1453 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1454 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1455 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1456 | goto out; |
| 1457 | } |
| 1458 | |
| 1459 | /* ndlp could be freed in DSM, save these values now */ |
| 1460 | type = ndlp->nlp_type; |
| 1461 | did = ndlp->nlp_DID; |
| 1462 | |
| 1463 | if (irsp->ulpStatus) { |
| 1464 | /* Check for retry */ |
| 1465 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1466 | /* ELS command is being retried */ |
| 1467 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1468 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1469 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1470 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1471 | } |
| 1472 | goto out; |
| 1473 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1474 | /* PLOGI failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1475 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1476 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", |
| 1477 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1478 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1479 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1480 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1481 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1482 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1483 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1484 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1485 | } else { |
| 1486 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1487 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1488 | cmdiocb->context2)->list.next, |
| 1489 | struct lpfc_dmabuf, list); |
| 1490 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1491 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1492 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1493 | } |
| 1494 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1495 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1496 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1497 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1498 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1499 | if (vport->num_disc_nodes == 0) { |
| 1500 | spin_lock_irq(shost->host_lock); |
| 1501 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1502 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1503 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1504 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1505 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1506 | } |
| 1507 | } |
| 1508 | |
| 1509 | out: |
| 1510 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1511 | return; |
| 1512 | } |
| 1513 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1514 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1515 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1516 | * @vport: pointer to a host virtual N_Port data structure. |
| 1517 | * @did: destination port identifier. |
| 1518 | * @retry: number of retries to the command IOCB. |
| 1519 | * |
| 1520 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1521 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1522 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1523 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1524 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1525 | * |
| 1526 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1527 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1528 | * will be stored into the context1 field of the IOCB for the completion |
| 1529 | * callback function to the PLOGI ELS command. |
| 1530 | * |
| 1531 | * Return code |
| 1532 | * 0 - Successfully issued a plogi for @vport |
| 1533 | * 1 - failed to issue a plogi for @vport |
| 1534 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1535 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1536 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1537 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1538 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1539 | struct serv_parm *sp; |
| 1540 | IOCB_t *icmd; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1541 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1542 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1543 | struct lpfc_sli *psli; |
| 1544 | uint8_t *pcmd; |
| 1545 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1546 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1547 | |
| 1548 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1549 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1550 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1551 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1552 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1553 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1554 | /* 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] | 1555 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1556 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1557 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1558 | if (!elsiocb) |
| 1559 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1560 | |
| 1561 | icmd = &elsiocb->iocb; |
| 1562 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1563 | |
| 1564 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1565 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1566 | pcmd += sizeof(uint32_t); |
| 1567 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1568 | sp = (struct serv_parm *) pcmd; |
| 1569 | |
| 1570 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1571 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1572 | |
| 1573 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1574 | sp->cmn.fcphHigh = FC_PH3; |
| 1575 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1576 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1577 | "Issue PLOGI: did:x%x", |
| 1578 | did, 0, 0); |
| 1579 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1580 | phba->fc_stat.elsXmitPLOGI++; |
| 1581 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1582 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1583 | |
| 1584 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1585 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1586 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1587 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1588 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1589 | } |
| 1590 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1591 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1592 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1593 | * @phba: pointer to lpfc hba data structure. |
| 1594 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1595 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1596 | * |
| 1597 | * This routine is the completion callback function for a Process Login |
| 1598 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 1599 | * status. If there is error status reported, PRLI retry shall be attempted |
| 1600 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 1601 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 1602 | * ndlp to mark the PRLI completion. |
| 1603 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1604 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1605 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1606 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1607 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1608 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1609 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1610 | IOCB_t *irsp; |
| 1611 | struct lpfc_sli *psli; |
| 1612 | struct lpfc_nodelist *ndlp; |
| 1613 | |
| 1614 | psli = &phba->sli; |
| 1615 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1616 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1617 | |
| 1618 | irsp = &(rspiocb->iocb); |
| 1619 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1620 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1621 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1622 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1623 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1624 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1625 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 1626 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1627 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1628 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1629 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1630 | "0103 PRLI completes to NPort x%x " |
| 1631 | "Data: x%x x%x x%x x%x\n", |
| 1632 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1633 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1634 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1635 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1636 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1637 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1638 | goto out; |
| 1639 | |
| 1640 | if (irsp->ulpStatus) { |
| 1641 | /* Check for retry */ |
| 1642 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1643 | /* ELS command is being retried */ |
| 1644 | goto out; |
| 1645 | } |
| 1646 | /* PRLI failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1647 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1648 | "2754 PRLI failure DID:%06X Status:x%x/x%x\n", |
| 1649 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1650 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1651 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1652 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1653 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1654 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1655 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1656 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1657 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1658 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1659 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1660 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1661 | out: |
| 1662 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1663 | return; |
| 1664 | } |
| 1665 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1666 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1667 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1668 | * @vport: pointer to a host virtual N_Port data structure. |
| 1669 | * @ndlp: pointer to a node-list data structure. |
| 1670 | * @retry: number of retries to the command IOCB. |
| 1671 | * |
| 1672 | * This routine issues a Process Login (PRLI) ELS command for the |
| 1673 | * @vport. The PRLI service parameters are set up in the payload of the |
| 1674 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 1675 | * is put to the IOCB completion callback func field before invoking the |
| 1676 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 1677 | * |
| 1678 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1679 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1680 | * will be stored into the context1 field of the IOCB for the completion |
| 1681 | * callback function to the PRLI ELS command. |
| 1682 | * |
| 1683 | * Return code |
| 1684 | * 0 - successfully issued prli iocb command for @vport |
| 1685 | * 1 - failed to issue prli iocb command for @vport |
| 1686 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1687 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1688 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1689 | uint8_t retry) |
| 1690 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1691 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1692 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1693 | PRLI *npr; |
| 1694 | IOCB_t *icmd; |
| 1695 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1696 | uint8_t *pcmd; |
| 1697 | uint16_t cmdsize; |
| 1698 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1699 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1700 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1701 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1702 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1703 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1704 | |
| 1705 | icmd = &elsiocb->iocb; |
| 1706 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1707 | |
| 1708 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1709 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1710 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1711 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1712 | |
| 1713 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 1714 | npr = (PRLI *) pcmd; |
| 1715 | /* |
| 1716 | * If our firmware version is 3.20 or later, |
| 1717 | * set the following bits for FC-TAPE support. |
| 1718 | */ |
| 1719 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 1720 | npr->ConfmComplAllowed = 1; |
| 1721 | npr->Retry = 1; |
| 1722 | npr->TaskRetryIdReq = 1; |
| 1723 | } |
| 1724 | npr->estabImagePair = 1; |
| 1725 | npr->readXferRdyDis = 1; |
| 1726 | |
| 1727 | /* For FCP support */ |
| 1728 | npr->prliType = PRLI_FCP_TYPE; |
| 1729 | npr->initiatorFunc = 1; |
| 1730 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1731 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1732 | "Issue PRLI: did:x%x", |
| 1733 | ndlp->nlp_DID, 0, 0); |
| 1734 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1735 | phba->fc_stat.elsXmitPRLI++; |
| 1736 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1737 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1738 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1739 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1740 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 1741 | IOCB_ERROR) { |
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); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1745 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1746 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1747 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1748 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1749 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1750 | } |
| 1751 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1752 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1753 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1754 | * @vport: pointer to a host virtual N_Port data structure. |
| 1755 | * |
| 1756 | * This routine performs Registration State Change Notification (RSCN) |
| 1757 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 1758 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 1759 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 1760 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 1761 | * invoked to check and handle possible more RSCN came in during the period |
| 1762 | * of processing the current ones. |
| 1763 | **/ |
| 1764 | static void |
| 1765 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 1766 | { |
| 1767 | lpfc_can_disctmo(vport); |
| 1768 | |
| 1769 | /* RSCN discovery */ |
| 1770 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 1771 | if (vport->fc_npr_cnt) |
| 1772 | if (lpfc_els_disc_plogi(vport)) |
| 1773 | return; |
| 1774 | |
| 1775 | lpfc_end_rscn(vport); |
| 1776 | } |
| 1777 | |
| 1778 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1779 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1780 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 1781 | * |
| 1782 | * This function is called when the final ADISC is completed during discovery. |
| 1783 | * This function handles clearing link attention or issuing reg_vpi depending |
| 1784 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 1785 | * discovery. |
| 1786 | * This function is called with no locks held. |
| 1787 | **/ |
| 1788 | static void |
| 1789 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 1790 | { |
| 1791 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1792 | struct lpfc_hba *phba = vport->phba; |
| 1793 | |
| 1794 | /* |
| 1795 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 1796 | * and continue discovery. |
| 1797 | */ |
| 1798 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1799 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 1800 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1801 | lpfc_issue_reg_vpi(phba, vport); |
| 1802 | return; |
| 1803 | } |
| 1804 | /* |
| 1805 | * For SLI2, we need to set port_state to READY |
| 1806 | * and continue discovery. |
| 1807 | */ |
| 1808 | if (vport->port_state < LPFC_VPORT_READY) { |
| 1809 | /* If we get here, there is nothing to ADISC */ |
| 1810 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1811 | lpfc_issue_clear_la(phba, vport); |
| 1812 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 1813 | vport->num_disc_nodes = 0; |
| 1814 | /* go thru NPR list, issue ELS PLOGIs */ |
| 1815 | if (vport->fc_npr_cnt) |
| 1816 | lpfc_els_disc_plogi(vport); |
| 1817 | if (!vport->num_disc_nodes) { |
| 1818 | spin_lock_irq(shost->host_lock); |
| 1819 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1820 | spin_unlock_irq(shost->host_lock); |
| 1821 | lpfc_can_disctmo(vport); |
| 1822 | lpfc_end_rscn(vport); |
| 1823 | } |
| 1824 | } |
| 1825 | vport->port_state = LPFC_VPORT_READY; |
| 1826 | } else |
| 1827 | lpfc_rscn_disc(vport); |
| 1828 | } |
| 1829 | |
| 1830 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1831 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1832 | * @vport: pointer to a host virtual N_Port data structure. |
| 1833 | * |
| 1834 | * This routine determines whether there are more ndlps on a @vport |
| 1835 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 1836 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 1837 | * remaining nodes which need to have ADISC sent. |
| 1838 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1839 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1840 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1841 | { |
| 1842 | int sentadisc; |
| 1843 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1844 | if (vport->num_disc_nodes) |
| 1845 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1846 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1847 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1848 | "0210 Continue discovery with %d ADISCs to go " |
| 1849 | "Data: x%x x%x x%x\n", |
| 1850 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 1851 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1852 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1853 | if (vport->fc_flag & FC_NLP_MORE) { |
| 1854 | lpfc_set_disctmo(vport); |
| 1855 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 1856 | sentadisc = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1857 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1858 | if (!vport->num_disc_nodes) |
| 1859 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1860 | return; |
| 1861 | } |
| 1862 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1863 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1864 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1865 | * @phba: pointer to lpfc hba data structure. |
| 1866 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1867 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1868 | * |
| 1869 | * This routine is the completion function for issuing the Address Discover |
| 1870 | * (ADISC) command. It first checks to see whether link went down during |
| 1871 | * the discovery process. If so, the node will be marked as node port |
| 1872 | * recovery for issuing discover IOCB by the link attention handler and |
| 1873 | * exit. Otherwise, the response status is checked. If error was reported |
| 1874 | * in the response status, the ADISC command shall be retried by invoking |
| 1875 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 1876 | * the response status, the state machine is invoked to set transition |
| 1877 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 1878 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1879 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1880 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1881 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1882 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1883 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1884 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1885 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1886 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1887 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1888 | |
| 1889 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1890 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1891 | |
| 1892 | irsp = &(rspiocb->iocb); |
| 1893 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1894 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1895 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1896 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 1897 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1898 | ndlp->nlp_DID); |
| 1899 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1900 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1901 | * is being used during discovery. |
| 1902 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1903 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1904 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1905 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1906 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1907 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1908 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1909 | "0104 ADISC completes to NPort x%x " |
| 1910 | "Data: x%x x%x x%x x%x x%x\n", |
| 1911 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1912 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1913 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1914 | if (lpfc_els_chk_latt(vport)) { |
| 1915 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1916 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1917 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1918 | goto out; |
| 1919 | } |
| 1920 | |
| 1921 | if (irsp->ulpStatus) { |
| 1922 | /* Check for retry */ |
| 1923 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1924 | /* ELS command is being retried */ |
| 1925 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1926 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1927 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1928 | spin_unlock_irq(shost->host_lock); |
| 1929 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1930 | } |
| 1931 | goto out; |
| 1932 | } |
| 1933 | /* ADISC failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1934 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1935 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", |
| 1936 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1937 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1938 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1939 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1940 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1941 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1942 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1943 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1944 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1945 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1946 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1947 | /* Check to see if there are more ADISCs to be sent */ |
| 1948 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1949 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1950 | out: |
| 1951 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1952 | return; |
| 1953 | } |
| 1954 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1955 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1956 | * 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] | 1957 | * @vport: pointer to a virtual N_Port data structure. |
| 1958 | * @ndlp: pointer to a node-list data structure. |
| 1959 | * @retry: number of retries to the command IOCB. |
| 1960 | * |
| 1961 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 1962 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 1963 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 1964 | * to issue the ADISC ELS command. |
| 1965 | * |
| 1966 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1967 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1968 | * will be stored into the context1 field of the IOCB for the completion |
| 1969 | * callback function to the ADISC ELS command. |
| 1970 | * |
| 1971 | * Return code |
| 1972 | * 0 - successfully issued adisc |
| 1973 | * 1 - failed to issue adisc |
| 1974 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1975 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1976 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1977 | uint8_t retry) |
| 1978 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1979 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1980 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1981 | ADISC *ap; |
| 1982 | IOCB_t *icmd; |
| 1983 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1984 | uint8_t *pcmd; |
| 1985 | uint16_t cmdsize; |
| 1986 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1987 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1988 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1989 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1990 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1991 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1992 | |
| 1993 | icmd = &elsiocb->iocb; |
| 1994 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1995 | |
| 1996 | /* For ADISC request, remainder of payload is service parameters */ |
| 1997 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1998 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1999 | |
| 2000 | /* Fill in ADISC payload */ |
| 2001 | ap = (ADISC *) pcmd; |
| 2002 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2003 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2004 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2005 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2006 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2007 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2008 | "Issue ADISC: did:x%x", |
| 2009 | ndlp->nlp_DID, 0, 0); |
| 2010 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2011 | phba->fc_stat.elsXmitADISC++; |
| 2012 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2013 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2014 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2015 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2016 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2017 | IOCB_ERROR) { |
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); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2021 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2022 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2023 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2024 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2025 | } |
| 2026 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2027 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2028 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2029 | * @phba: pointer to lpfc hba data structure. |
| 2030 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2031 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2032 | * |
| 2033 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 2034 | * command. If no error status was reported from the LOGO response, the |
| 2035 | * state machine of the associated ndlp shall be invoked for transition with |
| 2036 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 2037 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 2038 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2039 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2040 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2041 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2042 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2043 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2044 | struct lpfc_vport *vport = ndlp->vport; |
| 2045 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2046 | IOCB_t *irsp; |
| 2047 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2048 | |
| 2049 | psli = &phba->sli; |
| 2050 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2051 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2052 | |
| 2053 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2054 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2055 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2056 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2057 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2058 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2059 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 2060 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2061 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2062 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2063 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2064 | "0105 LOGO completes to NPort x%x " |
| 2065 | "Data: x%x x%x x%x x%x\n", |
| 2066 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2067 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2068 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2069 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2070 | goto out; |
| 2071 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2072 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 2073 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 2074 | * which should abort all outstanding IOs. |
| 2075 | */ |
| 2076 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2077 | NLP_EVT_DEVICE_RM); |
| 2078 | goto out; |
| 2079 | } |
| 2080 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2081 | if (irsp->ulpStatus) { |
| 2082 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2083 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2084 | /* ELS command is being retried */ |
| 2085 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2086 | /* LOGO failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2087 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2088 | "2756 LOGO failure DID:%06X Status:x%x/x%x\n", |
| 2089 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2090 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2091 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2092 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2093 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2094 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2095 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2096 | NLP_EVT_CMPL_LOGO); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2097 | } else |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2098 | /* Good status, call state machine. |
| 2099 | * This will unregister the rpi if needed. |
| 2100 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2101 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2102 | NLP_EVT_CMPL_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2103 | out: |
| 2104 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2105 | return; |
| 2106 | } |
| 2107 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2108 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2109 | * 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] | 2110 | * @vport: pointer to a virtual N_Port data structure. |
| 2111 | * @ndlp: pointer to a node-list data structure. |
| 2112 | * @retry: number of retries to the command IOCB. |
| 2113 | * |
| 2114 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2115 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2116 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2117 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2118 | * |
| 2119 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2120 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2121 | * will be stored into the context1 field of the IOCB for the completion |
| 2122 | * callback function to the LOGO ELS command. |
| 2123 | * |
| 2124 | * Return code |
| 2125 | * 0 - successfully issued logo |
| 2126 | * 1 - failed to issue logo |
| 2127 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2128 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2129 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2130 | uint8_t retry) |
| 2131 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2132 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2133 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2134 | IOCB_t *icmd; |
| 2135 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2136 | uint8_t *pcmd; |
| 2137 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2138 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2139 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2140 | spin_lock_irq(shost->host_lock); |
| 2141 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2142 | spin_unlock_irq(shost->host_lock); |
| 2143 | return 0; |
| 2144 | } |
| 2145 | spin_unlock_irq(shost->host_lock); |
| 2146 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2147 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2148 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2149 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2150 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2151 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2152 | |
| 2153 | icmd = &elsiocb->iocb; |
| 2154 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2155 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2156 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2157 | |
| 2158 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2159 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2160 | pcmd += sizeof(uint32_t); |
| 2161 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2162 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2163 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2164 | "Issue LOGO: did:x%x", |
| 2165 | ndlp->nlp_DID, 0, 0); |
| 2166 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2167 | phba->fc_stat.elsXmitLOGO++; |
| 2168 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2169 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2170 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2171 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2172 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2173 | |
| 2174 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2175 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2176 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2177 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2178 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2179 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2180 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2181 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2182 | } |
| 2183 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2184 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2185 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2186 | * @phba: pointer to lpfc hba data structure. |
| 2187 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2188 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2189 | * |
| 2190 | * This routine is a generic completion callback function for ELS commands. |
| 2191 | * Specifically, it is the callback function which does not need to perform |
| 2192 | * any command specific operations. It is currently used by the ELS command |
| 2193 | * issuing routines for the ELS State Change Request (SCR), |
| 2194 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 2195 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2196 | * certain debug loggings, this callback function simply invokes the |
| 2197 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2198 | * discovery process. |
| 2199 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2200 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2201 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2202 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2203 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2204 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2205 | IOCB_t *irsp; |
| 2206 | |
| 2207 | irsp = &rspiocb->iocb; |
| 2208 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2209 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2210 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2211 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2212 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2213 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2214 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2215 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2216 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2217 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2218 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2219 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2220 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2221 | return; |
| 2222 | } |
| 2223 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2224 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2225 | * 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] | 2226 | * @vport: pointer to a host virtual N_Port data structure. |
| 2227 | * @nportid: N_Port identifier to the remote node. |
| 2228 | * @retry: number of retries to the command IOCB. |
| 2229 | * |
| 2230 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2231 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2232 | * first search the @vport node list to find the matching ndlp. If no such |
| 2233 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2234 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2235 | * routine is invoked to send the SCR IOCB. |
| 2236 | * |
| 2237 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2238 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2239 | * will be stored into the context1 field of the IOCB for the completion |
| 2240 | * callback function to the SCR ELS command. |
| 2241 | * |
| 2242 | * Return code |
| 2243 | * 0 - Successfully issued scr command |
| 2244 | * 1 - Failed to issue scr command |
| 2245 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2246 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2247 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2248 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2249 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2250 | IOCB_t *icmd; |
| 2251 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2252 | struct lpfc_sli *psli; |
| 2253 | uint8_t *pcmd; |
| 2254 | uint16_t cmdsize; |
| 2255 | struct lpfc_nodelist *ndlp; |
| 2256 | |
| 2257 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2258 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2259 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2260 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2261 | if (!ndlp) { |
| 2262 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2263 | if (!ndlp) |
| 2264 | return 1; |
| 2265 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2266 | lpfc_enqueue_node(vport, ndlp); |
| 2267 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2268 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2269 | if (!ndlp) |
| 2270 | return 1; |
| 2271 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2272 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2273 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2274 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2275 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2276 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2277 | /* This will trigger the release of the node just |
| 2278 | * allocated |
| 2279 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2280 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2281 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2282 | } |
| 2283 | |
| 2284 | icmd = &elsiocb->iocb; |
| 2285 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2286 | |
| 2287 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2288 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2289 | |
| 2290 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2291 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2292 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2293 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2294 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2295 | "Issue SCR: did:x%x", |
| 2296 | ndlp->nlp_DID, 0, 0); |
| 2297 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2298 | phba->fc_stat.elsXmitSCR++; |
| 2299 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2300 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2301 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2302 | /* The additional lpfc_nlp_put will cause the following |
| 2303 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2304 | * the node. |
| 2305 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2306 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2307 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2308 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2309 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2310 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2311 | * trigger the release of node. |
| 2312 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2313 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2314 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2315 | } |
| 2316 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2317 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2318 | * 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] | 2319 | * @vport: pointer to a host virtual N_Port data structure. |
| 2320 | * @nportid: N_Port identifier to the remote node. |
| 2321 | * @retry: number of retries to the command IOCB. |
| 2322 | * |
| 2323 | * This routine issues a Fibre Channel Address Resolution Response |
| 2324 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2325 | * is passed into the function. It first search the @vport node list to find |
| 2326 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2327 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2328 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2329 | * |
| 2330 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2331 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2332 | * will be stored into the context1 field of the IOCB for the completion |
| 2333 | * callback function to the PARPR ELS command. |
| 2334 | * |
| 2335 | * Return code |
| 2336 | * 0 - Successfully issued farpr command |
| 2337 | * 1 - Failed to issue farpr command |
| 2338 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2339 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2340 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2341 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2342 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2343 | IOCB_t *icmd; |
| 2344 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2345 | struct lpfc_sli *psli; |
| 2346 | FARP *fp; |
| 2347 | uint8_t *pcmd; |
| 2348 | uint32_t *lp; |
| 2349 | uint16_t cmdsize; |
| 2350 | struct lpfc_nodelist *ondlp; |
| 2351 | struct lpfc_nodelist *ndlp; |
| 2352 | |
| 2353 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2354 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2355 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2356 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2357 | if (!ndlp) { |
| 2358 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2359 | if (!ndlp) |
| 2360 | return 1; |
| 2361 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2362 | lpfc_enqueue_node(vport, ndlp); |
| 2363 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2364 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2365 | if (!ndlp) |
| 2366 | return 1; |
| 2367 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2368 | |
| 2369 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2370 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2371 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2372 | /* This will trigger the release of the node just |
| 2373 | * allocated |
| 2374 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2375 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2376 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2377 | } |
| 2378 | |
| 2379 | icmd = &elsiocb->iocb; |
| 2380 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2381 | |
| 2382 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2383 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2384 | |
| 2385 | /* Fill in FARPR payload */ |
| 2386 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2387 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2388 | lp = (uint32_t *) pcmd; |
| 2389 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2390 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2391 | fp->Rflags = 0; |
| 2392 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2393 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2394 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2395 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2396 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2397 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2398 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2399 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2400 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2401 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2402 | } |
| 2403 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2404 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2405 | "Issue FARPR: did:x%x", |
| 2406 | ndlp->nlp_DID, 0, 0); |
| 2407 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2408 | phba->fc_stat.elsXmitFARPR++; |
| 2409 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2410 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2411 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2412 | /* The additional lpfc_nlp_put will cause the following |
| 2413 | * lpfc_els_free_iocb routine to trigger the release of |
| 2414 | * the node. |
| 2415 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2416 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2417 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2418 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2419 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2420 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2421 | * trigger the release of the node. |
| 2422 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2423 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2424 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2425 | } |
| 2426 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2427 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2428 | * 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] | 2429 | * @vport: pointer to a host virtual N_Port data structure. |
| 2430 | * @nlp: pointer to a node-list data structure. |
| 2431 | * |
| 2432 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2433 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2434 | * removes the ELS retry event if it presents. In addition, if the |
| 2435 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2436 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2437 | * ADISC. |
| 2438 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2439 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2440 | 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] | 2441 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2442 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2443 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2444 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2445 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2446 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2447 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2448 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2449 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2450 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2451 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2452 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2453 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2454 | /* Decrement nlp reference count held for the delayed retry */ |
| 2455 | evtp = &nlp->els_retry_evt; |
| 2456 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2457 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2458 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2459 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2460 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2461 | spin_unlock_irq(shost->host_lock); |
| 2462 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2463 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2464 | /* Check if there are more ADISCs to be sent */ |
| 2465 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2466 | } else { |
| 2467 | /* Check if there are more PLOGIs to be sent */ |
| 2468 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2469 | if (vport->num_disc_nodes == 0) { |
| 2470 | spin_lock_irq(shost->host_lock); |
| 2471 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2472 | spin_unlock_irq(shost->host_lock); |
| 2473 | lpfc_can_disctmo(vport); |
| 2474 | lpfc_end_rscn(vport); |
| 2475 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2476 | } |
| 2477 | } |
| 2478 | } |
| 2479 | return; |
| 2480 | } |
| 2481 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2482 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2483 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2484 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2485 | * |
| 2486 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2487 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2488 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2489 | * adds the delayed events to the HBA work list and invokes the |
| 2490 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2491 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2492 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2493 | * reference to ndlp will still be available when the worker thread gets |
| 2494 | * to the event associated with the ndlp. |
| 2495 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2496 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2497 | lpfc_els_retry_delay(unsigned long ptr) |
| 2498 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2499 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2500 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2501 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2502 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2503 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2504 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2505 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2506 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2507 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2508 | return; |
| 2509 | } |
| 2510 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2511 | /* We need to hold the node by incrementing the reference |
| 2512 | * count until the queued work is done |
| 2513 | */ |
| 2514 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2515 | if (evtp->evt_arg1) { |
| 2516 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2517 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2518 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2519 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2520 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2521 | return; |
| 2522 | } |
| 2523 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2524 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2525 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2526 | * @ndlp: pointer to a node-list data structure. |
| 2527 | * |
| 2528 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 2529 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 2530 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 2531 | * function according to the delayed ELS command to retry the command. |
| 2532 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2533 | void |
| 2534 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 2535 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2536 | struct lpfc_vport *vport = ndlp->vport; |
| 2537 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2538 | uint32_t cmd, did, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2539 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2540 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2541 | did = ndlp->nlp_DID; |
| 2542 | cmd = ndlp->nlp_last_elscmd; |
| 2543 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2544 | |
| 2545 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2546 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2547 | return; |
| 2548 | } |
| 2549 | |
| 2550 | 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); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 2552 | /* |
| 2553 | * If a discovery event readded nlp_delayfunc after timer |
| 2554 | * firing and before processing the timer, cancel the |
| 2555 | * nlp_delayfunc. |
| 2556 | */ |
| 2557 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2558 | retry = ndlp->nlp_retry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 2559 | ndlp->nlp_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2560 | |
| 2561 | switch (cmd) { |
| 2562 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2563 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2564 | break; |
| 2565 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2566 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2567 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2568 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2569 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2570 | break; |
| 2571 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2572 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2573 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2574 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2575 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2576 | break; |
| 2577 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2578 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2579 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2580 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2581 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2582 | break; |
| 2583 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2584 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2585 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2586 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2587 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2588 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2589 | case ELS_CMD_FDISC: |
| 2590 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
| 2591 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2592 | } |
| 2593 | return; |
| 2594 | } |
| 2595 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2596 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2597 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2598 | * @phba: pointer to lpfc hba data structure. |
| 2599 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2600 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2601 | * |
| 2602 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 2603 | * failed. The following ELS IOCBs use this function for retrying the command |
| 2604 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 2605 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 2606 | * returned error status, it makes the decision whether a retry shall be |
| 2607 | * issued for the command, and whether a retry shall be made immediately or |
| 2608 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 2609 | * is called to retry the command. In the later case, the ELS command shall |
| 2610 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 2611 | * ndlp for the delayed command issusing. |
| 2612 | * |
| 2613 | * Return code |
| 2614 | * 0 - No retry of els command is made |
| 2615 | * 1 - Immediate or delayed retry of els command is made |
| 2616 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2617 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2618 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2619 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2620 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2621 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2622 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2623 | IOCB_t *irsp = &rspiocb->iocb; |
| 2624 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2625 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2626 | uint32_t *elscmd; |
| 2627 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2628 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2629 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2630 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2631 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2632 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2633 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2634 | /* Note: context2 may be 0 for internal driver abort |
| 2635 | * of delays ELS command. |
| 2636 | */ |
| 2637 | |
| 2638 | if (pcmd && pcmd->virt) { |
| 2639 | elscmd = (uint32_t *) (pcmd->virt); |
| 2640 | cmd = *elscmd++; |
| 2641 | } |
| 2642 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2643 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2644 | did = ndlp->nlp_DID; |
| 2645 | else { |
| 2646 | /* We should only hit this case for retrying PLOGI */ |
| 2647 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2648 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2649 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 2650 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2651 | return 1; |
| 2652 | } |
| 2653 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2654 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2655 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 2656 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 2657 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2658 | switch (irsp->ulpStatus) { |
| 2659 | case IOSTAT_FCP_RSP_ERROR: |
| 2660 | case IOSTAT_REMOTE_STOP: |
| 2661 | break; |
| 2662 | |
| 2663 | case IOSTAT_LOCAL_REJECT: |
| 2664 | switch ((irsp->un.ulpWord[4] & 0xff)) { |
| 2665 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2666 | if (cmd == ELS_CMD_FLOGI) { |
| 2667 | if (PCI_DEVICE_ID_HORNET == |
| 2668 | phba->pcidev->device) { |
| 2669 | phba->fc_topology = TOPOLOGY_LOOP; |
| 2670 | phba->pport->fc_myDID = 0; |
| 2671 | phba->alpa_map[0] = 0; |
| 2672 | phba->alpa_map[1] = 0; |
| 2673 | } |
| 2674 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2675 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2676 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2677 | retry = 1; |
| 2678 | break; |
| 2679 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2680 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2681 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2682 | "0124 Retry illegal cmd x%x " |
| 2683 | "retry:x%x delay:x%x\n", |
| 2684 | cmd, cmdiocb->retry, delay); |
| 2685 | retry = 1; |
| 2686 | /* All command's retry policy */ |
| 2687 | maxretry = 8; |
| 2688 | if (cmdiocb->retry > 2) |
| 2689 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2690 | break; |
| 2691 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2692 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2693 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2694 | retry = 1; |
| 2695 | if (cmdiocb->retry > 100) |
| 2696 | delay = 100; |
| 2697 | maxretry = 250; |
| 2698 | break; |
| 2699 | |
| 2700 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2701 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2702 | retry = 1; |
| 2703 | break; |
| 2704 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2705 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2706 | case IOERR_INVALID_RPI: |
| 2707 | retry = 1; |
| 2708 | break; |
| 2709 | } |
| 2710 | break; |
| 2711 | |
| 2712 | case IOSTAT_NPORT_RJT: |
| 2713 | case IOSTAT_FABRIC_RJT: |
| 2714 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 2715 | retry = 1; |
| 2716 | break; |
| 2717 | } |
| 2718 | break; |
| 2719 | |
| 2720 | case IOSTAT_NPORT_BSY: |
| 2721 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2722 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2723 | retry = 1; |
| 2724 | break; |
| 2725 | |
| 2726 | case IOSTAT_LS_RJT: |
| 2727 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 2728 | /* Added for Vendor specifc support |
| 2729 | * Just keep retrying for these Rsn / Exp codes |
| 2730 | */ |
| 2731 | switch (stat.un.b.lsRjtRsnCode) { |
| 2732 | case LSRJT_UNABLE_TPC: |
| 2733 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2734 | LSEXP_CMD_IN_PROGRESS) { |
| 2735 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2736 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2737 | maxretry = 48; |
| 2738 | } |
| 2739 | retry = 1; |
| 2740 | break; |
| 2741 | } |
| 2742 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2743 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2744 | maxretry = lpfc_max_els_tries + 1; |
| 2745 | retry = 1; |
| 2746 | break; |
| 2747 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2748 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2749 | (cmd == ELS_CMD_FDISC) && |
| 2750 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2751 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2752 | "0125 FDISC Failed (x%x). " |
| 2753 | "Fabric out of resources\n", |
| 2754 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2755 | lpfc_vport_set_state(vport, |
| 2756 | FC_VPORT_NO_FABRIC_RSCS); |
| 2757 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2758 | break; |
| 2759 | |
| 2760 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2761 | if ((cmd == ELS_CMD_PLOGI) || |
| 2762 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2763 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2764 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2765 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2766 | /* FDISC retry policy */ |
| 2767 | maxretry = 48; |
| 2768 | if (cmdiocb->retry >= 32) |
| 2769 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2770 | } |
| 2771 | retry = 1; |
| 2772 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2773 | |
| 2774 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2775 | /* There are some cases where switches return this |
| 2776 | * error when they are not ready and should be returning |
| 2777 | * Logical Busy. We should delay every time. |
| 2778 | */ |
| 2779 | if (cmd == ELS_CMD_FDISC && |
| 2780 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 2781 | maxretry = 3; |
| 2782 | delay = 1000; |
| 2783 | retry = 1; |
| 2784 | break; |
| 2785 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2786 | case LSRJT_PROTOCOL_ERR: |
| 2787 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2788 | (cmd == ELS_CMD_FDISC) && |
| 2789 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 2790 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 2791 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2792 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2793 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2794 | "Fabric Detected Bad WWN\n", |
| 2795 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2796 | lpfc_vport_set_state(vport, |
| 2797 | FC_VPORT_FABRIC_REJ_WWN); |
| 2798 | } |
| 2799 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2800 | } |
| 2801 | break; |
| 2802 | |
| 2803 | case IOSTAT_INTERMED_RSP: |
| 2804 | case IOSTAT_BA_RJT: |
| 2805 | break; |
| 2806 | |
| 2807 | default: |
| 2808 | break; |
| 2809 | } |
| 2810 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2811 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2812 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2813 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2814 | if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 2815 | (phba->fc_topology != TOPOLOGY_LOOP) && |
| 2816 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2817 | /* FLOGI retry policy */ |
| 2818 | retry = 1; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2819 | /* retry forever */ |
| 2820 | maxretry = 0; |
| 2821 | if (cmdiocb->retry >= 100) |
| 2822 | delay = 5000; |
| 2823 | else if (cmdiocb->retry >= 32) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2824 | delay = 1000; |
| 2825 | } |
| 2826 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2827 | cmdiocb->retry++; |
| 2828 | if (maxretry && (cmdiocb->retry >= maxretry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2829 | phba->fc_stat.elsRetryExceeded++; |
| 2830 | retry = 0; |
| 2831 | } |
| 2832 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2833 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 2834 | retry = 0; |
| 2835 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2836 | if (retry) { |
| 2837 | |
| 2838 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2839 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2840 | "0107 Retry ELS command x%x to remote " |
| 2841 | "NPORT x%x Data: x%x x%x\n", |
| 2842 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2843 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2844 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 2845 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 2846 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { |
| 2847 | /* Don't reset timer for no resources */ |
| 2848 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2849 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2850 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2851 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2852 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2853 | } |
| 2854 | |
| 2855 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2856 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2857 | phba->fc_stat.elsDelayRetry++; |
| 2858 | ndlp->nlp_retry = cmdiocb->retry; |
| 2859 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2860 | /* delay is specified in milliseconds */ |
| 2861 | mod_timer(&ndlp->nlp_delayfunc, |
| 2862 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2863 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2864 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2865 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2866 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2867 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2868 | if (cmd == ELS_CMD_PRLI) |
| 2869 | lpfc_nlp_set_state(vport, ndlp, |
| 2870 | NLP_STE_REG_LOGIN_ISSUE); |
| 2871 | else |
| 2872 | lpfc_nlp_set_state(vport, ndlp, |
| 2873 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2874 | ndlp->nlp_last_elscmd = cmd; |
| 2875 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2876 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2877 | } |
| 2878 | switch (cmd) { |
| 2879 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2880 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2881 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2882 | case ELS_CMD_FDISC: |
| 2883 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 2884 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2885 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2886 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2887 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2888 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2889 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2890 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2891 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2892 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2893 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2894 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2895 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 2896 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2897 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2898 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2899 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2900 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 2901 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2902 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2903 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2904 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2905 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 2906 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2907 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2908 | } |
| 2909 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2910 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2911 | if (logerr) { |
| 2912 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2913 | "0137 No retry ELS command x%x to remote " |
| 2914 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 2915 | cmd, did, irsp->ulpStatus, |
| 2916 | irsp->un.ulpWord[4]); |
| 2917 | } |
| 2918 | else { |
| 2919 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2920 | "0108 No retry ELS command x%x to remote " |
| 2921 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 2922 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 2923 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2924 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2925 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2926 | } |
| 2927 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2928 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2929 | * 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] | 2930 | * @phba: pointer to lpfc hba data structure. |
| 2931 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 2932 | * |
| 2933 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 2934 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 2935 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 2936 | * response of the command IOCB. If so, it will be released before releasing |
| 2937 | * the lpfc DMA buffer associated with the IOCB itself. |
| 2938 | * |
| 2939 | * Return code |
| 2940 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2941 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2942 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2943 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 2944 | { |
| 2945 | struct lpfc_dmabuf *buf_ptr; |
| 2946 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2947 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2948 | if (!list_empty(&buf_ptr1->list)) { |
| 2949 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 2950 | struct lpfc_dmabuf, |
| 2951 | list); |
| 2952 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2953 | kfree(buf_ptr); |
| 2954 | } |
| 2955 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 2956 | kfree(buf_ptr1); |
| 2957 | return 0; |
| 2958 | } |
| 2959 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2960 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2961 | * 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] | 2962 | * @phba: pointer to lpfc hba data structure. |
| 2963 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 2964 | * |
| 2965 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 2966 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 2967 | * pool. |
| 2968 | * |
| 2969 | * Return code |
| 2970 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2971 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2972 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2973 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 2974 | { |
| 2975 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2976 | kfree(buf_ptr); |
| 2977 | return 0; |
| 2978 | } |
| 2979 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2980 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2981 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2982 | * @phba: pointer to lpfc hba data structure. |
| 2983 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 2984 | * |
| 2985 | * This routine frees a command IOCB and its associated resources. The |
| 2986 | * command IOCB data structure contains the reference to various associated |
| 2987 | * resources, these fields must be set to NULL if the associated reference |
| 2988 | * not present: |
| 2989 | * context1 - reference to ndlp |
| 2990 | * context2 - reference to cmd |
| 2991 | * context2->next - reference to rsp |
| 2992 | * context3 - reference to bpl |
| 2993 | * |
| 2994 | * It first properly decrements the reference count held on ndlp for the |
| 2995 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 2996 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 2997 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 2998 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 2999 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 3000 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 3001 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 3002 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 3003 | * |
| 3004 | * Return code |
| 3005 | * 0 - Success (currently, always return 0) |
| 3006 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3007 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3008 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3009 | { |
| 3010 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3011 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3012 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3013 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 3014 | if (ndlp) { |
| 3015 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 3016 | lpfc_nlp_put(ndlp); |
| 3017 | |
| 3018 | /* If the ndlp is not being used by another discovery |
| 3019 | * thread, free it. |
| 3020 | */ |
| 3021 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3022 | /* If ndlp is being used by another discovery |
| 3023 | * thread, just clear NLP_DEFER_RM |
| 3024 | */ |
| 3025 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 3026 | } |
| 3027 | } |
| 3028 | else |
| 3029 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3030 | elsiocb->context1 = NULL; |
| 3031 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3032 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 3033 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3034 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 3035 | /* Firmware could still be in progress of DMAing |
| 3036 | * payload, so don't free data buffer till after |
| 3037 | * a hbeat. |
| 3038 | */ |
| 3039 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 3040 | buf_ptr = elsiocb->context2; |
| 3041 | elsiocb->context2 = NULL; |
| 3042 | if (buf_ptr) { |
| 3043 | buf_ptr1 = NULL; |
| 3044 | spin_lock_irq(&phba->hbalock); |
| 3045 | if (!list_empty(&buf_ptr->list)) { |
| 3046 | list_remove_head(&buf_ptr->list, |
| 3047 | buf_ptr1, struct lpfc_dmabuf, |
| 3048 | list); |
| 3049 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 3050 | list_add_tail(&buf_ptr1->list, |
| 3051 | &phba->elsbuf); |
| 3052 | phba->elsbuf_cnt++; |
| 3053 | } |
| 3054 | INIT_LIST_HEAD(&buf_ptr->list); |
| 3055 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 3056 | phba->elsbuf_cnt++; |
| 3057 | spin_unlock_irq(&phba->hbalock); |
| 3058 | } |
| 3059 | } else { |
| 3060 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 3061 | lpfc_els_free_data(phba, buf_ptr1); |
| 3062 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3063 | } |
| 3064 | |
| 3065 | if (elsiocb->context3) { |
| 3066 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3067 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3068 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3069 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3070 | return 0; |
| 3071 | } |
| 3072 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3073 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3074 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3075 | * @phba: pointer to lpfc hba data structure. |
| 3076 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3077 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3078 | * |
| 3079 | * This routine is the completion callback function to the Logout (LOGO) |
| 3080 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 3081 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 3082 | * release the ndlp if it has the last reference remaining (reference count |
| 3083 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 3084 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 3085 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 3086 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 3087 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 3088 | * IOCB data structure. |
| 3089 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3090 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3091 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3092 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3093 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3094 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3095 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3096 | IOCB_t *irsp; |
| 3097 | |
| 3098 | irsp = &rspiocb->iocb; |
| 3099 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3100 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 3101 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3102 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3103 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3104 | "0109 ACC to LOGO completes to NPort x%x " |
| 3105 | "Data: x%x x%x x%x\n", |
| 3106 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3107 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3108 | |
| 3109 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 3110 | /* NPort Recovery mode or node is just allocated */ |
| 3111 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3112 | /* If the ndlp is being used by another discovery |
| 3113 | * thread, just unregister the RPI. |
| 3114 | */ |
| 3115 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3116 | } else { |
| 3117 | /* Indicate the node has already released, should |
| 3118 | * not reference to it from within lpfc_els_free_iocb. |
| 3119 | */ |
| 3120 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3121 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3122 | } |
| 3123 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3124 | return; |
| 3125 | } |
| 3126 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3127 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3128 | * 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] | 3129 | * @phba: pointer to lpfc hba data structure. |
| 3130 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 3131 | * |
| 3132 | * This routine is the completion callback function for unregister default |
| 3133 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 3134 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 3135 | * decrements the ndlp reference count held for this completion callback |
| 3136 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 3137 | * whether there is only one reference left on the ndlp. If so, it will |
| 3138 | * perform one more decrement and trigger the release of the ndlp. |
| 3139 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3140 | void |
| 3141 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3142 | { |
| 3143 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3144 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3145 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3146 | /* |
| 3147 | * This routine is used to register and unregister in previous SLI |
| 3148 | * modes. |
| 3149 | */ |
| 3150 | if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) && |
| 3151 | (phba->sli_rev == LPFC_SLI_REV4)) |
| 3152 | lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi); |
| 3153 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3154 | pmb->context1 = NULL; |
| 3155 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3156 | kfree(mp); |
| 3157 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3158 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3159 | lpfc_nlp_put(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3160 | /* This is the end of the default RPI cleanup logic for this |
| 3161 | * ndlp. If no other discovery threads are using this ndlp. |
| 3162 | * we should free all resources associated with it. |
| 3163 | */ |
| 3164 | lpfc_nlp_not_used(ndlp); |
| 3165 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3166 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3167 | return; |
| 3168 | } |
| 3169 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3170 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3171 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3172 | * @phba: pointer to lpfc hba data structure. |
| 3173 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3174 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3175 | * |
| 3176 | * This routine is the completion callback function for ELS Response IOCB |
| 3177 | * command. In normal case, this callback function just properly sets the |
| 3178 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 3179 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 3180 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 3181 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 3182 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 3183 | * routine shall be invoked trying to release the ndlp if no other threads |
| 3184 | * are currently referring it. |
| 3185 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3186 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3187 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3188 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3189 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3190 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3191 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 3192 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3193 | IOCB_t *irsp; |
| 3194 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3195 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3196 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3197 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3198 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3199 | irsp = &rspiocb->iocb; |
| 3200 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3201 | if (cmdiocb->context_un.mbox) |
| 3202 | mbox = cmdiocb->context_un.mbox; |
| 3203 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3204 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 3205 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 3206 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3207 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3208 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3209 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3210 | /* A LS_RJT associated with Default RPI cleanup has its own |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 3211 | * separate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3212 | */ |
| 3213 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 3214 | ls_rjt = 1; |
| 3215 | } |
| 3216 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3217 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3218 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3219 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3220 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3221 | if (mp) { |
| 3222 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3223 | kfree(mp); |
| 3224 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3225 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3226 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3227 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3228 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3229 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3230 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3231 | /* Indicate the node has already released, |
| 3232 | * should not reference to it from within |
| 3233 | * the routine lpfc_els_free_iocb. |
| 3234 | */ |
| 3235 | cmdiocb->context1 = NULL; |
| 3236 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3237 | goto out; |
| 3238 | } |
| 3239 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3240 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3241 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3242 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3243 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3244 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3245 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3246 | "0110 ELS response tag x%x completes " |
| 3247 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3248 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3249 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3250 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3251 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3252 | if (mbox) { |
| 3253 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3254 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3255 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3256 | /* Increment reference count to ndlp to hold the |
| 3257 | * reference to ndlp for the callback function. |
| 3258 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3259 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3260 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3261 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3262 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3263 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3264 | } |
| 3265 | else { |
| 3266 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3267 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3268 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3269 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3270 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3271 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3272 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3273 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3274 | else |
| 3275 | /* Decrement the ndlp reference count we |
| 3276 | * set for this failed mailbox command. |
| 3277 | */ |
| 3278 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3279 | |
| 3280 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3281 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3282 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3283 | "Data: x%x x%x x%x\n", |
| 3284 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3285 | ndlp->nlp_rpi); |
| 3286 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3287 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3288 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3289 | /* Indicate node has already been released, |
| 3290 | * should not reference to it from within |
| 3291 | * the routine lpfc_els_free_iocb. |
| 3292 | */ |
| 3293 | cmdiocb->context1 = NULL; |
| 3294 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3295 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3296 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3297 | if (!lpfc_error_lost_link(irsp) && |
| 3298 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3299 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3300 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3301 | /* Indicate node has already been |
| 3302 | * released, should not reference |
| 3303 | * to it from within the routine |
| 3304 | * lpfc_els_free_iocb. |
| 3305 | */ |
| 3306 | cmdiocb->context1 = NULL; |
| 3307 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3308 | } |
| 3309 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3310 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3311 | if (mp) { |
| 3312 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3313 | kfree(mp); |
| 3314 | } |
| 3315 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3316 | } |
| 3317 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3318 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3319 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3320 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3321 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3322 | |
| 3323 | /* If the node is not being used by another discovery thread, |
| 3324 | * and we are sending a reject, we are done with it. |
| 3325 | * Release driver reference count here and free associated |
| 3326 | * resources. |
| 3327 | */ |
| 3328 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3329 | if (lpfc_nlp_not_used(ndlp)) |
| 3330 | /* Indicate node has already been released, |
| 3331 | * should not reference to it from within |
| 3332 | * the routine lpfc_els_free_iocb. |
| 3333 | */ |
| 3334 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3335 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3336 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3337 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3338 | return; |
| 3339 | } |
| 3340 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3341 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3342 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3343 | * @vport: pointer to a host virtual N_Port data structure. |
| 3344 | * @flag: the els command code to be accepted. |
| 3345 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3346 | * @ndlp: pointer to a node-list data structure. |
| 3347 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3348 | * |
| 3349 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3350 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3351 | * specific ACC response command to be issued and invokes the |
| 3352 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3353 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3354 | * field of the IOCB for the completion callback function to issue the |
| 3355 | * mailbox command to the HBA later when callback is invoked. |
| 3356 | * |
| 3357 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3358 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3359 | * will be stored into the context1 field of the IOCB for the completion |
| 3360 | * callback function to the corresponding response ELS IOCB command. |
| 3361 | * |
| 3362 | * Return code |
| 3363 | * 0 - Successfully issued acc response |
| 3364 | * 1 - Failed to issue acc response |
| 3365 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3366 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3367 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3368 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3369 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3370 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3371 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3372 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3373 | IOCB_t *icmd; |
| 3374 | IOCB_t *oldcmd; |
| 3375 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3376 | struct lpfc_sli *psli; |
| 3377 | uint8_t *pcmd; |
| 3378 | uint16_t cmdsize; |
| 3379 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3380 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3381 | |
| 3382 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3383 | oldcmd = &oldiocb->iocb; |
| 3384 | |
| 3385 | switch (flag) { |
| 3386 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3387 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3388 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3389 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3390 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3391 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3392 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3393 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3394 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3395 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3396 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3397 | icmd = &elsiocb->iocb; |
| 3398 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3399 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3400 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3401 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3402 | |
| 3403 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3404 | "Issue ACC: did:x%x flg:x%x", |
| 3405 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3406 | break; |
| 3407 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3408 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3409 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3410 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3411 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3412 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3413 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3414 | icmd = &elsiocb->iocb; |
| 3415 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3416 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3417 | |
| 3418 | if (mbox) |
| 3419 | elsiocb->context_un.mbox = mbox; |
| 3420 | |
| 3421 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3422 | pcmd += sizeof(uint32_t); |
| 3423 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3424 | |
| 3425 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3426 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 3427 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3428 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3429 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3430 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3431 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3432 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3433 | if (!elsiocb) |
| 3434 | return 1; |
| 3435 | |
| 3436 | icmd = &elsiocb->iocb; |
| 3437 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3438 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3439 | |
| 3440 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3441 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3442 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 3443 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 3444 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3445 | |
| 3446 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3447 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 3448 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3449 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3450 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3451 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3452 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3453 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3454 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3455 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
| 3456 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", |
| 3457 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3458 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3459 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3460 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3461 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3462 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3463 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3464 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 3465 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3466 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3467 | } |
| 3468 | |
| 3469 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3470 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3471 | if (rc == IOCB_ERROR) { |
| 3472 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3473 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3474 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3475 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3476 | } |
| 3477 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3478 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3479 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3480 | * @vport: pointer to a virtual N_Port data structure. |
| 3481 | * @rejectError: |
| 3482 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3483 | * @ndlp: pointer to a node-list data structure. |
| 3484 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3485 | * |
| 3486 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 3487 | * command. If a @mbox pointer is passed in, it will be put into the |
| 3488 | * context_un.mbox field of the IOCB for the completion callback function |
| 3489 | * to issue to the HBA later. |
| 3490 | * |
| 3491 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3492 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3493 | * will be stored into the context1 field of the IOCB for the completion |
| 3494 | * callback function to the reject response ELS IOCB command. |
| 3495 | * |
| 3496 | * Return code |
| 3497 | * 0 - Successfully issued reject response |
| 3498 | * 1 - Failed to issue reject response |
| 3499 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3500 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3501 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3502 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 3503 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3504 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3505 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3506 | IOCB_t *icmd; |
| 3507 | IOCB_t *oldcmd; |
| 3508 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3509 | struct lpfc_sli *psli; |
| 3510 | uint8_t *pcmd; |
| 3511 | uint16_t cmdsize; |
| 3512 | int rc; |
| 3513 | |
| 3514 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3515 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3516 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3517 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3518 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3519 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3520 | |
| 3521 | icmd = &elsiocb->iocb; |
| 3522 | oldcmd = &oldiocb->iocb; |
| 3523 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3524 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3525 | |
| 3526 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3527 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3528 | *((uint32_t *) (pcmd)) = rejectError; |
| 3529 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3530 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3531 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3532 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3533 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3534 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3535 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 3536 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 3537 | "rpi x%x\n", |
| 3538 | rejectError, elsiocb->iotag, |
| 3539 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 3540 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3541 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3542 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 3543 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 3544 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3545 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3546 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3547 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3548 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3549 | if (rc == IOCB_ERROR) { |
| 3550 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3551 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3552 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3553 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3554 | } |
| 3555 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3556 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3557 | * 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] | 3558 | * @vport: pointer to a virtual N_Port data structure. |
| 3559 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3560 | * @ndlp: pointer to a node-list data structure. |
| 3561 | * |
| 3562 | * This routine prepares and issues an Accept (ACC) response to Address |
| 3563 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 3564 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3565 | * |
| 3566 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3567 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3568 | * will be stored into the context1 field of the IOCB for the completion |
| 3569 | * callback function to the ADISC Accept response ELS IOCB command. |
| 3570 | * |
| 3571 | * Return code |
| 3572 | * 0 - Successfully issued acc adisc response |
| 3573 | * 1 - Failed to issue adisc acc response |
| 3574 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3575 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3576 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 3577 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3578 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3579 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3580 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3581 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3582 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3583 | uint8_t *pcmd; |
| 3584 | uint16_t cmdsize; |
| 3585 | int rc; |
| 3586 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3587 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3588 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3589 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3590 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3591 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3592 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3593 | icmd = &elsiocb->iocb; |
| 3594 | oldcmd = &oldiocb->iocb; |
| 3595 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3596 | |
| 3597 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3598 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3599 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 3600 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 3601 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3602 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3603 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3604 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3605 | |
| 3606 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3607 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3608 | |
| 3609 | ap = (ADISC *) (pcmd); |
| 3610 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3611 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3612 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3613 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3614 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3615 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3616 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 3617 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3618 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3619 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3620 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3621 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3622 | if (rc == IOCB_ERROR) { |
| 3623 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3624 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3625 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3626 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3627 | } |
| 3628 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3629 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3630 | * 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] | 3631 | * @vport: pointer to a virtual N_Port data structure. |
| 3632 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3633 | * @ndlp: pointer to a node-list data structure. |
| 3634 | * |
| 3635 | * This routine prepares and issues an Accept (ACC) response to Process |
| 3636 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 3637 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3638 | * |
| 3639 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3640 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3641 | * will be stored into the context1 field of the IOCB for the completion |
| 3642 | * callback function to the PRLI Accept response ELS IOCB command. |
| 3643 | * |
| 3644 | * Return code |
| 3645 | * 0 - Successfully issued acc prli response |
| 3646 | * 1 - Failed to issue acc prli response |
| 3647 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3648 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3649 | 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] | 3650 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3651 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3652 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3653 | PRLI *npr; |
| 3654 | lpfc_vpd_t *vpd; |
| 3655 | IOCB_t *icmd; |
| 3656 | IOCB_t *oldcmd; |
| 3657 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3658 | struct lpfc_sli *psli; |
| 3659 | uint8_t *pcmd; |
| 3660 | uint16_t cmdsize; |
| 3661 | int rc; |
| 3662 | |
| 3663 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3664 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3665 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3666 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3667 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3668 | if (!elsiocb) |
| 3669 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3670 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3671 | icmd = &elsiocb->iocb; |
| 3672 | oldcmd = &oldiocb->iocb; |
| 3673 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3674 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3675 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3676 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 3677 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 3678 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3679 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3680 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3681 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3682 | |
| 3683 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3684 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3685 | |
| 3686 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3687 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3688 | |
| 3689 | npr = (PRLI *) pcmd; |
| 3690 | vpd = &phba->vpd; |
| 3691 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3692 | * If the remote port is a target and our firmware version is 3.20 or |
| 3693 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3694 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3695 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 3696 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3697 | npr->ConfmComplAllowed = 1; |
| 3698 | npr->Retry = 1; |
| 3699 | npr->TaskRetryIdReq = 1; |
| 3700 | } |
| 3701 | |
| 3702 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 3703 | npr->estabImagePair = 1; |
| 3704 | npr->readXferRdyDis = 1; |
| 3705 | npr->ConfmComplAllowed = 1; |
| 3706 | |
| 3707 | npr->prliType = PRLI_FCP_TYPE; |
| 3708 | npr->initiatorFunc = 1; |
| 3709 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3710 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3711 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 3712 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3713 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3714 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3715 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3716 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3717 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3718 | if (rc == IOCB_ERROR) { |
| 3719 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3720 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3721 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3722 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3723 | } |
| 3724 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3725 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3726 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3727 | * @vport: pointer to a virtual N_Port data structure. |
| 3728 | * @format: rnid command format. |
| 3729 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3730 | * @ndlp: pointer to a node-list data structure. |
| 3731 | * |
| 3732 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 3733 | * (ACC) response. It constructs the RNID ACC response command according to |
| 3734 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 3735 | * issue the response. Note that this command does not need to hold the ndlp |
| 3736 | * reference count for the callback. So, the ndlp reference count taken by |
| 3737 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 3738 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 3739 | * there is no ndlp reference available. |
| 3740 | * |
| 3741 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3742 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3743 | * will be stored into the context1 field of the IOCB for the completion |
| 3744 | * callback function. However, for the RNID Accept Response ELS command, |
| 3745 | * this is undone later by this routine after the IOCB is allocated. |
| 3746 | * |
| 3747 | * Return code |
| 3748 | * 0 - Successfully issued acc rnid response |
| 3749 | * 1 - Failed to issue acc rnid response |
| 3750 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3751 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3752 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3753 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3754 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3755 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3756 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3757 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3758 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3759 | struct lpfc_sli *psli; |
| 3760 | uint8_t *pcmd; |
| 3761 | uint16_t cmdsize; |
| 3762 | int rc; |
| 3763 | |
| 3764 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3765 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 3766 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3767 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3768 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3769 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3770 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3771 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3772 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3773 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3774 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3775 | icmd = &elsiocb->iocb; |
| 3776 | oldcmd = &oldiocb->iocb; |
| 3777 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3778 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3779 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3780 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 3781 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3782 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3783 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3784 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3785 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3786 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3787 | rn = (RNID *) (pcmd); |
| 3788 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3789 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 3790 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3791 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3792 | switch (format) { |
| 3793 | case 0: |
| 3794 | rn->SpecificLen = 0; |
| 3795 | break; |
| 3796 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3797 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3798 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3799 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3800 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 3801 | rn->un.topologyDisc.physPort = 0; |
| 3802 | rn->un.topologyDisc.attachedNodes = 0; |
| 3803 | break; |
| 3804 | default: |
| 3805 | rn->CommonLen = 0; |
| 3806 | rn->SpecificLen = 0; |
| 3807 | break; |
| 3808 | } |
| 3809 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3810 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3811 | "Issue ACC RNID: did:x%x flg:x%x", |
| 3812 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3813 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3814 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3815 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3816 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3817 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 3818 | * it could be freed */ |
| 3819 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3820 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3821 | if (rc == IOCB_ERROR) { |
| 3822 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3823 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3824 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3825 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3826 | } |
| 3827 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3828 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3829 | * 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] | 3830 | * @vport: pointer to a host virtual N_Port data structure. |
| 3831 | * |
| 3832 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 3833 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 3834 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 3835 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 3836 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 3837 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 3838 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 3839 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 3840 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 3841 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 3842 | * no more ADISC need to be sent. |
| 3843 | * |
| 3844 | * Return code |
| 3845 | * The number of N_Ports with adisc issued. |
| 3846 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3847 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3848 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3849 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3850 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3851 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3852 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3853 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3854 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3855 | 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] | 3856 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3857 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3858 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3859 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3860 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3861 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3862 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3863 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3864 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3865 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 3866 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3867 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3868 | vport->num_disc_nodes++; |
| 3869 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3870 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3871 | spin_lock_irq(shost->host_lock); |
| 3872 | vport->fc_flag |= FC_NLP_MORE; |
| 3873 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3874 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3875 | } |
| 3876 | } |
| 3877 | } |
| 3878 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3879 | spin_lock_irq(shost->host_lock); |
| 3880 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3881 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3882 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3883 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3884 | } |
| 3885 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3886 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3887 | * 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] | 3888 | * @vport: pointer to a host virtual N_Port data structure. |
| 3889 | * |
| 3890 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 3891 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 3892 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 3893 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 3894 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 3895 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 3896 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 3897 | * later pick up. On the other hand, after walking through all the ndlps with |
| 3898 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 3899 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 3900 | * PLOGI need to be sent. |
| 3901 | * |
| 3902 | * Return code |
| 3903 | * The number of N_Ports with plogi issued. |
| 3904 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3905 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3906 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3907 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3908 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3909 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3910 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3911 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3912 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 3913 | 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] | 3914 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3915 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3916 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3917 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3918 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 3919 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 3920 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3921 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 3922 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3923 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3924 | vport->num_disc_nodes++; |
| 3925 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3926 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3927 | spin_lock_irq(shost->host_lock); |
| 3928 | vport->fc_flag |= FC_NLP_MORE; |
| 3929 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3930 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3931 | } |
| 3932 | } |
| 3933 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3934 | if (sentplogi) { |
| 3935 | lpfc_set_disctmo(vport); |
| 3936 | } |
| 3937 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3938 | spin_lock_irq(shost->host_lock); |
| 3939 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3940 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3941 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3942 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3943 | } |
| 3944 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3945 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3946 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3947 | * @vport: pointer to a host virtual N_Port data structure. |
| 3948 | * |
| 3949 | * This routine cleans up any Registration State Change Notification |
| 3950 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 3951 | * @vport together with the host_lock is used to prevent multiple thread |
| 3952 | * trying to access the RSCN array on a same @vport at the same time. |
| 3953 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3954 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3955 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3956 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3957 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3958 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3959 | int i; |
| 3960 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3961 | spin_lock_irq(shost->host_lock); |
| 3962 | if (vport->fc_rscn_flush) { |
| 3963 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3964 | spin_unlock_irq(shost->host_lock); |
| 3965 | return; |
| 3966 | } |
| 3967 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 3968 | vport->fc_rscn_flush = 1; |
| 3969 | spin_unlock_irq(shost->host_lock); |
| 3970 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3971 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3972 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3973 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3974 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3975 | spin_lock_irq(shost->host_lock); |
| 3976 | vport->fc_rscn_id_cnt = 0; |
| 3977 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 3978 | spin_unlock_irq(shost->host_lock); |
| 3979 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3980 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 3981 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3982 | } |
| 3983 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3984 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3985 | * 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] | 3986 | * @vport: pointer to a host virtual N_Port data structure. |
| 3987 | * @did: remote destination port identifier. |
| 3988 | * |
| 3989 | * This routine checks whether there is any pending Registration State |
| 3990 | * Configuration Notification (RSCN) to a @did on @vport. |
| 3991 | * |
| 3992 | * Return code |
| 3993 | * None zero - The @did matched with a pending rscn |
| 3994 | * 0 - not able to match @did with a pending rscn |
| 3995 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3996 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3997 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3998 | { |
| 3999 | D_ID ns_did; |
| 4000 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4001 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4002 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4003 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4004 | |
| 4005 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4006 | |
| 4007 | /* Never match fabric nodes for RSCNs */ |
| 4008 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4009 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4010 | |
| 4011 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4012 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4013 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4014 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4015 | spin_lock_irq(shost->host_lock); |
| 4016 | if (vport->fc_rscn_flush) { |
| 4017 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4018 | spin_unlock_irq(shost->host_lock); |
| 4019 | return 0; |
| 4020 | } |
| 4021 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4022 | vport->fc_rscn_flush = 1; |
| 4023 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4024 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4025 | lp = vport->fc_rscn_id_list[i]->virt; |
| 4026 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4027 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4028 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4029 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 4030 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4031 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 4032 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4033 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4034 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 4035 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4036 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4037 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4038 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4039 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4040 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4041 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4042 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4043 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4044 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4045 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4046 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4047 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4048 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4049 | } |
| 4050 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4051 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4052 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4053 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4054 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4055 | return_did_out: |
| 4056 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4057 | vport->fc_rscn_flush = 0; |
| 4058 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4059 | } |
| 4060 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4061 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4062 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4063 | * @vport: pointer to a host virtual N_Port data structure. |
| 4064 | * |
| 4065 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 4066 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 4067 | * State Change Notification). |
| 4068 | * |
| 4069 | * Return code |
| 4070 | * 0 - Successful (currently alway return 0) |
| 4071 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4072 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4073 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4074 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4075 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4076 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4077 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4078 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4079 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4080 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 4081 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4082 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4083 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4084 | NLP_EVT_DEVICE_RECOVERY); |
| 4085 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4086 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4087 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4088 | } |
| 4089 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4090 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4091 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4092 | * @vport: pointer to a host virtual N_Port data structure. |
| 4093 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4094 | * |
| 4095 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 4096 | * applications. |
| 4097 | */ |
| 4098 | static void |
| 4099 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 4100 | struct lpfc_iocbq *cmdiocb) |
| 4101 | { |
| 4102 | struct lpfc_dmabuf *pcmd; |
| 4103 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4104 | uint32_t *payload_ptr; |
| 4105 | uint32_t payload_len; |
| 4106 | struct lpfc_rscn_event_header *rscn_event_data; |
| 4107 | |
| 4108 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4109 | payload_ptr = (uint32_t *) pcmd->virt; |
| 4110 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 4111 | |
| 4112 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 4113 | payload_len, GFP_KERNEL); |
| 4114 | if (!rscn_event_data) { |
| 4115 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4116 | "0147 Failed to allocate memory for RSCN event\n"); |
| 4117 | return; |
| 4118 | } |
| 4119 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 4120 | rscn_event_data->payload_length = payload_len; |
| 4121 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 4122 | payload_len); |
| 4123 | |
| 4124 | fc_host_post_vendor_event(shost, |
| 4125 | fc_get_event_number(), |
| 4126 | sizeof(struct lpfc_els_event_header) + payload_len, |
| 4127 | (char *)rscn_event_data, |
| 4128 | LPFC_NL_VENDOR_ID); |
| 4129 | |
| 4130 | kfree(rscn_event_data); |
| 4131 | } |
| 4132 | |
| 4133 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4134 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4135 | * @vport: pointer to a host virtual N_Port data structure. |
| 4136 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4137 | * @ndlp: pointer to a node-list data structure. |
| 4138 | * |
| 4139 | * This routine processes an unsolicited RSCN (Registration State Change |
| 4140 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 4141 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 4142 | * discover state machine is about to begin discovery, it just accepts the |
| 4143 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 4144 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 4145 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 4146 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 4147 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 4148 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 4149 | * routine is invoked to handle the RSCN event. |
| 4150 | * |
| 4151 | * Return code |
| 4152 | * 0 - Just sent the acc response |
| 4153 | * 1 - Sent the acc response and waited for name server completion |
| 4154 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4155 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4156 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4157 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4158 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4159 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4160 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4161 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4162 | uint32_t *lp, *datap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4163 | IOCB_t *icmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4164 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4165 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4166 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4167 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4168 | |
| 4169 | icmd = &cmdiocb->iocb; |
| 4170 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4171 | lp = (uint32_t *) pcmd->virt; |
| 4172 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4173 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4174 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4175 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4176 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4177 | "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] | 4178 | vport->fc_flag, payload_len, *lp, |
| 4179 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4180 | |
| 4181 | /* Send an RSCN event to the management application */ |
| 4182 | lpfc_send_rscn_event(vport, cmdiocb); |
| 4183 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4184 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4185 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4186 | FCH_EVT_RSCN, lp[i]); |
| 4187 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4188 | /* If we are about to begin discovery, just ACC the RSCN. |
| 4189 | * Discovery processing will satisfy it. |
| 4190 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4191 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4192 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4193 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 4194 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4195 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4196 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4197 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4198 | } |
| 4199 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4200 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 4201 | * just ACC and ignore it. |
| 4202 | */ |
| 4203 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4204 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4205 | i = payload_len; |
| 4206 | datap = lp; |
| 4207 | while (i > 0) { |
| 4208 | nportid = *datap++; |
| 4209 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 4210 | i -= sizeof(uint32_t); |
| 4211 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4212 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 4213 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4214 | } |
| 4215 | if (rscn_id == hba_id) { |
| 4216 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4217 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4218 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4219 | "Data: x%x x%x x%x x%x\n", |
| 4220 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4221 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4222 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4223 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 4224 | ndlp->nlp_DID, vport->port_state, |
| 4225 | ndlp->nlp_flag); |
| 4226 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4227 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4228 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4229 | return 0; |
| 4230 | } |
| 4231 | } |
| 4232 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4233 | spin_lock_irq(shost->host_lock); |
| 4234 | if (vport->fc_rscn_flush) { |
| 4235 | /* Another thread is walking fc_rscn_id_list on this vport */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4236 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 4237 | spin_unlock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4238 | /* Send back ACC */ |
| 4239 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4240 | return 0; |
| 4241 | } |
| 4242 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4243 | vport->fc_rscn_flush = 1; |
| 4244 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4245 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4246 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4247 | /* If we are already processing an RSCN, save the received |
| 4248 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 4249 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4250 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4251 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4252 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 4253 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4254 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4255 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4256 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 4257 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4258 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4259 | vport->fc_flag |= FC_RSCN_MODE; |
| 4260 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4261 | if (rscn_cnt) { |
| 4262 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 4263 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 4264 | } |
| 4265 | if ((rscn_cnt) && |
| 4266 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 4267 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4268 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4269 | memcpy(((uint8_t *)cmd) + length, lp, |
| 4270 | payload_len); |
| 4271 | } else { |
| 4272 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 4273 | vport->fc_rscn_id_cnt++; |
| 4274 | /* If we zero, cmdiocb->context2, the calling |
| 4275 | * routine will not try to free it. |
| 4276 | */ |
| 4277 | cmdiocb->context2 = NULL; |
| 4278 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4279 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4280 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4281 | "0235 Deferred RSCN " |
| 4282 | "Data: x%x x%x x%x\n", |
| 4283 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4284 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4285 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4286 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 4287 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4288 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4289 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4290 | "0234 ReDiscovery RSCN " |
| 4291 | "Data: x%x x%x x%x\n", |
| 4292 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4293 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4294 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4295 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4296 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4297 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4298 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4299 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4300 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4301 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4302 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4303 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4304 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4305 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4306 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4307 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 4308 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4309 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4310 | spin_lock_irq(shost->host_lock); |
| 4311 | vport->fc_flag |= FC_RSCN_MODE; |
| 4312 | spin_unlock_irq(shost->host_lock); |
| 4313 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4314 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4315 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4316 | /* |
| 4317 | * If we zero, cmdiocb->context2, the calling routine will |
| 4318 | * not try to free it. |
| 4319 | */ |
| 4320 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4321 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4322 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4323 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4324 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4325 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4326 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4327 | } |
| 4328 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4329 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4330 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4331 | * @vport: pointer to a host virtual N_Port data structure. |
| 4332 | * |
| 4333 | * This routine handles the Registration State Configuration Notification |
| 4334 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 4335 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 4336 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 4337 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 4338 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 4339 | * RSCN activities with the @vport. |
| 4340 | * |
| 4341 | * Return code |
| 4342 | * 0 - Cleaned up rscn on the @vport |
| 4343 | * 1 - Wait for plogi to name server before proceed |
| 4344 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4345 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4346 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4347 | { |
| 4348 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4349 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4350 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4351 | /* Ignore RSCN if the port is being torn down. */ |
| 4352 | if (vport->load_flag & FC_UNLOADING) { |
| 4353 | lpfc_els_flush_rscn(vport); |
| 4354 | return 0; |
| 4355 | } |
| 4356 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4357 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4358 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4359 | |
| 4360 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4361 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4362 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 4363 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 4364 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4365 | |
| 4366 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4367 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4368 | vport->num_disc_nodes = 0; |
| 4369 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4370 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4371 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 4372 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4373 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4374 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4375 | /* Wait for NameServer query cmpl before we can |
| 4376 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4377 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4378 | } else { |
| 4379 | /* If login to NameServer does not exist, issue one */ |
| 4380 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4381 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4382 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4383 | /* Wait for NameServer login cmpl before we can |
| 4384 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4385 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4386 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4387 | if (ndlp) { |
| 4388 | ndlp = lpfc_enable_node(vport, ndlp, |
| 4389 | NLP_STE_PLOGI_ISSUE); |
| 4390 | if (!ndlp) { |
| 4391 | lpfc_els_flush_rscn(vport); |
| 4392 | return 0; |
| 4393 | } |
| 4394 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4395 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4396 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4397 | if (!ndlp) { |
| 4398 | lpfc_els_flush_rscn(vport); |
| 4399 | return 0; |
| 4400 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4401 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4402 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4403 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4404 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4405 | ndlp->nlp_type |= NLP_FABRIC; |
| 4406 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 4407 | /* Wait for NameServer login cmpl before we can |
| 4408 | * continue |
| 4409 | */ |
| 4410 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4411 | } |
| 4412 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4413 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4414 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4415 | } |
| 4416 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4417 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4418 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4419 | * @vport: pointer to a host virtual N_Port data structure. |
| 4420 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4421 | * @ndlp: pointer to a node-list data structure. |
| 4422 | * |
| 4423 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 4424 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 4425 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 4426 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 4427 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 4428 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 4429 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 4430 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 4431 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 4432 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 4433 | * higher priority (as the winning port) and will initiate PLOGI and |
| 4434 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 4435 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 4436 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 4437 | * |
| 4438 | * Return code |
| 4439 | * 0 - Successfully processed the unsolicited flogi |
| 4440 | * 1 - Failed to process the unsolicited flogi |
| 4441 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4442 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4443 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4444 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4445 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4446 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4447 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4448 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4449 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 4450 | IOCB_t *icmd = &cmdiocb->iocb; |
| 4451 | struct serv_parm *sp; |
| 4452 | LPFC_MBOXQ_t *mbox; |
| 4453 | struct ls_rjt stat; |
| 4454 | uint32_t cmd, did; |
| 4455 | int rc; |
| 4456 | |
| 4457 | cmd = *lp++; |
| 4458 | sp = (struct serv_parm *) lp; |
| 4459 | |
| 4460 | /* FLOGI received */ |
| 4461 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4462 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4463 | |
| 4464 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 4465 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 4466 | did = icmd->un.elsreq64.remoteID; |
| 4467 | |
| 4468 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 4469 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4470 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4471 | "0113 An FLOGI ELS command x%x was " |
| 4472 | "received from DID x%x in Loop Mode\n", |
| 4473 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4474 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4475 | } |
| 4476 | |
| 4477 | did = Fabric_DID; |
| 4478 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 4479 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4480 | /* For a FLOGI we accept, then if our portname is greater |
| 4481 | * then the remote portname we initiate Nport login. |
| 4482 | */ |
| 4483 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4484 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4485 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4486 | |
| 4487 | if (!rc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4488 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4489 | if (!mbox) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4490 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4491 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4492 | lpfc_linkdown(phba); |
| 4493 | lpfc_init_link(phba, mbox, |
| 4494 | phba->cfg_topology, |
| 4495 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4496 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4497 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4498 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4499 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4500 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4501 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4502 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4503 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4504 | return 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4505 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4506 | spin_lock_irq(shost->host_lock); |
| 4507 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 4508 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4509 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4510 | spin_lock_irq(shost->host_lock); |
| 4511 | vport->fc_flag |= FC_PT2PT; |
| 4512 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 4513 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4514 | } else { |
| 4515 | /* Reject this request because invalid parameters */ |
| 4516 | stat.un.b.lsRjtRsvd0 = 0; |
| 4517 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4518 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 4519 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4520 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4521 | NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4522 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4523 | } |
| 4524 | |
| 4525 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4526 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4527 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4528 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4529 | } |
| 4530 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4531 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4532 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4533 | * @vport: pointer to a host virtual N_Port data structure. |
| 4534 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4535 | * @ndlp: pointer to a node-list data structure. |
| 4536 | * |
| 4537 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 4538 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 4539 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 4540 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 4541 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 4542 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 4543 | * |
| 4544 | * Return code |
| 4545 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 4546 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4547 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4548 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4549 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4550 | { |
| 4551 | struct lpfc_dmabuf *pcmd; |
| 4552 | uint32_t *lp; |
| 4553 | IOCB_t *icmd; |
| 4554 | RNID *rn; |
| 4555 | struct ls_rjt stat; |
| 4556 | uint32_t cmd, did; |
| 4557 | |
| 4558 | icmd = &cmdiocb->iocb; |
| 4559 | did = icmd->un.elsreq64.remoteID; |
| 4560 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4561 | lp = (uint32_t *) pcmd->virt; |
| 4562 | |
| 4563 | cmd = *lp++; |
| 4564 | rn = (RNID *) lp; |
| 4565 | |
| 4566 | /* RNID received */ |
| 4567 | |
| 4568 | switch (rn->Format) { |
| 4569 | case 0: |
| 4570 | case RNID_TOPOLOGY_DISC: |
| 4571 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4572 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4573 | break; |
| 4574 | default: |
| 4575 | /* Reject this request because format not supported */ |
| 4576 | stat.un.b.lsRjtRsvd0 = 0; |
| 4577 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4578 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4579 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4580 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4581 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4582 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4583 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4584 | } |
| 4585 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4586 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4587 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4588 | * @vport: pointer to a host virtual N_Port data structure. |
| 4589 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4590 | * @ndlp: pointer to a node-list data structure. |
| 4591 | * |
| 4592 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 4593 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 4594 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 4595 | * |
| 4596 | * Return code |
| 4597 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 4598 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4599 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4600 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4601 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4602 | { |
| 4603 | struct ls_rjt stat; |
| 4604 | |
| 4605 | /* For now, unconditionally reject this command */ |
| 4606 | stat.un.b.lsRjtRsvd0 = 0; |
| 4607 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4608 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4609 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4610 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4611 | return 0; |
| 4612 | } |
| 4613 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4614 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4615 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb |
| 4616 | * @vport: pointer to a host virtual N_Port data structure. |
| 4617 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4618 | * @ndlp: pointer to a node-list data structure. |
| 4619 | * |
| 4620 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB |
| 4621 | * received as an ELS unsolicited event. A request to RRQ shall only |
| 4622 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder |
| 4623 | * Nx_Port N_Port_ID of the target Exchange is the same as the |
| 4624 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is |
| 4625 | * not accepted, an LS_RJT with reason code "Unable to perform |
| 4626 | * command request" and reason code explanation "Invalid Originator |
| 4627 | * S_ID" shall be returned. For now, we just unconditionally accept |
| 4628 | * RRQ from the target. |
| 4629 | **/ |
| 4630 | static void |
| 4631 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4632 | struct lpfc_nodelist *ndlp) |
| 4633 | { |
| 4634 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| 4635 | } |
| 4636 | |
| 4637 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4638 | * 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] | 4639 | * @phba: pointer to lpfc hba data structure. |
| 4640 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4641 | * |
| 4642 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 4643 | * mailbox command. This callback function is to actually send the Accept |
| 4644 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 4645 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 4646 | * mailbox command, constructs the RPS response with the link statistics |
| 4647 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 4648 | * response to the RPS. |
| 4649 | * |
| 4650 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4651 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4652 | * will be stored into the context1 field of the IOCB for the completion |
| 4653 | * callback function to the RPS Accept Response ELS IOCB command. |
| 4654 | * |
| 4655 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4656 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4657 | 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] | 4658 | { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4659 | MAILBOX_t *mb; |
| 4660 | IOCB_t *icmd; |
| 4661 | RPS_RSP *rps_rsp; |
| 4662 | uint8_t *pcmd; |
| 4663 | struct lpfc_iocbq *elsiocb; |
| 4664 | struct lpfc_nodelist *ndlp; |
| 4665 | uint16_t xri, status; |
| 4666 | uint32_t cmdsize; |
| 4667 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4668 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4669 | |
| 4670 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4671 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 4672 | pmb->context1 = NULL; |
| 4673 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4674 | |
| 4675 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4676 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4677 | return; |
| 4678 | } |
| 4679 | |
| 4680 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4681 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4682 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 4683 | lpfc_max_els_tries, ndlp, |
| 4684 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4685 | |
| 4686 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4687 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4688 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4689 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4690 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4691 | |
| 4692 | icmd = &elsiocb->iocb; |
| 4693 | icmd->ulpContext = xri; |
| 4694 | |
| 4695 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4696 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4697 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4698 | rps_rsp = (RPS_RSP *)pcmd; |
| 4699 | |
| 4700 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| 4701 | status = 0x10; |
| 4702 | else |
| 4703 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4704 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4705 | status |= 0x4; |
| 4706 | |
| 4707 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4708 | rps_rsp->portStatus = cpu_to_be16(status); |
| 4709 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 4710 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 4711 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 4712 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 4713 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 4714 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4715 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4716 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 4717 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 4718 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4719 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4720 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4721 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4722 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4723 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4724 | 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] | 4725 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4726 | return; |
| 4727 | } |
| 4728 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4729 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4730 | * lpfc_els_rcv_rps - Process an unsolicited rps iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4731 | * @vport: pointer to a host virtual N_Port data structure. |
| 4732 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4733 | * @ndlp: pointer to a node-list data structure. |
| 4734 | * |
| 4735 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 4736 | * ELS unsolicited event. It first checks the remote port state. If the |
| 4737 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 4738 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 4739 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 4740 | * for reading the HBA link statistics. It is for the callback function, |
| 4741 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 4742 | * to actually sending out RPS Accept (ACC) response. |
| 4743 | * |
| 4744 | * Return codes |
| 4745 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 4746 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4747 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4748 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4749 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4750 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4751 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4752 | uint32_t *lp; |
| 4753 | uint8_t flag; |
| 4754 | LPFC_MBOXQ_t *mbox; |
| 4755 | struct lpfc_dmabuf *pcmd; |
| 4756 | RPS *rps; |
| 4757 | struct ls_rjt stat; |
| 4758 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4759 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4760 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 4761 | /* reject the unsolicited RPS request and done with it */ |
| 4762 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4763 | |
| 4764 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4765 | lp = (uint32_t *) pcmd->virt; |
| 4766 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 4767 | rps = (RPS *) lp; |
| 4768 | |
| 4769 | if ((flag == 0) || |
| 4770 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4771 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4772 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4773 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4774 | printk("Fix me....\n"); |
| 4775 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4776 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 4777 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4778 | lpfc_read_lnk_stat(phba, mbox); |
| 4779 | mbox->context1 = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4780 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4781 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4782 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4783 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4784 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4785 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4786 | /* Mbox completion will send ELS Response */ |
| 4787 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4788 | /* Decrement reference count used for the failed mbox |
| 4789 | * command. |
| 4790 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4791 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4792 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4793 | } |
| 4794 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4795 | |
| 4796 | reject_out: |
| 4797 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4798 | stat.un.b.lsRjtRsvd0 = 0; |
| 4799 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4800 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4801 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4802 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4803 | return 0; |
| 4804 | } |
| 4805 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4806 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4807 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4808 | * @vport: pointer to a host virtual N_Port data structure. |
| 4809 | * @cmdsize: size of the ELS command. |
| 4810 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4811 | * @ndlp: pointer to a node-list data structure. |
| 4812 | * |
| 4813 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 4814 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 4815 | * |
| 4816 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4817 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4818 | * will be stored into the context1 field of the IOCB for the completion |
| 4819 | * callback function to the RPL Accept Response ELS command. |
| 4820 | * |
| 4821 | * Return code |
| 4822 | * 0 - Successfully issued ACC RPL ELS command |
| 4823 | * 1 - Failed to issue ACC RPL ELS command |
| 4824 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4825 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4826 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 4827 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4828 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4829 | struct lpfc_hba *phba = vport->phba; |
| 4830 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4831 | RPL_RSP rpl_rsp; |
| 4832 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4833 | uint8_t *pcmd; |
| 4834 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4835 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4836 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4837 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4838 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4839 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4840 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4841 | icmd = &elsiocb->iocb; |
| 4842 | oldcmd = &oldiocb->iocb; |
| 4843 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 4844 | |
| 4845 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4846 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4847 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4848 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 4849 | pcmd += sizeof(uint16_t); |
| 4850 | |
| 4851 | /* Setup the RPL ACC payload */ |
| 4852 | rpl_rsp.listLen = be32_to_cpu(1); |
| 4853 | rpl_rsp.index = 0; |
| 4854 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4855 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 4856 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4857 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4858 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4859 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4860 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4861 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 4862 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 4863 | "rpi x%x\n", |
| 4864 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4865 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4866 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4867 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4868 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4869 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 4870 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4871 | lpfc_els_free_iocb(phba, elsiocb); |
| 4872 | return 1; |
| 4873 | } |
| 4874 | return 0; |
| 4875 | } |
| 4876 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4877 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4878 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4879 | * @vport: pointer to a host virtual N_Port data structure. |
| 4880 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4881 | * @ndlp: pointer to a node-list data structure. |
| 4882 | * |
| 4883 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 4884 | * unsolicited event. It first checks the remote port state. If the remote |
| 4885 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 4886 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 4887 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 4888 | * to accept the RPL. |
| 4889 | * |
| 4890 | * Return code |
| 4891 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 4892 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4893 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4894 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4895 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4896 | { |
| 4897 | struct lpfc_dmabuf *pcmd; |
| 4898 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4899 | uint32_t maxsize; |
| 4900 | uint16_t cmdsize; |
| 4901 | RPL *rpl; |
| 4902 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4903 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4904 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 4905 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4906 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4907 | stat.un.b.lsRjtRsvd0 = 0; |
| 4908 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4909 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4910 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4911 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4912 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4913 | /* rejected the unsolicited RPL request and done with it */ |
| 4914 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4915 | } |
| 4916 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4917 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4918 | lp = (uint32_t *) pcmd->virt; |
| 4919 | rpl = (RPL *) (lp + 1); |
| 4920 | |
| 4921 | maxsize = be32_to_cpu(rpl->maxsize); |
| 4922 | |
| 4923 | /* We support only one port */ |
| 4924 | if ((rpl->index == 0) && |
| 4925 | ((maxsize == 0) || |
| 4926 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 4927 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4928 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4929 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 4930 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4931 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4932 | |
| 4933 | return 0; |
| 4934 | } |
| 4935 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4936 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4937 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4938 | * @vport: pointer to a virtual N_Port data structure. |
| 4939 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4940 | * @ndlp: pointer to a node-list data structure. |
| 4941 | * |
| 4942 | * This routine processes Fibre Channel Address Resolution Protocol |
| 4943 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 4944 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 4945 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 4946 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 4947 | * remote PortName is compared against the FC PortName stored in the @vport |
| 4948 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 4949 | * compared against the FC NodeName stored in the @vport data structure. |
| 4950 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 4951 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 4952 | * invoked to send out FARP Response to the remote node. Before sending the |
| 4953 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 4954 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 4955 | * routine is invoked to log into the remote port first. |
| 4956 | * |
| 4957 | * Return code |
| 4958 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 4959 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4960 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4961 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4962 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4963 | { |
| 4964 | struct lpfc_dmabuf *pcmd; |
| 4965 | uint32_t *lp; |
| 4966 | IOCB_t *icmd; |
| 4967 | FARP *fp; |
| 4968 | uint32_t cmd, cnt, did; |
| 4969 | |
| 4970 | icmd = &cmdiocb->iocb; |
| 4971 | did = icmd->un.elsreq64.remoteID; |
| 4972 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4973 | lp = (uint32_t *) pcmd->virt; |
| 4974 | |
| 4975 | cmd = *lp++; |
| 4976 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4977 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4978 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4979 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4980 | /* We will only support match on WWPN or WWNN */ |
| 4981 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4982 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4983 | } |
| 4984 | |
| 4985 | cnt = 0; |
| 4986 | /* If this FARP command is searching for my portname */ |
| 4987 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4988 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4989 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4990 | cnt = 1; |
| 4991 | } |
| 4992 | |
| 4993 | /* If this FARP command is searching for my nodename */ |
| 4994 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4995 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4996 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4997 | cnt = 1; |
| 4998 | } |
| 4999 | |
| 5000 | if (cnt) { |
| 5001 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 5002 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 5003 | /* Log back into the node before sending the FARP. */ |
| 5004 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5005 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5006 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 5007 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5008 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5009 | } |
| 5010 | |
| 5011 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5012 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 5013 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5014 | } |
| 5015 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5016 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5017 | } |
| 5018 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5019 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5020 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5021 | * @vport: pointer to a host virtual N_Port data structure. |
| 5022 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5023 | * @ndlp: pointer to a node-list data structure. |
| 5024 | * |
| 5025 | * This routine processes Fibre Channel Address Resolution Protocol |
| 5026 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 5027 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 5028 | * the FARP response request. |
| 5029 | * |
| 5030 | * Return code |
| 5031 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 5032 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5033 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5034 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5035 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5036 | { |
| 5037 | struct lpfc_dmabuf *pcmd; |
| 5038 | uint32_t *lp; |
| 5039 | IOCB_t *icmd; |
| 5040 | uint32_t cmd, did; |
| 5041 | |
| 5042 | icmd = &cmdiocb->iocb; |
| 5043 | did = icmd->un.elsreq64.remoteID; |
| 5044 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5045 | lp = (uint32_t *) pcmd->virt; |
| 5046 | |
| 5047 | cmd = *lp++; |
| 5048 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5049 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5050 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5051 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5052 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5053 | |
| 5054 | return 0; |
| 5055 | } |
| 5056 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5057 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5058 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5059 | * @vport: pointer to a host virtual N_Port data structure. |
| 5060 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5061 | * @fan_ndlp: pointer to a node-list data structure. |
| 5062 | * |
| 5063 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 5064 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 5065 | * only be processed on a physical port (i.e., the @vport represents the |
| 5066 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 5067 | * compared against those in the phba data structure. If any of those is |
| 5068 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 5069 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 5070 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 5071 | * is invoked to register login to the fabric. |
| 5072 | * |
| 5073 | * Return code |
| 5074 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 5075 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5076 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5077 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5078 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5079 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5080 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5081 | uint32_t *lp; |
| 5082 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5083 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5084 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 5085 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 5086 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5087 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5088 | if ((vport == phba->pport) && |
| 5089 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5090 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5091 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5092 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5093 | sizeof(struct lpfc_name)))) { |
| 5094 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5095 | lpfc_initial_flogi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5096 | } else { |
| 5097 | /* FAN verified - skip FLOGI */ |
| 5098 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5099 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5100 | lpfc_issue_fabric_reglogin(vport); |
| 5101 | else |
| 5102 | lpfc_issue_reg_vfi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5103 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5104 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5105 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5106 | } |
| 5107 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5108 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5109 | * lpfc_els_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5110 | * @ptr: holder for the timer function associated data. |
| 5111 | * |
| 5112 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 5113 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 5114 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 5115 | * up the worker thread. It is for the worker thread to invoke the routine |
| 5116 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 5117 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5118 | void |
| 5119 | lpfc_els_timeout(unsigned long ptr) |
| 5120 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5121 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 5122 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5123 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5124 | unsigned long iflag; |
| 5125 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5126 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5127 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
| 5128 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5129 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5130 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5131 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5132 | if (!tmo_posted) |
| 5133 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5134 | return; |
| 5135 | } |
| 5136 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5137 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5138 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5139 | * @vport: pointer to a virtual N_Port data structure. |
| 5140 | * |
| 5141 | * This routine is the actual handler function that processes an ELS timeout |
| 5142 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 5143 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 5144 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5145 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5146 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5147 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5148 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5149 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5150 | struct lpfc_sli_ring *pring; |
| 5151 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5152 | IOCB_t *cmd = NULL; |
| 5153 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5154 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5155 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5156 | uint32_t remote_ID = 0xffffffff; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5157 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5158 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5159 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 5160 | |
| 5161 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5162 | |
| 5163 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5164 | cmd = &piocb->iocb; |
| 5165 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5166 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 5167 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 5168 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5169 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5170 | |
| 5171 | if (piocb->vport != vport) |
| 5172 | continue; |
| 5173 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5174 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5175 | if (pcmd) |
| 5176 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5177 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5178 | if (els_command == ELS_CMD_FARP || |
| 5179 | els_command == ELS_CMD_FARPR || |
| 5180 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5181 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5182 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5183 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5184 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5185 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5186 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5187 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5188 | continue; |
| 5189 | } |
| 5190 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5191 | remote_ID = 0xffffffff; |
| 5192 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5193 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5194 | else { |
| 5195 | struct lpfc_nodelist *ndlp; |
| 5196 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5197 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5198 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5199 | } |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5200 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5201 | "0127 ELS timeout Data: x%x x%x x%x " |
| 5202 | "x%x\n", els_command, |
| 5203 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5204 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5205 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5206 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 5207 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5208 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
| 5209 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5210 | } |
| 5211 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5212 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5213 | * 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] | 5214 | * @vport: pointer to a host virtual N_Port data structure. |
| 5215 | * |
| 5216 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5217 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 5218 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5219 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5220 | * the IOCBs with a non-NULL completion callback function, the callback |
| 5221 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5222 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 5223 | * callback function, the IOCB will simply be released. Finally, it walks |
| 5224 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 5225 | * completion queue IOCB that is associated with the @vport and is not |
| 5226 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 5227 | * part of the discovery state machine) out to HBA by invoking the |
| 5228 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 5229 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 5230 | * the IOCBs are aborted when this function returns. |
| 5231 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5232 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5233 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5234 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5235 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5236 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5237 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5238 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5239 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5240 | |
| 5241 | lpfc_fabric_abort_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5242 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5243 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5244 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5245 | cmd = &piocb->iocb; |
| 5246 | |
| 5247 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5248 | continue; |
| 5249 | } |
| 5250 | |
| 5251 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5252 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5253 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5254 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5255 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5256 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5257 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5258 | if (piocb->vport != vport) |
| 5259 | continue; |
| 5260 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5261 | list_move_tail(&piocb->list, &completions); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5262 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5263 | } |
| 5264 | |
| 5265 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5266 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5267 | continue; |
| 5268 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5269 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5270 | if (piocb->vport != vport) |
| 5271 | continue; |
| 5272 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5273 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5274 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5275 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5276 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5277 | /* Cancell all the IOCBs from the completions list */ |
| 5278 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5279 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5280 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5281 | return; |
| 5282 | } |
| 5283 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5284 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5285 | * 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] | 5286 | * @phba: pointer to lpfc hba data structure. |
| 5287 | * |
| 5288 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5289 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 5290 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5291 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5292 | * the IOCBs with the completion callback function associated, the callback |
| 5293 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5294 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 5295 | * callback function associated, the IOCB will simply be released. Finally, |
| 5296 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 5297 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 5298 | * management plane IOCBs that are not part of the discovery state machine) |
| 5299 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5300 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5301 | void |
| 5302 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 5303 | { |
| 5304 | LIST_HEAD(completions); |
| 5305 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 5306 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5307 | IOCB_t *cmd = NULL; |
| 5308 | |
| 5309 | lpfc_fabric_abort_hba(phba); |
| 5310 | spin_lock_irq(&phba->hbalock); |
| 5311 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5312 | cmd = &piocb->iocb; |
| 5313 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5314 | continue; |
| 5315 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
| 5316 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5317 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5318 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5319 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| 5320 | continue; |
| 5321 | list_move_tail(&piocb->list, &completions); |
| 5322 | pring->txq_cnt--; |
| 5323 | } |
| 5324 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5325 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5326 | continue; |
| 5327 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5328 | } |
| 5329 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5330 | |
| 5331 | /* Cancel all the IOCBs from the completions list */ |
| 5332 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5333 | IOERR_SLI_ABORTED); |
| 5334 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5335 | return; |
| 5336 | } |
| 5337 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5338 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5339 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5340 | * @phba: Pointer to hba context object. |
| 5341 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 5342 | * @rspiocbp: Pointer to response iocb which reported error. |
| 5343 | * |
| 5344 | * This function sends an event when there is an ELS command |
| 5345 | * failure. |
| 5346 | **/ |
| 5347 | void |
| 5348 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 5349 | struct lpfc_iocbq *cmdiocbp, |
| 5350 | struct lpfc_iocbq *rspiocbp) |
| 5351 | { |
| 5352 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 5353 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5354 | struct lpfc_lsrjt_event lsrjt_event; |
| 5355 | struct lpfc_fabric_event_header fabric_event; |
| 5356 | struct ls_rjt stat; |
| 5357 | struct lpfc_nodelist *ndlp; |
| 5358 | uint32_t *pcmd; |
| 5359 | |
| 5360 | ndlp = cmdiocbp->context1; |
| 5361 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 5362 | return; |
| 5363 | |
| 5364 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 5365 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 5366 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 5367 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 5368 | sizeof(struct lpfc_name)); |
| 5369 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 5370 | sizeof(struct lpfc_name)); |
| 5371 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 5372 | cmdiocbp->context2)->virt); |
| 5373 | lsrjt_event.command = *pcmd; |
| 5374 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 5375 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 5376 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 5377 | fc_host_post_vendor_event(shost, |
| 5378 | fc_get_event_number(), |
| 5379 | sizeof(lsrjt_event), |
| 5380 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5381 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5382 | return; |
| 5383 | } |
| 5384 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 5385 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 5386 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 5387 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 5388 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 5389 | else |
| 5390 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 5391 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 5392 | sizeof(struct lpfc_name)); |
| 5393 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 5394 | sizeof(struct lpfc_name)); |
| 5395 | fc_host_post_vendor_event(shost, |
| 5396 | fc_get_event_number(), |
| 5397 | sizeof(fabric_event), |
| 5398 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5399 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5400 | return; |
| 5401 | } |
| 5402 | |
| 5403 | } |
| 5404 | |
| 5405 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5406 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5407 | * @vport: Pointer to vport object. |
| 5408 | * @ndlp: Pointer FC node object. |
| 5409 | * @cmd: ELS command code. |
| 5410 | * |
| 5411 | * This function posts an event when there is an incoming |
| 5412 | * unsolicited ELS command. |
| 5413 | **/ |
| 5414 | static void |
| 5415 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 5416 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5417 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5418 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5419 | struct lpfc_els_event_header *els_data = NULL; |
| 5420 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5421 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5422 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5423 | if (*payload == ELS_CMD_LOGO) { |
| 5424 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 5425 | if (!logo_data) { |
| 5426 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5427 | "0148 Failed to allocate memory " |
| 5428 | "for LOGO event\n"); |
| 5429 | return; |
| 5430 | } |
| 5431 | els_data = &logo_data->header; |
| 5432 | } else { |
| 5433 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 5434 | GFP_KERNEL); |
| 5435 | if (!els_data) { |
| 5436 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5437 | "0149 Failed to allocate memory " |
| 5438 | "for ELS event\n"); |
| 5439 | return; |
| 5440 | } |
| 5441 | } |
| 5442 | els_data->event_type = FC_REG_ELS_EVENT; |
| 5443 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5444 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5445 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5446 | break; |
| 5447 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5448 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5449 | break; |
| 5450 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5451 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 5452 | break; |
| 5453 | case ELS_CMD_LOGO: |
| 5454 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 5455 | /* Copy the WWPN in the LOGO payload */ |
| 5456 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 5457 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5458 | break; |
| 5459 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 5460 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5461 | return; |
| 5462 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5463 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 5464 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 5465 | if (*payload == ELS_CMD_LOGO) { |
| 5466 | fc_host_post_vendor_event(shost, |
| 5467 | fc_get_event_number(), |
| 5468 | sizeof(struct lpfc_logo_event), |
| 5469 | (char *)logo_data, |
| 5470 | LPFC_NL_VENDOR_ID); |
| 5471 | kfree(logo_data); |
| 5472 | } else { |
| 5473 | fc_host_post_vendor_event(shost, |
| 5474 | fc_get_event_number(), |
| 5475 | sizeof(struct lpfc_els_event_header), |
| 5476 | (char *)els_data, |
| 5477 | LPFC_NL_VENDOR_ID); |
| 5478 | kfree(els_data); |
| 5479 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5480 | |
| 5481 | return; |
| 5482 | } |
| 5483 | |
| 5484 | |
| 5485 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5486 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5487 | * @phba: pointer to lpfc hba data structure. |
| 5488 | * @pring: pointer to a SLI ring. |
| 5489 | * @vport: pointer to a host virtual N_Port data structure. |
| 5490 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 5491 | * |
| 5492 | * This routine is used for processing the IOCB associated with a unsolicited |
| 5493 | * event. It first determines whether there is an existing ndlp that matches |
| 5494 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 5495 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 5496 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 5497 | * of the discovery state machine. |
| 5498 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5499 | static void |
| 5500 | 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] | 5501 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5502 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5503 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5504 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5505 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5506 | uint32_t *payload; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5507 | uint32_t cmd, did, newnode, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5508 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5509 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5510 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5511 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5512 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5513 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5514 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 5515 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5516 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5517 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5518 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5519 | did = icmd->un.rcvels.remoteID; |
| 5520 | if (icmd->ulpStatus) { |
| 5521 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5522 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 5523 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5524 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5525 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5526 | |
| 5527 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5528 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5529 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5530 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 5531 | /* Ignore traffic received during vport shutdown. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5532 | if (vport->load_flag & FC_UNLOADING) |
| 5533 | goto dropit; |
| 5534 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5535 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5536 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5537 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5538 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5539 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5540 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5541 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5542 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5543 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5544 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5545 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5546 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5547 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5548 | ndlp = lpfc_enable_node(vport, ndlp, |
| 5549 | NLP_STE_UNUSED_NODE); |
| 5550 | if (!ndlp) |
| 5551 | goto dropit; |
| 5552 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5553 | newnode = 1; |
| 5554 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 5555 | ndlp->nlp_type |= NLP_FABRIC; |
| 5556 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 5557 | /* This is similar to the new node path */ |
| 5558 | ndlp = lpfc_nlp_get(ndlp); |
| 5559 | if (!ndlp) |
| 5560 | goto dropit; |
| 5561 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5562 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5563 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5564 | |
| 5565 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5566 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5567 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5568 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5569 | |
| 5570 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 5571 | cmd &= ELS_CMD_MASK; |
| 5572 | } |
| 5573 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5574 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5575 | "0112 ELS command x%x received from NPORT x%x " |
| 5576 | "Data: x%x\n", cmd, did, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5577 | switch (cmd) { |
| 5578 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5579 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5580 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 5581 | did, vport->port_state, ndlp->nlp_flag); |
| 5582 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5583 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5584 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
| 5585 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5586 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5587 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5588 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 5589 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 5590 | rjt_err = LSRJT_UNABLE_TPC; |
| 5591 | break; |
| 5592 | } |
| 5593 | /* We get here, and drop thru, if we are PT2PT with |
| 5594 | * another NPort and the other side has initiated |
| 5595 | * the PLOGI before responding to our FLOGI. |
| 5596 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5597 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5598 | |
| 5599 | shost = lpfc_shost_from_vport(vport); |
| 5600 | spin_lock_irq(shost->host_lock); |
| 5601 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 5602 | spin_unlock_irq(shost->host_lock); |
| 5603 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5604 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5605 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5606 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5607 | break; |
| 5608 | case ELS_CMD_FLOGI: |
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 FLOGI: 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.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5614 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5615 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5616 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5617 | break; |
| 5618 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5619 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5620 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 5621 | did, vport->port_state, ndlp->nlp_flag); |
| 5622 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5623 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5624 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5625 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5626 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5627 | break; |
| 5628 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5629 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5630 | break; |
| 5631 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5632 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5633 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 5634 | did, vport->port_state, ndlp->nlp_flag); |
| 5635 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5636 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5637 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5638 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5639 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5640 | break; |
| 5641 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5642 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5643 | break; |
| 5644 | case ELS_CMD_RSCN: |
| 5645 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5646 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5647 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5648 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5649 | break; |
| 5650 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5651 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5652 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 5653 | did, vport->port_state, ndlp->nlp_flag); |
| 5654 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5655 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5656 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5657 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5658 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5659 | break; |
| 5660 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5661 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5662 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5663 | break; |
| 5664 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5665 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5666 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 5667 | did, vport->port_state, ndlp->nlp_flag); |
| 5668 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5669 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5670 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5671 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5672 | break; |
| 5673 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5674 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5675 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5676 | break; |
| 5677 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5678 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5679 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 5680 | did, vport->port_state, ndlp->nlp_flag); |
| 5681 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5682 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5683 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5684 | break; |
| 5685 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5686 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5687 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 5688 | did, vport->port_state, ndlp->nlp_flag); |
| 5689 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5690 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5691 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5692 | break; |
| 5693 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5694 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5695 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 5696 | did, vport->port_state, ndlp->nlp_flag); |
| 5697 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5698 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5699 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5700 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5701 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5702 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5703 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 5704 | did, vport->port_state, ndlp->nlp_flag); |
| 5705 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5706 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5707 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5708 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5709 | break; |
| 5710 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5711 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5712 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5713 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5714 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5715 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 5716 | did, vport->port_state, ndlp->nlp_flag); |
| 5717 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5718 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5719 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5720 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5721 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5722 | break; |
| 5723 | case ELS_CMD_RPS: |
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 RPS: did:x%x/ste:x%x flg:x%x", |
| 5726 | did, vport->port_state, ndlp->nlp_flag); |
| 5727 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5728 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5729 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5730 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5731 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5732 | break; |
| 5733 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5734 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5735 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 5736 | did, vport->port_state, ndlp->nlp_flag); |
| 5737 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5738 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5739 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5740 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5741 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5742 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5743 | case ELS_CMD_RNID: |
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 RNID: did:x%x/ste:x%x flg:x%x", |
| 5746 | did, vport->port_state, ndlp->nlp_flag); |
| 5747 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5748 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5749 | lpfc_els_rcv_rnid(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); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5752 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 5753 | case ELS_CMD_RRQ: |
| 5754 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5755 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", |
| 5756 | did, vport->port_state, ndlp->nlp_flag); |
| 5757 | |
| 5758 | phba->fc_stat.elsRcvRRQ++; |
| 5759 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); |
| 5760 | if (newnode) |
| 5761 | lpfc_nlp_put(ndlp); |
| 5762 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5763 | default: |
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 ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 5766 | cmd, did, vport->port_state); |
| 5767 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5768 | /* Unsupported ELS command, reject */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5769 | rjt_err = LSRJT_INVALID_CMD; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5770 | |
| 5771 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5772 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5773 | "0115 Unknown ELS command x%x " |
| 5774 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5775 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5776 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5777 | break; |
| 5778 | } |
| 5779 | |
| 5780 | /* check if need to LS_RJT received ELS cmd */ |
| 5781 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5782 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5783 | stat.un.b.lsRjtRsnCode = rjt_err; |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 5784 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5785 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 5786 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5787 | } |
| 5788 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5789 | lpfc_nlp_put(elsiocb->context1); |
| 5790 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5791 | return; |
| 5792 | |
| 5793 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5794 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5795 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5796 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5797 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5798 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5799 | phba->fc_stat.elsRcvDrop++; |
| 5800 | } |
| 5801 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5802 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5803 | * 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] | 5804 | * @phba: pointer to lpfc hba data structure. |
| 5805 | * @vpi: host virtual N_Port identifier. |
| 5806 | * |
| 5807 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 5808 | * @vpi. The function walks the HBA's vport list and returns the address |
| 5809 | * of the vport with the matching @vpi. |
| 5810 | * |
| 5811 | * Return code |
| 5812 | * NULL - No vport with the matching @vpi found |
| 5813 | * Otherwise - Address to the vport with the matching @vpi. |
| 5814 | **/ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5815 | struct lpfc_vport * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5816 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 5817 | { |
| 5818 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5819 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5820 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5821 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5822 | list_for_each_entry(vport, &phba->port_list, listentry) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5823 | if (vport->vpi == vpi) { |
| 5824 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5825 | return vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5826 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5827 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5828 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5829 | return NULL; |
| 5830 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 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_els_unsol_event - Process an unsolicited event from an els sli ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5834 | * @phba: pointer to lpfc hba data structure. |
| 5835 | * @pring: pointer to a SLI ring. |
| 5836 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 5837 | * |
| 5838 | * This routine is used to process an unsolicited event received from a SLI |
| 5839 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 5840 | * associated with the unsolicited event is done by invoking the routine |
| 5841 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 5842 | * SLI ring on which the unsolicited event was received. |
| 5843 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5844 | void |
| 5845 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 5846 | struct lpfc_iocbq *elsiocb) |
| 5847 | { |
| 5848 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5849 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5850 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5851 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 5852 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5853 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5854 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5855 | elsiocb->context2 = NULL; |
| 5856 | elsiocb->context3 = NULL; |
| 5857 | |
| 5858 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 5859 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 5860 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 5861 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5862 | phba->fc_stat.NoRcvBuf++; |
| 5863 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5864 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5865 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5866 | return; |
| 5867 | } |
| 5868 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5869 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 5870 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 5871 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 5872 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 5873 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5874 | else |
| 5875 | vport = lpfc_find_vport_by_vpid(phba, |
| 5876 | icmd->unsli3.rcvsli3.vpi - phba->vpi_base); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5877 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5878 | /* If there are no BDEs associated |
| 5879 | * with this IOCB, there is nothing to do. |
| 5880 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5881 | if (icmd->ulpBdeCount == 0) |
| 5882 | return; |
| 5883 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5884 | /* type of ELS cmd is first 32bit word |
| 5885 | * in packet |
| 5886 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5887 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5888 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5889 | } else { |
| 5890 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 5891 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5892 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 5893 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5894 | } |
| 5895 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5896 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 5897 | /* |
| 5898 | * The different unsolicited event handlers would tell us |
| 5899 | * if they are done with "mp" by setting context2 to NULL. |
| 5900 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5901 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5902 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 5903 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5904 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5905 | |
| 5906 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5907 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5908 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5909 | elsiocb->context2 = bdeBuf2; |
| 5910 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5911 | /* free mp if we are done with it */ |
| 5912 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5913 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 5914 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5915 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5916 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5917 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5918 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5919 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5920 | * 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] | 5921 | * @phba: pointer to lpfc hba data structure. |
| 5922 | * @vport: pointer to a virtual N_Port data structure. |
| 5923 | * |
| 5924 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 5925 | * State Change Request (SCR) for a @vport. This routine will create an |
| 5926 | * ndlp for the Name Server associated to the @vport if such node does |
| 5927 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 5928 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 5929 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 5930 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 5931 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5932 | void |
| 5933 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 5934 | { |
| 5935 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
| 5936 | |
| 5937 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 5938 | if (!ndlp) { |
| 5939 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 5940 | if (!ndlp) { |
| 5941 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5942 | lpfc_disc_start(vport); |
| 5943 | return; |
| 5944 | } |
| 5945 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5946 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5947 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5948 | return; |
| 5949 | } |
| 5950 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5951 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5952 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 5953 | if (!ndlp) { |
| 5954 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5955 | lpfc_disc_start(vport); |
| 5956 | return; |
| 5957 | } |
| 5958 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5959 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5960 | "0348 NameServer login: node freed\n"); |
| 5961 | return; |
| 5962 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5963 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5964 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5965 | |
| 5966 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 5967 | |
| 5968 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 5969 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5970 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5971 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5972 | return; |
| 5973 | } |
| 5974 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5975 | if (vport->cfg_fdmi_on) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5976 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 5977 | GFP_KERNEL); |
| 5978 | if (ndlp_fdmi) { |
| 5979 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 5980 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5981 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
| 5982 | NLP_STE_PLOGI_ISSUE); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5983 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, |
| 5984 | 0); |
| 5985 | } |
| 5986 | } |
| 5987 | return; |
| 5988 | } |
| 5989 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5990 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5991 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5992 | * @phba: pointer to lpfc hba data structure. |
| 5993 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 5994 | * |
| 5995 | * This routine is the completion callback function to register new vport |
| 5996 | * mailbox command. If the new vport mailbox command completes successfully, |
| 5997 | * the fabric registration login shall be performed on physical port (the |
| 5998 | * new vport created is actually a physical port, with VPI 0) or the port |
| 5999 | * login to Name Server for State Change Request (SCR) will be performed |
| 6000 | * on virtual port (real virtual port, with VPI greater than 0). |
| 6001 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6002 | static void |
| 6003 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6004 | { |
| 6005 | struct lpfc_vport *vport = pmb->vport; |
| 6006 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6007 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6008 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6009 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6010 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6011 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6012 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6013 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6014 | |
| 6015 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6016 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6017 | "0915 Register VPI failed: 0x%x\n", |
| 6018 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6019 | |
| 6020 | switch (mb->mbxStatus) { |
| 6021 | case 0x11: /* unsupported feature */ |
| 6022 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6023 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6024 | /* giving up on vport registration */ |
| 6025 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6026 | spin_lock_irq(shost->host_lock); |
| 6027 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 6028 | spin_unlock_irq(shost->host_lock); |
| 6029 | lpfc_can_disctmo(vport); |
| 6030 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6031 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
| 6032 | case 0x20: |
| 6033 | spin_lock_irq(shost->host_lock); |
| 6034 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 6035 | spin_unlock_irq(shost->host_lock); |
| 6036 | lpfc_init_vpi(phba, pmb, vport->vpi); |
| 6037 | pmb->vport = vport; |
| 6038 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 6039 | rc = lpfc_sli_issue_mbox(phba, pmb, |
| 6040 | MBX_NOWAIT); |
| 6041 | if (rc == MBX_NOT_FINISHED) { |
| 6042 | lpfc_printf_vlog(vport, |
| 6043 | KERN_ERR, LOG_MBOX, |
| 6044 | "2732 Failed to issue INIT_VPI" |
| 6045 | " mailbox command\n"); |
| 6046 | } else { |
| 6047 | lpfc_nlp_put(ndlp); |
| 6048 | return; |
| 6049 | } |
| 6050 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6051 | default: |
| 6052 | /* Try to recover from this error */ |
| 6053 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6054 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6055 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6056 | spin_unlock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame^] | 6057 | if (vport->port_type == LPFC_PHYSICAL_PORT |
| 6058 | && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6059 | lpfc_initial_flogi(vport); |
| 6060 | else |
| 6061 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6062 | break; |
| 6063 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6064 | } else { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6065 | spin_lock_irq(shost->host_lock); |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 6066 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6067 | spin_unlock_irq(shost->host_lock); |
| 6068 | if (vport == phba->pport) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6069 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 6070 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6071 | else { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6072 | /* |
| 6073 | * If the physical port is instantiated using |
| 6074 | * FDISC, do not start vport discovery. |
| 6075 | */ |
| 6076 | if (vport->port_state != LPFC_FDISC) |
| 6077 | lpfc_start_fdiscs(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6078 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6079 | } |
| 6080 | } else |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6081 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6082 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6083 | |
| 6084 | /* Now, we decrement the ndlp reference count held for this |
| 6085 | * callback function |
| 6086 | */ |
| 6087 | lpfc_nlp_put(ndlp); |
| 6088 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6089 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6090 | return; |
| 6091 | } |
| 6092 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6093 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6094 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6095 | * @phba: pointer to lpfc hba data structure. |
| 6096 | * @vport: pointer to a host virtual N_Port data structure. |
| 6097 | * @ndlp: pointer to a node-list data structure. |
| 6098 | * |
| 6099 | * This routine registers the @vport as a new virtual port with a HBA. |
| 6100 | * It is done through a registering vpi mailbox command. |
| 6101 | **/ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6102 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6103 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 6104 | struct lpfc_nodelist *ndlp) |
| 6105 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6106 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6107 | LPFC_MBOXQ_t *mbox; |
| 6108 | |
| 6109 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6110 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6111 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6112 | mbox->vport = vport; |
| 6113 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 6114 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 6115 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6116 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6117 | /* mailbox command not success, decrement ndlp |
| 6118 | * reference count for this command |
| 6119 | */ |
| 6120 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6121 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6122 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6123 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6124 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6125 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6126 | } |
| 6127 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6128 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6129 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6130 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6131 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6132 | return; |
| 6133 | |
| 6134 | mbox_err_exit: |
| 6135 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6136 | spin_lock_irq(shost->host_lock); |
| 6137 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 6138 | spin_unlock_irq(shost->host_lock); |
| 6139 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6140 | } |
| 6141 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6142 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6143 | * 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] | 6144 | * @phba: pointer to lpfc hba data structure. |
| 6145 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6146 | * This routine cancels the retry delay timers to all the vports. |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6147 | **/ |
| 6148 | void |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6149 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6150 | { |
| 6151 | struct lpfc_vport **vports; |
| 6152 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6153 | uint32_t link_state; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6154 | int i; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6155 | |
| 6156 | /* Treat this failure as linkdown for all vports */ |
| 6157 | link_state = phba->link_state; |
| 6158 | lpfc_linkdown(phba); |
| 6159 | phba->link_state = link_state; |
| 6160 | |
| 6161 | vports = lpfc_create_vport_work_array(phba); |
| 6162 | |
| 6163 | if (vports) { |
| 6164 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 6165 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 6166 | if (ndlp) |
| 6167 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
| 6168 | lpfc_els_flush_cmd(vports[i]); |
| 6169 | } |
| 6170 | lpfc_destroy_vport_work_array(phba, vports); |
| 6171 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6172 | } |
| 6173 | |
| 6174 | /** |
| 6175 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. |
| 6176 | * @phba: pointer to lpfc hba data structure. |
| 6177 | * |
| 6178 | * This routine abort all pending discovery commands and |
| 6179 | * start a timer to retry FLOGI for the physical port |
| 6180 | * discovery. |
| 6181 | **/ |
| 6182 | void |
| 6183 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) |
| 6184 | { |
| 6185 | struct lpfc_nodelist *ndlp; |
| 6186 | struct Scsi_Host *shost; |
| 6187 | |
| 6188 | /* Cancel the all vports retry delay retry timers */ |
| 6189 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6190 | |
| 6191 | /* If fabric require FLOGI, then re-instantiate physical login */ |
| 6192 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 6193 | if (!ndlp) |
| 6194 | return; |
| 6195 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6196 | shost = lpfc_shost_from_vport(phba->pport); |
| 6197 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); |
| 6198 | spin_lock_irq(shost->host_lock); |
| 6199 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 6200 | spin_unlock_irq(shost->host_lock); |
| 6201 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; |
| 6202 | phba->pport->port_state = LPFC_FLOGI; |
| 6203 | return; |
| 6204 | } |
| 6205 | |
| 6206 | /** |
| 6207 | * lpfc_fabric_login_reqd - Check if FLOGI required. |
| 6208 | * @phba: pointer to lpfc hba data structure. |
| 6209 | * @cmdiocb: pointer to FDISC command iocb. |
| 6210 | * @rspiocb: pointer to FDISC response iocb. |
| 6211 | * |
| 6212 | * This routine checks if a FLOGI is reguired for FDISC |
| 6213 | * to succeed. |
| 6214 | **/ |
| 6215 | static int |
| 6216 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, |
| 6217 | struct lpfc_iocbq *cmdiocb, |
| 6218 | struct lpfc_iocbq *rspiocb) |
| 6219 | { |
| 6220 | |
| 6221 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || |
| 6222 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) |
| 6223 | return 0; |
| 6224 | else |
| 6225 | return 1; |
| 6226 | } |
| 6227 | |
| 6228 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6229 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6230 | * @phba: pointer to lpfc hba data structure. |
| 6231 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6232 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6233 | * |
| 6234 | * This routine is the completion callback function to a Fabric Discover |
| 6235 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 6236 | * single threaded, each FDISC completion callback function will reset |
| 6237 | * the discovery timer for all vports such that the timers will not get |
| 6238 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 6239 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 6240 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 6241 | * assigned to the vport has been changed with the completion of the FDISC |
| 6242 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 6243 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 6244 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 6245 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 6246 | * Server for State Change Request (SCR). |
| 6247 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6248 | static void |
| 6249 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6250 | struct lpfc_iocbq *rspiocb) |
| 6251 | { |
| 6252 | struct lpfc_vport *vport = cmdiocb->vport; |
| 6253 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6254 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 6255 | struct lpfc_nodelist *np; |
| 6256 | struct lpfc_nodelist *next_np; |
| 6257 | IOCB_t *irsp = &rspiocb->iocb; |
| 6258 | struct lpfc_iocbq *piocb; |
| 6259 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6260 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6261 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 6262 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 6263 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6264 | /* Since all FDISCs are being single threaded, we |
| 6265 | * must reset the discovery timer for ALL vports |
| 6266 | * waiting to send FDISC when one completes. |
| 6267 | */ |
| 6268 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 6269 | lpfc_set_disctmo(piocb->vport); |
| 6270 | } |
| 6271 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6272 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6273 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 6274 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 6275 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6276 | if (irsp->ulpStatus) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6277 | |
| 6278 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { |
| 6279 | lpfc_retry_pport_discovery(phba); |
| 6280 | goto out; |
| 6281 | } |
| 6282 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6283 | /* Check for retry */ |
| 6284 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 6285 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6286 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6287 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6288 | "0126 FDISC failed. (%d/%d)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6289 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6290 | goto fdisc_failed; |
| 6291 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6292 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6293 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame^] | 6294 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6295 | vport->fc_flag |= FC_FABRIC; |
| 6296 | if (vport->phba->fc_topology == TOPOLOGY_LOOP) |
| 6297 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 6298 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6299 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6300 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 6301 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
| 6302 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 6303 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 6304 | /* If our NportID changed, we need to ensure all |
| 6305 | * remaining NPORTs get unreg_login'ed so we can |
| 6306 | * issue unreg_vpi. |
| 6307 | */ |
| 6308 | list_for_each_entry_safe(np, next_np, |
| 6309 | &vport->fc_nodes, nlp_listp) { |
| 6310 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 6311 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 6312 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 6313 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6314 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6315 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6316 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6317 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6318 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6319 | lpfc_mbx_unreg_vpi(vport); |
| 6320 | spin_lock_irq(shost->host_lock); |
| 6321 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 6322 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6323 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame^] | 6324 | else |
| 6325 | vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6326 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6327 | } |
| 6328 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6329 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
| 6330 | lpfc_issue_init_vpi(vport); |
| 6331 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6332 | lpfc_register_new_vport(phba, vport, ndlp); |
| 6333 | else |
| 6334 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6335 | goto out; |
| 6336 | fdisc_failed: |
| 6337 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6338 | /* Cancel discovery timer */ |
| 6339 | lpfc_can_disctmo(vport); |
| 6340 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6341 | out: |
| 6342 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6343 | } |
| 6344 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6345 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6346 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6347 | * @vport: pointer to a virtual N_Port data structure. |
| 6348 | * @ndlp: pointer to a node-list data structure. |
| 6349 | * @retry: number of retries to the command IOCB. |
| 6350 | * |
| 6351 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 6352 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 6353 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 6354 | * IOCB will be sent off HBA at any given time. |
| 6355 | * |
| 6356 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6357 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6358 | * will be stored into the context1 field of the IOCB for the completion |
| 6359 | * callback function to the FDISC ELS command. |
| 6360 | * |
| 6361 | * Return code |
| 6362 | * 0 - Successfully issued fdisc iocb command |
| 6363 | * 1 - Failed to issue fdisc iocb command |
| 6364 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6365 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6366 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 6367 | uint8_t retry) |
| 6368 | { |
| 6369 | struct lpfc_hba *phba = vport->phba; |
| 6370 | IOCB_t *icmd; |
| 6371 | struct lpfc_iocbq *elsiocb; |
| 6372 | struct serv_parm *sp; |
| 6373 | uint8_t *pcmd; |
| 6374 | uint16_t cmdsize; |
| 6375 | int did = ndlp->nlp_DID; |
| 6376 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6377 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6378 | vport->port_state = LPFC_FDISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6379 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 6380 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 6381 | ELS_CMD_FDISC); |
| 6382 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6383 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6384 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6385 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6386 | return 1; |
| 6387 | } |
| 6388 | |
| 6389 | icmd = &elsiocb->iocb; |
| 6390 | icmd->un.elsreq64.myID = 0; |
| 6391 | icmd->un.elsreq64.fl = 1; |
| 6392 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6393 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 6394 | /* FDISC needs to be 1 for WQE VPI */ |
| 6395 | elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1; |
| 6396 | elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ; |
| 6397 | /* Set the ulpContext to the vpi */ |
| 6398 | elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base; |
| 6399 | } else { |
| 6400 | /* For FDISC, Let FDISC rsp set the NPortID for this VPI */ |
| 6401 | icmd->ulpCt_h = 1; |
| 6402 | icmd->ulpCt_l = 0; |
| 6403 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6404 | |
| 6405 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6406 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 6407 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 6408 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 6409 | sp = (struct serv_parm *) pcmd; |
| 6410 | /* Setup CSPs accordingly for Fabric */ |
| 6411 | sp->cmn.e_d_tov = 0; |
| 6412 | sp->cmn.w2.r_a_tov = 0; |
| 6413 | sp->cls1.classValid = 0; |
| 6414 | sp->cls2.seqDelivery = 1; |
| 6415 | sp->cls3.seqDelivery = 1; |
| 6416 | |
| 6417 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 6418 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 6419 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 6420 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 6421 | memcpy(pcmd, &vport->fc_portname, 8); |
| 6422 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6423 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6424 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 6425 | |
| 6426 | lpfc_set_disctmo(vport); |
| 6427 | |
| 6428 | phba->fc_stat.elsXmitFDISC++; |
| 6429 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 6430 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6431 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6432 | "Issue FDISC: did:x%x", |
| 6433 | did, 0, 0); |
| 6434 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6435 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 6436 | if (rc == IOCB_ERROR) { |
| 6437 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6438 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6439 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6440 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6441 | return 1; |
| 6442 | } |
| 6443 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6444 | return 0; |
| 6445 | } |
| 6446 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6447 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6448 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6449 | * @phba: pointer to lpfc hba data structure. |
| 6450 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6451 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6452 | * |
| 6453 | * This routine is the completion callback function to the issuing of a LOGO |
| 6454 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 6455 | * reference count held on ndlp for this completion function, indicating that |
| 6456 | * the reference to the ndlp is no long needed. Note that the |
| 6457 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 6458 | * callback function and an additional explicit ndlp reference decrementation |
| 6459 | * will trigger the actual release of the ndlp. |
| 6460 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6461 | static void |
| 6462 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6463 | struct lpfc_iocbq *rspiocb) |
| 6464 | { |
| 6465 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6466 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6467 | struct lpfc_nodelist *ndlp; |
| 6468 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6469 | |
| 6470 | irsp = &rspiocb->iocb; |
| 6471 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6472 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 6473 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6474 | |
| 6475 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6476 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6477 | |
| 6478 | /* Trigger the release of the ndlp after logo */ |
| 6479 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6480 | } |
| 6481 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6482 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6483 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6484 | * @vport: pointer to a virtual N_Port data structure. |
| 6485 | * @ndlp: pointer to a node-list data structure. |
| 6486 | * |
| 6487 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 6488 | * |
| 6489 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6490 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6491 | * will be stored into the context1 field of the IOCB for the completion |
| 6492 | * callback function to the LOGO ELS command. |
| 6493 | * |
| 6494 | * Return codes |
| 6495 | * 0 - Successfully issued logo off the @vport |
| 6496 | * 1 - Failed to issue logo off the @vport |
| 6497 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6498 | int |
| 6499 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 6500 | { |
| 6501 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6502 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6503 | IOCB_t *icmd; |
| 6504 | struct lpfc_iocbq *elsiocb; |
| 6505 | uint8_t *pcmd; |
| 6506 | uint16_t cmdsize; |
| 6507 | |
| 6508 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 6509 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 6510 | ELS_CMD_LOGO); |
| 6511 | if (!elsiocb) |
| 6512 | return 1; |
| 6513 | |
| 6514 | icmd = &elsiocb->iocb; |
| 6515 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6516 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 6517 | pcmd += sizeof(uint32_t); |
| 6518 | |
| 6519 | /* Fill in LOGO payload */ |
| 6520 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 6521 | pcmd += sizeof(uint32_t); |
| 6522 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 6523 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6524 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6525 | "Issue LOGO npiv did:x%x flg:x%x", |
| 6526 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 6527 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6528 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 6529 | spin_lock_irq(shost->host_lock); |
| 6530 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 6531 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6532 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 6533 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6534 | spin_lock_irq(shost->host_lock); |
| 6535 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 6536 | spin_unlock_irq(shost->host_lock); |
| 6537 | lpfc_els_free_iocb(phba, elsiocb); |
| 6538 | return 1; |
| 6539 | } |
| 6540 | return 0; |
| 6541 | } |
| 6542 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6543 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6544 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6545 | * @ptr: holder for the timer function associated data. |
| 6546 | * |
| 6547 | * This routine is invoked by the fabric iocb block timer after |
| 6548 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 6549 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 6550 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 6551 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 6552 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 6553 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6554 | void |
| 6555 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 6556 | { |
| 6557 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 6558 | unsigned long iflags; |
| 6559 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6560 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6561 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 6562 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 6563 | if (!tmo_posted) |
| 6564 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 6565 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 6566 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6567 | if (!tmo_posted) |
| 6568 | lpfc_worker_wake_up(phba); |
| 6569 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6570 | } |
| 6571 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6572 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6573 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6574 | * @phba: pointer to lpfc hba data structure. |
| 6575 | * |
| 6576 | * This routine issues one fabric iocb from the driver internal list to |
| 6577 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 6578 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 6579 | * remove one pending fabric iocb from the driver internal list and invokes |
| 6580 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 6581 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6582 | static void |
| 6583 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 6584 | { |
| 6585 | struct lpfc_iocbq *iocb; |
| 6586 | unsigned long iflags; |
| 6587 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6588 | IOCB_t *cmd; |
| 6589 | |
| 6590 | repeat: |
| 6591 | iocb = NULL; |
| 6592 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6593 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6594 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 6595 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 6596 | list); |
| 6597 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6598 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6599 | atomic_inc(&phba->fabric_iocb_count); |
| 6600 | } |
| 6601 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6602 | if (iocb) { |
| 6603 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6604 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6605 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6606 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6607 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6608 | "Fabric sched1: ste:x%x", |
| 6609 | iocb->vport->port_state, 0, 0); |
| 6610 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6611 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6612 | |
| 6613 | if (ret == IOCB_ERROR) { |
| 6614 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6615 | iocb->fabric_iocb_cmpl = NULL; |
| 6616 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6617 | cmd = &iocb->iocb; |
| 6618 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6619 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6620 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 6621 | |
| 6622 | atomic_dec(&phba->fabric_iocb_count); |
| 6623 | goto repeat; |
| 6624 | } |
| 6625 | } |
| 6626 | |
| 6627 | return; |
| 6628 | } |
| 6629 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6630 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6631 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6632 | * @phba: pointer to lpfc hba data structure. |
| 6633 | * |
| 6634 | * This routine unblocks the issuing fabric iocb command. The function |
| 6635 | * will clear the fabric iocb block bit and then invoke the routine |
| 6636 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 6637 | * from the driver internal fabric iocb list. |
| 6638 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6639 | void |
| 6640 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 6641 | { |
| 6642 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6643 | |
| 6644 | lpfc_resume_fabric_iocbs(phba); |
| 6645 | return; |
| 6646 | } |
| 6647 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6648 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6649 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6650 | * @phba: pointer to lpfc hba data structure. |
| 6651 | * |
| 6652 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 6653 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 6654 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 6655 | * fabric iocb will be issued out of the HBA. |
| 6656 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6657 | static void |
| 6658 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 6659 | { |
| 6660 | int blocked; |
| 6661 | |
| 6662 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6663 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6664 | if (!blocked) |
| 6665 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); |
| 6666 | |
| 6667 | return; |
| 6668 | } |
| 6669 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6670 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6671 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6672 | * @phba: pointer to lpfc hba data structure. |
| 6673 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6674 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6675 | * |
| 6676 | * This routine is the callback function that is put to the fabric iocb's |
| 6677 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 6678 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 6679 | * function first restores and invokes the original iocb's callback function |
| 6680 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 6681 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 6682 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6683 | static void |
| 6684 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6685 | struct lpfc_iocbq *rspiocb) |
| 6686 | { |
| 6687 | struct ls_rjt stat; |
| 6688 | |
| 6689 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 6690 | BUG(); |
| 6691 | |
| 6692 | switch (rspiocb->iocb.ulpStatus) { |
| 6693 | case IOSTAT_NPORT_RJT: |
| 6694 | case IOSTAT_FABRIC_RJT: |
| 6695 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 6696 | lpfc_block_fabric_iocbs(phba); |
| 6697 | } |
| 6698 | break; |
| 6699 | |
| 6700 | case IOSTAT_NPORT_BSY: |
| 6701 | case IOSTAT_FABRIC_BSY: |
| 6702 | lpfc_block_fabric_iocbs(phba); |
| 6703 | break; |
| 6704 | |
| 6705 | case IOSTAT_LS_RJT: |
| 6706 | stat.un.lsRjtError = |
| 6707 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 6708 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 6709 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 6710 | lpfc_block_fabric_iocbs(phba); |
| 6711 | break; |
| 6712 | } |
| 6713 | |
| 6714 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 6715 | BUG(); |
| 6716 | |
| 6717 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 6718 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 6719 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6720 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 6721 | |
| 6722 | atomic_dec(&phba->fabric_iocb_count); |
| 6723 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6724 | /* Post any pending iocbs to HBA */ |
| 6725 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6726 | } |
| 6727 | } |
| 6728 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6729 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6730 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6731 | * @phba: pointer to lpfc hba data structure. |
| 6732 | * @iocb: pointer to lpfc command iocb data structure. |
| 6733 | * |
| 6734 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 6735 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 6736 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 6737 | * any given time. As such, this function will first check to see whether there |
| 6738 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 6739 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 6740 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 6741 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 6742 | * |
| 6743 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 6744 | * order. The problem is caused by the construction of the "ready" boolen does |
| 6745 | * not include the condition that the internal fabric IOCB list is empty. As |
| 6746 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 6747 | * ahead of the fabric IOCBs in the internal list. |
| 6748 | * |
| 6749 | * Return code |
| 6750 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 6751 | * IOCB_ERROR - failed to issue fabric iocb |
| 6752 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6753 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6754 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 6755 | { |
| 6756 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6757 | int ready; |
| 6758 | int ret; |
| 6759 | |
| 6760 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 6761 | BUG(); |
| 6762 | |
| 6763 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6764 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 6765 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6766 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6767 | if (ready) |
| 6768 | /* Increment fabric iocb count to hold the position */ |
| 6769 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6770 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6771 | if (ready) { |
| 6772 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6773 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6774 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6775 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6776 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6777 | "Fabric sched2: ste:x%x", |
| 6778 | iocb->vport->port_state, 0, 0); |
| 6779 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6780 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6781 | |
| 6782 | if (ret == IOCB_ERROR) { |
| 6783 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6784 | iocb->fabric_iocb_cmpl = NULL; |
| 6785 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6786 | atomic_dec(&phba->fabric_iocb_count); |
| 6787 | } |
| 6788 | } else { |
| 6789 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6790 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 6791 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6792 | ret = IOCB_SUCCESS; |
| 6793 | } |
| 6794 | return ret; |
| 6795 | } |
| 6796 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6797 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6798 | * 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] | 6799 | * @vport: pointer to a virtual N_Port data structure. |
| 6800 | * |
| 6801 | * This routine aborts all the IOCBs associated with a @vport from the |
| 6802 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6803 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6804 | * list, removes each IOCB associated with the @vport off the list, set the |
| 6805 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6806 | * associated with the IOCB. |
| 6807 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6808 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6809 | { |
| 6810 | LIST_HEAD(completions); |
| 6811 | struct lpfc_hba *phba = vport->phba; |
| 6812 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6813 | |
| 6814 | spin_lock_irq(&phba->hbalock); |
| 6815 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6816 | list) { |
| 6817 | |
| 6818 | if (piocb->vport != vport) |
| 6819 | continue; |
| 6820 | |
| 6821 | list_move_tail(&piocb->list, &completions); |
| 6822 | } |
| 6823 | spin_unlock_irq(&phba->hbalock); |
| 6824 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6825 | /* Cancel all the IOCBs from the completions list */ |
| 6826 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6827 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6828 | } |
| 6829 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6830 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6831 | * 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] | 6832 | * @ndlp: pointer to a node-list data structure. |
| 6833 | * |
| 6834 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 6835 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6836 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6837 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 6838 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6839 | * associated with the IOCB. |
| 6840 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6841 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 6842 | { |
| 6843 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6844 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6845 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6846 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6847 | |
| 6848 | spin_lock_irq(&phba->hbalock); |
| 6849 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6850 | list) { |
| 6851 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 6852 | |
| 6853 | list_move_tail(&piocb->list, &completions); |
| 6854 | } |
| 6855 | } |
| 6856 | spin_unlock_irq(&phba->hbalock); |
| 6857 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6858 | /* Cancel all the IOCBs from the completions list */ |
| 6859 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6860 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6861 | } |
| 6862 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6863 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6864 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6865 | * @phba: pointer to lpfc hba data structure. |
| 6866 | * |
| 6867 | * This routine aborts all the IOCBs currently on the driver internal |
| 6868 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 6869 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 6870 | * list, removes IOCBs off the list, set the status feild to |
| 6871 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 6872 | * the IOCB. |
| 6873 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6874 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 6875 | { |
| 6876 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6877 | |
| 6878 | spin_lock_irq(&phba->hbalock); |
| 6879 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 6880 | spin_unlock_irq(&phba->hbalock); |
| 6881 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6882 | /* Cancel all the IOCBs from the completions list */ |
| 6883 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6884 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6885 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6886 | |
| 6887 | /** |
| 6888 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 6889 | * @phba: pointer to lpfc hba data structure. |
| 6890 | * @axri: pointer to the els xri abort wcqe structure. |
| 6891 | * |
| 6892 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 6893 | * ELS aborted xri. |
| 6894 | **/ |
| 6895 | void |
| 6896 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 6897 | struct sli4_wcqe_xri_aborted *axri) |
| 6898 | { |
| 6899 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
| 6900 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 6901 | unsigned long iflag = 0; |
| 6902 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 6903 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 6904 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6905 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 6906 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 6907 | if (sglq_entry->sli4_xritag == xri) { |
| 6908 | list_del(&sglq_entry->list); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6909 | list_add_tail(&sglq_entry->list, |
| 6910 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 6911 | sglq_entry->state = SGL_FREED; |
| 6912 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6913 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 6914 | return; |
| 6915 | } |
| 6916 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 6917 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 6918 | sglq_entry = __lpfc_get_active_sglq(phba, xri); |
| 6919 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { |
| 6920 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 6921 | return; |
| 6922 | } |
| 6923 | sglq_entry->state = SGL_XRI_ABORTED; |
| 6924 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 6925 | return; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6926 | } |