| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | d8e93df | 2009-05-22 14:53:05 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2009 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 5 | * EMULEX and SLI are trademarks of Emulex. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6 | * www.emulex.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8 | * * |
| 9 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 10 | * modify it under the terms of version 2 of the GNU General * |
| 11 | * Public License as published by the Free Software Foundation. * |
| 12 | * This program is distributed in the hope that it will be useful. * |
| 13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 18 | * more details, a copy of which can be found in the file COPYING * |
| 19 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 20 | *******************************************************************/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 21 | /* See Fibre Channel protocol T11 FC-LS for details */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | #include <linux/blkdev.h> |
| 23 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/slab.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 25 | #include <linux/interrupt.h> |
| 26 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 27 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 28 | #include <scsi/scsi_device.h> |
| 29 | #include <scsi/scsi_host.h> |
| 30 | #include <scsi/scsi_transport_fc.h> |
| 31 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 32 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 33 | #include "lpfc_hw.h" |
| 34 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 35 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 36 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 37 | #include "lpfc_disc.h" |
| 38 | #include "lpfc_scsi.h" |
| 39 | #include "lpfc.h" |
| 40 | #include "lpfc_logmsg.h" |
| 41 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 42 | #include "lpfc_vport.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 43 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 44 | |
| 45 | static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *, |
| 46 | struct lpfc_iocbq *); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 47 | static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *, |
| 48 | struct lpfc_iocbq *); |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 49 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport); |
| 50 | static int lpfc_issue_els_fdisc(struct lpfc_vport *vport, |
| 51 | struct lpfc_nodelist *ndlp, uint8_t retry); |
| 52 | static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba, |
| 53 | struct lpfc_iocbq *iocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 54 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 55 | static int lpfc_max_els_tries = 3; |
| 56 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 57 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 58 | * lpfc_els_chk_latt - Check host link attention event for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 59 | * @vport: pointer to a host virtual N_Port data structure. |
| 60 | * |
| 61 | * This routine checks whether there is an outstanding host link |
| 62 | * attention event during the discovery process with the @vport. It is done |
| 63 | * by reading the HBA's Host Attention (HA) register. If there is any host |
| 64 | * link attention events during this @vport's discovery process, the @vport |
| 65 | * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall |
| 66 | * be issued if the link state is not already in host link cleared state, |
| 67 | * and a return code shall indicate whether the host link attention event |
| 68 | * had happened. |
| 69 | * |
| 70 | * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport |
| 71 | * state in LPFC_VPORT_READY, the request for checking host link attention |
| 72 | * event will be ignored and a return code shall indicate no host link |
| 73 | * attention event had happened. |
| 74 | * |
| 75 | * Return codes |
| 76 | * 0 - no host link attention event happened |
| 77 | * 1 - host link attention event happened |
| 78 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 79 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 80 | lpfc_els_chk_latt(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 81 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 82 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 83 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 84 | uint32_t ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 85 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 86 | if (vport->port_state >= LPFC_VPORT_READY || |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 87 | phba->link_state == LPFC_LINK_DOWN || |
| 88 | phba->sli_rev > LPFC_SLI_REV3) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 89 | return 0; |
| 90 | |
| 91 | /* Read the HBA Host Attention Register */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 92 | ha_copy = readl(phba->HAregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 93 | |
| 94 | if (!(ha_copy & HA_LATT)) |
| 95 | return 0; |
| 96 | |
| 97 | /* Pending Link Event during Discovery */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 98 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 99 | "0237 Pending Link Event during " |
| 100 | "Discovery: State x%x\n", |
| 101 | phba->pport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 102 | |
| 103 | /* CLEAR_LA should re-enable link attention events and |
| 104 | * we should then imediately take a LATT event. The |
| 105 | * LATT processing should call lpfc_linkdown() which |
| 106 | * will cleanup any left over in-progress discovery |
| 107 | * events. |
| 108 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 109 | spin_lock_irq(shost->host_lock); |
| 110 | vport->fc_flag |= FC_ABORT_DISCOVERY; |
| 111 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 112 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 113 | if (phba->link_state != LPFC_CLEAR_LA) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 114 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 115 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 116 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 117 | } |
| 118 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 119 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 120 | * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 121 | * @vport: pointer to a host virtual N_Port data structure. |
| 122 | * @expectRsp: flag indicating whether response is expected. |
| 123 | * @cmdSize: size of the ELS command. |
| 124 | * @retry: number of retries to the command IOCB when it fails. |
| 125 | * @ndlp: pointer to a node-list data structure. |
| 126 | * @did: destination identifier. |
| 127 | * @elscmd: the ELS command code. |
| 128 | * |
| 129 | * This routine is used for allocating a lpfc-IOCB data structure from |
| 130 | * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters |
| 131 | * passed into the routine for discovery state machine to issue an Extended |
| 132 | * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation |
| 133 | * and preparation routine that is used by all the discovery state machine |
| 134 | * routines and the ELS command-specific fields will be later set up by |
| 135 | * the individual discovery machine routines after calling this routine |
| 136 | * allocating and preparing a generic IOCB data structure. It fills in the |
| 137 | * Buffer Descriptor Entries (BDEs), allocates buffers for both command |
| 138 | * payload and response payload (if expected). The reference count on the |
| 139 | * ndlp is incremented by 1 and the reference to the ndlp is put into |
| 140 | * context1 of the IOCB data structure for this IOCB to hold the ndlp |
| 141 | * reference for the command's callback function to access later. |
| 142 | * |
| 143 | * Return code |
| 144 | * Pointer to the newly allocated/prepared els iocb data structure |
| 145 | * NULL - when els iocb data structure allocation/preparation failed |
| 146 | **/ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 147 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 148 | lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, |
| 149 | uint16_t cmdSize, uint8_t retry, |
| 150 | struct lpfc_nodelist *ndlp, uint32_t did, |
| 151 | uint32_t elscmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 152 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 153 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 154 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 155 | struct lpfc_dmabuf *pcmd, *prsp, *pbuflist; |
| 156 | struct ulp_bde64 *bpl; |
| 157 | IOCB_t *icmd; |
| 158 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 159 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 160 | if (!lpfc_is_link_up(phba)) |
| 161 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 162 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 163 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 164 | elsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 165 | |
| 166 | if (elsiocb == NULL) |
| 167 | return NULL; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 168 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 169 | /* |
| 170 | * If this command is for fabric controller and HBA running |
| 171 | * in FIP mode send FLOGI, FDISC and LOGO as FIP frames. |
| 172 | */ |
| 173 | if ((did == Fabric_DID) && |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 174 | (phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 175 | ((elscmd == ELS_CMD_FLOGI) || |
| 176 | (elscmd == ELS_CMD_FDISC) || |
| 177 | (elscmd == ELS_CMD_LOGO))) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 178 | switch (elscmd) { |
| 179 | case ELS_CMD_FLOGI: |
| 180 | elsiocb->iocb_flag |= ((ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT) |
| 181 | & LPFC_FIP_ELS_ID_MASK); |
| 182 | break; |
| 183 | case ELS_CMD_FDISC: |
| 184 | elsiocb->iocb_flag |= ((ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT) |
| 185 | & LPFC_FIP_ELS_ID_MASK); |
| 186 | break; |
| 187 | case ELS_CMD_LOGO: |
| 188 | elsiocb->iocb_flag |= ((ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT) |
| 189 | & LPFC_FIP_ELS_ID_MASK); |
| 190 | break; |
| 191 | } |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 192 | else |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 193 | elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 194 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 195 | icmd = &elsiocb->iocb; |
| 196 | |
| 197 | /* fill in BDEs for command */ |
| 198 | /* Allocate buffer for command payload */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 199 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 200 | if (pcmd) |
| 201 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 202 | if (!pcmd || !pcmd->virt) |
| 203 | goto els_iocb_free_pcmb_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 204 | |
| 205 | INIT_LIST_HEAD(&pcmd->list); |
| 206 | |
| 207 | /* Allocate buffer for response payload */ |
| 208 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 209 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 210 | if (prsp) |
| 211 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 212 | &prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 213 | if (!prsp || !prsp->virt) |
| 214 | goto els_iocb_free_prsp_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 215 | INIT_LIST_HEAD(&prsp->list); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 216 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 217 | prsp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 218 | |
| 219 | /* Allocate buffer for Buffer ptr list */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 220 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 221 | if (pbuflist) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 222 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 223 | &pbuflist->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 224 | if (!pbuflist || !pbuflist->virt) |
| 225 | goto els_iocb_free_pbuf_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 226 | |
| 227 | INIT_LIST_HEAD(&pbuflist->list); |
| 228 | |
| 229 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 230 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 231 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 232 | icmd->un.elsreq64.remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 233 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 234 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 235 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 236 | icmd->ulpTimeout = phba->fc_ratov * 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 237 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 238 | icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 239 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; |
| 240 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 241 | icmd->ulpBdeCount = 1; |
| 242 | icmd->ulpLe = 1; |
| 243 | icmd->ulpClass = CLASS3; |
| 244 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 245 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 246 | icmd->un.elsreq64.myID = vport->fc_myDID; |
| 247 | |
| 248 | /* For ELS_REQUEST64_CR, use the VPI by default */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 249 | icmd->ulpContext = vport->vpi + phba->vpi_base; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 250 | icmd->ulpCt_h = 0; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 251 | /* The CT field must be 0=INVALID_RPI for the ECHO cmd */ |
| 252 | if (elscmd == ELS_CMD_ECHO) |
| 253 | icmd->ulpCt_l = 0; /* context = invalid RPI */ |
| 254 | else |
| 255 | icmd->ulpCt_l = 1; /* context = VPI */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 256 | } |
| 257 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 258 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
| 259 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); |
| 260 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); |
| 261 | bpl->tus.f.bdeSize = cmdSize; |
| 262 | bpl->tus.f.bdeFlags = 0; |
| 263 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 264 | |
| 265 | if (expectRsp) { |
| 266 | bpl++; |
| 267 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); |
| 268 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); |
| 269 | bpl->tus.f.bdeSize = FCELSSIZE; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 270 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 271 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 272 | } |
| 273 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 274 | /* prevent preparing iocb with NULL ndlp reference */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 275 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 276 | if (!elsiocb->context1) |
| 277 | goto els_iocb_free_pbuf_exit; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 278 | elsiocb->context2 = pcmd; |
| 279 | elsiocb->context3 = pbuflist; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 280 | elsiocb->retry = retry; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 281 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 282 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
| 283 | |
| 284 | if (prsp) { |
| 285 | list_add(&prsp->list, &pcmd->list); |
| 286 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 287 | if (expectRsp) { |
| 288 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 289 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 290 | "0116 Xmit ELS command x%x to remote " |
| 291 | "NPORT x%x I/O tag: x%x, port state: x%x\n", |
| 292 | elscmd, did, elsiocb->iotag, |
| 293 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 294 | } else { |
| 295 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 296 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 297 | "0117 Xmit ELS response x%x to remote " |
| 298 | "NPORT x%x I/O tag: x%x, size: x%x\n", |
| 299 | elscmd, ndlp->nlp_DID, elsiocb->iotag, |
| 300 | cmdSize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 301 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 302 | return elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 303 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 304 | els_iocb_free_pbuf_exit: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 305 | if (expectRsp) |
| 306 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 307 | kfree(pbuflist); |
| 308 | |
| 309 | els_iocb_free_prsp_exit: |
| 310 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 311 | kfree(prsp); |
| 312 | |
| 313 | els_iocb_free_pcmb_exit: |
| 314 | kfree(pcmd); |
| 315 | lpfc_sli_release_iocbq(phba, elsiocb); |
| 316 | return NULL; |
| 317 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 318 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 319 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 320 | * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 321 | * @vport: pointer to a host virtual N_Port data structure. |
| 322 | * |
| 323 | * This routine issues a fabric registration login for a @vport. An |
| 324 | * active ndlp node with Fabric_DID must already exist for this @vport. |
| 325 | * The routine invokes two mailbox commands to carry out fabric registration |
| 326 | * login through the HBA firmware: the first mailbox command requests the |
| 327 | * HBA to perform link configuration for the @vport; and the second mailbox |
| 328 | * command requests the HBA to perform the actual fabric registration login |
| 329 | * with the @vport. |
| 330 | * |
| 331 | * Return code |
| 332 | * 0 - successfully issued fabric registration login for @vport |
| 333 | * -ENXIO -- failed to issue fabric registration login for @vport |
| 334 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 335 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 336 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
| 337 | { |
| 338 | struct lpfc_hba *phba = vport->phba; |
| 339 | LPFC_MBOXQ_t *mbox; |
| 340 | struct lpfc_dmabuf *mp; |
| 341 | struct lpfc_nodelist *ndlp; |
| 342 | struct serv_parm *sp; |
| 343 | int rc; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 344 | int err = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 345 | |
| 346 | sp = &phba->fc_fabparam; |
| 347 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 348 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 349 | err = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 350 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 351 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 352 | |
| 353 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 354 | if (!mbox) { |
| 355 | err = 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 356 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 357 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 358 | |
| 359 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 360 | lpfc_config_link(phba, mbox); |
| 361 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 362 | mbox->vport = vport; |
| 363 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 364 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 365 | if (rc == MBX_NOT_FINISHED) { |
| 366 | err = 3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 367 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 368 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 369 | |
| 370 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 371 | if (!mbox) { |
| 372 | err = 4; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 373 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 374 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 375 | rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, 0); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 376 | if (rc) { |
| 377 | err = 5; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 378 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 379 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 380 | |
| 381 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; |
| 382 | mbox->vport = vport; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 383 | /* increment the reference count on ndlp to hold reference |
| 384 | * for the callback routine. |
| 385 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 386 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 387 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 388 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 389 | if (rc == MBX_NOT_FINISHED) { |
| 390 | err = 6; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 391 | goto fail_issue_reg_login; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 392 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 393 | |
| 394 | return 0; |
| 395 | |
| 396 | fail_issue_reg_login: |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 397 | /* decrement the reference count on ndlp just incremented |
| 398 | * for the failed mbox command. |
| 399 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 400 | lpfc_nlp_put(ndlp); |
| 401 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 402 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 403 | kfree(mp); |
| 404 | fail_free_mbox: |
| 405 | mempool_free(mbox, phba->mbox_mem_pool); |
| 406 | |
| 407 | fail: |
| 408 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 409 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 410 | "0249 Cannot issue Register Fabric login: Err %d\n", err); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 411 | return -ENXIO; |
| 412 | } |
| 413 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 414 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 415 | * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login |
| 416 | * @vport: pointer to a host virtual N_Port data structure. |
| 417 | * |
| 418 | * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for |
| 419 | * the @vport. This mailbox command is necessary for FCoE only. |
| 420 | * |
| 421 | * Return code |
| 422 | * 0 - successfully issued REG_VFI for @vport |
| 423 | * A failure code otherwise. |
| 424 | **/ |
| 425 | static int |
| 426 | lpfc_issue_reg_vfi(struct lpfc_vport *vport) |
| 427 | { |
| 428 | struct lpfc_hba *phba = vport->phba; |
| 429 | LPFC_MBOXQ_t *mboxq; |
| 430 | struct lpfc_nodelist *ndlp; |
| 431 | struct serv_parm *sp; |
| 432 | struct lpfc_dmabuf *dmabuf; |
| 433 | int rc = 0; |
| 434 | |
| 435 | sp = &phba->fc_fabparam; |
| 436 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 437 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
| 438 | rc = -ENODEV; |
| 439 | goto fail; |
| 440 | } |
| 441 | |
| 442 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 443 | if (!dmabuf) { |
| 444 | rc = -ENOMEM; |
| 445 | goto fail; |
| 446 | } |
| 447 | dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys); |
| 448 | if (!dmabuf->virt) { |
| 449 | rc = -ENOMEM; |
| 450 | goto fail_free_dmabuf; |
| 451 | } |
| 452 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 453 | if (!mboxq) { |
| 454 | rc = -ENOMEM; |
| 455 | goto fail_free_coherent; |
| 456 | } |
| 457 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 458 | memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam)); |
| 459 | lpfc_reg_vfi(mboxq, vport, dmabuf->phys); |
| 460 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi; |
| 461 | mboxq->vport = vport; |
| 462 | mboxq->context1 = dmabuf; |
| 463 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 464 | if (rc == MBX_NOT_FINISHED) { |
| 465 | rc = -ENXIO; |
| 466 | goto fail_free_mbox; |
| 467 | } |
| 468 | return 0; |
| 469 | |
| 470 | fail_free_mbox: |
| 471 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 472 | fail_free_coherent: |
| 473 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 474 | fail_free_dmabuf: |
| 475 | kfree(dmabuf); |
| 476 | fail: |
| 477 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 478 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 479 | "0289 Issue Register VFI failed: Err %d\n", rc); |
| 480 | return rc; |
| 481 | } |
| 482 | |
| 483 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 484 | * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 485 | * @vport: pointer to a host virtual N_Port data structure. |
| 486 | * @ndlp: pointer to a node-list data structure. |
| 487 | * @sp: pointer to service parameter data structure. |
| 488 | * @irsp: pointer to the IOCB within the lpfc response IOCB. |
| 489 | * |
| 490 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 491 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric |
| 492 | * port in a fabric topology. It properly sets up the parameters to the @ndlp |
| 493 | * from the IOCB response. It also check the newly assigned N_Port ID to the |
| 494 | * @vport against the previously assigned N_Port ID. If it is different from |
| 495 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine |
| 496 | * is invoked on all the remaining nodes with the @vport to unregister the |
| 497 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() |
| 498 | * is invoked to register login to the fabric. |
| 499 | * |
| 500 | * Return code |
| 501 | * 0 - Success (currently, always return 0) |
| 502 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 503 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 504 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 505 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 506 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 507 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 508 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 509 | struct lpfc_nodelist *np; |
| 510 | struct lpfc_nodelist *next_np; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 511 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 512 | spin_lock_irq(shost->host_lock); |
| 513 | vport->fc_flag |= FC_FABRIC; |
| 514 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 515 | |
| 516 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 517 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 518 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 519 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 520 | phba->fc_edtovResol = sp->cmn.edtovResolution; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 521 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 522 | |
| 523 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 524 | spin_lock_irq(shost->host_lock); |
| 525 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 526 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 527 | } |
| 528 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 529 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 530 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 531 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 532 | ndlp->nlp_class_sup = 0; |
| 533 | if (sp->cls1.classValid) |
| 534 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 535 | if (sp->cls2.classValid) |
| 536 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 537 | if (sp->cls3.classValid) |
| 538 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 539 | if (sp->cls4.classValid) |
| 540 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 541 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 542 | sp->cmn.bbRcvSizeLsb; |
| 543 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 544 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 545 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 546 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 547 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 548 | LOG_ELS | LOG_VPORT, |
| 549 | "1816 FLOGI NPIV supported, " |
| 550 | "response data 0x%x\n", |
| 551 | sp->cmn.response_multiple_NPort); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 552 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 553 | } else { |
| 554 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 555 | to call reg_vnpid atleast for the physcial host */ |
| 556 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 557 | LOG_ELS | LOG_VPORT, |
| 558 | "1817 Fabric does not support NPIV " |
| 559 | "- configuring single port mode.\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 560 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 565 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 566 | |
| 567 | /* If our NportID changed, we need to ensure all |
| 568 | * remaining NPORTs get unreg_login'ed. |
| 569 | */ |
| 570 | list_for_each_entry_safe(np, next_np, |
| 571 | &vport->fc_nodes, nlp_listp) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 572 | if (!NLP_CHK_NODE_ACT(np)) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 573 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 574 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 575 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 576 | continue; |
| 577 | spin_lock_irq(shost->host_lock); |
| 578 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 579 | spin_unlock_irq(shost->host_lock); |
| 580 | lpfc_unreg_rpi(vport, np); |
| 581 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 582 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame^] | 583 | |
| 584 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 585 | lpfc_sli4_unreg_all_rpis(vport); |
| 586 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 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 | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 602 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 603 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 604 | /* |
| 605 | * Driver needs to re-reg VPI in order for f/w |
| 606 | * to update the MAC address. |
| 607 | */ |
| 608 | lpfc_register_new_vport(phba, vport, ndlp); |
| 609 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 610 | } |
| 611 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 612 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 613 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
| 614 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 615 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 616 | lpfc_register_new_vport(phba, vport, ndlp); |
| 617 | else |
| 618 | lpfc_issue_fabric_reglogin(vport); |
| 619 | } else { |
| 620 | ndlp->nlp_type |= NLP_FABRIC; |
| 621 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 622 | if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) && |
| 623 | (vport->vpi_state & LPFC_VPI_REGISTERED)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 624 | lpfc_start_fdiscs(phba); |
| 625 | lpfc_do_scr_ns_plogi(phba, vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 626 | } else if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 627 | lpfc_issue_init_vpi(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 628 | else |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 629 | lpfc_issue_reg_vfi(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 630 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 631 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 632 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 633 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 634 | * 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] | 635 | * @vport: pointer to a host virtual N_Port data structure. |
| 636 | * @ndlp: pointer to a node-list data structure. |
| 637 | * @sp: pointer to service parameter data structure. |
| 638 | * |
| 639 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 640 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 641 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 642 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 643 | * the received N_Port Name lexicographically, this node shall assign local |
| 644 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 645 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 646 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 647 | * N_Port IDs. |
| 648 | * |
| 649 | * Return code |
| 650 | * 0 - Success |
| 651 | * -ENXIO - Fail |
| 652 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 653 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 654 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 655 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 656 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 657 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 658 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 659 | LPFC_MBOXQ_t *mbox; |
| 660 | int rc; |
| 661 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 662 | spin_lock_irq(shost->host_lock); |
| 663 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 664 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 665 | |
| 666 | phba->fc_edtov = FF_DEF_EDTOV; |
| 667 | phba->fc_ratov = FF_DEF_RATOV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 668 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 669 | sizeof(vport->fc_portname)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 670 | if (rc >= 0) { |
| 671 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 672 | spin_lock_irq(shost->host_lock); |
| 673 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 674 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 675 | |
| 676 | /* |
| 677 | * N_Port ID cannot be 0, set our to LocalID the other |
| 678 | * side will be RemoteID. |
| 679 | */ |
| 680 | |
| 681 | /* not equal */ |
| 682 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 683 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 684 | |
| 685 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 686 | if (!mbox) |
| 687 | goto fail; |
| 688 | |
| 689 | lpfc_config_link(phba, mbox); |
| 690 | |
| 691 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 692 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 693 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 694 | if (rc == MBX_NOT_FINISHED) { |
| 695 | mempool_free(mbox, phba->mbox_mem_pool); |
| 696 | goto fail; |
| 697 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 698 | /* Decrement ndlp reference count indicating that ndlp can be |
| 699 | * safely released when other references to it are done. |
| 700 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 701 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 702 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 703 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 704 | if (!ndlp) { |
| 705 | /* |
| 706 | * Cannot find existing Fabric ndlp, so allocate a |
| 707 | * new one |
| 708 | */ |
| 709 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 710 | if (!ndlp) |
| 711 | goto fail; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 712 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 713 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 714 | ndlp = lpfc_enable_node(vport, ndlp, |
| 715 | NLP_STE_UNUSED_NODE); |
| 716 | if(!ndlp) |
| 717 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 721 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 722 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 723 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 724 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 725 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 726 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 727 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 728 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 729 | } else |
| 730 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 731 | * count indicating that ndlp can be released when other |
| 732 | * references to it are done. |
| 733 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 734 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 735 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 736 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 737 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 738 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 739 | spin_lock_irq(shost->host_lock); |
| 740 | vport->fc_flag |= FC_PT2PT; |
| 741 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 742 | |
| 743 | /* Start discovery - this should just do CLEAR_LA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 744 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 745 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 746 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 747 | return -ENXIO; |
| 748 | } |
| 749 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 750 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 751 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 752 | * @phba: pointer to lpfc hba data structure. |
| 753 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 754 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 755 | * |
| 756 | * This routine is the top-level completion callback function for issuing |
| 757 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 758 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 759 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 760 | * returning 1), the command IOCB will be released and function returned. |
| 761 | * If the retry attempt has been given up (possibly reach the maximum |
| 762 | * number of retries), one additional decrement of ndlp reference shall be |
| 763 | * invoked before going out after releasing the command IOCB. This will |
| 764 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 765 | * invoke one decrement of ndlp reference count). If no error reported in |
| 766 | * the IOCB status, the command Port ID field is used to determine whether |
| 767 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 768 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 769 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 770 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 771 | * specific topology completion conditions. |
| 772 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 773 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 774 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 775 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 776 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 777 | struct lpfc_vport *vport = cmdiocb->vport; |
| 778 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 779 | IOCB_t *irsp = &rspiocb->iocb; |
| 780 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 781 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 782 | struct serv_parm *sp; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 783 | uint16_t fcf_index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 784 | int rc; |
| 785 | |
| 786 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 787 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 788 | /* One additional decrement on node reference count to |
| 789 | * trigger the release of the node |
| 790 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 791 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 792 | goto out; |
| 793 | } |
| 794 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 795 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 796 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 797 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 798 | vport->port_state); |
| 799 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 800 | if (irsp->ulpStatus) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 801 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 802 | * In case of FIP mode, perform roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 803 | * due to new FCF discovery |
| 804 | */ |
| 805 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 806 | (phba->fcf.fcf_flag & FCF_DISCOVERY) && |
| 807 | (irsp->ulpStatus != IOSTAT_LOCAL_REJECT) && |
| 808 | (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 809 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 810 | "2611 FLOGI failed on FCF (x%x), " |
| 811 | "status:x%x/x%x, tmo:x%x, perform " |
| 812 | "roundrobin FCF failover\n", |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 813 | phba->fcf.current_rec.fcf_indx, |
| 814 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 815 | irsp->ulpTimeout); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 816 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 817 | rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index); |
| 818 | if (rc) |
| 819 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 820 | } |
| 821 | |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 822 | /* FLOGI failure */ |
| 823 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 824 | "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
| 825 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 826 | irsp->ulpTimeout); |
| 827 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 828 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 829 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 830 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 831 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 832 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 833 | spin_lock_irq(shost->host_lock); |
| 834 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 835 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 836 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 837 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 838 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 839 | * alpa map would take too long otherwise. |
| 840 | */ |
| 841 | if (phba->alpa_map[0] == 0) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 842 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | /* FLOGI failure */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 846 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 847 | "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 848 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 849 | irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 850 | goto flogifail; |
| 851 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 852 | spin_lock_irq(shost->host_lock); |
| 853 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 854 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 855 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 856 | |
| 857 | /* |
| 858 | * The FLogI succeeded. Sync the data for the CPU before |
| 859 | * accessing it. |
| 860 | */ |
| 861 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 862 | |
| 863 | sp = prsp->virt + sizeof(uint32_t); |
| 864 | |
| 865 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 866 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 867 | "0101 FLOGI completes successfully " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 868 | "Data: x%x x%x x%x x%x\n", |
| 869 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
| 870 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 871 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 872 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 873 | /* |
| 874 | * If Common Service Parameters indicate Nport |
| 875 | * we are point to point, if Fport we are Fabric. |
| 876 | */ |
| 877 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 878 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 879 | else if (!(phba->hba_flag & HBA_FCOE_SUPPORT)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 880 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 881 | else { |
| 882 | lpfc_printf_vlog(vport, KERN_ERR, |
| 883 | LOG_FIP | LOG_ELS, |
| 884 | "2831 FLOGI response with cleared Fabric " |
| 885 | "bit fcf_index 0x%x " |
| 886 | "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x " |
| 887 | "Fabric Name " |
| 888 | "%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 889 | phba->fcf.current_rec.fcf_indx, |
| 890 | phba->fcf.current_rec.switch_name[0], |
| 891 | phba->fcf.current_rec.switch_name[1], |
| 892 | phba->fcf.current_rec.switch_name[2], |
| 893 | phba->fcf.current_rec.switch_name[3], |
| 894 | phba->fcf.current_rec.switch_name[4], |
| 895 | phba->fcf.current_rec.switch_name[5], |
| 896 | phba->fcf.current_rec.switch_name[6], |
| 897 | phba->fcf.current_rec.switch_name[7], |
| 898 | phba->fcf.current_rec.fabric_name[0], |
| 899 | phba->fcf.current_rec.fabric_name[1], |
| 900 | phba->fcf.current_rec.fabric_name[2], |
| 901 | phba->fcf.current_rec.fabric_name[3], |
| 902 | phba->fcf.current_rec.fabric_name[4], |
| 903 | phba->fcf.current_rec.fabric_name[5], |
| 904 | phba->fcf.current_rec.fabric_name[6], |
| 905 | phba->fcf.current_rec.fabric_name[7]); |
| 906 | lpfc_nlp_put(ndlp); |
| 907 | spin_lock_irq(&phba->hbalock); |
| 908 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 909 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 910 | spin_unlock_irq(&phba->hbalock); |
| 911 | goto out; |
| 912 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 913 | if (!rc) { |
| 914 | /* Mark the FCF discovery process done */ |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 915 | if (phba->hba_flag & HBA_FIP_SUPPORT) |
| 916 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | |
| 917 | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 918 | "2769 FLOGI to FCF (x%x) " |
| 919 | "completed successfully\n", |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 920 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 921 | spin_lock_irq(&phba->hbalock); |
| 922 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 923 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 924 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 925 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 926 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | flogifail: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 930 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 931 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 932 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 933 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 934 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 935 | |
| 936 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 937 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 938 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 939 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && |
| 940 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) && |
| 941 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 942 | /* If FLOGI failed enable link interrupt. */ |
| 943 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 944 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 945 | out: |
| 946 | lpfc_els_free_iocb(phba, cmdiocb); |
| 947 | } |
| 948 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 949 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 950 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 951 | * @vport: pointer to a host virtual N_Port data structure. |
| 952 | * @ndlp: pointer to a node-list data structure. |
| 953 | * @retry: number of retries to the command IOCB. |
| 954 | * |
| 955 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 956 | * for a @vport. The initiator service parameters are put into the payload |
| 957 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 958 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 959 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 960 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 961 | * |
| 962 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 963 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 964 | * will be stored into the context1 field of the IOCB for the completion |
| 965 | * callback function to the FLOGI ELS command. |
| 966 | * |
| 967 | * Return code |
| 968 | * 0 - successfully issued flogi iocb for @vport |
| 969 | * 1 - failed to issue flogi iocb for @vport |
| 970 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 971 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 972 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 973 | uint8_t retry) |
| 974 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 975 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 976 | struct serv_parm *sp; |
| 977 | IOCB_t *icmd; |
| 978 | struct lpfc_iocbq *elsiocb; |
| 979 | struct lpfc_sli_ring *pring; |
| 980 | uint8_t *pcmd; |
| 981 | uint16_t cmdsize; |
| 982 | uint32_t tmo; |
| 983 | int rc; |
| 984 | |
| 985 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 986 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 987 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 988 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 989 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 990 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 991 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 992 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 993 | |
| 994 | icmd = &elsiocb->iocb; |
| 995 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 996 | |
| 997 | /* For FLOGI request, remainder of payload is service parameters */ |
| 998 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 999 | pcmd += sizeof(uint32_t); |
| 1000 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1001 | sp = (struct serv_parm *) pcmd; |
| 1002 | |
| 1003 | /* Setup CSPs accordingly for Fabric */ |
| 1004 | sp->cmn.e_d_tov = 0; |
| 1005 | sp->cmn.w2.r_a_tov = 0; |
| 1006 | sp->cls1.classValid = 0; |
| 1007 | sp->cls2.seqDelivery = 1; |
| 1008 | sp->cls3.seqDelivery = 1; |
| 1009 | if (sp->cmn.fcphLow < FC_PH3) |
| 1010 | sp->cmn.fcphLow = FC_PH3; |
| 1011 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1012 | sp->cmn.fcphHigh = FC_PH3; |
| 1013 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1014 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1015 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 1016 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 1017 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 1018 | /* Set the fcfi to the fcfi we registered with */ |
| 1019 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 1020 | } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1021 | sp->cmn.request_multiple_Nport = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1022 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 1023 | icmd->ulpCt_h = 1; |
| 1024 | icmd->ulpCt_l = 0; |
| 1025 | } |
| 1026 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1027 | if (phba->fc_topology != TOPOLOGY_LOOP) { |
| 1028 | icmd->un.elsreq64.myID = 0; |
| 1029 | icmd->un.elsreq64.fl = 1; |
| 1030 | } |
| 1031 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1032 | tmo = phba->fc_ratov; |
| 1033 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1034 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1035 | phba->fc_ratov = tmo; |
| 1036 | |
| 1037 | phba->fc_stat.elsXmitFLOGI++; |
| 1038 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1039 | |
| 1040 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1041 | "Issue FLOGI: opt:x%x", |
| 1042 | phba->sli3_options, 0, 0); |
| 1043 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1044 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1045 | if (rc == IOCB_ERROR) { |
| 1046 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1047 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1048 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1049 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1050 | } |
| 1051 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1052 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1053 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1054 | * @phba: pointer to lpfc hba data structure. |
| 1055 | * |
| 1056 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 1057 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 1058 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 1059 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 1060 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 1061 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 1062 | * |
| 1063 | * Return code |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 1064 | * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1065 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1066 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1067 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1068 | { |
| 1069 | struct lpfc_sli_ring *pring; |
| 1070 | struct lpfc_iocbq *iocb, *next_iocb; |
| 1071 | struct lpfc_nodelist *ndlp; |
| 1072 | IOCB_t *icmd; |
| 1073 | |
| 1074 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 1075 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1076 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 1077 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1078 | |
| 1079 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 1080 | |
| 1081 | /* |
| 1082 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 1083 | * searching for. |
| 1084 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1085 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1086 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 1087 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1088 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR && |
| 1089 | icmd->un.elsreq64.bdl.ulpIoTag32) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1090 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1091 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 1092 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1093 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1094 | } |
| 1095 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1096 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1097 | |
| 1098 | return 0; |
| 1099 | } |
| 1100 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1101 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1102 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1103 | * @vport: pointer to a host virtual N_Port data structure. |
| 1104 | * |
| 1105 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 1106 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1107 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1108 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1109 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 1110 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 1111 | * @vport. |
| 1112 | * |
| 1113 | * Return code |
| 1114 | * 0 - failed to issue initial flogi for @vport |
| 1115 | * 1 - successfully issued initial flogi for @vport |
| 1116 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1117 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1118 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1119 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1120 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1121 | struct lpfc_nodelist *ndlp; |
| 1122 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1123 | vport->port_state = LPFC_FLOGI; |
| 1124 | lpfc_set_disctmo(vport); |
| 1125 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1126 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1127 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1128 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1129 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1130 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1131 | if (!ndlp) |
| 1132 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1133 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1134 | /* Set the node type */ |
| 1135 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1136 | /* Put ndlp onto node list */ |
| 1137 | lpfc_enqueue_node(vport, ndlp); |
| 1138 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1139 | /* re-setup ndlp without removing from node list */ |
| 1140 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1141 | if (!ndlp) |
| 1142 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1143 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1144 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1145 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1146 | /* This decrement of reference count to node shall kick off |
| 1147 | * the release of the node. |
| 1148 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1149 | lpfc_nlp_put(ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1150 | return 0; |
| 1151 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1152 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1153 | } |
| 1154 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1155 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1156 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1157 | * @vport: pointer to a host virtual N_Port data structure. |
| 1158 | * |
| 1159 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 1160 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1161 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1162 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1163 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 1164 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 1165 | * @vport. |
| 1166 | * |
| 1167 | * Return code |
| 1168 | * 0 - failed to issue initial fdisc for @vport |
| 1169 | * 1 - successfully issued initial fdisc for @vport |
| 1170 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1171 | int |
| 1172 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 1173 | { |
| 1174 | struct lpfc_hba *phba = vport->phba; |
| 1175 | struct lpfc_nodelist *ndlp; |
| 1176 | |
| 1177 | /* First look for the Fabric ndlp */ |
| 1178 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1179 | if (!ndlp) { |
| 1180 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 1181 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1182 | if (!ndlp) |
| 1183 | return 0; |
| 1184 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1185 | /* Put ndlp onto node list */ |
| 1186 | lpfc_enqueue_node(vport, ndlp); |
| 1187 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1188 | /* re-setup ndlp without removing from node list */ |
| 1189 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1190 | if (!ndlp) |
| 1191 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1192 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1193 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1194 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1195 | /* decrement node reference count to trigger the release of |
| 1196 | * the node. |
| 1197 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1198 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1199 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1200 | } |
| 1201 | return 1; |
| 1202 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1203 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1204 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1205 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1206 | * @vport: pointer to a host virtual N_Port data structure. |
| 1207 | * |
| 1208 | * This routine checks whether there are more remaining Port Logins |
| 1209 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1210 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1211 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1212 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1213 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1214 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1215 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1216 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1217 | { |
| 1218 | int sentplogi; |
| 1219 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1220 | if (vport->num_disc_nodes) |
| 1221 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1222 | |
| 1223 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1224 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1225 | "0232 Continue discovery with %d PLOGIs to go " |
| 1226 | "Data: x%x x%x x%x\n", |
| 1227 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1228 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1229 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1230 | if (vport->fc_flag & FC_NLP_MORE) |
| 1231 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 1232 | sentplogi = lpfc_els_disc_plogi(vport); |
| 1233 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1234 | return; |
| 1235 | } |
| 1236 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1237 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1238 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1239 | * @phba: pointer to lpfc hba data structure. |
| 1240 | * @prsp: pointer to response IOCB payload. |
| 1241 | * @ndlp: pointer to a node-list data structure. |
| 1242 | * |
| 1243 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1244 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1245 | * The following cases are considered N_Port confirmed: |
| 1246 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1247 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1248 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1249 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1250 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1251 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1252 | * on that node to release the RPI associated with the node; 2) if there is |
| 1253 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1254 | * into, a new node shall be allocated (or activated). In either case, the |
| 1255 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1256 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1257 | * its pointer returned as the confirmed node. |
| 1258 | * |
| 1259 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1260 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1261 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1262 | * into an inactive state on the vport node list and the vport node list |
| 1263 | * management algorithm does not allow two node with a same DID. |
| 1264 | * |
| 1265 | * Return code |
| 1266 | * pointer to the PLOGI N_Port @ndlp |
| 1267 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1268 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1269 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1270 | struct lpfc_nodelist *ndlp) |
| 1271 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1272 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1273 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1274 | struct lpfc_rport_data *rdata; |
| 1275 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1276 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1277 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1278 | uint32_t rc, keepDID = 0; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1279 | int put_node; |
| 1280 | int put_rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1281 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1282 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1283 | * by WWPN. Just return the ndlp that was given to us. |
| 1284 | */ |
| 1285 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1286 | return ndlp; |
| 1287 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1288 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1289 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1290 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1291 | /* 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] | 1292 | * we have for that ndlp. If not, we have some work to do. |
| 1293 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1294 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1295 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1296 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1297 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1298 | |
| 1299 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1300 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1301 | sizeof(struct lpfc_name)); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1302 | if (!rc) |
| 1303 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1304 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
| 1305 | if (!new_ndlp) |
| 1306 | return ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1307 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1308 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1309 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1310 | sizeof(struct lpfc_name)); |
| 1311 | if (!rc) |
| 1312 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1313 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1314 | NLP_STE_UNUSED_NODE); |
| 1315 | if (!new_ndlp) |
| 1316 | return ndlp; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1317 | keepDID = new_ndlp->nlp_DID; |
| 1318 | } else |
| 1319 | keepDID = new_ndlp->nlp_DID; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1320 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1321 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1322 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1323 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1324 | |
| 1325 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) |
| 1326 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 1327 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 1328 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1329 | /* 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] | 1330 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1331 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1332 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1333 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1334 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1335 | * to put ndlp on UNUSED list and try to free it. |
| 1336 | */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1337 | |
| 1338 | /* Fix up the rport accordingly */ |
| 1339 | rport = ndlp->rport; |
| 1340 | if (rport) { |
| 1341 | rdata = rport->dd_data; |
| 1342 | if (rdata->pnode == ndlp) { |
| 1343 | lpfc_nlp_put(ndlp); |
| 1344 | ndlp->rport = NULL; |
| 1345 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1346 | new_ndlp->rport = rport; |
| 1347 | } |
| 1348 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1349 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1350 | /* We shall actually free the ndlp with both nlp_DID and |
| 1351 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1352 | * nodelist never to be used. |
| 1353 | */ |
| 1354 | if (ndlp->nlp_DID == 0) { |
| 1355 | spin_lock_irq(&phba->ndlp_lock); |
| 1356 | NLP_SET_FREE_REQ(ndlp); |
| 1357 | spin_unlock_irq(&phba->ndlp_lock); |
| 1358 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1359 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1360 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1361 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1362 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1363 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1364 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1365 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1366 | /* Two ndlps cannot have the same did */ |
| 1367 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1368 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1369 | /* Since we are swapping the ndlp passed in with the new one |
| 1370 | * and the did has already been swapped, copy over the |
| 1371 | * state and names. |
| 1372 | */ |
| 1373 | memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname, |
| 1374 | sizeof(struct lpfc_name)); |
| 1375 | memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename, |
| 1376 | sizeof(struct lpfc_name)); |
| 1377 | new_ndlp->nlp_state = ndlp->nlp_state; |
| 1378 | /* Fix up the rport accordingly */ |
| 1379 | rport = ndlp->rport; |
| 1380 | if (rport) { |
| 1381 | rdata = rport->dd_data; |
| 1382 | put_node = rdata->pnode != NULL; |
| 1383 | put_rport = ndlp->rport != NULL; |
| 1384 | rdata->pnode = NULL; |
| 1385 | ndlp->rport = NULL; |
| 1386 | if (put_node) |
| 1387 | lpfc_nlp_put(ndlp); |
| 1388 | if (put_rport) |
| 1389 | put_device(&rport->dev); |
| 1390 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1391 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1392 | return new_ndlp; |
| 1393 | } |
| 1394 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1395 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1396 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1397 | * @vport: pointer to a host virtual N_Port data structure. |
| 1398 | * |
| 1399 | * This routine checks whether more Registration State Change |
| 1400 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1401 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1402 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1403 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1404 | * handling the RSCNs. |
| 1405 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1406 | void |
| 1407 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1408 | { |
| 1409 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1410 | |
| 1411 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1412 | /* |
| 1413 | * Check to see if more RSCNs came in while we were |
| 1414 | * processing this one. |
| 1415 | */ |
| 1416 | if (vport->fc_rscn_id_cnt || |
| 1417 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1418 | lpfc_els_handle_rscn(vport); |
| 1419 | else { |
| 1420 | spin_lock_irq(shost->host_lock); |
| 1421 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1422 | spin_unlock_irq(shost->host_lock); |
| 1423 | } |
| 1424 | } |
| 1425 | } |
| 1426 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1427 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1428 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1429 | * @phba: pointer to lpfc hba data structure. |
| 1430 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1431 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1432 | * |
| 1433 | * This routine is the completion callback function for issuing the Port |
| 1434 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1435 | * ndlp on the vport node list that matches the remote node ID from the |
| 1436 | * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply |
| 1437 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1438 | * checked for error conditons. If there is error status reported, PLOGI |
| 1439 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1440 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1441 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1442 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1443 | * there are additional N_Port nodes with the vport that need to perform |
| 1444 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1445 | * PLOGIs. |
| 1446 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1447 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1448 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1449 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1450 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1451 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1452 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1453 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1454 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1455 | struct lpfc_dmabuf *prsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1456 | int disc, rc, did, type; |
| 1457 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1458 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1459 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1460 | |
| 1461 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1462 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1463 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1464 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1465 | irsp->un.elsreq64.remoteID); |
| 1466 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1467 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1468 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1469 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1470 | "0136 PLOGI completes to NPort x%x " |
| 1471 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1472 | irsp->un.elsreq64.remoteID, |
| 1473 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1474 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1475 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1476 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1477 | |
| 1478 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1479 | * is being used during discovery. |
| 1480 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1481 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1482 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1483 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1484 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1485 | rc = 0; |
| 1486 | |
| 1487 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1488 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1489 | "0102 PLOGI completes to NPort x%x " |
| 1490 | "Data: x%x x%x x%x x%x x%x\n", |
| 1491 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1492 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1493 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1494 | if (lpfc_els_chk_latt(vport)) { |
| 1495 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1496 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1497 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1498 | goto out; |
| 1499 | } |
| 1500 | |
| 1501 | /* ndlp could be freed in DSM, save these values now */ |
| 1502 | type = ndlp->nlp_type; |
| 1503 | did = ndlp->nlp_DID; |
| 1504 | |
| 1505 | if (irsp->ulpStatus) { |
| 1506 | /* Check for retry */ |
| 1507 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1508 | /* ELS command is being retried */ |
| 1509 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1510 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1511 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1512 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1513 | } |
| 1514 | goto out; |
| 1515 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1516 | /* PLOGI failed Don't print the vport to vport rjts */ |
| 1517 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1518 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1519 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1520 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1521 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1522 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", |
| 1523 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1524 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1525 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1526 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1527 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1528 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1529 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1530 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1531 | } else { |
| 1532 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1533 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1534 | cmdiocb->context2)->list.next, |
| 1535 | struct lpfc_dmabuf, list); |
| 1536 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1537 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1538 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1539 | } |
| 1540 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1541 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1542 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1543 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1544 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1545 | if (vport->num_disc_nodes == 0) { |
| 1546 | spin_lock_irq(shost->host_lock); |
| 1547 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1548 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1549 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1550 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1551 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1552 | } |
| 1553 | } |
| 1554 | |
| 1555 | out: |
| 1556 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1557 | return; |
| 1558 | } |
| 1559 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1560 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1561 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1562 | * @vport: pointer to a host virtual N_Port data structure. |
| 1563 | * @did: destination port identifier. |
| 1564 | * @retry: number of retries to the command IOCB. |
| 1565 | * |
| 1566 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1567 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1568 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1569 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1570 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1571 | * |
| 1572 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1573 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1574 | * will be stored into the context1 field of the IOCB for the completion |
| 1575 | * callback function to the PLOGI ELS command. |
| 1576 | * |
| 1577 | * Return code |
| 1578 | * 0 - Successfully issued a plogi for @vport |
| 1579 | * 1 - failed to issue a plogi for @vport |
| 1580 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1581 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1582 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1583 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1584 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1585 | struct serv_parm *sp; |
| 1586 | IOCB_t *icmd; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1587 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1588 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1589 | struct lpfc_sli *psli; |
| 1590 | uint8_t *pcmd; |
| 1591 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1592 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1593 | |
| 1594 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1595 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1596 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1597 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1598 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1599 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1600 | /* 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] | 1601 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1602 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1603 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1604 | if (!elsiocb) |
| 1605 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1606 | |
| 1607 | icmd = &elsiocb->iocb; |
| 1608 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1609 | |
| 1610 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1611 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1612 | pcmd += sizeof(uint32_t); |
| 1613 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1614 | sp = (struct serv_parm *) pcmd; |
| 1615 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1616 | /* |
| 1617 | * If we are a N-port connected to a Fabric, fix-up paramm's so logins |
| 1618 | * to device on remote loops work. |
| 1619 | */ |
| 1620 | if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP)) |
| 1621 | sp->cmn.altBbCredit = 1; |
| 1622 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1623 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1624 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1625 | |
| 1626 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1627 | sp->cmn.fcphHigh = FC_PH3; |
| 1628 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1629 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1630 | "Issue PLOGI: did:x%x", |
| 1631 | did, 0, 0); |
| 1632 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1633 | phba->fc_stat.elsXmitPLOGI++; |
| 1634 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1635 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1636 | |
| 1637 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1638 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1639 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1640 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1641 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1642 | } |
| 1643 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1644 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1645 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1646 | * @phba: pointer to lpfc hba data structure. |
| 1647 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1648 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1649 | * |
| 1650 | * This routine is the completion callback function for a Process Login |
| 1651 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 1652 | * status. If there is error status reported, PRLI retry shall be attempted |
| 1653 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 1654 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 1655 | * ndlp to mark the PRLI completion. |
| 1656 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1657 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1658 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1659 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1660 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1661 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1662 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1663 | IOCB_t *irsp; |
| 1664 | struct lpfc_sli *psli; |
| 1665 | struct lpfc_nodelist *ndlp; |
| 1666 | |
| 1667 | psli = &phba->sli; |
| 1668 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1669 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1670 | |
| 1671 | irsp = &(rspiocb->iocb); |
| 1672 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1673 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1674 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1675 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1676 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1677 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1678 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 1679 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1680 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1681 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1682 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1683 | "0103 PRLI completes to NPort x%x " |
| 1684 | "Data: x%x x%x x%x x%x\n", |
| 1685 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1686 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1687 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1688 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1689 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1690 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1691 | goto out; |
| 1692 | |
| 1693 | if (irsp->ulpStatus) { |
| 1694 | /* Check for retry */ |
| 1695 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1696 | /* ELS command is being retried */ |
| 1697 | goto out; |
| 1698 | } |
| 1699 | /* PRLI failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1700 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1701 | "2754 PRLI failure DID:%06X Status:x%x/x%x\n", |
| 1702 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1703 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1704 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1705 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1706 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1707 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1708 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1709 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1710 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1711 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1712 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1713 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1714 | out: |
| 1715 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1716 | return; |
| 1717 | } |
| 1718 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1719 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1720 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1721 | * @vport: pointer to a host virtual N_Port data structure. |
| 1722 | * @ndlp: pointer to a node-list data structure. |
| 1723 | * @retry: number of retries to the command IOCB. |
| 1724 | * |
| 1725 | * This routine issues a Process Login (PRLI) ELS command for the |
| 1726 | * @vport. The PRLI service parameters are set up in the payload of the |
| 1727 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 1728 | * is put to the IOCB completion callback func field before invoking the |
| 1729 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 1730 | * |
| 1731 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1732 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1733 | * will be stored into the context1 field of the IOCB for the completion |
| 1734 | * callback function to the PRLI ELS command. |
| 1735 | * |
| 1736 | * Return code |
| 1737 | * 0 - successfully issued prli iocb command for @vport |
| 1738 | * 1 - failed to issue prli iocb command for @vport |
| 1739 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1740 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1741 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1742 | uint8_t retry) |
| 1743 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1744 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1745 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1746 | PRLI *npr; |
| 1747 | IOCB_t *icmd; |
| 1748 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1749 | uint8_t *pcmd; |
| 1750 | uint16_t cmdsize; |
| 1751 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1752 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1753 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1754 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1755 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1756 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1757 | |
| 1758 | icmd = &elsiocb->iocb; |
| 1759 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1760 | |
| 1761 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1762 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1763 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1764 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1765 | |
| 1766 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 1767 | npr = (PRLI *) pcmd; |
| 1768 | /* |
| 1769 | * If our firmware version is 3.20 or later, |
| 1770 | * set the following bits for FC-TAPE support. |
| 1771 | */ |
| 1772 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 1773 | npr->ConfmComplAllowed = 1; |
| 1774 | npr->Retry = 1; |
| 1775 | npr->TaskRetryIdReq = 1; |
| 1776 | } |
| 1777 | npr->estabImagePair = 1; |
| 1778 | npr->readXferRdyDis = 1; |
| 1779 | |
| 1780 | /* For FCP support */ |
| 1781 | npr->prliType = PRLI_FCP_TYPE; |
| 1782 | npr->initiatorFunc = 1; |
| 1783 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1784 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1785 | "Issue PRLI: did:x%x", |
| 1786 | ndlp->nlp_DID, 0, 0); |
| 1787 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1788 | phba->fc_stat.elsXmitPRLI++; |
| 1789 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1790 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1791 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1792 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1793 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 1794 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1795 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1796 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1797 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1798 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1799 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1800 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1801 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1802 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1803 | } |
| 1804 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1805 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1806 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1807 | * @vport: pointer to a host virtual N_Port data structure. |
| 1808 | * |
| 1809 | * This routine performs Registration State Change Notification (RSCN) |
| 1810 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 1811 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 1812 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 1813 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 1814 | * invoked to check and handle possible more RSCN came in during the period |
| 1815 | * of processing the current ones. |
| 1816 | **/ |
| 1817 | static void |
| 1818 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 1819 | { |
| 1820 | lpfc_can_disctmo(vport); |
| 1821 | |
| 1822 | /* RSCN discovery */ |
| 1823 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 1824 | if (vport->fc_npr_cnt) |
| 1825 | if (lpfc_els_disc_plogi(vport)) |
| 1826 | return; |
| 1827 | |
| 1828 | lpfc_end_rscn(vport); |
| 1829 | } |
| 1830 | |
| 1831 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1832 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1833 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 1834 | * |
| 1835 | * This function is called when the final ADISC is completed during discovery. |
| 1836 | * This function handles clearing link attention or issuing reg_vpi depending |
| 1837 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 1838 | * discovery. |
| 1839 | * This function is called with no locks held. |
| 1840 | **/ |
| 1841 | static void |
| 1842 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 1843 | { |
| 1844 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1845 | struct lpfc_hba *phba = vport->phba; |
| 1846 | |
| 1847 | /* |
| 1848 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 1849 | * and continue discovery. |
| 1850 | */ |
| 1851 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1852 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 1853 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1854 | lpfc_issue_reg_vpi(phba, vport); |
| 1855 | return; |
| 1856 | } |
| 1857 | /* |
| 1858 | * For SLI2, we need to set port_state to READY |
| 1859 | * and continue discovery. |
| 1860 | */ |
| 1861 | if (vport->port_state < LPFC_VPORT_READY) { |
| 1862 | /* If we get here, there is nothing to ADISC */ |
| 1863 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1864 | lpfc_issue_clear_la(phba, vport); |
| 1865 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 1866 | vport->num_disc_nodes = 0; |
| 1867 | /* go thru NPR list, issue ELS PLOGIs */ |
| 1868 | if (vport->fc_npr_cnt) |
| 1869 | lpfc_els_disc_plogi(vport); |
| 1870 | if (!vport->num_disc_nodes) { |
| 1871 | spin_lock_irq(shost->host_lock); |
| 1872 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1873 | spin_unlock_irq(shost->host_lock); |
| 1874 | lpfc_can_disctmo(vport); |
| 1875 | lpfc_end_rscn(vport); |
| 1876 | } |
| 1877 | } |
| 1878 | vport->port_state = LPFC_VPORT_READY; |
| 1879 | } else |
| 1880 | lpfc_rscn_disc(vport); |
| 1881 | } |
| 1882 | |
| 1883 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1884 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1885 | * @vport: pointer to a host virtual N_Port data structure. |
| 1886 | * |
| 1887 | * This routine determines whether there are more ndlps on a @vport |
| 1888 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 1889 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 1890 | * remaining nodes which need to have ADISC sent. |
| 1891 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1892 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1893 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1894 | { |
| 1895 | int sentadisc; |
| 1896 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1897 | if (vport->num_disc_nodes) |
| 1898 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1899 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1900 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1901 | "0210 Continue discovery with %d ADISCs to go " |
| 1902 | "Data: x%x x%x x%x\n", |
| 1903 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 1904 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1905 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1906 | if (vport->fc_flag & FC_NLP_MORE) { |
| 1907 | lpfc_set_disctmo(vport); |
| 1908 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 1909 | sentadisc = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1910 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1911 | if (!vport->num_disc_nodes) |
| 1912 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1913 | return; |
| 1914 | } |
| 1915 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1916 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1917 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1918 | * @phba: pointer to lpfc hba data structure. |
| 1919 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1920 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1921 | * |
| 1922 | * This routine is the completion function for issuing the Address Discover |
| 1923 | * (ADISC) command. It first checks to see whether link went down during |
| 1924 | * the discovery process. If so, the node will be marked as node port |
| 1925 | * recovery for issuing discover IOCB by the link attention handler and |
| 1926 | * exit. Otherwise, the response status is checked. If error was reported |
| 1927 | * in the response status, the ADISC command shall be retried by invoking |
| 1928 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 1929 | * the response status, the state machine is invoked to set transition |
| 1930 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 1931 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1932 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1933 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1934 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1935 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1936 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1937 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1938 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1939 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1940 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1941 | |
| 1942 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1943 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1944 | |
| 1945 | irsp = &(rspiocb->iocb); |
| 1946 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1947 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1948 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1949 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 1950 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1951 | ndlp->nlp_DID); |
| 1952 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1953 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1954 | * is being used during discovery. |
| 1955 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1956 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1957 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1958 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1959 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1960 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1961 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1962 | "0104 ADISC completes to NPort x%x " |
| 1963 | "Data: x%x x%x x%x x%x x%x\n", |
| 1964 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1965 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1966 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1967 | if (lpfc_els_chk_latt(vport)) { |
| 1968 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1969 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1970 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1971 | goto out; |
| 1972 | } |
| 1973 | |
| 1974 | if (irsp->ulpStatus) { |
| 1975 | /* Check for retry */ |
| 1976 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1977 | /* ELS command is being retried */ |
| 1978 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1979 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1980 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1981 | spin_unlock_irq(shost->host_lock); |
| 1982 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1983 | } |
| 1984 | goto out; |
| 1985 | } |
| 1986 | /* ADISC failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1987 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1988 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", |
| 1989 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1990 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1991 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1992 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1993 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1994 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1995 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1996 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1997 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1998 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1999 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2000 | /* Check to see if there are more ADISCs to be sent */ |
| 2001 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2002 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2003 | out: |
| 2004 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2005 | return; |
| 2006 | } |
| 2007 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2008 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2009 | * 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] | 2010 | * @vport: pointer to a virtual N_Port data structure. |
| 2011 | * @ndlp: pointer to a node-list data structure. |
| 2012 | * @retry: number of retries to the command IOCB. |
| 2013 | * |
| 2014 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 2015 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 2016 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 2017 | * to issue the ADISC ELS command. |
| 2018 | * |
| 2019 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2020 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2021 | * will be stored into the context1 field of the IOCB for the completion |
| 2022 | * callback function to the ADISC ELS command. |
| 2023 | * |
| 2024 | * Return code |
| 2025 | * 0 - successfully issued adisc |
| 2026 | * 1 - failed to issue adisc |
| 2027 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2028 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2029 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2030 | uint8_t retry) |
| 2031 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2032 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2033 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2034 | ADISC *ap; |
| 2035 | IOCB_t *icmd; |
| 2036 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2037 | uint8_t *pcmd; |
| 2038 | uint16_t cmdsize; |
| 2039 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2040 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2041 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2042 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2043 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2044 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2045 | |
| 2046 | icmd = &elsiocb->iocb; |
| 2047 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2048 | |
| 2049 | /* For ADISC request, remainder of payload is service parameters */ |
| 2050 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2051 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2052 | |
| 2053 | /* Fill in ADISC payload */ |
| 2054 | ap = (ADISC *) pcmd; |
| 2055 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2056 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2057 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2058 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2059 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2060 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2061 | "Issue ADISC: did:x%x", |
| 2062 | ndlp->nlp_DID, 0, 0); |
| 2063 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2064 | phba->fc_stat.elsXmitADISC++; |
| 2065 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2066 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2067 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2068 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2069 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2070 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2071 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2072 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2073 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2074 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2075 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2076 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2077 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2078 | } |
| 2079 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2080 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2081 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2082 | * @phba: pointer to lpfc hba data structure. |
| 2083 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2084 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2085 | * |
| 2086 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 2087 | * command. If no error status was reported from the LOGO response, the |
| 2088 | * state machine of the associated ndlp shall be invoked for transition with |
| 2089 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 2090 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 2091 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2092 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2093 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2094 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2095 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2096 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2097 | struct lpfc_vport *vport = ndlp->vport; |
| 2098 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2099 | IOCB_t *irsp; |
| 2100 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2101 | |
| 2102 | psli = &phba->sli; |
| 2103 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2104 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2105 | |
| 2106 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2107 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2108 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2109 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2110 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2111 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2112 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 2113 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2114 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2115 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2116 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2117 | "0105 LOGO completes to NPort x%x " |
| 2118 | "Data: x%x x%x x%x x%x\n", |
| 2119 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2120 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2121 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2122 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2123 | goto out; |
| 2124 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2125 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 2126 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 2127 | * which should abort all outstanding IOs. |
| 2128 | */ |
| 2129 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2130 | NLP_EVT_DEVICE_RM); |
| 2131 | goto out; |
| 2132 | } |
| 2133 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2134 | if (irsp->ulpStatus) { |
| 2135 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2136 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2137 | /* ELS command is being retried */ |
| 2138 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2139 | /* LOGO failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2140 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2141 | "2756 LOGO failure DID:%06X Status:x%x/x%x\n", |
| 2142 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2143 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2144 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2145 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2146 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2147 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2148 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2149 | NLP_EVT_CMPL_LOGO); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2150 | } else |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2151 | /* Good status, call state machine. |
| 2152 | * This will unregister the rpi if needed. |
| 2153 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2154 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2155 | NLP_EVT_CMPL_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2156 | out: |
| 2157 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2158 | return; |
| 2159 | } |
| 2160 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2161 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2162 | * 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] | 2163 | * @vport: pointer to a virtual N_Port data structure. |
| 2164 | * @ndlp: pointer to a node-list data structure. |
| 2165 | * @retry: number of retries to the command IOCB. |
| 2166 | * |
| 2167 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2168 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2169 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2170 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2171 | * |
| 2172 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2173 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2174 | * will be stored into the context1 field of the IOCB for the completion |
| 2175 | * callback function to the LOGO ELS command. |
| 2176 | * |
| 2177 | * Return code |
| 2178 | * 0 - successfully issued logo |
| 2179 | * 1 - failed to issue logo |
| 2180 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2181 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2182 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2183 | uint8_t retry) |
| 2184 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2185 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2186 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2187 | IOCB_t *icmd; |
| 2188 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2189 | uint8_t *pcmd; |
| 2190 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2191 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2192 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2193 | spin_lock_irq(shost->host_lock); |
| 2194 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2195 | spin_unlock_irq(shost->host_lock); |
| 2196 | return 0; |
| 2197 | } |
| 2198 | spin_unlock_irq(shost->host_lock); |
| 2199 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2200 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2201 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2202 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2203 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2204 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2205 | |
| 2206 | icmd = &elsiocb->iocb; |
| 2207 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2208 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2209 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2210 | |
| 2211 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2212 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2213 | pcmd += sizeof(uint32_t); |
| 2214 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2215 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2216 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2217 | "Issue LOGO: did:x%x", |
| 2218 | ndlp->nlp_DID, 0, 0); |
| 2219 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2220 | phba->fc_stat.elsXmitLOGO++; |
| 2221 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2222 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2223 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2224 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2225 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2226 | |
| 2227 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2228 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2229 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2230 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2231 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2232 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2233 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2234 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2235 | } |
| 2236 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2237 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2238 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2239 | * @phba: pointer to lpfc hba data structure. |
| 2240 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2241 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2242 | * |
| 2243 | * This routine is a generic completion callback function for ELS commands. |
| 2244 | * Specifically, it is the callback function which does not need to perform |
| 2245 | * any command specific operations. It is currently used by the ELS command |
| 2246 | * issuing routines for the ELS State Change Request (SCR), |
| 2247 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 2248 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2249 | * certain debug loggings, this callback function simply invokes the |
| 2250 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2251 | * discovery process. |
| 2252 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2253 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2254 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2255 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2256 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2257 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2258 | IOCB_t *irsp; |
| 2259 | |
| 2260 | irsp = &rspiocb->iocb; |
| 2261 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2262 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2263 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2264 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2265 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2266 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2267 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2268 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2269 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2270 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2271 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2272 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2273 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2274 | return; |
| 2275 | } |
| 2276 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2277 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2278 | * 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] | 2279 | * @vport: pointer to a host virtual N_Port data structure. |
| 2280 | * @nportid: N_Port identifier to the remote node. |
| 2281 | * @retry: number of retries to the command IOCB. |
| 2282 | * |
| 2283 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2284 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2285 | * first search the @vport node list to find the matching ndlp. If no such |
| 2286 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2287 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2288 | * routine is invoked to send the SCR IOCB. |
| 2289 | * |
| 2290 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2291 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2292 | * will be stored into the context1 field of the IOCB for the completion |
| 2293 | * callback function to the SCR ELS command. |
| 2294 | * |
| 2295 | * Return code |
| 2296 | * 0 - Successfully issued scr command |
| 2297 | * 1 - Failed to issue scr command |
| 2298 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2299 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2300 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2301 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2302 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2303 | IOCB_t *icmd; |
| 2304 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2305 | struct lpfc_sli *psli; |
| 2306 | uint8_t *pcmd; |
| 2307 | uint16_t cmdsize; |
| 2308 | struct lpfc_nodelist *ndlp; |
| 2309 | |
| 2310 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2311 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2312 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2313 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2314 | if (!ndlp) { |
| 2315 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2316 | if (!ndlp) |
| 2317 | return 1; |
| 2318 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2319 | lpfc_enqueue_node(vport, ndlp); |
| 2320 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2321 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2322 | if (!ndlp) |
| 2323 | return 1; |
| 2324 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2325 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2326 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2327 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2328 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2329 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2330 | /* This will trigger the release of the node just |
| 2331 | * allocated |
| 2332 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2333 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2334 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2335 | } |
| 2336 | |
| 2337 | icmd = &elsiocb->iocb; |
| 2338 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2339 | |
| 2340 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2341 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2342 | |
| 2343 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2344 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2345 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2346 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2347 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2348 | "Issue SCR: did:x%x", |
| 2349 | ndlp->nlp_DID, 0, 0); |
| 2350 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2351 | phba->fc_stat.elsXmitSCR++; |
| 2352 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2353 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2354 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2355 | /* The additional lpfc_nlp_put will cause the following |
| 2356 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2357 | * the node. |
| 2358 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2359 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2360 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2361 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2362 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2363 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2364 | * trigger the release of node. |
| 2365 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2366 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2367 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2368 | } |
| 2369 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2370 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2371 | * 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] | 2372 | * @vport: pointer to a host virtual N_Port data structure. |
| 2373 | * @nportid: N_Port identifier to the remote node. |
| 2374 | * @retry: number of retries to the command IOCB. |
| 2375 | * |
| 2376 | * This routine issues a Fibre Channel Address Resolution Response |
| 2377 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2378 | * is passed into the function. It first search the @vport node list to find |
| 2379 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2380 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2381 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2382 | * |
| 2383 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2384 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2385 | * will be stored into the context1 field of the IOCB for the completion |
| 2386 | * callback function to the PARPR ELS command. |
| 2387 | * |
| 2388 | * Return code |
| 2389 | * 0 - Successfully issued farpr command |
| 2390 | * 1 - Failed to issue farpr command |
| 2391 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2392 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2393 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2394 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2395 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2396 | IOCB_t *icmd; |
| 2397 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2398 | struct lpfc_sli *psli; |
| 2399 | FARP *fp; |
| 2400 | uint8_t *pcmd; |
| 2401 | uint32_t *lp; |
| 2402 | uint16_t cmdsize; |
| 2403 | struct lpfc_nodelist *ondlp; |
| 2404 | struct lpfc_nodelist *ndlp; |
| 2405 | |
| 2406 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2407 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2408 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2409 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2410 | if (!ndlp) { |
| 2411 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2412 | if (!ndlp) |
| 2413 | return 1; |
| 2414 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2415 | lpfc_enqueue_node(vport, ndlp); |
| 2416 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2417 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2418 | if (!ndlp) |
| 2419 | return 1; |
| 2420 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2421 | |
| 2422 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2423 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2424 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2425 | /* This will trigger the release of the node just |
| 2426 | * allocated |
| 2427 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2428 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2429 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2430 | } |
| 2431 | |
| 2432 | icmd = &elsiocb->iocb; |
| 2433 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2434 | |
| 2435 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2436 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2437 | |
| 2438 | /* Fill in FARPR payload */ |
| 2439 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2440 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2441 | lp = (uint32_t *) pcmd; |
| 2442 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2443 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2444 | fp->Rflags = 0; |
| 2445 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2446 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2447 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2448 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2449 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2450 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2451 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2452 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2453 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2454 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2455 | } |
| 2456 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2457 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2458 | "Issue FARPR: did:x%x", |
| 2459 | ndlp->nlp_DID, 0, 0); |
| 2460 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2461 | phba->fc_stat.elsXmitFARPR++; |
| 2462 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2463 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2464 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2465 | /* The additional lpfc_nlp_put will cause the following |
| 2466 | * lpfc_els_free_iocb routine to trigger the release of |
| 2467 | * the node. |
| 2468 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2469 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2470 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2471 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2472 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2473 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2474 | * trigger the release of the node. |
| 2475 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2476 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2477 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2478 | } |
| 2479 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2480 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2481 | * 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] | 2482 | * @vport: pointer to a host virtual N_Port data structure. |
| 2483 | * @nlp: pointer to a node-list data structure. |
| 2484 | * |
| 2485 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2486 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2487 | * removes the ELS retry event if it presents. In addition, if the |
| 2488 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2489 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2490 | * ADISC. |
| 2491 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2492 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2493 | 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] | 2494 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2495 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2496 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2497 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2498 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2499 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2500 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2501 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2502 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2503 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2504 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2505 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2506 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2507 | /* Decrement nlp reference count held for the delayed retry */ |
| 2508 | evtp = &nlp->els_retry_evt; |
| 2509 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2510 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2511 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2512 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2513 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2514 | spin_unlock_irq(shost->host_lock); |
| 2515 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2516 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2517 | /* Check if there are more ADISCs to be sent */ |
| 2518 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2519 | } else { |
| 2520 | /* Check if there are more PLOGIs to be sent */ |
| 2521 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2522 | if (vport->num_disc_nodes == 0) { |
| 2523 | spin_lock_irq(shost->host_lock); |
| 2524 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2525 | spin_unlock_irq(shost->host_lock); |
| 2526 | lpfc_can_disctmo(vport); |
| 2527 | lpfc_end_rscn(vport); |
| 2528 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2529 | } |
| 2530 | } |
| 2531 | } |
| 2532 | return; |
| 2533 | } |
| 2534 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2535 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2536 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2537 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2538 | * |
| 2539 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2540 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2541 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2542 | * adds the delayed events to the HBA work list and invokes the |
| 2543 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2544 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2545 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2546 | * reference to ndlp will still be available when the worker thread gets |
| 2547 | * to the event associated with the ndlp. |
| 2548 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2549 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2550 | lpfc_els_retry_delay(unsigned long ptr) |
| 2551 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2552 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2553 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2554 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2555 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2556 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2557 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2558 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2559 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2560 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2561 | return; |
| 2562 | } |
| 2563 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2564 | /* We need to hold the node by incrementing the reference |
| 2565 | * count until the queued work is done |
| 2566 | */ |
| 2567 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2568 | if (evtp->evt_arg1) { |
| 2569 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2570 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2571 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2572 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2573 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2574 | return; |
| 2575 | } |
| 2576 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2577 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2578 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2579 | * @ndlp: pointer to a node-list data structure. |
| 2580 | * |
| 2581 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 2582 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 2583 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 2584 | * function according to the delayed ELS command to retry the command. |
| 2585 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2586 | void |
| 2587 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 2588 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2589 | struct lpfc_vport *vport = ndlp->vport; |
| 2590 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2591 | uint32_t cmd, did, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2592 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2593 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2594 | did = ndlp->nlp_DID; |
| 2595 | cmd = ndlp->nlp_last_elscmd; |
| 2596 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2597 | |
| 2598 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2599 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2600 | return; |
| 2601 | } |
| 2602 | |
| 2603 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2604 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 2605 | /* |
| 2606 | * If a discovery event readded nlp_delayfunc after timer |
| 2607 | * firing and before processing the timer, cancel the |
| 2608 | * nlp_delayfunc. |
| 2609 | */ |
| 2610 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2611 | retry = ndlp->nlp_retry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 2612 | ndlp->nlp_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2613 | |
| 2614 | switch (cmd) { |
| 2615 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2616 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2617 | break; |
| 2618 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2619 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2620 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2621 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2622 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2623 | break; |
| 2624 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2625 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2626 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2627 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2628 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2629 | break; |
| 2630 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2631 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2632 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2633 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2634 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2635 | break; |
| 2636 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2637 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2638 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2639 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2640 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2641 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2642 | case ELS_CMD_FDISC: |
| 2643 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
| 2644 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2645 | } |
| 2646 | return; |
| 2647 | } |
| 2648 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2649 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2650 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2651 | * @phba: pointer to lpfc hba data structure. |
| 2652 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2653 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2654 | * |
| 2655 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 2656 | * failed. The following ELS IOCBs use this function for retrying the command |
| 2657 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 2658 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 2659 | * returned error status, it makes the decision whether a retry shall be |
| 2660 | * issued for the command, and whether a retry shall be made immediately or |
| 2661 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 2662 | * is called to retry the command. In the later case, the ELS command shall |
| 2663 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 2664 | * ndlp for the delayed command issusing. |
| 2665 | * |
| 2666 | * Return code |
| 2667 | * 0 - No retry of els command is made |
| 2668 | * 1 - Immediate or delayed retry of els command is made |
| 2669 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2670 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2671 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2672 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2673 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2674 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2675 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2676 | IOCB_t *irsp = &rspiocb->iocb; |
| 2677 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2678 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2679 | uint32_t *elscmd; |
| 2680 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2681 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2682 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2683 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2684 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2685 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2686 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2687 | /* Note: context2 may be 0 for internal driver abort |
| 2688 | * of delays ELS command. |
| 2689 | */ |
| 2690 | |
| 2691 | if (pcmd && pcmd->virt) { |
| 2692 | elscmd = (uint32_t *) (pcmd->virt); |
| 2693 | cmd = *elscmd++; |
| 2694 | } |
| 2695 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2696 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2697 | did = ndlp->nlp_DID; |
| 2698 | else { |
| 2699 | /* We should only hit this case for retrying PLOGI */ |
| 2700 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2701 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2702 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 2703 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2704 | return 1; |
| 2705 | } |
| 2706 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2707 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2708 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 2709 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 2710 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2711 | switch (irsp->ulpStatus) { |
| 2712 | case IOSTAT_FCP_RSP_ERROR: |
| 2713 | case IOSTAT_REMOTE_STOP: |
| 2714 | break; |
| 2715 | |
| 2716 | case IOSTAT_LOCAL_REJECT: |
| 2717 | switch ((irsp->un.ulpWord[4] & 0xff)) { |
| 2718 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2719 | if (cmd == ELS_CMD_FLOGI) { |
| 2720 | if (PCI_DEVICE_ID_HORNET == |
| 2721 | phba->pcidev->device) { |
| 2722 | phba->fc_topology = TOPOLOGY_LOOP; |
| 2723 | phba->pport->fc_myDID = 0; |
| 2724 | phba->alpa_map[0] = 0; |
| 2725 | phba->alpa_map[1] = 0; |
| 2726 | } |
| 2727 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2728 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2729 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2730 | retry = 1; |
| 2731 | break; |
| 2732 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2733 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2734 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2735 | "0124 Retry illegal cmd x%x " |
| 2736 | "retry:x%x delay:x%x\n", |
| 2737 | cmd, cmdiocb->retry, delay); |
| 2738 | retry = 1; |
| 2739 | /* All command's retry policy */ |
| 2740 | maxretry = 8; |
| 2741 | if (cmdiocb->retry > 2) |
| 2742 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2743 | break; |
| 2744 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2745 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2746 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2747 | retry = 1; |
| 2748 | if (cmdiocb->retry > 100) |
| 2749 | delay = 100; |
| 2750 | maxretry = 250; |
| 2751 | break; |
| 2752 | |
| 2753 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2754 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2755 | retry = 1; |
| 2756 | break; |
| 2757 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2758 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2759 | case IOERR_INVALID_RPI: |
| 2760 | retry = 1; |
| 2761 | break; |
| 2762 | } |
| 2763 | break; |
| 2764 | |
| 2765 | case IOSTAT_NPORT_RJT: |
| 2766 | case IOSTAT_FABRIC_RJT: |
| 2767 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 2768 | retry = 1; |
| 2769 | break; |
| 2770 | } |
| 2771 | break; |
| 2772 | |
| 2773 | case IOSTAT_NPORT_BSY: |
| 2774 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2775 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2776 | retry = 1; |
| 2777 | break; |
| 2778 | |
| 2779 | case IOSTAT_LS_RJT: |
| 2780 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 2781 | /* Added for Vendor specifc support |
| 2782 | * Just keep retrying for these Rsn / Exp codes |
| 2783 | */ |
| 2784 | switch (stat.un.b.lsRjtRsnCode) { |
| 2785 | case LSRJT_UNABLE_TPC: |
| 2786 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2787 | LSEXP_CMD_IN_PROGRESS) { |
| 2788 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2789 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2790 | maxretry = 48; |
| 2791 | } |
| 2792 | retry = 1; |
| 2793 | break; |
| 2794 | } |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 2795 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2796 | LSEXP_CANT_GIVE_DATA) { |
| 2797 | if (cmd == ELS_CMD_PLOGI) { |
| 2798 | delay = 1000; |
| 2799 | maxretry = 48; |
| 2800 | } |
| 2801 | retry = 1; |
| 2802 | break; |
| 2803 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2804 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2805 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2806 | maxretry = lpfc_max_els_tries + 1; |
| 2807 | retry = 1; |
| 2808 | break; |
| 2809 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2810 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2811 | (cmd == ELS_CMD_FDISC) && |
| 2812 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2813 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2814 | "0125 FDISC Failed (x%x). " |
| 2815 | "Fabric out of resources\n", |
| 2816 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2817 | lpfc_vport_set_state(vport, |
| 2818 | FC_VPORT_NO_FABRIC_RSCS); |
| 2819 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2820 | break; |
| 2821 | |
| 2822 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2823 | if ((cmd == ELS_CMD_PLOGI) || |
| 2824 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2825 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2826 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2827 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2828 | /* FDISC retry policy */ |
| 2829 | maxretry = 48; |
| 2830 | if (cmdiocb->retry >= 32) |
| 2831 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2832 | } |
| 2833 | retry = 1; |
| 2834 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2835 | |
| 2836 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2837 | /* There are some cases where switches return this |
| 2838 | * error when they are not ready and should be returning |
| 2839 | * Logical Busy. We should delay every time. |
| 2840 | */ |
| 2841 | if (cmd == ELS_CMD_FDISC && |
| 2842 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 2843 | maxretry = 3; |
| 2844 | delay = 1000; |
| 2845 | retry = 1; |
| 2846 | break; |
| 2847 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2848 | case LSRJT_PROTOCOL_ERR: |
| 2849 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2850 | (cmd == ELS_CMD_FDISC) && |
| 2851 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 2852 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 2853 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2854 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2855 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2856 | "Fabric Detected Bad WWN\n", |
| 2857 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2858 | lpfc_vport_set_state(vport, |
| 2859 | FC_VPORT_FABRIC_REJ_WWN); |
| 2860 | } |
| 2861 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2862 | } |
| 2863 | break; |
| 2864 | |
| 2865 | case IOSTAT_INTERMED_RSP: |
| 2866 | case IOSTAT_BA_RJT: |
| 2867 | break; |
| 2868 | |
| 2869 | default: |
| 2870 | break; |
| 2871 | } |
| 2872 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2873 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2874 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2875 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2876 | if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 2877 | (phba->fc_topology != TOPOLOGY_LOOP) && |
| 2878 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2879 | /* FLOGI retry policy */ |
| 2880 | retry = 1; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2881 | /* retry forever */ |
| 2882 | maxretry = 0; |
| 2883 | if (cmdiocb->retry >= 100) |
| 2884 | delay = 5000; |
| 2885 | else if (cmdiocb->retry >= 32) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2886 | delay = 1000; |
| 2887 | } |
| 2888 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2889 | cmdiocb->retry++; |
| 2890 | if (maxretry && (cmdiocb->retry >= maxretry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2891 | phba->fc_stat.elsRetryExceeded++; |
| 2892 | retry = 0; |
| 2893 | } |
| 2894 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2895 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 2896 | retry = 0; |
| 2897 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2898 | if (retry) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 2899 | if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) { |
| 2900 | /* Stop retrying PLOGI and FDISC if in FCF discovery */ |
| 2901 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 2902 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2903 | "2849 Stop retry ELS command " |
| 2904 | "x%x to remote NPORT x%x, " |
| 2905 | "Data: x%x x%x\n", cmd, did, |
| 2906 | cmdiocb->retry, delay); |
| 2907 | return 0; |
| 2908 | } |
| 2909 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2910 | |
| 2911 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2912 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2913 | "0107 Retry ELS command x%x to remote " |
| 2914 | "NPORT x%x Data: x%x x%x\n", |
| 2915 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2916 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2917 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 2918 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 2919 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { |
| 2920 | /* Don't reset timer for no resources */ |
| 2921 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2922 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2923 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2924 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2925 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2926 | } |
| 2927 | |
| 2928 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2929 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2930 | phba->fc_stat.elsDelayRetry++; |
| 2931 | ndlp->nlp_retry = cmdiocb->retry; |
| 2932 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2933 | /* delay is specified in milliseconds */ |
| 2934 | mod_timer(&ndlp->nlp_delayfunc, |
| 2935 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2936 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2937 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2938 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2939 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2940 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2941 | if (cmd == ELS_CMD_PRLI) |
| 2942 | lpfc_nlp_set_state(vport, ndlp, |
| 2943 | NLP_STE_REG_LOGIN_ISSUE); |
| 2944 | else |
| 2945 | lpfc_nlp_set_state(vport, ndlp, |
| 2946 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2947 | ndlp->nlp_last_elscmd = cmd; |
| 2948 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2949 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2950 | } |
| 2951 | switch (cmd) { |
| 2952 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2953 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2954 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2955 | case ELS_CMD_FDISC: |
| 2956 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 2957 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2958 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2959 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2960 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2961 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2962 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2963 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2964 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2965 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2966 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2967 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2968 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 2969 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2970 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2971 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2972 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2973 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 2974 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2975 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2976 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2977 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2978 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 2979 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2980 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2981 | } |
| 2982 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2983 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2984 | if (logerr) { |
| 2985 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2986 | "0137 No retry ELS command x%x to remote " |
| 2987 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 2988 | cmd, did, irsp->ulpStatus, |
| 2989 | irsp->un.ulpWord[4]); |
| 2990 | } |
| 2991 | else { |
| 2992 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2993 | "0108 No retry ELS command x%x to remote " |
| 2994 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 2995 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 2996 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2997 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2998 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2999 | } |
| 3000 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3001 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3002 | * 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] | 3003 | * @phba: pointer to lpfc hba data structure. |
| 3004 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 3005 | * |
| 3006 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 3007 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 3008 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 3009 | * response of the command IOCB. If so, it will be released before releasing |
| 3010 | * the lpfc DMA buffer associated with the IOCB itself. |
| 3011 | * |
| 3012 | * Return code |
| 3013 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3014 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3015 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3016 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 3017 | { |
| 3018 | struct lpfc_dmabuf *buf_ptr; |
| 3019 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3020 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3021 | if (!list_empty(&buf_ptr1->list)) { |
| 3022 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 3023 | struct lpfc_dmabuf, |
| 3024 | list); |
| 3025 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3026 | kfree(buf_ptr); |
| 3027 | } |
| 3028 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 3029 | kfree(buf_ptr1); |
| 3030 | return 0; |
| 3031 | } |
| 3032 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3033 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3034 | * 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] | 3035 | * @phba: pointer to lpfc hba data structure. |
| 3036 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 3037 | * |
| 3038 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 3039 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 3040 | * pool. |
| 3041 | * |
| 3042 | * Return code |
| 3043 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3044 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3045 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3046 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 3047 | { |
| 3048 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3049 | kfree(buf_ptr); |
| 3050 | return 0; |
| 3051 | } |
| 3052 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3053 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3054 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3055 | * @phba: pointer to lpfc hba data structure. |
| 3056 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 3057 | * |
| 3058 | * This routine frees a command IOCB and its associated resources. The |
| 3059 | * command IOCB data structure contains the reference to various associated |
| 3060 | * resources, these fields must be set to NULL if the associated reference |
| 3061 | * not present: |
| 3062 | * context1 - reference to ndlp |
| 3063 | * context2 - reference to cmd |
| 3064 | * context2->next - reference to rsp |
| 3065 | * context3 - reference to bpl |
| 3066 | * |
| 3067 | * It first properly decrements the reference count held on ndlp for the |
| 3068 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 3069 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 3070 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 3071 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 3072 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 3073 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 3074 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 3075 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 3076 | * |
| 3077 | * Return code |
| 3078 | * 0 - Success (currently, always return 0) |
| 3079 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3080 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3081 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3082 | { |
| 3083 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3084 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3085 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3086 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 3087 | if (ndlp) { |
| 3088 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 3089 | lpfc_nlp_put(ndlp); |
| 3090 | |
| 3091 | /* If the ndlp is not being used by another discovery |
| 3092 | * thread, free it. |
| 3093 | */ |
| 3094 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3095 | /* If ndlp is being used by another discovery |
| 3096 | * thread, just clear NLP_DEFER_RM |
| 3097 | */ |
| 3098 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 3099 | } |
| 3100 | } |
| 3101 | else |
| 3102 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3103 | elsiocb->context1 = NULL; |
| 3104 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3105 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 3106 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3107 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 3108 | /* Firmware could still be in progress of DMAing |
| 3109 | * payload, so don't free data buffer till after |
| 3110 | * a hbeat. |
| 3111 | */ |
| 3112 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 3113 | buf_ptr = elsiocb->context2; |
| 3114 | elsiocb->context2 = NULL; |
| 3115 | if (buf_ptr) { |
| 3116 | buf_ptr1 = NULL; |
| 3117 | spin_lock_irq(&phba->hbalock); |
| 3118 | if (!list_empty(&buf_ptr->list)) { |
| 3119 | list_remove_head(&buf_ptr->list, |
| 3120 | buf_ptr1, struct lpfc_dmabuf, |
| 3121 | list); |
| 3122 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 3123 | list_add_tail(&buf_ptr1->list, |
| 3124 | &phba->elsbuf); |
| 3125 | phba->elsbuf_cnt++; |
| 3126 | } |
| 3127 | INIT_LIST_HEAD(&buf_ptr->list); |
| 3128 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 3129 | phba->elsbuf_cnt++; |
| 3130 | spin_unlock_irq(&phba->hbalock); |
| 3131 | } |
| 3132 | } else { |
| 3133 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 3134 | lpfc_els_free_data(phba, buf_ptr1); |
| 3135 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3136 | } |
| 3137 | |
| 3138 | if (elsiocb->context3) { |
| 3139 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3140 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3141 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3142 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3143 | return 0; |
| 3144 | } |
| 3145 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3146 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3147 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3148 | * @phba: pointer to lpfc hba data structure. |
| 3149 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3150 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3151 | * |
| 3152 | * This routine is the completion callback function to the Logout (LOGO) |
| 3153 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 3154 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 3155 | * release the ndlp if it has the last reference remaining (reference count |
| 3156 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 3157 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 3158 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 3159 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 3160 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 3161 | * IOCB data structure. |
| 3162 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3163 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3164 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3165 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3166 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3167 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3168 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3169 | IOCB_t *irsp; |
| 3170 | |
| 3171 | irsp = &rspiocb->iocb; |
| 3172 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3173 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 3174 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3175 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3176 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3177 | "0109 ACC to LOGO completes to NPort x%x " |
| 3178 | "Data: x%x x%x x%x\n", |
| 3179 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3180 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3181 | |
| 3182 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 3183 | /* NPort Recovery mode or node is just allocated */ |
| 3184 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3185 | /* If the ndlp is being used by another discovery |
| 3186 | * thread, just unregister the RPI. |
| 3187 | */ |
| 3188 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3189 | } else { |
| 3190 | /* Indicate the node has already released, should |
| 3191 | * not reference to it from within lpfc_els_free_iocb. |
| 3192 | */ |
| 3193 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3194 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3195 | } |
| 3196 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3197 | return; |
| 3198 | } |
| 3199 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3200 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3201 | * 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] | 3202 | * @phba: pointer to lpfc hba data structure. |
| 3203 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 3204 | * |
| 3205 | * This routine is the completion callback function for unregister default |
| 3206 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 3207 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 3208 | * decrements the ndlp reference count held for this completion callback |
| 3209 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 3210 | * whether there is only one reference left on the ndlp. If so, it will |
| 3211 | * perform one more decrement and trigger the release of the ndlp. |
| 3212 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3213 | void |
| 3214 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3215 | { |
| 3216 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3217 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3218 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3219 | /* |
| 3220 | * This routine is used to register and unregister in previous SLI |
| 3221 | * modes. |
| 3222 | */ |
| 3223 | if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) && |
| 3224 | (phba->sli_rev == LPFC_SLI_REV4)) |
| 3225 | lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi); |
| 3226 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3227 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3228 | pmb->context2 = NULL; |
| 3229 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3230 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3231 | kfree(mp); |
| 3232 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3233 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3234 | lpfc_nlp_put(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3235 | /* This is the end of the default RPI cleanup logic for this |
| 3236 | * ndlp. If no other discovery threads are using this ndlp. |
| 3237 | * we should free all resources associated with it. |
| 3238 | */ |
| 3239 | lpfc_nlp_not_used(ndlp); |
| 3240 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3241 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3242 | return; |
| 3243 | } |
| 3244 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3245 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3246 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3247 | * @phba: pointer to lpfc hba data structure. |
| 3248 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3249 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3250 | * |
| 3251 | * This routine is the completion callback function for ELS Response IOCB |
| 3252 | * command. In normal case, this callback function just properly sets the |
| 3253 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 3254 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 3255 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 3256 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 3257 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 3258 | * routine shall be invoked trying to release the ndlp if no other threads |
| 3259 | * are currently referring it. |
| 3260 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3261 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3262 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3263 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3264 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3265 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3266 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 3267 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3268 | IOCB_t *irsp; |
| 3269 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3270 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3271 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3272 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3273 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3274 | irsp = &rspiocb->iocb; |
| 3275 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3276 | if (cmdiocb->context_un.mbox) |
| 3277 | mbox = cmdiocb->context_un.mbox; |
| 3278 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3279 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 3280 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 3281 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3282 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3283 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3284 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3285 | /* A LS_RJT associated with Default RPI cleanup has its own |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 3286 | * separate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3287 | */ |
| 3288 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 3289 | ls_rjt = 1; |
| 3290 | } |
| 3291 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3292 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3293 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3294 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3295 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3296 | if (mp) { |
| 3297 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3298 | kfree(mp); |
| 3299 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3300 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3301 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3302 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3303 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3304 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3305 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3306 | /* Indicate the node has already released, |
| 3307 | * should not reference to it from within |
| 3308 | * the routine lpfc_els_free_iocb. |
| 3309 | */ |
| 3310 | cmdiocb->context1 = NULL; |
| 3311 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3312 | goto out; |
| 3313 | } |
| 3314 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3315 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3316 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3317 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3318 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3319 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3320 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3321 | "0110 ELS response tag x%x completes " |
| 3322 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3323 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3324 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3325 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3326 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3327 | if (mbox) { |
| 3328 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3329 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3330 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3331 | /* Increment reference count to ndlp to hold the |
| 3332 | * reference to ndlp for the callback function. |
| 3333 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3334 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3335 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3336 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3337 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3338 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3339 | } |
| 3340 | else { |
| 3341 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3342 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3343 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3344 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3345 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3346 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3347 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3348 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3349 | else |
| 3350 | /* Decrement the ndlp reference count we |
| 3351 | * set for this failed mailbox command. |
| 3352 | */ |
| 3353 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3354 | |
| 3355 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3356 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3357 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3358 | "Data: x%x x%x x%x\n", |
| 3359 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3360 | ndlp->nlp_rpi); |
| 3361 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3362 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3363 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3364 | /* Indicate node has already been released, |
| 3365 | * should not reference to it from within |
| 3366 | * the routine lpfc_els_free_iocb. |
| 3367 | */ |
| 3368 | cmdiocb->context1 = NULL; |
| 3369 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3370 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3371 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3372 | if (!lpfc_error_lost_link(irsp) && |
| 3373 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3374 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3375 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3376 | /* Indicate node has already been |
| 3377 | * released, should not reference |
| 3378 | * to it from within the routine |
| 3379 | * lpfc_els_free_iocb. |
| 3380 | */ |
| 3381 | cmdiocb->context1 = NULL; |
| 3382 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3383 | } |
| 3384 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3385 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3386 | if (mp) { |
| 3387 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3388 | kfree(mp); |
| 3389 | } |
| 3390 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3391 | } |
| 3392 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3393 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3394 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3395 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3396 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3397 | |
| 3398 | /* If the node is not being used by another discovery thread, |
| 3399 | * and we are sending a reject, we are done with it. |
| 3400 | * Release driver reference count here and free associated |
| 3401 | * resources. |
| 3402 | */ |
| 3403 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3404 | if (lpfc_nlp_not_used(ndlp)) |
| 3405 | /* Indicate node has already been released, |
| 3406 | * should not reference to it from within |
| 3407 | * the routine lpfc_els_free_iocb. |
| 3408 | */ |
| 3409 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3410 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3411 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3412 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3413 | return; |
| 3414 | } |
| 3415 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3416 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3417 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3418 | * @vport: pointer to a host virtual N_Port data structure. |
| 3419 | * @flag: the els command code to be accepted. |
| 3420 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3421 | * @ndlp: pointer to a node-list data structure. |
| 3422 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3423 | * |
| 3424 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3425 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3426 | * specific ACC response command to be issued and invokes the |
| 3427 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3428 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3429 | * field of the IOCB for the completion callback function to issue the |
| 3430 | * mailbox command to the HBA later when callback is invoked. |
| 3431 | * |
| 3432 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3433 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3434 | * will be stored into the context1 field of the IOCB for the completion |
| 3435 | * callback function to the corresponding response ELS IOCB command. |
| 3436 | * |
| 3437 | * Return code |
| 3438 | * 0 - Successfully issued acc response |
| 3439 | * 1 - Failed to issue acc response |
| 3440 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3441 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3442 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3443 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3444 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3445 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3446 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3447 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3448 | IOCB_t *icmd; |
| 3449 | IOCB_t *oldcmd; |
| 3450 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3451 | struct lpfc_sli *psli; |
| 3452 | uint8_t *pcmd; |
| 3453 | uint16_t cmdsize; |
| 3454 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3455 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3456 | |
| 3457 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3458 | oldcmd = &oldiocb->iocb; |
| 3459 | |
| 3460 | switch (flag) { |
| 3461 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3462 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3463 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3464 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3465 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3466 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3467 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3468 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3469 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3470 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3471 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3472 | icmd = &elsiocb->iocb; |
| 3473 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3474 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3475 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3476 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3477 | |
| 3478 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3479 | "Issue ACC: did:x%x flg:x%x", |
| 3480 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3481 | break; |
| 3482 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3483 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3484 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3485 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3486 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3487 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3488 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3489 | icmd = &elsiocb->iocb; |
| 3490 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3491 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3492 | |
| 3493 | if (mbox) |
| 3494 | elsiocb->context_un.mbox = mbox; |
| 3495 | |
| 3496 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3497 | pcmd += sizeof(uint32_t); |
| 3498 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3499 | |
| 3500 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3501 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 3502 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3503 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3504 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3505 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3506 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3507 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3508 | if (!elsiocb) |
| 3509 | return 1; |
| 3510 | |
| 3511 | icmd = &elsiocb->iocb; |
| 3512 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3513 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3514 | |
| 3515 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3516 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3517 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 3518 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 3519 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3520 | |
| 3521 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3522 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 3523 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3524 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3525 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3526 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3527 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3528 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3529 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3530 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
| 3531 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", |
| 3532 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3533 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3534 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3535 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3536 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3537 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3538 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3539 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 3540 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3541 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3542 | } |
| 3543 | |
| 3544 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3545 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3546 | if (rc == IOCB_ERROR) { |
| 3547 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3548 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3549 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3550 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3551 | } |
| 3552 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3553 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3554 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3555 | * @vport: pointer to a virtual N_Port data structure. |
| 3556 | * @rejectError: |
| 3557 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3558 | * @ndlp: pointer to a node-list data structure. |
| 3559 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3560 | * |
| 3561 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 3562 | * command. If a @mbox pointer is passed in, it will be put into the |
| 3563 | * context_un.mbox field of the IOCB for the completion callback function |
| 3564 | * to issue to the HBA later. |
| 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 reject response ELS IOCB command. |
| 3570 | * |
| 3571 | * Return code |
| 3572 | * 0 - Successfully issued reject response |
| 3573 | * 1 - Failed to issue reject 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_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3577 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 3578 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3579 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3580 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3581 | IOCB_t *icmd; |
| 3582 | IOCB_t *oldcmd; |
| 3583 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3584 | struct lpfc_sli *psli; |
| 3585 | uint8_t *pcmd; |
| 3586 | uint16_t cmdsize; |
| 3587 | int rc; |
| 3588 | |
| 3589 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3590 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3591 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3592 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3593 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3594 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3595 | |
| 3596 | icmd = &elsiocb->iocb; |
| 3597 | oldcmd = &oldiocb->iocb; |
| 3598 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3599 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3600 | |
| 3601 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3602 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3603 | *((uint32_t *) (pcmd)) = rejectError; |
| 3604 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3605 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3606 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3607 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3608 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3609 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3610 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 3611 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 3612 | "rpi x%x\n", |
| 3613 | rejectError, elsiocb->iotag, |
| 3614 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 3615 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3616 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3617 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 3618 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 3619 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3620 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3621 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3622 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3623 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3624 | if (rc == IOCB_ERROR) { |
| 3625 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3626 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3627 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3628 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3629 | } |
| 3630 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3631 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3632 | * 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] | 3633 | * @vport: pointer to a virtual N_Port data structure. |
| 3634 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3635 | * @ndlp: pointer to a node-list data structure. |
| 3636 | * |
| 3637 | * This routine prepares and issues an Accept (ACC) response to Address |
| 3638 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 3639 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3640 | * |
| 3641 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3642 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3643 | * will be stored into the context1 field of the IOCB for the completion |
| 3644 | * callback function to the ADISC Accept response ELS IOCB command. |
| 3645 | * |
| 3646 | * Return code |
| 3647 | * 0 - Successfully issued acc adisc response |
| 3648 | * 1 - Failed to issue adisc acc response |
| 3649 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3650 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3651 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 3652 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3653 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3654 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3655 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3656 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3657 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3658 | uint8_t *pcmd; |
| 3659 | uint16_t cmdsize; |
| 3660 | int rc; |
| 3661 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3662 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3663 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3664 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3665 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3666 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3667 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3668 | icmd = &elsiocb->iocb; |
| 3669 | oldcmd = &oldiocb->iocb; |
| 3670 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3671 | |
| 3672 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3673 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3674 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 3675 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 3676 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3677 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3678 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3679 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3680 | |
| 3681 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3682 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3683 | |
| 3684 | ap = (ADISC *) (pcmd); |
| 3685 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3686 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3687 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3688 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3689 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3690 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3691 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 3692 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3693 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3694 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3695 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3696 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3697 | if (rc == IOCB_ERROR) { |
| 3698 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3699 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3700 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3701 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3702 | } |
| 3703 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3704 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3705 | * 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] | 3706 | * @vport: pointer to a virtual N_Port data structure. |
| 3707 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3708 | * @ndlp: pointer to a node-list data structure. |
| 3709 | * |
| 3710 | * This routine prepares and issues an Accept (ACC) response to Process |
| 3711 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 3712 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3713 | * |
| 3714 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3715 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3716 | * will be stored into the context1 field of the IOCB for the completion |
| 3717 | * callback function to the PRLI Accept response ELS IOCB command. |
| 3718 | * |
| 3719 | * Return code |
| 3720 | * 0 - Successfully issued acc prli response |
| 3721 | * 1 - Failed to issue acc prli response |
| 3722 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3723 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3724 | 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] | 3725 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3726 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3727 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3728 | PRLI *npr; |
| 3729 | lpfc_vpd_t *vpd; |
| 3730 | IOCB_t *icmd; |
| 3731 | IOCB_t *oldcmd; |
| 3732 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3733 | struct lpfc_sli *psli; |
| 3734 | uint8_t *pcmd; |
| 3735 | uint16_t cmdsize; |
| 3736 | int rc; |
| 3737 | |
| 3738 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3739 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3740 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3741 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3742 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3743 | if (!elsiocb) |
| 3744 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3745 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3746 | icmd = &elsiocb->iocb; |
| 3747 | oldcmd = &oldiocb->iocb; |
| 3748 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3749 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3750 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3751 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 3752 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 3753 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3754 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3755 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3756 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3757 | |
| 3758 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3759 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3760 | |
| 3761 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3762 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3763 | |
| 3764 | npr = (PRLI *) pcmd; |
| 3765 | vpd = &phba->vpd; |
| 3766 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3767 | * If the remote port is a target and our firmware version is 3.20 or |
| 3768 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3769 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3770 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 3771 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3772 | npr->ConfmComplAllowed = 1; |
| 3773 | npr->Retry = 1; |
| 3774 | npr->TaskRetryIdReq = 1; |
| 3775 | } |
| 3776 | |
| 3777 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 3778 | npr->estabImagePair = 1; |
| 3779 | npr->readXferRdyDis = 1; |
| 3780 | npr->ConfmComplAllowed = 1; |
| 3781 | |
| 3782 | npr->prliType = PRLI_FCP_TYPE; |
| 3783 | npr->initiatorFunc = 1; |
| 3784 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3785 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3786 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 3787 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3788 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3789 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3790 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3791 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3792 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3793 | if (rc == IOCB_ERROR) { |
| 3794 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3795 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3796 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3797 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3798 | } |
| 3799 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3800 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3801 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3802 | * @vport: pointer to a virtual N_Port data structure. |
| 3803 | * @format: rnid command format. |
| 3804 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3805 | * @ndlp: pointer to a node-list data structure. |
| 3806 | * |
| 3807 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 3808 | * (ACC) response. It constructs the RNID ACC response command according to |
| 3809 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 3810 | * issue the response. Note that this command does not need to hold the ndlp |
| 3811 | * reference count for the callback. So, the ndlp reference count taken by |
| 3812 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 3813 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 3814 | * there is no ndlp reference available. |
| 3815 | * |
| 3816 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3817 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3818 | * will be stored into the context1 field of the IOCB for the completion |
| 3819 | * callback function. However, for the RNID Accept Response ELS command, |
| 3820 | * this is undone later by this routine after the IOCB is allocated. |
| 3821 | * |
| 3822 | * Return code |
| 3823 | * 0 - Successfully issued acc rnid response |
| 3824 | * 1 - Failed to issue acc rnid response |
| 3825 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3826 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3827 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3828 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3829 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3830 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3831 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3832 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3833 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3834 | struct lpfc_sli *psli; |
| 3835 | uint8_t *pcmd; |
| 3836 | uint16_t cmdsize; |
| 3837 | int rc; |
| 3838 | |
| 3839 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3840 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 3841 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3842 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3843 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3844 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3845 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3846 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3847 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3848 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3849 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3850 | icmd = &elsiocb->iocb; |
| 3851 | oldcmd = &oldiocb->iocb; |
| 3852 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3853 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3854 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3855 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 3856 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3857 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3858 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3859 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3860 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3861 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3862 | rn = (RNID *) (pcmd); |
| 3863 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3864 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 3865 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3866 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3867 | switch (format) { |
| 3868 | case 0: |
| 3869 | rn->SpecificLen = 0; |
| 3870 | break; |
| 3871 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3872 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3873 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3874 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3875 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 3876 | rn->un.topologyDisc.physPort = 0; |
| 3877 | rn->un.topologyDisc.attachedNodes = 0; |
| 3878 | break; |
| 3879 | default: |
| 3880 | rn->CommonLen = 0; |
| 3881 | rn->SpecificLen = 0; |
| 3882 | break; |
| 3883 | } |
| 3884 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3885 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3886 | "Issue ACC RNID: did:x%x flg:x%x", |
| 3887 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3888 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3889 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3890 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3891 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3892 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 3893 | * it could be freed */ |
| 3894 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3895 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3896 | if (rc == IOCB_ERROR) { |
| 3897 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3898 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3899 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3900 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3901 | } |
| 3902 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3903 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 3904 | * lpfc_els_rsp_echo_acc - Issue echo acc response |
| 3905 | * @vport: pointer to a virtual N_Port data structure. |
| 3906 | * @data: pointer to echo data to return in the accept. |
| 3907 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3908 | * @ndlp: pointer to a node-list data structure. |
| 3909 | * |
| 3910 | * Return code |
| 3911 | * 0 - Successfully issued acc echo response |
| 3912 | * 1 - Failed to issue acc echo response |
| 3913 | **/ |
| 3914 | static int |
| 3915 | lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data, |
| 3916 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| 3917 | { |
| 3918 | struct lpfc_hba *phba = vport->phba; |
| 3919 | struct lpfc_iocbq *elsiocb; |
| 3920 | struct lpfc_sli *psli; |
| 3921 | uint8_t *pcmd; |
| 3922 | uint16_t cmdsize; |
| 3923 | int rc; |
| 3924 | |
| 3925 | psli = &phba->sli; |
| 3926 | cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len; |
| 3927 | |
| 3928 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3929 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 3930 | if (!elsiocb) |
| 3931 | return 1; |
| 3932 | |
| 3933 | elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri */ |
| 3934 | /* Xmit ECHO ACC response tag <ulpIoTag> */ |
| 3935 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3936 | "2876 Xmit ECHO ACC response tag x%x xri x%x\n", |
| 3937 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| 3938 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3939 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 3940 | pcmd += sizeof(uint32_t); |
| 3941 | memcpy(pcmd, data, cmdsize - sizeof(uint32_t)); |
| 3942 | |
| 3943 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3944 | "Issue ACC ECHO: did:x%x flg:x%x", |
| 3945 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3946 | |
| 3947 | phba->fc_stat.elsXmitACC++; |
| 3948 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 3949 | lpfc_nlp_put(ndlp); |
| 3950 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 3951 | * it could be freed */ |
| 3952 | |
| 3953 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 3954 | if (rc == IOCB_ERROR) { |
| 3955 | lpfc_els_free_iocb(phba, elsiocb); |
| 3956 | return 1; |
| 3957 | } |
| 3958 | return 0; |
| 3959 | } |
| 3960 | |
| 3961 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3962 | * 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] | 3963 | * @vport: pointer to a host virtual N_Port data structure. |
| 3964 | * |
| 3965 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 3966 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 3967 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 3968 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 3969 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 3970 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 3971 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 3972 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 3973 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 3974 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 3975 | * no more ADISC need to be sent. |
| 3976 | * |
| 3977 | * Return code |
| 3978 | * The number of N_Ports with adisc issued. |
| 3979 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3980 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3981 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3982 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3983 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3984 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3985 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3986 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3987 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3988 | 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] | 3989 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3990 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3991 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3992 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3993 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3994 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3995 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3996 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3997 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3998 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 3999 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4000 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4001 | vport->num_disc_nodes++; |
| 4002 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4003 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4004 | spin_lock_irq(shost->host_lock); |
| 4005 | vport->fc_flag |= FC_NLP_MORE; |
| 4006 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4007 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4008 | } |
| 4009 | } |
| 4010 | } |
| 4011 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4012 | spin_lock_irq(shost->host_lock); |
| 4013 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4014 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4015 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4016 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4017 | } |
| 4018 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4019 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4020 | * 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] | 4021 | * @vport: pointer to a host virtual N_Port data structure. |
| 4022 | * |
| 4023 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 4024 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 4025 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 4026 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 4027 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 4028 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 4029 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 4030 | * later pick up. On the other hand, after walking through all the ndlps with |
| 4031 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 4032 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 4033 | * PLOGI need to be sent. |
| 4034 | * |
| 4035 | * Return code |
| 4036 | * The number of N_Ports with plogi issued. |
| 4037 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4038 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4039 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4040 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4041 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4042 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4043 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4044 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4045 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 4046 | 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] | 4047 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4048 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4049 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 4050 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4051 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 4052 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 4053 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4054 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 4055 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4056 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4057 | vport->num_disc_nodes++; |
| 4058 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4059 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4060 | spin_lock_irq(shost->host_lock); |
| 4061 | vport->fc_flag |= FC_NLP_MORE; |
| 4062 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4063 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4064 | } |
| 4065 | } |
| 4066 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4067 | if (sentplogi) { |
| 4068 | lpfc_set_disctmo(vport); |
| 4069 | } |
| 4070 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4071 | spin_lock_irq(shost->host_lock); |
| 4072 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4073 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4074 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4075 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4076 | } |
| 4077 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4078 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4079 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4080 | * @vport: pointer to a host virtual N_Port data structure. |
| 4081 | * |
| 4082 | * This routine cleans up any Registration State Change Notification |
| 4083 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 4084 | * @vport together with the host_lock is used to prevent multiple thread |
| 4085 | * trying to access the RSCN array on a same @vport at the same time. |
| 4086 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4087 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4088 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4089 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4090 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4091 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4092 | int i; |
| 4093 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4094 | spin_lock_irq(shost->host_lock); |
| 4095 | if (vport->fc_rscn_flush) { |
| 4096 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4097 | spin_unlock_irq(shost->host_lock); |
| 4098 | return; |
| 4099 | } |
| 4100 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 4101 | vport->fc_rscn_flush = 1; |
| 4102 | spin_unlock_irq(shost->host_lock); |
| 4103 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4104 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4105 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4106 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4107 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4108 | spin_lock_irq(shost->host_lock); |
| 4109 | vport->fc_rscn_id_cnt = 0; |
| 4110 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 4111 | spin_unlock_irq(shost->host_lock); |
| 4112 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4113 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 4114 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4115 | } |
| 4116 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4117 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4118 | * 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] | 4119 | * @vport: pointer to a host virtual N_Port data structure. |
| 4120 | * @did: remote destination port identifier. |
| 4121 | * |
| 4122 | * This routine checks whether there is any pending Registration State |
| 4123 | * Configuration Notification (RSCN) to a @did on @vport. |
| 4124 | * |
| 4125 | * Return code |
| 4126 | * None zero - The @did matched with a pending rscn |
| 4127 | * 0 - not able to match @did with a pending rscn |
| 4128 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4129 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4130 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4131 | { |
| 4132 | D_ID ns_did; |
| 4133 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4134 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4135 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4136 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4137 | |
| 4138 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4139 | |
| 4140 | /* Never match fabric nodes for RSCNs */ |
| 4141 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4142 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4143 | |
| 4144 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4145 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4146 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4147 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4148 | spin_lock_irq(shost->host_lock); |
| 4149 | if (vport->fc_rscn_flush) { |
| 4150 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4151 | spin_unlock_irq(shost->host_lock); |
| 4152 | return 0; |
| 4153 | } |
| 4154 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4155 | vport->fc_rscn_flush = 1; |
| 4156 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4157 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4158 | lp = vport->fc_rscn_id_list[i]->virt; |
| 4159 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4160 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4161 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4162 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 4163 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4164 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 4165 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4166 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4167 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 4168 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4169 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4170 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4171 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4172 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4173 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4174 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4175 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4176 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4177 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4178 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4179 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4180 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4181 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4182 | } |
| 4183 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4184 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4185 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4186 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4187 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4188 | return_did_out: |
| 4189 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4190 | vport->fc_rscn_flush = 0; |
| 4191 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4192 | } |
| 4193 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4194 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4195 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4196 | * @vport: pointer to a host virtual N_Port data structure. |
| 4197 | * |
| 4198 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 4199 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 4200 | * State Change Notification). |
| 4201 | * |
| 4202 | * Return code |
| 4203 | * 0 - Successful (currently alway return 0) |
| 4204 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4205 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4206 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4207 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4208 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4209 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4210 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4211 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4212 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4213 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 4214 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4215 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4216 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4217 | NLP_EVT_DEVICE_RECOVERY); |
| 4218 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4219 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4220 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4221 | } |
| 4222 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4223 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4224 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4225 | * @vport: pointer to a host virtual N_Port data structure. |
| 4226 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4227 | * |
| 4228 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 4229 | * applications. |
| 4230 | */ |
| 4231 | static void |
| 4232 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 4233 | struct lpfc_iocbq *cmdiocb) |
| 4234 | { |
| 4235 | struct lpfc_dmabuf *pcmd; |
| 4236 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4237 | uint32_t *payload_ptr; |
| 4238 | uint32_t payload_len; |
| 4239 | struct lpfc_rscn_event_header *rscn_event_data; |
| 4240 | |
| 4241 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4242 | payload_ptr = (uint32_t *) pcmd->virt; |
| 4243 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 4244 | |
| 4245 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 4246 | payload_len, GFP_KERNEL); |
| 4247 | if (!rscn_event_data) { |
| 4248 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4249 | "0147 Failed to allocate memory for RSCN event\n"); |
| 4250 | return; |
| 4251 | } |
| 4252 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 4253 | rscn_event_data->payload_length = payload_len; |
| 4254 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 4255 | payload_len); |
| 4256 | |
| 4257 | fc_host_post_vendor_event(shost, |
| 4258 | fc_get_event_number(), |
| 4259 | sizeof(struct lpfc_els_event_header) + payload_len, |
| 4260 | (char *)rscn_event_data, |
| 4261 | LPFC_NL_VENDOR_ID); |
| 4262 | |
| 4263 | kfree(rscn_event_data); |
| 4264 | } |
| 4265 | |
| 4266 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4267 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4268 | * @vport: pointer to a host virtual N_Port data structure. |
| 4269 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4270 | * @ndlp: pointer to a node-list data structure. |
| 4271 | * |
| 4272 | * This routine processes an unsolicited RSCN (Registration State Change |
| 4273 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 4274 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 4275 | * discover state machine is about to begin discovery, it just accepts the |
| 4276 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 4277 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 4278 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 4279 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 4280 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 4281 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 4282 | * routine is invoked to handle the RSCN event. |
| 4283 | * |
| 4284 | * Return code |
| 4285 | * 0 - Just sent the acc response |
| 4286 | * 1 - Sent the acc response and waited for name server completion |
| 4287 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4288 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4289 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4290 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4291 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4292 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4293 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4294 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4295 | uint32_t *lp, *datap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4296 | IOCB_t *icmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4297 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4298 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4299 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4300 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4301 | |
| 4302 | icmd = &cmdiocb->iocb; |
| 4303 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4304 | lp = (uint32_t *) pcmd->virt; |
| 4305 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4306 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4307 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4308 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4309 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4310 | "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] | 4311 | vport->fc_flag, payload_len, *lp, |
| 4312 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4313 | |
| 4314 | /* Send an RSCN event to the management application */ |
| 4315 | lpfc_send_rscn_event(vport, cmdiocb); |
| 4316 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4317 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4318 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4319 | FCH_EVT_RSCN, lp[i]); |
| 4320 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4321 | /* If we are about to begin discovery, just ACC the RSCN. |
| 4322 | * Discovery processing will satisfy it. |
| 4323 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4324 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4325 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4326 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 4327 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4328 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4329 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4330 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4331 | } |
| 4332 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4333 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 4334 | * just ACC and ignore it. |
| 4335 | */ |
| 4336 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4337 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4338 | i = payload_len; |
| 4339 | datap = lp; |
| 4340 | while (i > 0) { |
| 4341 | nportid = *datap++; |
| 4342 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 4343 | i -= sizeof(uint32_t); |
| 4344 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4345 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 4346 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4347 | } |
| 4348 | if (rscn_id == hba_id) { |
| 4349 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4350 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4351 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4352 | "Data: x%x x%x x%x x%x\n", |
| 4353 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4354 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4355 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4356 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 4357 | ndlp->nlp_DID, vport->port_state, |
| 4358 | ndlp->nlp_flag); |
| 4359 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4360 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4361 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4362 | return 0; |
| 4363 | } |
| 4364 | } |
| 4365 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4366 | spin_lock_irq(shost->host_lock); |
| 4367 | if (vport->fc_rscn_flush) { |
| 4368 | /* Another thread is walking fc_rscn_id_list on this vport */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4369 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 4370 | spin_unlock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4371 | /* Send back ACC */ |
| 4372 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4373 | return 0; |
| 4374 | } |
| 4375 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4376 | vport->fc_rscn_flush = 1; |
| 4377 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4378 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4379 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4380 | /* If we are already processing an RSCN, save the received |
| 4381 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 4382 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4383 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4384 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4385 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 4386 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4387 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4388 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4389 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 4390 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4391 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4392 | vport->fc_flag |= FC_RSCN_MODE; |
| 4393 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4394 | if (rscn_cnt) { |
| 4395 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 4396 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 4397 | } |
| 4398 | if ((rscn_cnt) && |
| 4399 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 4400 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4401 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4402 | memcpy(((uint8_t *)cmd) + length, lp, |
| 4403 | payload_len); |
| 4404 | } else { |
| 4405 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 4406 | vport->fc_rscn_id_cnt++; |
| 4407 | /* If we zero, cmdiocb->context2, the calling |
| 4408 | * routine will not try to free it. |
| 4409 | */ |
| 4410 | cmdiocb->context2 = NULL; |
| 4411 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4412 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4413 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4414 | "0235 Deferred RSCN " |
| 4415 | "Data: x%x x%x x%x\n", |
| 4416 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4417 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4418 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4419 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 4420 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4421 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4422 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4423 | "0234 ReDiscovery RSCN " |
| 4424 | "Data: x%x x%x x%x\n", |
| 4425 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4426 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4427 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4428 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4429 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4430 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4431 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4432 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4433 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4434 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4435 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4436 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4437 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4438 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4439 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4440 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 4441 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4442 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4443 | spin_lock_irq(shost->host_lock); |
| 4444 | vport->fc_flag |= FC_RSCN_MODE; |
| 4445 | spin_unlock_irq(shost->host_lock); |
| 4446 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4447 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4448 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4449 | /* |
| 4450 | * If we zero, cmdiocb->context2, the calling routine will |
| 4451 | * not try to free it. |
| 4452 | */ |
| 4453 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4454 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4455 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4456 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4457 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4458 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4459 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4460 | } |
| 4461 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4462 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4463 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4464 | * @vport: pointer to a host virtual N_Port data structure. |
| 4465 | * |
| 4466 | * This routine handles the Registration State Configuration Notification |
| 4467 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 4468 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 4469 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 4470 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 4471 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 4472 | * RSCN activities with the @vport. |
| 4473 | * |
| 4474 | * Return code |
| 4475 | * 0 - Cleaned up rscn on the @vport |
| 4476 | * 1 - Wait for plogi to name server before proceed |
| 4477 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4478 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4479 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4480 | { |
| 4481 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4482 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4483 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4484 | /* Ignore RSCN if the port is being torn down. */ |
| 4485 | if (vport->load_flag & FC_UNLOADING) { |
| 4486 | lpfc_els_flush_rscn(vport); |
| 4487 | return 0; |
| 4488 | } |
| 4489 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4490 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4491 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4492 | |
| 4493 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4494 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4495 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 4496 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 4497 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4498 | |
| 4499 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4500 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4501 | vport->num_disc_nodes = 0; |
| 4502 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4503 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4504 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 4505 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4506 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4507 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4508 | /* Wait for NameServer query cmpl before we can |
| 4509 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4510 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4511 | } else { |
| 4512 | /* If login to NameServer does not exist, issue one */ |
| 4513 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4514 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4515 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4516 | /* Wait for NameServer login cmpl before we can |
| 4517 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4518 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4519 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4520 | if (ndlp) { |
| 4521 | ndlp = lpfc_enable_node(vport, ndlp, |
| 4522 | NLP_STE_PLOGI_ISSUE); |
| 4523 | if (!ndlp) { |
| 4524 | lpfc_els_flush_rscn(vport); |
| 4525 | return 0; |
| 4526 | } |
| 4527 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4528 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4529 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4530 | if (!ndlp) { |
| 4531 | lpfc_els_flush_rscn(vport); |
| 4532 | return 0; |
| 4533 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4534 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4535 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4536 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4537 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4538 | ndlp->nlp_type |= NLP_FABRIC; |
| 4539 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 4540 | /* Wait for NameServer login cmpl before we can |
| 4541 | * continue |
| 4542 | */ |
| 4543 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4544 | } |
| 4545 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4546 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4547 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4548 | } |
| 4549 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4550 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4551 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4552 | * @vport: pointer to a host virtual N_Port data structure. |
| 4553 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4554 | * @ndlp: pointer to a node-list data structure. |
| 4555 | * |
| 4556 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 4557 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 4558 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 4559 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 4560 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 4561 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 4562 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 4563 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 4564 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 4565 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 4566 | * higher priority (as the winning port) and will initiate PLOGI and |
| 4567 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 4568 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 4569 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 4570 | * |
| 4571 | * Return code |
| 4572 | * 0 - Successfully processed the unsolicited flogi |
| 4573 | * 1 - Failed to process the unsolicited flogi |
| 4574 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4575 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4576 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4577 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4578 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4579 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4580 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4581 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4582 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 4583 | IOCB_t *icmd = &cmdiocb->iocb; |
| 4584 | struct serv_parm *sp; |
| 4585 | LPFC_MBOXQ_t *mbox; |
| 4586 | struct ls_rjt stat; |
| 4587 | uint32_t cmd, did; |
| 4588 | int rc; |
| 4589 | |
| 4590 | cmd = *lp++; |
| 4591 | sp = (struct serv_parm *) lp; |
| 4592 | |
| 4593 | /* FLOGI received */ |
| 4594 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4595 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4596 | |
| 4597 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 4598 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 4599 | did = icmd->un.elsreq64.remoteID; |
| 4600 | |
| 4601 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 4602 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4603 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4604 | "0113 An FLOGI ELS command x%x was " |
| 4605 | "received from DID x%x in Loop Mode\n", |
| 4606 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4607 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4608 | } |
| 4609 | |
| 4610 | did = Fabric_DID; |
| 4611 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 4612 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4613 | /* For a FLOGI we accept, then if our portname is greater |
| 4614 | * then the remote portname we initiate Nport login. |
| 4615 | */ |
| 4616 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4617 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4618 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4619 | |
| 4620 | if (!rc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4621 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4622 | if (!mbox) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4623 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4624 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4625 | lpfc_linkdown(phba); |
| 4626 | lpfc_init_link(phba, mbox, |
| 4627 | phba->cfg_topology, |
| 4628 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4629 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4630 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4631 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4632 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4633 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4634 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4635 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4636 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4637 | return 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4638 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4639 | spin_lock_irq(shost->host_lock); |
| 4640 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 4641 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4642 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4643 | spin_lock_irq(shost->host_lock); |
| 4644 | vport->fc_flag |= FC_PT2PT; |
| 4645 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 4646 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4647 | } else { |
| 4648 | /* Reject this request because invalid parameters */ |
| 4649 | stat.un.b.lsRjtRsvd0 = 0; |
| 4650 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4651 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 4652 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4653 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4654 | NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4655 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4656 | } |
| 4657 | |
| 4658 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4659 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4660 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4661 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4662 | } |
| 4663 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4664 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4665 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4666 | * @vport: pointer to a host virtual N_Port data structure. |
| 4667 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4668 | * @ndlp: pointer to a node-list data structure. |
| 4669 | * |
| 4670 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 4671 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 4672 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 4673 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 4674 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 4675 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 4676 | * |
| 4677 | * Return code |
| 4678 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 4679 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4680 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4681 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4682 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4683 | { |
| 4684 | struct lpfc_dmabuf *pcmd; |
| 4685 | uint32_t *lp; |
| 4686 | IOCB_t *icmd; |
| 4687 | RNID *rn; |
| 4688 | struct ls_rjt stat; |
| 4689 | uint32_t cmd, did; |
| 4690 | |
| 4691 | icmd = &cmdiocb->iocb; |
| 4692 | did = icmd->un.elsreq64.remoteID; |
| 4693 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4694 | lp = (uint32_t *) pcmd->virt; |
| 4695 | |
| 4696 | cmd = *lp++; |
| 4697 | rn = (RNID *) lp; |
| 4698 | |
| 4699 | /* RNID received */ |
| 4700 | |
| 4701 | switch (rn->Format) { |
| 4702 | case 0: |
| 4703 | case RNID_TOPOLOGY_DISC: |
| 4704 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4705 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4706 | break; |
| 4707 | default: |
| 4708 | /* Reject this request because format not supported */ |
| 4709 | stat.un.b.lsRjtRsvd0 = 0; |
| 4710 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4711 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4712 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4713 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4714 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4715 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4716 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4717 | } |
| 4718 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4719 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4720 | * lpfc_els_rcv_echo - Process an unsolicited echo iocb |
| 4721 | * @vport: pointer to a host virtual N_Port data structure. |
| 4722 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4723 | * @ndlp: pointer to a node-list data structure. |
| 4724 | * |
| 4725 | * Return code |
| 4726 | * 0 - Successfully processed echo iocb (currently always return 0) |
| 4727 | **/ |
| 4728 | static int |
| 4729 | lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4730 | struct lpfc_nodelist *ndlp) |
| 4731 | { |
| 4732 | uint8_t *pcmd; |
| 4733 | |
| 4734 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
| 4735 | |
| 4736 | /* skip over first word of echo command to find echo data */ |
| 4737 | pcmd += sizeof(uint32_t); |
| 4738 | |
| 4739 | lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp); |
| 4740 | return 0; |
| 4741 | } |
| 4742 | |
| 4743 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4744 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4745 | * @vport: pointer to a host virtual N_Port data structure. |
| 4746 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4747 | * @ndlp: pointer to a node-list data structure. |
| 4748 | * |
| 4749 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 4750 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 4751 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 4752 | * |
| 4753 | * Return code |
| 4754 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 4755 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4756 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4757 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4758 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4759 | { |
| 4760 | struct ls_rjt stat; |
| 4761 | |
| 4762 | /* For now, unconditionally reject this command */ |
| 4763 | stat.un.b.lsRjtRsvd0 = 0; |
| 4764 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4765 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4766 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4767 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4768 | return 0; |
| 4769 | } |
| 4770 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4771 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4772 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb |
| 4773 | * @vport: pointer to a host virtual N_Port data structure. |
| 4774 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4775 | * @ndlp: pointer to a node-list data structure. |
| 4776 | * |
| 4777 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB |
| 4778 | * received as an ELS unsolicited event. A request to RRQ shall only |
| 4779 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder |
| 4780 | * Nx_Port N_Port_ID of the target Exchange is the same as the |
| 4781 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is |
| 4782 | * not accepted, an LS_RJT with reason code "Unable to perform |
| 4783 | * command request" and reason code explanation "Invalid Originator |
| 4784 | * S_ID" shall be returned. For now, we just unconditionally accept |
| 4785 | * RRQ from the target. |
| 4786 | **/ |
| 4787 | static void |
| 4788 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4789 | struct lpfc_nodelist *ndlp) |
| 4790 | { |
| 4791 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| 4792 | } |
| 4793 | |
| 4794 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4795 | * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd |
| 4796 | * @phba: pointer to lpfc hba data structure. |
| 4797 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4798 | * |
| 4799 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 4800 | * mailbox command. This callback function is to actually send the Accept |
| 4801 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 4802 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 4803 | * mailbox command, constructs the RPS response with the link statistics |
| 4804 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 4805 | * response to the RPS. |
| 4806 | * |
| 4807 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4808 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4809 | * will be stored into the context1 field of the IOCB for the completion |
| 4810 | * callback function to the RPS Accept Response ELS IOCB command. |
| 4811 | * |
| 4812 | **/ |
| 4813 | static void |
| 4814 | lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 4815 | { |
| 4816 | MAILBOX_t *mb; |
| 4817 | IOCB_t *icmd; |
| 4818 | struct RLS_RSP *rls_rsp; |
| 4819 | uint8_t *pcmd; |
| 4820 | struct lpfc_iocbq *elsiocb; |
| 4821 | struct lpfc_nodelist *ndlp; |
| 4822 | uint16_t xri; |
| 4823 | uint32_t cmdsize; |
| 4824 | |
| 4825 | mb = &pmb->u.mb; |
| 4826 | |
| 4827 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4828 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
| 4829 | pmb->context1 = NULL; |
| 4830 | pmb->context2 = NULL; |
| 4831 | |
| 4832 | if (mb->mbxStatus) { |
| 4833 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4834 | return; |
| 4835 | } |
| 4836 | |
| 4837 | cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t); |
| 4838 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4839 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 4840 | lpfc_max_els_tries, ndlp, |
| 4841 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 4842 | |
| 4843 | /* Decrement the ndlp reference count from previous mbox command */ |
| 4844 | lpfc_nlp_put(ndlp); |
| 4845 | |
| 4846 | if (!elsiocb) |
| 4847 | return; |
| 4848 | |
| 4849 | icmd = &elsiocb->iocb; |
| 4850 | icmd->ulpContext = xri; |
| 4851 | |
| 4852 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4853 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 4854 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 4855 | rls_rsp = (struct RLS_RSP *)pcmd; |
| 4856 | |
| 4857 | rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 4858 | rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 4859 | rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 4860 | rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 4861 | rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 4862 | rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
| 4863 | |
| 4864 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 4865 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 4866 | "2874 Xmit ELS RLS ACC response tag x%x xri x%x, " |
| 4867 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4868 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4869 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4870 | ndlp->nlp_rpi); |
| 4871 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 4872 | phba->fc_stat.elsXmitACC++; |
| 4873 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 4874 | lpfc_els_free_iocb(phba, elsiocb); |
| 4875 | } |
| 4876 | |
| 4877 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4878 | * 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] | 4879 | * @phba: pointer to lpfc hba data structure. |
| 4880 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4881 | * |
| 4882 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 4883 | * mailbox command. This callback function is to actually send the Accept |
| 4884 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 4885 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 4886 | * mailbox command, constructs the RPS response with the link statistics |
| 4887 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 4888 | * response to the RPS. |
| 4889 | * |
| 4890 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4891 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4892 | * will be stored into the context1 field of the IOCB for the completion |
| 4893 | * callback function to the RPS Accept Response ELS IOCB command. |
| 4894 | * |
| 4895 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4896 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4897 | 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] | 4898 | { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4899 | MAILBOX_t *mb; |
| 4900 | IOCB_t *icmd; |
| 4901 | RPS_RSP *rps_rsp; |
| 4902 | uint8_t *pcmd; |
| 4903 | struct lpfc_iocbq *elsiocb; |
| 4904 | struct lpfc_nodelist *ndlp; |
| 4905 | uint16_t xri, status; |
| 4906 | uint32_t cmdsize; |
| 4907 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4908 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4909 | |
| 4910 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4911 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 4912 | pmb->context1 = NULL; |
| 4913 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4914 | |
| 4915 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4916 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4917 | return; |
| 4918 | } |
| 4919 | |
| 4920 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4921 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4922 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 4923 | lpfc_max_els_tries, ndlp, |
| 4924 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4925 | |
| 4926 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4927 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4928 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4929 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4930 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4931 | |
| 4932 | icmd = &elsiocb->iocb; |
| 4933 | icmd->ulpContext = xri; |
| 4934 | |
| 4935 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4936 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4937 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4938 | rps_rsp = (RPS_RSP *)pcmd; |
| 4939 | |
| 4940 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| 4941 | status = 0x10; |
| 4942 | else |
| 4943 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4944 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4945 | status |= 0x4; |
| 4946 | |
| 4947 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4948 | rps_rsp->portStatus = cpu_to_be16(status); |
| 4949 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 4950 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 4951 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 4952 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 4953 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 4954 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4955 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4956 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 4957 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 4958 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4959 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4960 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4961 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4962 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4963 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4964 | 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] | 4965 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4966 | return; |
| 4967 | } |
| 4968 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4969 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4970 | * lpfc_els_rcv_rls - Process an unsolicited rls iocb |
| 4971 | * @vport: pointer to a host virtual N_Port data structure. |
| 4972 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4973 | * @ndlp: pointer to a node-list data structure. |
| 4974 | * |
| 4975 | * This routine processes Read Port Status (RPL) IOCB received as an |
| 4976 | * ELS unsolicited event. It first checks the remote port state. If the |
| 4977 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 4978 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 4979 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 4980 | * for reading the HBA link statistics. It is for the callback function, |
| 4981 | * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 4982 | * to actually sending out RPL Accept (ACC) response. |
| 4983 | * |
| 4984 | * Return codes |
| 4985 | * 0 - Successfully processed rls iocb (currently always return 0) |
| 4986 | **/ |
| 4987 | static int |
| 4988 | lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4989 | struct lpfc_nodelist *ndlp) |
| 4990 | { |
| 4991 | struct lpfc_hba *phba = vport->phba; |
| 4992 | LPFC_MBOXQ_t *mbox; |
| 4993 | struct lpfc_dmabuf *pcmd; |
| 4994 | struct ls_rjt stat; |
| 4995 | |
| 4996 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 4997 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 4998 | /* reject the unsolicited RPS request and done with it */ |
| 4999 | goto reject_out; |
| 5000 | |
| 5001 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5002 | |
| 5003 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 5004 | if (mbox) { |
| 5005 | lpfc_read_lnk_stat(phba, mbox); |
| 5006 | mbox->context1 = |
| 5007 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
| 5008 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 5009 | mbox->vport = vport; |
| 5010 | mbox->mbox_cmpl = lpfc_els_rsp_rls_acc; |
| 5011 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
| 5012 | != MBX_NOT_FINISHED) |
| 5013 | /* Mbox completion will send ELS Response */ |
| 5014 | return 0; |
| 5015 | /* Decrement reference count used for the failed mbox |
| 5016 | * command. |
| 5017 | */ |
| 5018 | lpfc_nlp_put(ndlp); |
| 5019 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5020 | } |
| 5021 | reject_out: |
| 5022 | /* issue rejection response */ |
| 5023 | stat.un.b.lsRjtRsvd0 = 0; |
| 5024 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5025 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5026 | stat.un.b.vendorUnique = 0; |
| 5027 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5028 | return 0; |
| 5029 | } |
| 5030 | |
| 5031 | /** |
| 5032 | * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb |
| 5033 | * @vport: pointer to a host virtual N_Port data structure. |
| 5034 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5035 | * @ndlp: pointer to a node-list data structure. |
| 5036 | * |
| 5037 | * This routine processes Read Timout Value (RTV) IOCB received as an |
| 5038 | * ELS unsolicited event. It first checks the remote port state. If the |
| 5039 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 5040 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 5041 | * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout |
| 5042 | * Value (RTV) unsolicited IOCB event. |
| 5043 | * |
| 5044 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5045 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5046 | * will be stored into the context1 field of the IOCB for the completion |
| 5047 | * callback function to the RPS Accept Response ELS IOCB command. |
| 5048 | * |
| 5049 | * Return codes |
| 5050 | * 0 - Successfully processed rtv iocb (currently always return 0) |
| 5051 | **/ |
| 5052 | static int |
| 5053 | lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5054 | struct lpfc_nodelist *ndlp) |
| 5055 | { |
| 5056 | struct lpfc_hba *phba = vport->phba; |
| 5057 | struct ls_rjt stat; |
| 5058 | struct RTV_RSP *rtv_rsp; |
| 5059 | uint8_t *pcmd; |
| 5060 | struct lpfc_iocbq *elsiocb; |
| 5061 | uint32_t cmdsize; |
| 5062 | |
| 5063 | |
| 5064 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 5065 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5066 | /* reject the unsolicited RPS request and done with it */ |
| 5067 | goto reject_out; |
| 5068 | |
| 5069 | cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t); |
| 5070 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5071 | lpfc_max_els_tries, ndlp, |
| 5072 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 5073 | |
| 5074 | if (!elsiocb) |
| 5075 | return 1; |
| 5076 | |
| 5077 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5078 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 5079 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 5080 | |
| 5081 | /* use the command's xri in the response */ |
| 5082 | elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; |
| 5083 | |
| 5084 | rtv_rsp = (struct RTV_RSP *)pcmd; |
| 5085 | |
| 5086 | /* populate RTV payload */ |
| 5087 | rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */ |
| 5088 | rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov); |
| 5089 | bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0); |
| 5090 | bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */ |
| 5091 | rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov); |
| 5092 | |
| 5093 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 5094 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 5095 | "2875 Xmit ELS RTV ACC response tag x%x xri x%x, " |
| 5096 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, " |
| 5097 | "Data: x%x x%x x%x\n", |
| 5098 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5099 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5100 | ndlp->nlp_rpi, |
| 5101 | rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov); |
| 5102 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5103 | phba->fc_stat.elsXmitACC++; |
| 5104 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 5105 | lpfc_els_free_iocb(phba, elsiocb); |
| 5106 | return 0; |
| 5107 | |
| 5108 | reject_out: |
| 5109 | /* issue rejection response */ |
| 5110 | stat.un.b.lsRjtRsvd0 = 0; |
| 5111 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5112 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5113 | stat.un.b.vendorUnique = 0; |
| 5114 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5115 | return 0; |
| 5116 | } |
| 5117 | |
| 5118 | /* lpfc_els_rcv_rps - Process an unsolicited rps iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5119 | * @vport: pointer to a host virtual N_Port data structure. |
| 5120 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5121 | * @ndlp: pointer to a node-list data structure. |
| 5122 | * |
| 5123 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 5124 | * ELS unsolicited event. It first checks the remote port state. If the |
| 5125 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 5126 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 5127 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 5128 | * for reading the HBA link statistics. It is for the callback function, |
| 5129 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 5130 | * to actually sending out RPS Accept (ACC) response. |
| 5131 | * |
| 5132 | * Return codes |
| 5133 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 5134 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5135 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5136 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5137 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5138 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5139 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5140 | uint32_t *lp; |
| 5141 | uint8_t flag; |
| 5142 | LPFC_MBOXQ_t *mbox; |
| 5143 | struct lpfc_dmabuf *pcmd; |
| 5144 | RPS *rps; |
| 5145 | struct ls_rjt stat; |
| 5146 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5147 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5148 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5149 | /* reject the unsolicited RPS request and done with it */ |
| 5150 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5151 | |
| 5152 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5153 | lp = (uint32_t *) pcmd->virt; |
| 5154 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 5155 | rps = (RPS *) lp; |
| 5156 | |
| 5157 | if ((flag == 0) || |
| 5158 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5159 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5160 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5161 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5162 | printk("Fix me....\n"); |
| 5163 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5164 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 5165 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5166 | lpfc_read_lnk_stat(phba, mbox); |
| 5167 | mbox->context1 = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5168 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5169 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5170 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5171 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5172 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5173 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5174 | /* Mbox completion will send ELS Response */ |
| 5175 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5176 | /* Decrement reference count used for the failed mbox |
| 5177 | * command. |
| 5178 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5179 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5180 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5181 | } |
| 5182 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5183 | |
| 5184 | reject_out: |
| 5185 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5186 | stat.un.b.lsRjtRsvd0 = 0; |
| 5187 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5188 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5189 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5190 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5191 | return 0; |
| 5192 | } |
| 5193 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5194 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5195 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5196 | * @vport: pointer to a host virtual N_Port data structure. |
| 5197 | * @cmdsize: size of the ELS command. |
| 5198 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 5199 | * @ndlp: pointer to a node-list data structure. |
| 5200 | * |
| 5201 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 5202 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 5203 | * |
| 5204 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5205 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5206 | * will be stored into the context1 field of the IOCB for the completion |
| 5207 | * callback function to the RPL Accept Response ELS command. |
| 5208 | * |
| 5209 | * Return code |
| 5210 | * 0 - Successfully issued ACC RPL ELS command |
| 5211 | * 1 - Failed to issue ACC RPL ELS command |
| 5212 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 5213 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5214 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 5215 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5216 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5217 | struct lpfc_hba *phba = vport->phba; |
| 5218 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5219 | RPL_RSP rpl_rsp; |
| 5220 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5221 | uint8_t *pcmd; |
| 5222 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5223 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 5224 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5225 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5226 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5227 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5228 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5229 | icmd = &elsiocb->iocb; |
| 5230 | oldcmd = &oldiocb->iocb; |
| 5231 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 5232 | |
| 5233 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5234 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5235 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5236 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 5237 | pcmd += sizeof(uint16_t); |
| 5238 | |
| 5239 | /* Setup the RPL ACC payload */ |
| 5240 | rpl_rsp.listLen = be32_to_cpu(1); |
| 5241 | rpl_rsp.index = 0; |
| 5242 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5243 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 5244 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5245 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5246 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5247 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5248 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5249 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 5250 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 5251 | "rpi x%x\n", |
| 5252 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5253 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5254 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5255 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5256 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5257 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 5258 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5259 | lpfc_els_free_iocb(phba, elsiocb); |
| 5260 | return 1; |
| 5261 | } |
| 5262 | return 0; |
| 5263 | } |
| 5264 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5265 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5266 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5267 | * @vport: pointer to a host virtual N_Port data structure. |
| 5268 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5269 | * @ndlp: pointer to a node-list data structure. |
| 5270 | * |
| 5271 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 5272 | * unsolicited event. It first checks the remote port state. If the remote |
| 5273 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 5274 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 5275 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 5276 | * to accept the RPL. |
| 5277 | * |
| 5278 | * Return code |
| 5279 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 5280 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5281 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5282 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5283 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5284 | { |
| 5285 | struct lpfc_dmabuf *pcmd; |
| 5286 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5287 | uint32_t maxsize; |
| 5288 | uint16_t cmdsize; |
| 5289 | RPL *rpl; |
| 5290 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5291 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5292 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 5293 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5294 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5295 | stat.un.b.lsRjtRsvd0 = 0; |
| 5296 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5297 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5298 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5299 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 5300 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5301 | /* rejected the unsolicited RPL request and done with it */ |
| 5302 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5303 | } |
| 5304 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5305 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5306 | lp = (uint32_t *) pcmd->virt; |
| 5307 | rpl = (RPL *) (lp + 1); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5308 | maxsize = be32_to_cpu(rpl->maxsize); |
| 5309 | |
| 5310 | /* We support only one port */ |
| 5311 | if ((rpl->index == 0) && |
| 5312 | ((maxsize == 0) || |
| 5313 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 5314 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5315 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5316 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 5317 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5318 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5319 | |
| 5320 | return 0; |
| 5321 | } |
| 5322 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5323 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5324 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5325 | * @vport: pointer to a virtual N_Port data structure. |
| 5326 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5327 | * @ndlp: pointer to a node-list data structure. |
| 5328 | * |
| 5329 | * This routine processes Fibre Channel Address Resolution Protocol |
| 5330 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 5331 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 5332 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 5333 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 5334 | * remote PortName is compared against the FC PortName stored in the @vport |
| 5335 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 5336 | * compared against the FC NodeName stored in the @vport data structure. |
| 5337 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 5338 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 5339 | * invoked to send out FARP Response to the remote node. Before sending the |
| 5340 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 5341 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 5342 | * routine is invoked to log into the remote port first. |
| 5343 | * |
| 5344 | * Return code |
| 5345 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 5346 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5347 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5348 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5349 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5350 | { |
| 5351 | struct lpfc_dmabuf *pcmd; |
| 5352 | uint32_t *lp; |
| 5353 | IOCB_t *icmd; |
| 5354 | FARP *fp; |
| 5355 | uint32_t cmd, cnt, did; |
| 5356 | |
| 5357 | icmd = &cmdiocb->iocb; |
| 5358 | did = icmd->un.elsreq64.remoteID; |
| 5359 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5360 | lp = (uint32_t *) pcmd->virt; |
| 5361 | |
| 5362 | cmd = *lp++; |
| 5363 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5364 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5365 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5366 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5367 | /* We will only support match on WWPN or WWNN */ |
| 5368 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5369 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5370 | } |
| 5371 | |
| 5372 | cnt = 0; |
| 5373 | /* If this FARP command is searching for my portname */ |
| 5374 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5375 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5376 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5377 | cnt = 1; |
| 5378 | } |
| 5379 | |
| 5380 | /* If this FARP command is searching for my nodename */ |
| 5381 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5382 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5383 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5384 | cnt = 1; |
| 5385 | } |
| 5386 | |
| 5387 | if (cnt) { |
| 5388 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 5389 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 5390 | /* Log back into the node before sending the FARP. */ |
| 5391 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5392 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5393 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 5394 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5395 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5396 | } |
| 5397 | |
| 5398 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5399 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 5400 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5401 | } |
| 5402 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5403 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5404 | } |
| 5405 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5406 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5407 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5408 | * @vport: pointer to a host virtual N_Port data structure. |
| 5409 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5410 | * @ndlp: pointer to a node-list data structure. |
| 5411 | * |
| 5412 | * This routine processes Fibre Channel Address Resolution Protocol |
| 5413 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 5414 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 5415 | * the FARP response request. |
| 5416 | * |
| 5417 | * Return code |
| 5418 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 5419 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5420 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5421 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5422 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5423 | { |
| 5424 | struct lpfc_dmabuf *pcmd; |
| 5425 | uint32_t *lp; |
| 5426 | IOCB_t *icmd; |
| 5427 | uint32_t cmd, did; |
| 5428 | |
| 5429 | icmd = &cmdiocb->iocb; |
| 5430 | did = icmd->un.elsreq64.remoteID; |
| 5431 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5432 | lp = (uint32_t *) pcmd->virt; |
| 5433 | |
| 5434 | cmd = *lp++; |
| 5435 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5436 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5437 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5438 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5439 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5440 | |
| 5441 | return 0; |
| 5442 | } |
| 5443 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5444 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5445 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5446 | * @vport: pointer to a host virtual N_Port data structure. |
| 5447 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5448 | * @fan_ndlp: pointer to a node-list data structure. |
| 5449 | * |
| 5450 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 5451 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 5452 | * only be processed on a physical port (i.e., the @vport represents the |
| 5453 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 5454 | * compared against those in the phba data structure. If any of those is |
| 5455 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 5456 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 5457 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 5458 | * is invoked to register login to the fabric. |
| 5459 | * |
| 5460 | * Return code |
| 5461 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 5462 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5463 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5464 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5465 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5466 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5467 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5468 | uint32_t *lp; |
| 5469 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5470 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5471 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 5472 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 5473 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5474 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5475 | if ((vport == phba->pport) && |
| 5476 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5477 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5478 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5479 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5480 | sizeof(struct lpfc_name)))) { |
| 5481 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5482 | lpfc_initial_flogi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5483 | } else { |
| 5484 | /* FAN verified - skip FLOGI */ |
| 5485 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5486 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5487 | lpfc_issue_fabric_reglogin(vport); |
| 5488 | else |
| 5489 | lpfc_issue_reg_vfi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5490 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5491 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5492 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5493 | } |
| 5494 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5495 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5496 | * lpfc_els_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5497 | * @ptr: holder for the timer function associated data. |
| 5498 | * |
| 5499 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 5500 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 5501 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 5502 | * up the worker thread. It is for the worker thread to invoke the routine |
| 5503 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 5504 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5505 | void |
| 5506 | lpfc_els_timeout(unsigned long ptr) |
| 5507 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5508 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 5509 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5510 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5511 | unsigned long iflag; |
| 5512 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5513 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5514 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
| 5515 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5516 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5517 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5518 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5519 | if (!tmo_posted) |
| 5520 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5521 | return; |
| 5522 | } |
| 5523 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5524 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5525 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5526 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5527 | * @vport: pointer to a virtual N_Port data structure. |
| 5528 | * |
| 5529 | * This routine is the actual handler function that processes an ELS timeout |
| 5530 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 5531 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 5532 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5533 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5534 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5535 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5536 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5537 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5538 | struct lpfc_sli_ring *pring; |
| 5539 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5540 | IOCB_t *cmd = NULL; |
| 5541 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5542 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5543 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5544 | uint32_t remote_ID = 0xffffffff; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5545 | LIST_HEAD(txcmplq_completions); |
| 5546 | LIST_HEAD(abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5547 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5548 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5549 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 5550 | |
| 5551 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5552 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5553 | spin_lock_irq(&phba->hbalock); |
| 5554 | list_splice_init(&pring->txcmplq, &txcmplq_completions); |
| 5555 | spin_unlock_irq(&phba->hbalock); |
| 5556 | |
| 5557 | list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5558 | cmd = &piocb->iocb; |
| 5559 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5560 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 5561 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 5562 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5563 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5564 | |
| 5565 | if (piocb->vport != vport) |
| 5566 | continue; |
| 5567 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5568 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5569 | if (pcmd) |
| 5570 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5571 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5572 | if (els_command == ELS_CMD_FARP || |
| 5573 | els_command == ELS_CMD_FARPR || |
| 5574 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5575 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5576 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5577 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5578 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5579 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5580 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5581 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5582 | continue; |
| 5583 | } |
| 5584 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5585 | remote_ID = 0xffffffff; |
| 5586 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5587 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5588 | else { |
| 5589 | struct lpfc_nodelist *ndlp; |
| 5590 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5591 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5592 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5593 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5594 | list_add_tail(&piocb->dlist, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5595 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5596 | spin_lock_irq(&phba->hbalock); |
| 5597 | list_splice(&txcmplq_completions, &pring->txcmplq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5598 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 5599 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5600 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
| 5601 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5602 | "0127 ELS timeout Data: x%x x%x x%x " |
| 5603 | "x%x\n", els_command, |
| 5604 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
| 5605 | spin_lock_irq(&phba->hbalock); |
| 5606 | list_del_init(&piocb->dlist); |
| 5607 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5608 | spin_unlock_irq(&phba->hbalock); |
| 5609 | } |
| 5610 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5611 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
| 5612 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5613 | } |
| 5614 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5615 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5616 | * 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] | 5617 | * @vport: pointer to a host virtual N_Port data structure. |
| 5618 | * |
| 5619 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5620 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 5621 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5622 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5623 | * the IOCBs with a non-NULL completion callback function, the callback |
| 5624 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5625 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 5626 | * callback function, the IOCB will simply be released. Finally, it walks |
| 5627 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 5628 | * completion queue IOCB that is associated with the @vport and is not |
| 5629 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 5630 | * part of the discovery state machine) out to HBA by invoking the |
| 5631 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 5632 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 5633 | * the IOCBs are aborted when this function returns. |
| 5634 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5635 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5636 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5637 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5638 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5639 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5640 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5641 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5642 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5643 | |
| 5644 | lpfc_fabric_abort_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5645 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5646 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5647 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5648 | cmd = &piocb->iocb; |
| 5649 | |
| 5650 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5651 | continue; |
| 5652 | } |
| 5653 | |
| 5654 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5655 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5656 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5657 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5658 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5659 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5660 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5661 | if (piocb->vport != vport) |
| 5662 | continue; |
| 5663 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5664 | list_move_tail(&piocb->list, &completions); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5665 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5666 | } |
| 5667 | |
| 5668 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5669 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5670 | continue; |
| 5671 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5672 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5673 | if (piocb->vport != vport) |
| 5674 | continue; |
| 5675 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5676 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5677 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5678 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5679 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5680 | /* Cancell all the IOCBs from the completions list */ |
| 5681 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5682 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5683 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5684 | return; |
| 5685 | } |
| 5686 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5687 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5688 | * 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] | 5689 | * @phba: pointer to lpfc hba data structure. |
| 5690 | * |
| 5691 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5692 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 5693 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5694 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5695 | * the IOCBs with the completion callback function associated, the callback |
| 5696 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5697 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 5698 | * callback function associated, the IOCB will simply be released. Finally, |
| 5699 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 5700 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 5701 | * management plane IOCBs that are not part of the discovery state machine) |
| 5702 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5703 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5704 | void |
| 5705 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 5706 | { |
| 5707 | LIST_HEAD(completions); |
| 5708 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 5709 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5710 | IOCB_t *cmd = NULL; |
| 5711 | |
| 5712 | lpfc_fabric_abort_hba(phba); |
| 5713 | spin_lock_irq(&phba->hbalock); |
| 5714 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5715 | cmd = &piocb->iocb; |
| 5716 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5717 | continue; |
| 5718 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
| 5719 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5720 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5721 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5722 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| 5723 | continue; |
| 5724 | list_move_tail(&piocb->list, &completions); |
| 5725 | pring->txq_cnt--; |
| 5726 | } |
| 5727 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5728 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5729 | continue; |
| 5730 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5731 | } |
| 5732 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5733 | |
| 5734 | /* Cancel all the IOCBs from the completions list */ |
| 5735 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5736 | IOERR_SLI_ABORTED); |
| 5737 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5738 | return; |
| 5739 | } |
| 5740 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5741 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5742 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5743 | * @phba: Pointer to hba context object. |
| 5744 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 5745 | * @rspiocbp: Pointer to response iocb which reported error. |
| 5746 | * |
| 5747 | * This function sends an event when there is an ELS command |
| 5748 | * failure. |
| 5749 | **/ |
| 5750 | void |
| 5751 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 5752 | struct lpfc_iocbq *cmdiocbp, |
| 5753 | struct lpfc_iocbq *rspiocbp) |
| 5754 | { |
| 5755 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 5756 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5757 | struct lpfc_lsrjt_event lsrjt_event; |
| 5758 | struct lpfc_fabric_event_header fabric_event; |
| 5759 | struct ls_rjt stat; |
| 5760 | struct lpfc_nodelist *ndlp; |
| 5761 | uint32_t *pcmd; |
| 5762 | |
| 5763 | ndlp = cmdiocbp->context1; |
| 5764 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 5765 | return; |
| 5766 | |
| 5767 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 5768 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 5769 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 5770 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 5771 | sizeof(struct lpfc_name)); |
| 5772 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 5773 | sizeof(struct lpfc_name)); |
| 5774 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 5775 | cmdiocbp->context2)->virt); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 5776 | lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5777 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 5778 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 5779 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 5780 | fc_host_post_vendor_event(shost, |
| 5781 | fc_get_event_number(), |
| 5782 | sizeof(lsrjt_event), |
| 5783 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5784 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5785 | return; |
| 5786 | } |
| 5787 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 5788 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 5789 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 5790 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 5791 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 5792 | else |
| 5793 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 5794 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 5795 | sizeof(struct lpfc_name)); |
| 5796 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 5797 | sizeof(struct lpfc_name)); |
| 5798 | fc_host_post_vendor_event(shost, |
| 5799 | fc_get_event_number(), |
| 5800 | sizeof(fabric_event), |
| 5801 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5802 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5803 | return; |
| 5804 | } |
| 5805 | |
| 5806 | } |
| 5807 | |
| 5808 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5809 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5810 | * @vport: Pointer to vport object. |
| 5811 | * @ndlp: Pointer FC node object. |
| 5812 | * @cmd: ELS command code. |
| 5813 | * |
| 5814 | * This function posts an event when there is an incoming |
| 5815 | * unsolicited ELS command. |
| 5816 | **/ |
| 5817 | static void |
| 5818 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 5819 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5820 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5821 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5822 | struct lpfc_els_event_header *els_data = NULL; |
| 5823 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5824 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5825 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5826 | if (*payload == ELS_CMD_LOGO) { |
| 5827 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 5828 | if (!logo_data) { |
| 5829 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5830 | "0148 Failed to allocate memory " |
| 5831 | "for LOGO event\n"); |
| 5832 | return; |
| 5833 | } |
| 5834 | els_data = &logo_data->header; |
| 5835 | } else { |
| 5836 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 5837 | GFP_KERNEL); |
| 5838 | if (!els_data) { |
| 5839 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5840 | "0149 Failed to allocate memory " |
| 5841 | "for ELS event\n"); |
| 5842 | return; |
| 5843 | } |
| 5844 | } |
| 5845 | els_data->event_type = FC_REG_ELS_EVENT; |
| 5846 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5847 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5848 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5849 | break; |
| 5850 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5851 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5852 | break; |
| 5853 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5854 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 5855 | break; |
| 5856 | case ELS_CMD_LOGO: |
| 5857 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 5858 | /* Copy the WWPN in the LOGO payload */ |
| 5859 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 5860 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5861 | break; |
| 5862 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 5863 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5864 | return; |
| 5865 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5866 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 5867 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 5868 | if (*payload == ELS_CMD_LOGO) { |
| 5869 | fc_host_post_vendor_event(shost, |
| 5870 | fc_get_event_number(), |
| 5871 | sizeof(struct lpfc_logo_event), |
| 5872 | (char *)logo_data, |
| 5873 | LPFC_NL_VENDOR_ID); |
| 5874 | kfree(logo_data); |
| 5875 | } else { |
| 5876 | fc_host_post_vendor_event(shost, |
| 5877 | fc_get_event_number(), |
| 5878 | sizeof(struct lpfc_els_event_header), |
| 5879 | (char *)els_data, |
| 5880 | LPFC_NL_VENDOR_ID); |
| 5881 | kfree(els_data); |
| 5882 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5883 | |
| 5884 | return; |
| 5885 | } |
| 5886 | |
| 5887 | |
| 5888 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5889 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5890 | * @phba: pointer to lpfc hba data structure. |
| 5891 | * @pring: pointer to a SLI ring. |
| 5892 | * @vport: pointer to a host virtual N_Port data structure. |
| 5893 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 5894 | * |
| 5895 | * This routine is used for processing the IOCB associated with a unsolicited |
| 5896 | * event. It first determines whether there is an existing ndlp that matches |
| 5897 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 5898 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 5899 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 5900 | * of the discovery state machine. |
| 5901 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5902 | static void |
| 5903 | 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] | 5904 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5905 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5906 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5907 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5908 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5909 | uint32_t *payload; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5910 | uint32_t cmd, did, newnode, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5911 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5912 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5913 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5914 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5915 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5916 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5917 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 5918 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5919 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5920 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5921 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5922 | did = icmd->un.rcvels.remoteID; |
| 5923 | if (icmd->ulpStatus) { |
| 5924 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5925 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 5926 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5927 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5928 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5929 | |
| 5930 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5931 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5932 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5933 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 5934 | /* Ignore traffic received during vport shutdown. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5935 | if (vport->load_flag & FC_UNLOADING) |
| 5936 | goto dropit; |
| 5937 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5938 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5939 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5940 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5941 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5942 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5943 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5944 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5945 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5946 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5947 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5948 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5949 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5950 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5951 | ndlp = lpfc_enable_node(vport, ndlp, |
| 5952 | NLP_STE_UNUSED_NODE); |
| 5953 | if (!ndlp) |
| 5954 | goto dropit; |
| 5955 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5956 | newnode = 1; |
| 5957 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 5958 | ndlp->nlp_type |= NLP_FABRIC; |
| 5959 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 5960 | /* This is similar to the new node path */ |
| 5961 | ndlp = lpfc_nlp_get(ndlp); |
| 5962 | if (!ndlp) |
| 5963 | goto dropit; |
| 5964 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5965 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5966 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5967 | |
| 5968 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5969 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5970 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5971 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5972 | |
| 5973 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 5974 | cmd &= ELS_CMD_MASK; |
| 5975 | } |
| 5976 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5977 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5978 | "0112 ELS command x%x received from NPORT x%x " |
| 5979 | "Data: x%x\n", cmd, did, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5980 | switch (cmd) { |
| 5981 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5982 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5983 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 5984 | did, vport->port_state, ndlp->nlp_flag); |
| 5985 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5986 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5987 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
| 5988 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5989 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5990 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5991 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 5992 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 5993 | rjt_err = LSRJT_UNABLE_TPC; |
| 5994 | break; |
| 5995 | } |
| 5996 | /* We get here, and drop thru, if we are PT2PT with |
| 5997 | * another NPort and the other side has initiated |
| 5998 | * the PLOGI before responding to our FLOGI. |
| 5999 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6000 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6001 | |
| 6002 | shost = lpfc_shost_from_vport(vport); |
| 6003 | spin_lock_irq(shost->host_lock); |
| 6004 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 6005 | spin_unlock_irq(shost->host_lock); |
| 6006 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6007 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 6008 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6009 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6010 | break; |
| 6011 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6012 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6013 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 6014 | did, vport->port_state, ndlp->nlp_flag); |
| 6015 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6016 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6017 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6018 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6019 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6020 | break; |
| 6021 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6022 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6023 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 6024 | did, vport->port_state, ndlp->nlp_flag); |
| 6025 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6026 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6027 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6028 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6029 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6030 | break; |
| 6031 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6032 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6033 | break; |
| 6034 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6035 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6036 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 6037 | did, vport->port_state, ndlp->nlp_flag); |
| 6038 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6039 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6040 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6041 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6042 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6043 | break; |
| 6044 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6045 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6046 | break; |
| 6047 | case ELS_CMD_RSCN: |
| 6048 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6049 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6050 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6051 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6052 | break; |
| 6053 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6054 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6055 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 6056 | did, vport->port_state, ndlp->nlp_flag); |
| 6057 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6058 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6059 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6060 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6061 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6062 | break; |
| 6063 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6064 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 6065 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6066 | break; |
| 6067 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6068 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6069 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 6070 | did, vport->port_state, ndlp->nlp_flag); |
| 6071 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6072 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6073 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6074 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6075 | break; |
| 6076 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6077 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 6078 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6079 | break; |
| 6080 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6081 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6082 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 6083 | did, vport->port_state, ndlp->nlp_flag); |
| 6084 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6085 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6086 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6087 | break; |
| 6088 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6089 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6090 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 6091 | did, vport->port_state, ndlp->nlp_flag); |
| 6092 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6093 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6094 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6095 | break; |
| 6096 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6097 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6098 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 6099 | did, vport->port_state, ndlp->nlp_flag); |
| 6100 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6101 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6102 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6103 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6104 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6105 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6106 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 6107 | did, vport->port_state, ndlp->nlp_flag); |
| 6108 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6109 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6110 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6111 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6112 | break; |
| 6113 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6114 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6115 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6116 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6117 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6118 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 6119 | did, vport->port_state, ndlp->nlp_flag); |
| 6120 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6121 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6122 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6123 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6124 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6125 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6126 | case ELS_CMD_RLS: |
| 6127 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6128 | "RCV RLS: did:x%x/ste:x%x flg:x%x", |
| 6129 | did, vport->port_state, ndlp->nlp_flag); |
| 6130 | |
| 6131 | phba->fc_stat.elsRcvRLS++; |
| 6132 | lpfc_els_rcv_rls(vport, elsiocb, ndlp); |
| 6133 | if (newnode) |
| 6134 | lpfc_nlp_put(ndlp); |
| 6135 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6136 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6137 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6138 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 6139 | did, vport->port_state, ndlp->nlp_flag); |
| 6140 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6141 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6142 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6143 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6144 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6145 | break; |
| 6146 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6147 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6148 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 6149 | did, vport->port_state, ndlp->nlp_flag); |
| 6150 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6151 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6152 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6153 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6154 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6155 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6156 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6157 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6158 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 6159 | did, vport->port_state, ndlp->nlp_flag); |
| 6160 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6161 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6162 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6163 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6164 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6165 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6166 | case ELS_CMD_RTV: |
| 6167 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6168 | "RCV RTV: did:x%x/ste:x%x flg:x%x", |
| 6169 | did, vport->port_state, ndlp->nlp_flag); |
| 6170 | phba->fc_stat.elsRcvRTV++; |
| 6171 | lpfc_els_rcv_rtv(vport, elsiocb, ndlp); |
| 6172 | if (newnode) |
| 6173 | lpfc_nlp_put(ndlp); |
| 6174 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6175 | case ELS_CMD_RRQ: |
| 6176 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6177 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", |
| 6178 | did, vport->port_state, ndlp->nlp_flag); |
| 6179 | |
| 6180 | phba->fc_stat.elsRcvRRQ++; |
| 6181 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); |
| 6182 | if (newnode) |
| 6183 | lpfc_nlp_put(ndlp); |
| 6184 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6185 | case ELS_CMD_ECHO: |
| 6186 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6187 | "RCV ECHO: did:x%x/ste:x%x flg:x%x", |
| 6188 | did, vport->port_state, ndlp->nlp_flag); |
| 6189 | |
| 6190 | phba->fc_stat.elsRcvECHO++; |
| 6191 | lpfc_els_rcv_echo(vport, elsiocb, ndlp); |
| 6192 | if (newnode) |
| 6193 | lpfc_nlp_put(ndlp); |
| 6194 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6195 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6196 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6197 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 6198 | cmd, did, vport->port_state); |
| 6199 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6200 | /* Unsupported ELS command, reject */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6201 | rjt_err = LSRJT_INVALID_CMD; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6202 | |
| 6203 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6204 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6205 | "0115 Unknown ELS command x%x " |
| 6206 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6207 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6208 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6209 | break; |
| 6210 | } |
| 6211 | |
| 6212 | /* check if need to LS_RJT received ELS cmd */ |
| 6213 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6214 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6215 | stat.un.b.lsRjtRsnCode = rjt_err; |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 6216 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6217 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 6218 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6219 | } |
| 6220 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6221 | lpfc_nlp_put(elsiocb->context1); |
| 6222 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6223 | return; |
| 6224 | |
| 6225 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6226 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6227 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6228 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6229 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6230 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6231 | phba->fc_stat.elsRcvDrop++; |
| 6232 | } |
| 6233 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6234 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6235 | * 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] | 6236 | * @phba: pointer to lpfc hba data structure. |
| 6237 | * @vpi: host virtual N_Port identifier. |
| 6238 | * |
| 6239 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 6240 | * @vpi. The function walks the HBA's vport list and returns the address |
| 6241 | * of the vport with the matching @vpi. |
| 6242 | * |
| 6243 | * Return code |
| 6244 | * NULL - No vport with the matching @vpi found |
| 6245 | * Otherwise - Address to the vport with the matching @vpi. |
| 6246 | **/ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 6247 | struct lpfc_vport * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6248 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 6249 | { |
| 6250 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6251 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6252 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6253 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6254 | list_for_each_entry(vport, &phba->port_list, listentry) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6255 | if (vport->vpi == vpi) { |
| 6256 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6257 | return vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6258 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6259 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6260 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6261 | return NULL; |
| 6262 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6263 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6264 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6265 | * 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] | 6266 | * @phba: pointer to lpfc hba data structure. |
| 6267 | * @pring: pointer to a SLI ring. |
| 6268 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 6269 | * |
| 6270 | * This routine is used to process an unsolicited event received from a SLI |
| 6271 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 6272 | * associated with the unsolicited event is done by invoking the routine |
| 6273 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 6274 | * SLI ring on which the unsolicited event was received. |
| 6275 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6276 | void |
| 6277 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 6278 | struct lpfc_iocbq *elsiocb) |
| 6279 | { |
| 6280 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6281 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6282 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6283 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 6284 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6285 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6286 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6287 | elsiocb->context2 = NULL; |
| 6288 | elsiocb->context3 = NULL; |
| 6289 | |
| 6290 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 6291 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 6292 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 6293 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6294 | phba->fc_stat.NoRcvBuf++; |
| 6295 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6296 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 6297 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6298 | return; |
| 6299 | } |
| 6300 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6301 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 6302 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 6303 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 6304 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 6305 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6306 | else |
| 6307 | vport = lpfc_find_vport_by_vpid(phba, |
| 6308 | icmd->unsli3.rcvsli3.vpi - phba->vpi_base); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6309 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6310 | /* If there are no BDEs associated |
| 6311 | * with this IOCB, there is nothing to do. |
| 6312 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6313 | if (icmd->ulpBdeCount == 0) |
| 6314 | return; |
| 6315 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6316 | /* type of ELS cmd is first 32bit word |
| 6317 | * in packet |
| 6318 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6319 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6320 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6321 | } else { |
| 6322 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 6323 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6324 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 6325 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6326 | } |
| 6327 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6328 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 6329 | /* |
| 6330 | * The different unsolicited event handlers would tell us |
| 6331 | * if they are done with "mp" by setting context2 to NULL. |
| 6332 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6333 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6334 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 6335 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6336 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6337 | |
| 6338 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6339 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6340 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6341 | elsiocb->context2 = bdeBuf2; |
| 6342 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6343 | /* free mp if we are done with it */ |
| 6344 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6345 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 6346 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6347 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6348 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6349 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6350 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6351 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6352 | * 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] | 6353 | * @phba: pointer to lpfc hba data structure. |
| 6354 | * @vport: pointer to a virtual N_Port data structure. |
| 6355 | * |
| 6356 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 6357 | * State Change Request (SCR) for a @vport. This routine will create an |
| 6358 | * ndlp for the Name Server associated to the @vport if such node does |
| 6359 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 6360 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 6361 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 6362 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 6363 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6364 | void |
| 6365 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 6366 | { |
| 6367 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
| 6368 | |
| 6369 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 6370 | if (!ndlp) { |
| 6371 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 6372 | if (!ndlp) { |
| 6373 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 6374 | lpfc_disc_start(vport); |
| 6375 | return; |
| 6376 | } |
| 6377 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6378 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6379 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6380 | return; |
| 6381 | } |
| 6382 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6383 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 6384 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 6385 | if (!ndlp) { |
| 6386 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 6387 | lpfc_disc_start(vport); |
| 6388 | return; |
| 6389 | } |
| 6390 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6391 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6392 | "0348 NameServer login: node freed\n"); |
| 6393 | return; |
| 6394 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6395 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6396 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6397 | |
| 6398 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 6399 | |
| 6400 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 6401 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6402 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6403 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6404 | return; |
| 6405 | } |
| 6406 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6407 | if (vport->cfg_fdmi_on) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6408 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 6409 | GFP_KERNEL); |
| 6410 | if (ndlp_fdmi) { |
| 6411 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 6412 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6413 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
| 6414 | NLP_STE_PLOGI_ISSUE); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6415 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, |
| 6416 | 0); |
| 6417 | } |
| 6418 | } |
| 6419 | return; |
| 6420 | } |
| 6421 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6422 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6423 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6424 | * @phba: pointer to lpfc hba data structure. |
| 6425 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 6426 | * |
| 6427 | * This routine is the completion callback function to register new vport |
| 6428 | * mailbox command. If the new vport mailbox command completes successfully, |
| 6429 | * the fabric registration login shall be performed on physical port (the |
| 6430 | * new vport created is actually a physical port, with VPI 0) or the port |
| 6431 | * login to Name Server for State Change Request (SCR) will be performed |
| 6432 | * on virtual port (real virtual port, with VPI greater than 0). |
| 6433 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6434 | static void |
| 6435 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6436 | { |
| 6437 | struct lpfc_vport *vport = pmb->vport; |
| 6438 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6439 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6440 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6441 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6442 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6443 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6444 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6445 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6446 | |
| 6447 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6448 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6449 | "0915 Register VPI failed : Status: x%x" |
| 6450 | " upd bit: x%x \n", mb->mbxStatus, |
| 6451 | mb->un.varRegVpi.upd); |
| 6452 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 6453 | mb->un.varRegVpi.upd) |
| 6454 | goto mbox_err_exit ; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6455 | |
| 6456 | switch (mb->mbxStatus) { |
| 6457 | case 0x11: /* unsupported feature */ |
| 6458 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6459 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6460 | /* giving up on vport registration */ |
| 6461 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6462 | spin_lock_irq(shost->host_lock); |
| 6463 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 6464 | spin_unlock_irq(shost->host_lock); |
| 6465 | lpfc_can_disctmo(vport); |
| 6466 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6467 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
| 6468 | case 0x20: |
| 6469 | spin_lock_irq(shost->host_lock); |
| 6470 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 6471 | spin_unlock_irq(shost->host_lock); |
| 6472 | lpfc_init_vpi(phba, pmb, vport->vpi); |
| 6473 | pmb->vport = vport; |
| 6474 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 6475 | rc = lpfc_sli_issue_mbox(phba, pmb, |
| 6476 | MBX_NOWAIT); |
| 6477 | if (rc == MBX_NOT_FINISHED) { |
| 6478 | lpfc_printf_vlog(vport, |
| 6479 | KERN_ERR, LOG_MBOX, |
| 6480 | "2732 Failed to issue INIT_VPI" |
| 6481 | " mailbox command\n"); |
| 6482 | } else { |
| 6483 | lpfc_nlp_put(ndlp); |
| 6484 | return; |
| 6485 | } |
| 6486 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6487 | default: |
| 6488 | /* Try to recover from this error */ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame^] | 6489 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6490 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6491 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6492 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6493 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6494 | spin_unlock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6495 | if (vport->port_type == LPFC_PHYSICAL_PORT |
| 6496 | && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6497 | lpfc_initial_flogi(vport); |
| 6498 | else |
| 6499 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6500 | break; |
| 6501 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6502 | } else { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6503 | spin_lock_irq(shost->host_lock); |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 6504 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6505 | spin_unlock_irq(shost->host_lock); |
| 6506 | if (vport == phba->pport) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6507 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 6508 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6509 | else { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6510 | /* |
| 6511 | * If the physical port is instantiated using |
| 6512 | * FDISC, do not start vport discovery. |
| 6513 | */ |
| 6514 | if (vport->port_state != LPFC_FDISC) |
| 6515 | lpfc_start_fdiscs(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6516 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6517 | } |
| 6518 | } else |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6519 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6520 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6521 | mbox_err_exit: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6522 | /* Now, we decrement the ndlp reference count held for this |
| 6523 | * callback function |
| 6524 | */ |
| 6525 | lpfc_nlp_put(ndlp); |
| 6526 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6527 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6528 | return; |
| 6529 | } |
| 6530 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6531 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6532 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6533 | * @phba: pointer to lpfc hba data structure. |
| 6534 | * @vport: pointer to a host virtual N_Port data structure. |
| 6535 | * @ndlp: pointer to a node-list data structure. |
| 6536 | * |
| 6537 | * This routine registers the @vport as a new virtual port with a HBA. |
| 6538 | * It is done through a registering vpi mailbox command. |
| 6539 | **/ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6540 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6541 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 6542 | struct lpfc_nodelist *ndlp) |
| 6543 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6544 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6545 | LPFC_MBOXQ_t *mbox; |
| 6546 | |
| 6547 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6548 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6549 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6550 | mbox->vport = vport; |
| 6551 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 6552 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 6553 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6554 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6555 | /* mailbox command not success, decrement ndlp |
| 6556 | * reference count for this command |
| 6557 | */ |
| 6558 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6559 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6560 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6561 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6562 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6563 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6564 | } |
| 6565 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6566 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6567 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6568 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6569 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6570 | return; |
| 6571 | |
| 6572 | mbox_err_exit: |
| 6573 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6574 | spin_lock_irq(shost->host_lock); |
| 6575 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 6576 | spin_unlock_irq(shost->host_lock); |
| 6577 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6578 | } |
| 6579 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6580 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6581 | * 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] | 6582 | * @phba: pointer to lpfc hba data structure. |
| 6583 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6584 | * This routine cancels the retry delay timers to all the vports. |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6585 | **/ |
| 6586 | void |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6587 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6588 | { |
| 6589 | struct lpfc_vport **vports; |
| 6590 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6591 | uint32_t link_state; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6592 | int i; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6593 | |
| 6594 | /* Treat this failure as linkdown for all vports */ |
| 6595 | link_state = phba->link_state; |
| 6596 | lpfc_linkdown(phba); |
| 6597 | phba->link_state = link_state; |
| 6598 | |
| 6599 | vports = lpfc_create_vport_work_array(phba); |
| 6600 | |
| 6601 | if (vports) { |
| 6602 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 6603 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 6604 | if (ndlp) |
| 6605 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
| 6606 | lpfc_els_flush_cmd(vports[i]); |
| 6607 | } |
| 6608 | lpfc_destroy_vport_work_array(phba, vports); |
| 6609 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6610 | } |
| 6611 | |
| 6612 | /** |
| 6613 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. |
| 6614 | * @phba: pointer to lpfc hba data structure. |
| 6615 | * |
| 6616 | * This routine abort all pending discovery commands and |
| 6617 | * start a timer to retry FLOGI for the physical port |
| 6618 | * discovery. |
| 6619 | **/ |
| 6620 | void |
| 6621 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) |
| 6622 | { |
| 6623 | struct lpfc_nodelist *ndlp; |
| 6624 | struct Scsi_Host *shost; |
| 6625 | |
| 6626 | /* Cancel the all vports retry delay retry timers */ |
| 6627 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6628 | |
| 6629 | /* If fabric require FLOGI, then re-instantiate physical login */ |
| 6630 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 6631 | if (!ndlp) |
| 6632 | return; |
| 6633 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6634 | shost = lpfc_shost_from_vport(phba->pport); |
| 6635 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); |
| 6636 | spin_lock_irq(shost->host_lock); |
| 6637 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 6638 | spin_unlock_irq(shost->host_lock); |
| 6639 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; |
| 6640 | phba->pport->port_state = LPFC_FLOGI; |
| 6641 | return; |
| 6642 | } |
| 6643 | |
| 6644 | /** |
| 6645 | * lpfc_fabric_login_reqd - Check if FLOGI required. |
| 6646 | * @phba: pointer to lpfc hba data structure. |
| 6647 | * @cmdiocb: pointer to FDISC command iocb. |
| 6648 | * @rspiocb: pointer to FDISC response iocb. |
| 6649 | * |
| 6650 | * This routine checks if a FLOGI is reguired for FDISC |
| 6651 | * to succeed. |
| 6652 | **/ |
| 6653 | static int |
| 6654 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, |
| 6655 | struct lpfc_iocbq *cmdiocb, |
| 6656 | struct lpfc_iocbq *rspiocb) |
| 6657 | { |
| 6658 | |
| 6659 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || |
| 6660 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) |
| 6661 | return 0; |
| 6662 | else |
| 6663 | return 1; |
| 6664 | } |
| 6665 | |
| 6666 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6667 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6668 | * @phba: pointer to lpfc hba data structure. |
| 6669 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6670 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6671 | * |
| 6672 | * This routine is the completion callback function to a Fabric Discover |
| 6673 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 6674 | * single threaded, each FDISC completion callback function will reset |
| 6675 | * the discovery timer for all vports such that the timers will not get |
| 6676 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 6677 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 6678 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 6679 | * assigned to the vport has been changed with the completion of the FDISC |
| 6680 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 6681 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 6682 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 6683 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 6684 | * Server for State Change Request (SCR). |
| 6685 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6686 | static void |
| 6687 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6688 | struct lpfc_iocbq *rspiocb) |
| 6689 | { |
| 6690 | struct lpfc_vport *vport = cmdiocb->vport; |
| 6691 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6692 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 6693 | struct lpfc_nodelist *np; |
| 6694 | struct lpfc_nodelist *next_np; |
| 6695 | IOCB_t *irsp = &rspiocb->iocb; |
| 6696 | struct lpfc_iocbq *piocb; |
| 6697 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6698 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6699 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 6700 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 6701 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6702 | /* Since all FDISCs are being single threaded, we |
| 6703 | * must reset the discovery timer for ALL vports |
| 6704 | * waiting to send FDISC when one completes. |
| 6705 | */ |
| 6706 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 6707 | lpfc_set_disctmo(piocb->vport); |
| 6708 | } |
| 6709 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6710 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6711 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 6712 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 6713 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6714 | if (irsp->ulpStatus) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6715 | |
| 6716 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { |
| 6717 | lpfc_retry_pport_discovery(phba); |
| 6718 | goto out; |
| 6719 | } |
| 6720 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6721 | /* Check for retry */ |
| 6722 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 6723 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6724 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6725 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6726 | "0126 FDISC failed. (%d/%d)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6727 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6728 | goto fdisc_failed; |
| 6729 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6730 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6731 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6732 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6733 | vport->fc_flag |= FC_FABRIC; |
| 6734 | if (vport->phba->fc_topology == TOPOLOGY_LOOP) |
| 6735 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 6736 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6737 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6738 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 6739 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
| 6740 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 6741 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 6742 | /* If our NportID changed, we need to ensure all |
| 6743 | * remaining NPORTs get unreg_login'ed so we can |
| 6744 | * issue unreg_vpi. |
| 6745 | */ |
| 6746 | list_for_each_entry_safe(np, next_np, |
| 6747 | &vport->fc_nodes, nlp_listp) { |
| 6748 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 6749 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 6750 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 6751 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6752 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6753 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6754 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6755 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6756 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 6757 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame^] | 6758 | |
| 6759 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6760 | lpfc_sli4_unreg_all_rpis(vport); |
| 6761 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6762 | lpfc_mbx_unreg_vpi(vport); |
| 6763 | spin_lock_irq(shost->host_lock); |
| 6764 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 6765 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6766 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6767 | else |
| 6768 | vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6769 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6770 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 6771 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 6772 | /* |
| 6773 | * Driver needs to re-reg VPI in order for f/w |
| 6774 | * to update the MAC address. |
| 6775 | */ |
| 6776 | lpfc_register_new_vport(phba, vport, ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 6777 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6778 | } |
| 6779 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6780 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
| 6781 | lpfc_issue_init_vpi(vport); |
| 6782 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6783 | lpfc_register_new_vport(phba, vport, ndlp); |
| 6784 | else |
| 6785 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6786 | goto out; |
| 6787 | fdisc_failed: |
| 6788 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6789 | /* Cancel discovery timer */ |
| 6790 | lpfc_can_disctmo(vport); |
| 6791 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6792 | out: |
| 6793 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6794 | } |
| 6795 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6796 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6797 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6798 | * @vport: pointer to a virtual N_Port data structure. |
| 6799 | * @ndlp: pointer to a node-list data structure. |
| 6800 | * @retry: number of retries to the command IOCB. |
| 6801 | * |
| 6802 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 6803 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 6804 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 6805 | * IOCB will be sent off HBA at any given time. |
| 6806 | * |
| 6807 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6808 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6809 | * will be stored into the context1 field of the IOCB for the completion |
| 6810 | * callback function to the FDISC ELS command. |
| 6811 | * |
| 6812 | * Return code |
| 6813 | * 0 - Successfully issued fdisc iocb command |
| 6814 | * 1 - Failed to issue fdisc iocb command |
| 6815 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6816 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6817 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 6818 | uint8_t retry) |
| 6819 | { |
| 6820 | struct lpfc_hba *phba = vport->phba; |
| 6821 | IOCB_t *icmd; |
| 6822 | struct lpfc_iocbq *elsiocb; |
| 6823 | struct serv_parm *sp; |
| 6824 | uint8_t *pcmd; |
| 6825 | uint16_t cmdsize; |
| 6826 | int did = ndlp->nlp_DID; |
| 6827 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6828 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6829 | vport->port_state = LPFC_FDISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6830 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 6831 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 6832 | ELS_CMD_FDISC); |
| 6833 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6834 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6835 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6836 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6837 | return 1; |
| 6838 | } |
| 6839 | |
| 6840 | icmd = &elsiocb->iocb; |
| 6841 | icmd->un.elsreq64.myID = 0; |
| 6842 | icmd->un.elsreq64.fl = 1; |
| 6843 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6844 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 6845 | /* FDISC needs to be 1 for WQE VPI */ |
| 6846 | elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1; |
| 6847 | elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ; |
| 6848 | /* Set the ulpContext to the vpi */ |
| 6849 | elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base; |
| 6850 | } else { |
| 6851 | /* For FDISC, Let FDISC rsp set the NPortID for this VPI */ |
| 6852 | icmd->ulpCt_h = 1; |
| 6853 | icmd->ulpCt_l = 0; |
| 6854 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6855 | |
| 6856 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6857 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 6858 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 6859 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 6860 | sp = (struct serv_parm *) pcmd; |
| 6861 | /* Setup CSPs accordingly for Fabric */ |
| 6862 | sp->cmn.e_d_tov = 0; |
| 6863 | sp->cmn.w2.r_a_tov = 0; |
| 6864 | sp->cls1.classValid = 0; |
| 6865 | sp->cls2.seqDelivery = 1; |
| 6866 | sp->cls3.seqDelivery = 1; |
| 6867 | |
| 6868 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 6869 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 6870 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 6871 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 6872 | memcpy(pcmd, &vport->fc_portname, 8); |
| 6873 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6874 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6875 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 6876 | |
| 6877 | lpfc_set_disctmo(vport); |
| 6878 | |
| 6879 | phba->fc_stat.elsXmitFDISC++; |
| 6880 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 6881 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6882 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6883 | "Issue FDISC: did:x%x", |
| 6884 | did, 0, 0); |
| 6885 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6886 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 6887 | if (rc == IOCB_ERROR) { |
| 6888 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6889 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6890 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6891 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6892 | return 1; |
| 6893 | } |
| 6894 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6895 | return 0; |
| 6896 | } |
| 6897 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6898 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6899 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6900 | * @phba: pointer to lpfc hba data structure. |
| 6901 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6902 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6903 | * |
| 6904 | * This routine is the completion callback function to the issuing of a LOGO |
| 6905 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 6906 | * reference count held on ndlp for this completion function, indicating that |
| 6907 | * the reference to the ndlp is no long needed. Note that the |
| 6908 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 6909 | * callback function and an additional explicit ndlp reference decrementation |
| 6910 | * will trigger the actual release of the ndlp. |
| 6911 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6912 | static void |
| 6913 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6914 | struct lpfc_iocbq *rspiocb) |
| 6915 | { |
| 6916 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6917 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6918 | struct lpfc_nodelist *ndlp; |
| 6919 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6920 | |
| 6921 | irsp = &rspiocb->iocb; |
| 6922 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6923 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 6924 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6925 | |
| 6926 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6927 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6928 | |
| 6929 | /* Trigger the release of the ndlp after logo */ |
| 6930 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6931 | } |
| 6932 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6933 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6934 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6935 | * @vport: pointer to a virtual N_Port data structure. |
| 6936 | * @ndlp: pointer to a node-list data structure. |
| 6937 | * |
| 6938 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 6939 | * |
| 6940 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6941 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6942 | * will be stored into the context1 field of the IOCB for the completion |
| 6943 | * callback function to the LOGO ELS command. |
| 6944 | * |
| 6945 | * Return codes |
| 6946 | * 0 - Successfully issued logo off the @vport |
| 6947 | * 1 - Failed to issue logo off the @vport |
| 6948 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6949 | int |
| 6950 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 6951 | { |
| 6952 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6953 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6954 | IOCB_t *icmd; |
| 6955 | struct lpfc_iocbq *elsiocb; |
| 6956 | uint8_t *pcmd; |
| 6957 | uint16_t cmdsize; |
| 6958 | |
| 6959 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 6960 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 6961 | ELS_CMD_LOGO); |
| 6962 | if (!elsiocb) |
| 6963 | return 1; |
| 6964 | |
| 6965 | icmd = &elsiocb->iocb; |
| 6966 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6967 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 6968 | pcmd += sizeof(uint32_t); |
| 6969 | |
| 6970 | /* Fill in LOGO payload */ |
| 6971 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 6972 | pcmd += sizeof(uint32_t); |
| 6973 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 6974 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6975 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6976 | "Issue LOGO npiv did:x%x flg:x%x", |
| 6977 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 6978 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6979 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 6980 | spin_lock_irq(shost->host_lock); |
| 6981 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 6982 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6983 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 6984 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6985 | spin_lock_irq(shost->host_lock); |
| 6986 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 6987 | spin_unlock_irq(shost->host_lock); |
| 6988 | lpfc_els_free_iocb(phba, elsiocb); |
| 6989 | return 1; |
| 6990 | } |
| 6991 | return 0; |
| 6992 | } |
| 6993 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6994 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6995 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6996 | * @ptr: holder for the timer function associated data. |
| 6997 | * |
| 6998 | * This routine is invoked by the fabric iocb block timer after |
| 6999 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 7000 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 7001 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 7002 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 7003 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 7004 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7005 | void |
| 7006 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 7007 | { |
| 7008 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 7009 | unsigned long iflags; |
| 7010 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7011 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7012 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 7013 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 7014 | if (!tmo_posted) |
| 7015 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 7016 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 7017 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7018 | if (!tmo_posted) |
| 7019 | lpfc_worker_wake_up(phba); |
| 7020 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7021 | } |
| 7022 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7023 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7024 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7025 | * @phba: pointer to lpfc hba data structure. |
| 7026 | * |
| 7027 | * This routine issues one fabric iocb from the driver internal list to |
| 7028 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 7029 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 7030 | * remove one pending fabric iocb from the driver internal list and invokes |
| 7031 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 7032 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7033 | static void |
| 7034 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 7035 | { |
| 7036 | struct lpfc_iocbq *iocb; |
| 7037 | unsigned long iflags; |
| 7038 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7039 | IOCB_t *cmd; |
| 7040 | |
| 7041 | repeat: |
| 7042 | iocb = NULL; |
| 7043 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7044 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7045 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 7046 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 7047 | list); |
| 7048 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7049 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7050 | atomic_inc(&phba->fabric_iocb_count); |
| 7051 | } |
| 7052 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7053 | if (iocb) { |
| 7054 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 7055 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 7056 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 7057 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7058 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 7059 | "Fabric sched1: ste:x%x", |
| 7060 | iocb->vport->port_state, 0, 0); |
| 7061 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7062 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7063 | |
| 7064 | if (ret == IOCB_ERROR) { |
| 7065 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 7066 | iocb->fabric_iocb_cmpl = NULL; |
| 7067 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 7068 | cmd = &iocb->iocb; |
| 7069 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 7070 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 7071 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 7072 | |
| 7073 | atomic_dec(&phba->fabric_iocb_count); |
| 7074 | goto repeat; |
| 7075 | } |
| 7076 | } |
| 7077 | |
| 7078 | return; |
| 7079 | } |
| 7080 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7081 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7082 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7083 | * @phba: pointer to lpfc hba data structure. |
| 7084 | * |
| 7085 | * This routine unblocks the issuing fabric iocb command. The function |
| 7086 | * will clear the fabric iocb block bit and then invoke the routine |
| 7087 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 7088 | * from the driver internal fabric iocb list. |
| 7089 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7090 | void |
| 7091 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 7092 | { |
| 7093 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 7094 | |
| 7095 | lpfc_resume_fabric_iocbs(phba); |
| 7096 | return; |
| 7097 | } |
| 7098 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7099 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7100 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7101 | * @phba: pointer to lpfc hba data structure. |
| 7102 | * |
| 7103 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 7104 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 7105 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 7106 | * fabric iocb will be issued out of the HBA. |
| 7107 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7108 | static void |
| 7109 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 7110 | { |
| 7111 | int blocked; |
| 7112 | |
| 7113 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7114 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7115 | if (!blocked) |
| 7116 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); |
| 7117 | |
| 7118 | return; |
| 7119 | } |
| 7120 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7121 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7122 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7123 | * @phba: pointer to lpfc hba data structure. |
| 7124 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7125 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 7126 | * |
| 7127 | * This routine is the callback function that is put to the fabric iocb's |
| 7128 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 7129 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 7130 | * function first restores and invokes the original iocb's callback function |
| 7131 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 7132 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 7133 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7134 | static void |
| 7135 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 7136 | struct lpfc_iocbq *rspiocb) |
| 7137 | { |
| 7138 | struct ls_rjt stat; |
| 7139 | |
| 7140 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 7141 | BUG(); |
| 7142 | |
| 7143 | switch (rspiocb->iocb.ulpStatus) { |
| 7144 | case IOSTAT_NPORT_RJT: |
| 7145 | case IOSTAT_FABRIC_RJT: |
| 7146 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 7147 | lpfc_block_fabric_iocbs(phba); |
| 7148 | } |
| 7149 | break; |
| 7150 | |
| 7151 | case IOSTAT_NPORT_BSY: |
| 7152 | case IOSTAT_FABRIC_BSY: |
| 7153 | lpfc_block_fabric_iocbs(phba); |
| 7154 | break; |
| 7155 | |
| 7156 | case IOSTAT_LS_RJT: |
| 7157 | stat.un.lsRjtError = |
| 7158 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 7159 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 7160 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 7161 | lpfc_block_fabric_iocbs(phba); |
| 7162 | break; |
| 7163 | } |
| 7164 | |
| 7165 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 7166 | BUG(); |
| 7167 | |
| 7168 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 7169 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 7170 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 7171 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 7172 | |
| 7173 | atomic_dec(&phba->fabric_iocb_count); |
| 7174 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7175 | /* Post any pending iocbs to HBA */ |
| 7176 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7177 | } |
| 7178 | } |
| 7179 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7180 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7181 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7182 | * @phba: pointer to lpfc hba data structure. |
| 7183 | * @iocb: pointer to lpfc command iocb data structure. |
| 7184 | * |
| 7185 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 7186 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 7187 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 7188 | * any given time. As such, this function will first check to see whether there |
| 7189 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 7190 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 7191 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 7192 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 7193 | * |
| 7194 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 7195 | * order. The problem is caused by the construction of the "ready" boolen does |
| 7196 | * not include the condition that the internal fabric IOCB list is empty. As |
| 7197 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 7198 | * ahead of the fabric IOCBs in the internal list. |
| 7199 | * |
| 7200 | * Return code |
| 7201 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 7202 | * IOCB_ERROR - failed to issue fabric iocb |
| 7203 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 7204 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7205 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 7206 | { |
| 7207 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7208 | int ready; |
| 7209 | int ret; |
| 7210 | |
| 7211 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 7212 | BUG(); |
| 7213 | |
| 7214 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7215 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 7216 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 7217 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7218 | if (ready) |
| 7219 | /* Increment fabric iocb count to hold the position */ |
| 7220 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7221 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7222 | if (ready) { |
| 7223 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 7224 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 7225 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 7226 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7227 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 7228 | "Fabric sched2: ste:x%x", |
| 7229 | iocb->vport->port_state, 0, 0); |
| 7230 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7231 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7232 | |
| 7233 | if (ret == IOCB_ERROR) { |
| 7234 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 7235 | iocb->fabric_iocb_cmpl = NULL; |
| 7236 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 7237 | atomic_dec(&phba->fabric_iocb_count); |
| 7238 | } |
| 7239 | } else { |
| 7240 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7241 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 7242 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7243 | ret = IOCB_SUCCESS; |
| 7244 | } |
| 7245 | return ret; |
| 7246 | } |
| 7247 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7248 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7249 | * 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] | 7250 | * @vport: pointer to a virtual N_Port data structure. |
| 7251 | * |
| 7252 | * This routine aborts all the IOCBs associated with a @vport from the |
| 7253 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 7254 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 7255 | * list, removes each IOCB associated with the @vport off the list, set the |
| 7256 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 7257 | * associated with the IOCB. |
| 7258 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 7259 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7260 | { |
| 7261 | LIST_HEAD(completions); |
| 7262 | struct lpfc_hba *phba = vport->phba; |
| 7263 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7264 | |
| 7265 | spin_lock_irq(&phba->hbalock); |
| 7266 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 7267 | list) { |
| 7268 | |
| 7269 | if (piocb->vport != vport) |
| 7270 | continue; |
| 7271 | |
| 7272 | list_move_tail(&piocb->list, &completions); |
| 7273 | } |
| 7274 | spin_unlock_irq(&phba->hbalock); |
| 7275 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7276 | /* Cancel all the IOCBs from the completions list */ |
| 7277 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 7278 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7279 | } |
| 7280 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7281 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7282 | * 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] | 7283 | * @ndlp: pointer to a node-list data structure. |
| 7284 | * |
| 7285 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 7286 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 7287 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 7288 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 7289 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 7290 | * associated with the IOCB. |
| 7291 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7292 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 7293 | { |
| 7294 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7295 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7296 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 7297 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7298 | |
| 7299 | spin_lock_irq(&phba->hbalock); |
| 7300 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 7301 | list) { |
| 7302 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 7303 | |
| 7304 | list_move_tail(&piocb->list, &completions); |
| 7305 | } |
| 7306 | } |
| 7307 | spin_unlock_irq(&phba->hbalock); |
| 7308 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7309 | /* Cancel all the IOCBs from the completions list */ |
| 7310 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 7311 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7312 | } |
| 7313 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7314 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7315 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7316 | * @phba: pointer to lpfc hba data structure. |
| 7317 | * |
| 7318 | * This routine aborts all the IOCBs currently on the driver internal |
| 7319 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 7320 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 7321 | * list, removes IOCBs off the list, set the status feild to |
| 7322 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 7323 | * the IOCB. |
| 7324 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7325 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 7326 | { |
| 7327 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7328 | |
| 7329 | spin_lock_irq(&phba->hbalock); |
| 7330 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 7331 | spin_unlock_irq(&phba->hbalock); |
| 7332 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7333 | /* Cancel all the IOCBs from the completions list */ |
| 7334 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 7335 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7336 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7337 | |
| 7338 | /** |
| 7339 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 7340 | * @phba: pointer to lpfc hba data structure. |
| 7341 | * @axri: pointer to the els xri abort wcqe structure. |
| 7342 | * |
| 7343 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 7344 | * ELS aborted xri. |
| 7345 | **/ |
| 7346 | void |
| 7347 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 7348 | struct sli4_wcqe_xri_aborted *axri) |
| 7349 | { |
| 7350 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
| 7351 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 7352 | unsigned long iflag = 0; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 7353 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7354 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7355 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7356 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7357 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 7358 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 7359 | if (sglq_entry->sli4_xritag == xri) { |
| 7360 | list_del(&sglq_entry->list); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7361 | list_add_tail(&sglq_entry->list, |
| 7362 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7363 | sglq_entry->state = SGL_FREED; |
| 7364 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7365 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 7366 | |
| 7367 | /* Check if TXQ queue needs to be serviced */ |
| 7368 | if (pring->txq_cnt) |
| 7369 | lpfc_worker_wake_up(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7370 | return; |
| 7371 | } |
| 7372 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7373 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 7374 | sglq_entry = __lpfc_get_active_sglq(phba, xri); |
| 7375 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { |
| 7376 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7377 | return; |
| 7378 | } |
| 7379 | sglq_entry->state = SGL_XRI_ABORTED; |
| 7380 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7381 | return; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7382 | } |