| 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: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 180 | elsiocb->iocb_flag |= |
| 181 | ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 182 | & LPFC_FIP_ELS_ID_MASK); |
| 183 | break; |
| 184 | case ELS_CMD_FDISC: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 185 | elsiocb->iocb_flag |= |
| 186 | ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 187 | & LPFC_FIP_ELS_ID_MASK); |
| 188 | break; |
| 189 | case ELS_CMD_LOGO: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 190 | elsiocb->iocb_flag |= |
| 191 | ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 192 | & LPFC_FIP_ELS_ID_MASK); |
| 193 | break; |
| 194 | } |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 195 | else |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 196 | elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 197 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 198 | icmd = &elsiocb->iocb; |
| 199 | |
| 200 | /* fill in BDEs for command */ |
| 201 | /* Allocate buffer for command payload */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 202 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 203 | if (pcmd) |
| 204 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 205 | if (!pcmd || !pcmd->virt) |
| 206 | goto els_iocb_free_pcmb_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 207 | |
| 208 | INIT_LIST_HEAD(&pcmd->list); |
| 209 | |
| 210 | /* Allocate buffer for response payload */ |
| 211 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 212 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 213 | if (prsp) |
| 214 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 215 | &prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 216 | if (!prsp || !prsp->virt) |
| 217 | goto els_iocb_free_prsp_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 218 | INIT_LIST_HEAD(&prsp->list); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 219 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 220 | prsp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 221 | |
| 222 | /* Allocate buffer for Buffer ptr list */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 223 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 224 | if (pbuflist) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 225 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 226 | &pbuflist->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 227 | if (!pbuflist || !pbuflist->virt) |
| 228 | goto els_iocb_free_pbuf_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 229 | |
| 230 | INIT_LIST_HEAD(&pbuflist->list); |
| 231 | |
| 232 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 233 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 234 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 235 | icmd->un.elsreq64.remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 236 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 237 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 238 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 239 | icmd->ulpTimeout = phba->fc_ratov * 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 240 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 241 | icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 242 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; |
| 243 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 244 | icmd->ulpBdeCount = 1; |
| 245 | icmd->ulpLe = 1; |
| 246 | icmd->ulpClass = CLASS3; |
| 247 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 248 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 249 | icmd->un.elsreq64.myID = vport->fc_myDID; |
| 250 | |
| 251 | /* For ELS_REQUEST64_CR, use the VPI by default */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 252 | icmd->ulpContext = vport->vpi + phba->vpi_base; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 253 | icmd->ulpCt_h = 0; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 254 | /* The CT field must be 0=INVALID_RPI for the ECHO cmd */ |
| 255 | if (elscmd == ELS_CMD_ECHO) |
| 256 | icmd->ulpCt_l = 0; /* context = invalid RPI */ |
| 257 | else |
| 258 | icmd->ulpCt_l = 1; /* context = VPI */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 259 | } |
| 260 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 261 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
| 262 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); |
| 263 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); |
| 264 | bpl->tus.f.bdeSize = cmdSize; |
| 265 | bpl->tus.f.bdeFlags = 0; |
| 266 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 267 | |
| 268 | if (expectRsp) { |
| 269 | bpl++; |
| 270 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); |
| 271 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); |
| 272 | bpl->tus.f.bdeSize = FCELSSIZE; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 273 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 274 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 275 | } |
| 276 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 277 | /* prevent preparing iocb with NULL ndlp reference */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 278 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 279 | if (!elsiocb->context1) |
| 280 | goto els_iocb_free_pbuf_exit; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 281 | elsiocb->context2 = pcmd; |
| 282 | elsiocb->context3 = pbuflist; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 283 | elsiocb->retry = retry; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 284 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 285 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
| 286 | |
| 287 | if (prsp) { |
| 288 | list_add(&prsp->list, &pcmd->list); |
| 289 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 290 | if (expectRsp) { |
| 291 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 292 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 293 | "0116 Xmit ELS command x%x to remote " |
| 294 | "NPORT x%x I/O tag: x%x, port state: x%x\n", |
| 295 | elscmd, did, elsiocb->iotag, |
| 296 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 297 | } else { |
| 298 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 299 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 300 | "0117 Xmit ELS response x%x to remote " |
| 301 | "NPORT x%x I/O tag: x%x, size: x%x\n", |
| 302 | elscmd, ndlp->nlp_DID, elsiocb->iotag, |
| 303 | cmdSize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 304 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 305 | return elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 306 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 307 | els_iocb_free_pbuf_exit: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 308 | if (expectRsp) |
| 309 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 310 | kfree(pbuflist); |
| 311 | |
| 312 | els_iocb_free_prsp_exit: |
| 313 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 314 | kfree(prsp); |
| 315 | |
| 316 | els_iocb_free_pcmb_exit: |
| 317 | kfree(pcmd); |
| 318 | lpfc_sli_release_iocbq(phba, elsiocb); |
| 319 | return NULL; |
| 320 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 321 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 322 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 323 | * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 324 | * @vport: pointer to a host virtual N_Port data structure. |
| 325 | * |
| 326 | * This routine issues a fabric registration login for a @vport. An |
| 327 | * active ndlp node with Fabric_DID must already exist for this @vport. |
| 328 | * The routine invokes two mailbox commands to carry out fabric registration |
| 329 | * login through the HBA firmware: the first mailbox command requests the |
| 330 | * HBA to perform link configuration for the @vport; and the second mailbox |
| 331 | * command requests the HBA to perform the actual fabric registration login |
| 332 | * with the @vport. |
| 333 | * |
| 334 | * Return code |
| 335 | * 0 - successfully issued fabric registration login for @vport |
| 336 | * -ENXIO -- failed to issue fabric registration login for @vport |
| 337 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 338 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 339 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
| 340 | { |
| 341 | struct lpfc_hba *phba = vport->phba; |
| 342 | LPFC_MBOXQ_t *mbox; |
| 343 | struct lpfc_dmabuf *mp; |
| 344 | struct lpfc_nodelist *ndlp; |
| 345 | struct serv_parm *sp; |
| 346 | int rc; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 347 | int err = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 348 | |
| 349 | sp = &phba->fc_fabparam; |
| 350 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 351 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 352 | err = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 353 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 354 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 355 | |
| 356 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 357 | if (!mbox) { |
| 358 | err = 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 359 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 360 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 361 | |
| 362 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 363 | lpfc_config_link(phba, mbox); |
| 364 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 365 | mbox->vport = vport; |
| 366 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 367 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 368 | if (rc == MBX_NOT_FINISHED) { |
| 369 | err = 3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 370 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 371 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 372 | |
| 373 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 374 | if (!mbox) { |
| 375 | err = 4; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 376 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 377 | } |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 378 | rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, |
| 379 | ndlp->nlp_rpi); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 380 | if (rc) { |
| 381 | err = 5; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 382 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 383 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 384 | |
| 385 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; |
| 386 | mbox->vport = vport; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 387 | /* increment the reference count on ndlp to hold reference |
| 388 | * for the callback routine. |
| 389 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 390 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 391 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 392 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 393 | if (rc == MBX_NOT_FINISHED) { |
| 394 | err = 6; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 395 | goto fail_issue_reg_login; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 396 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 397 | |
| 398 | return 0; |
| 399 | |
| 400 | fail_issue_reg_login: |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 401 | /* decrement the reference count on ndlp just incremented |
| 402 | * for the failed mbox command. |
| 403 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 404 | lpfc_nlp_put(ndlp); |
| 405 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 406 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 407 | kfree(mp); |
| 408 | fail_free_mbox: |
| 409 | mempool_free(mbox, phba->mbox_mem_pool); |
| 410 | |
| 411 | fail: |
| 412 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 413 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 414 | "0249 Cannot issue Register Fabric login: Err %d\n", err); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 415 | return -ENXIO; |
| 416 | } |
| 417 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 418 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 419 | * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login |
| 420 | * @vport: pointer to a host virtual N_Port data structure. |
| 421 | * |
| 422 | * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for |
| 423 | * the @vport. This mailbox command is necessary for FCoE only. |
| 424 | * |
| 425 | * Return code |
| 426 | * 0 - successfully issued REG_VFI for @vport |
| 427 | * A failure code otherwise. |
| 428 | **/ |
| 429 | static int |
| 430 | lpfc_issue_reg_vfi(struct lpfc_vport *vport) |
| 431 | { |
| 432 | struct lpfc_hba *phba = vport->phba; |
| 433 | LPFC_MBOXQ_t *mboxq; |
| 434 | struct lpfc_nodelist *ndlp; |
| 435 | struct serv_parm *sp; |
| 436 | struct lpfc_dmabuf *dmabuf; |
| 437 | int rc = 0; |
| 438 | |
| 439 | sp = &phba->fc_fabparam; |
| 440 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 441 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
| 442 | rc = -ENODEV; |
| 443 | goto fail; |
| 444 | } |
| 445 | |
| 446 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 447 | if (!dmabuf) { |
| 448 | rc = -ENOMEM; |
| 449 | goto fail; |
| 450 | } |
| 451 | dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys); |
| 452 | if (!dmabuf->virt) { |
| 453 | rc = -ENOMEM; |
| 454 | goto fail_free_dmabuf; |
| 455 | } |
| 456 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 457 | if (!mboxq) { |
| 458 | rc = -ENOMEM; |
| 459 | goto fail_free_coherent; |
| 460 | } |
| 461 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 462 | memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam)); |
| 463 | lpfc_reg_vfi(mboxq, vport, dmabuf->phys); |
| 464 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi; |
| 465 | mboxq->vport = vport; |
| 466 | mboxq->context1 = dmabuf; |
| 467 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 468 | if (rc == MBX_NOT_FINISHED) { |
| 469 | rc = -ENXIO; |
| 470 | goto fail_free_mbox; |
| 471 | } |
| 472 | return 0; |
| 473 | |
| 474 | fail_free_mbox: |
| 475 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 476 | fail_free_coherent: |
| 477 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 478 | fail_free_dmabuf: |
| 479 | kfree(dmabuf); |
| 480 | fail: |
| 481 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 482 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 483 | "0289 Issue Register VFI failed: Err %d\n", rc); |
| 484 | return rc; |
| 485 | } |
| 486 | |
| 487 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 488 | * 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] | 489 | * @vport: pointer to a host virtual N_Port data structure. |
| 490 | * @ndlp: pointer to a node-list data structure. |
| 491 | * @sp: pointer to service parameter data structure. |
| 492 | * @irsp: pointer to the IOCB within the lpfc response IOCB. |
| 493 | * |
| 494 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 495 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric |
| 496 | * port in a fabric topology. It properly sets up the parameters to the @ndlp |
| 497 | * from the IOCB response. It also check the newly assigned N_Port ID to the |
| 498 | * @vport against the previously assigned N_Port ID. If it is different from |
| 499 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine |
| 500 | * is invoked on all the remaining nodes with the @vport to unregister the |
| 501 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() |
| 502 | * is invoked to register login to the fabric. |
| 503 | * |
| 504 | * Return code |
| 505 | * 0 - Success (currently, always return 0) |
| 506 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 507 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 508 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 509 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 510 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 511 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 512 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 513 | struct lpfc_nodelist *np; |
| 514 | struct lpfc_nodelist *next_np; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 515 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 516 | spin_lock_irq(shost->host_lock); |
| 517 | vport->fc_flag |= FC_FABRIC; |
| 518 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 519 | |
| 520 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 521 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 522 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 523 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 524 | phba->fc_edtovResol = sp->cmn.edtovResolution; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 525 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 526 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 527 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 528 | spin_lock_irq(shost->host_lock); |
| 529 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 530 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 531 | } |
| 532 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 533 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 534 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 535 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 536 | ndlp->nlp_class_sup = 0; |
| 537 | if (sp->cls1.classValid) |
| 538 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 539 | if (sp->cls2.classValid) |
| 540 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 541 | if (sp->cls3.classValid) |
| 542 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 543 | if (sp->cls4.classValid) |
| 544 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 545 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 546 | sp->cmn.bbRcvSizeLsb; |
| 547 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 548 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 549 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 550 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 551 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 552 | LOG_ELS | LOG_VPORT, |
| 553 | "1816 FLOGI NPIV supported, " |
| 554 | "response data 0x%x\n", |
| 555 | sp->cmn.response_multiple_NPort); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 556 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 557 | } else { |
| 558 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 559 | to call reg_vnpid atleast for the physcial host */ |
| 560 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 561 | LOG_ELS | LOG_VPORT, |
| 562 | "1817 Fabric does not support NPIV " |
| 563 | "- configuring single port mode.\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 564 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 569 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 570 | |
| 571 | /* If our NportID changed, we need to ensure all |
| 572 | * remaining NPORTs get unreg_login'ed. |
| 573 | */ |
| 574 | list_for_each_entry_safe(np, next_np, |
| 575 | &vport->fc_nodes, nlp_listp) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 576 | if (!NLP_CHK_NODE_ACT(np)) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 577 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 578 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 579 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 580 | continue; |
| 581 | spin_lock_irq(shost->host_lock); |
| 582 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 583 | spin_unlock_irq(shost->host_lock); |
| 584 | lpfc_unreg_rpi(vport, np); |
| 585 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 586 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 587 | |
| 588 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 589 | lpfc_sli4_unreg_all_rpis(vport); |
| 590 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 591 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 592 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 593 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 594 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 595 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 596 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 597 | /* |
| 598 | * If VPI is unreged, driver need to do INIT_VPI |
| 599 | * before re-registering |
| 600 | */ |
| 601 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 602 | spin_lock_irq(shost->host_lock); |
| 603 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 604 | spin_unlock_irq(shost->host_lock); |
| 605 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 606 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 607 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 608 | /* |
| 609 | * Driver needs to re-reg VPI in order for f/w |
| 610 | * to update the MAC address. |
| 611 | */ |
| 612 | lpfc_register_new_vport(phba, vport, ndlp); |
| 613 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 614 | } |
| 615 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 616 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 617 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
| 618 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 619 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 620 | lpfc_register_new_vport(phba, vport, ndlp); |
| 621 | else |
| 622 | lpfc_issue_fabric_reglogin(vport); |
| 623 | } else { |
| 624 | ndlp->nlp_type |= NLP_FABRIC; |
| 625 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 626 | if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) && |
| 627 | (vport->vpi_state & LPFC_VPI_REGISTERED)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 628 | lpfc_start_fdiscs(phba); |
| 629 | lpfc_do_scr_ns_plogi(phba, vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 630 | } else if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 631 | lpfc_issue_init_vpi(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 632 | else |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 633 | lpfc_issue_reg_vfi(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 634 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 635 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 636 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 637 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 638 | * 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] | 639 | * @vport: pointer to a host virtual N_Port data structure. |
| 640 | * @ndlp: pointer to a node-list data structure. |
| 641 | * @sp: pointer to service parameter data structure. |
| 642 | * |
| 643 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 644 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 645 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 646 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 647 | * the received N_Port Name lexicographically, this node shall assign local |
| 648 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 649 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 650 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 651 | * N_Port IDs. |
| 652 | * |
| 653 | * Return code |
| 654 | * 0 - Success |
| 655 | * -ENXIO - Fail |
| 656 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 657 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 658 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 659 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 660 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 661 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 662 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 663 | LPFC_MBOXQ_t *mbox; |
| 664 | int rc; |
| 665 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 666 | spin_lock_irq(shost->host_lock); |
| 667 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 668 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 669 | |
| 670 | phba->fc_edtov = FF_DEF_EDTOV; |
| 671 | phba->fc_ratov = FF_DEF_RATOV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 672 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 673 | sizeof(vport->fc_portname)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 674 | if (rc >= 0) { |
| 675 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 676 | spin_lock_irq(shost->host_lock); |
| 677 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 678 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 679 | |
| 680 | /* |
| 681 | * N_Port ID cannot be 0, set our to LocalID the other |
| 682 | * side will be RemoteID. |
| 683 | */ |
| 684 | |
| 685 | /* not equal */ |
| 686 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 687 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 688 | |
| 689 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 690 | if (!mbox) |
| 691 | goto fail; |
| 692 | |
| 693 | lpfc_config_link(phba, mbox); |
| 694 | |
| 695 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 696 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 697 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 698 | if (rc == MBX_NOT_FINISHED) { |
| 699 | mempool_free(mbox, phba->mbox_mem_pool); |
| 700 | goto fail; |
| 701 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 702 | /* Decrement ndlp reference count indicating that ndlp can be |
| 703 | * safely released when other references to it are done. |
| 704 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 705 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 706 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 707 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 708 | if (!ndlp) { |
| 709 | /* |
| 710 | * Cannot find existing Fabric ndlp, so allocate a |
| 711 | * new one |
| 712 | */ |
| 713 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 714 | if (!ndlp) |
| 715 | goto fail; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 716 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 717 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 718 | ndlp = lpfc_enable_node(vport, ndlp, |
| 719 | NLP_STE_UNUSED_NODE); |
| 720 | if(!ndlp) |
| 721 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 725 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 726 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 727 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 728 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 729 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 730 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 731 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 732 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 733 | } else |
| 734 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 735 | * count indicating that ndlp can be released when other |
| 736 | * references to it are done. |
| 737 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 738 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 739 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 740 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 741 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 742 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 743 | spin_lock_irq(shost->host_lock); |
| 744 | vport->fc_flag |= FC_PT2PT; |
| 745 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 746 | |
| 747 | /* Start discovery - this should just do CLEAR_LA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 748 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 749 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 750 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 751 | return -ENXIO; |
| 752 | } |
| 753 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 754 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 755 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 756 | * @phba: pointer to lpfc hba data structure. |
| 757 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 758 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 759 | * |
| 760 | * This routine is the top-level completion callback function for issuing |
| 761 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 762 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 763 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 764 | * returning 1), the command IOCB will be released and function returned. |
| 765 | * If the retry attempt has been given up (possibly reach the maximum |
| 766 | * number of retries), one additional decrement of ndlp reference shall be |
| 767 | * invoked before going out after releasing the command IOCB. This will |
| 768 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 769 | * invoke one decrement of ndlp reference count). If no error reported in |
| 770 | * the IOCB status, the command Port ID field is used to determine whether |
| 771 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 772 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 773 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 774 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 775 | * specific topology completion conditions. |
| 776 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 777 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 778 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 779 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 780 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 781 | struct lpfc_vport *vport = cmdiocb->vport; |
| 782 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 783 | IOCB_t *irsp = &rspiocb->iocb; |
| 784 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 785 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 786 | struct serv_parm *sp; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 787 | uint16_t fcf_index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 788 | int rc; |
| 789 | |
| 790 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 791 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 792 | /* One additional decrement on node reference count to |
| 793 | * trigger the release of the node |
| 794 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 795 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 796 | goto out; |
| 797 | } |
| 798 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 799 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 800 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 801 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 802 | vport->port_state); |
| 803 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 804 | if (irsp->ulpStatus) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 805 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 806 | * In case of FIP mode, perform roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 807 | * due to new FCF discovery |
| 808 | */ |
| 809 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 810 | (phba->fcf.fcf_flag & FCF_DISCOVERY) && |
| 811 | (irsp->ulpStatus != IOSTAT_LOCAL_REJECT) && |
| 812 | (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 813 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 814 | "2611 FLOGI failed on FCF (x%x), " |
| 815 | "status:x%x/x%x, tmo:x%x, perform " |
| 816 | "roundrobin FCF failover\n", |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 817 | phba->fcf.current_rec.fcf_indx, |
| 818 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 819 | irsp->ulpTimeout); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 820 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 821 | rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index); |
| 822 | if (rc) |
| 823 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 824 | } |
| 825 | |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 826 | /* FLOGI failure */ |
| 827 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 828 | "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
| 829 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 830 | irsp->ulpTimeout); |
| 831 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 832 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 833 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 834 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 835 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 836 | /* FLOGI failure */ |
| 837 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 838 | "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
| 839 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 840 | irsp->ulpTimeout); |
| 841 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 842 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 843 | spin_lock_irq(shost->host_lock); |
| 844 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 845 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 846 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 847 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 848 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 849 | * alpa map would take too long otherwise. |
| 850 | */ |
| 851 | if (phba->alpa_map[0] == 0) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 852 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 853 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 854 | (!(vport->fc_flag & FC_VFI_REGISTERED) || |
| 855 | (vport->fc_prevDID != vport->fc_myDID))) { |
| 856 | if (vport->fc_flag & FC_VFI_REGISTERED) |
| 857 | lpfc_sli4_unreg_all_rpis(vport); |
| 858 | lpfc_issue_reg_vfi(vport); |
| 859 | lpfc_nlp_put(ndlp); |
| 860 | goto out; |
| 861 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 862 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 863 | goto flogifail; |
| 864 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 865 | spin_lock_irq(shost->host_lock); |
| 866 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 867 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 868 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 869 | |
| 870 | /* |
| 871 | * The FLogI succeeded. Sync the data for the CPU before |
| 872 | * accessing it. |
| 873 | */ |
| 874 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 875 | |
| 876 | sp = prsp->virt + sizeof(uint32_t); |
| 877 | |
| 878 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 879 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 880 | "0101 FLOGI completes successfully " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 881 | "Data: x%x x%x x%x x%x\n", |
| 882 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
| 883 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 884 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 885 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 886 | /* |
| 887 | * If Common Service Parameters indicate Nport |
| 888 | * we are point to point, if Fport we are Fabric. |
| 889 | */ |
| 890 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 891 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 892 | else if (!(phba->hba_flag & HBA_FCOE_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 893 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 894 | else { |
| 895 | lpfc_printf_vlog(vport, KERN_ERR, |
| 896 | LOG_FIP | LOG_ELS, |
| 897 | "2831 FLOGI response with cleared Fabric " |
| 898 | "bit fcf_index 0x%x " |
| 899 | "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x " |
| 900 | "Fabric Name " |
| 901 | "%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 902 | phba->fcf.current_rec.fcf_indx, |
| 903 | phba->fcf.current_rec.switch_name[0], |
| 904 | phba->fcf.current_rec.switch_name[1], |
| 905 | phba->fcf.current_rec.switch_name[2], |
| 906 | phba->fcf.current_rec.switch_name[3], |
| 907 | phba->fcf.current_rec.switch_name[4], |
| 908 | phba->fcf.current_rec.switch_name[5], |
| 909 | phba->fcf.current_rec.switch_name[6], |
| 910 | phba->fcf.current_rec.switch_name[7], |
| 911 | phba->fcf.current_rec.fabric_name[0], |
| 912 | phba->fcf.current_rec.fabric_name[1], |
| 913 | phba->fcf.current_rec.fabric_name[2], |
| 914 | phba->fcf.current_rec.fabric_name[3], |
| 915 | phba->fcf.current_rec.fabric_name[4], |
| 916 | phba->fcf.current_rec.fabric_name[5], |
| 917 | phba->fcf.current_rec.fabric_name[6], |
| 918 | phba->fcf.current_rec.fabric_name[7]); |
| 919 | lpfc_nlp_put(ndlp); |
| 920 | spin_lock_irq(&phba->hbalock); |
| 921 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 922 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 923 | spin_unlock_irq(&phba->hbalock); |
| 924 | goto out; |
| 925 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 926 | if (!rc) { |
| 927 | /* Mark the FCF discovery process done */ |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 928 | if (phba->hba_flag & HBA_FIP_SUPPORT) |
| 929 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | |
| 930 | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 931 | "2769 FLOGI to FCF (x%x) " |
| 932 | "completed successfully\n", |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 933 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 934 | spin_lock_irq(&phba->hbalock); |
| 935 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 936 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 937 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 938 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 939 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | flogifail: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 943 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 944 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 945 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 946 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 947 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 948 | |
| 949 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 950 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 951 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 952 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && |
| 953 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) && |
| 954 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 955 | /* If FLOGI failed enable link interrupt. */ |
| 956 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 957 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 958 | out: |
| 959 | lpfc_els_free_iocb(phba, cmdiocb); |
| 960 | } |
| 961 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 962 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 963 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 964 | * @vport: pointer to a host virtual N_Port data structure. |
| 965 | * @ndlp: pointer to a node-list data structure. |
| 966 | * @retry: number of retries to the command IOCB. |
| 967 | * |
| 968 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 969 | * for a @vport. The initiator service parameters are put into the payload |
| 970 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 971 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 972 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 973 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 974 | * |
| 975 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 976 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 977 | * will be stored into the context1 field of the IOCB for the completion |
| 978 | * callback function to the FLOGI ELS command. |
| 979 | * |
| 980 | * Return code |
| 981 | * 0 - successfully issued flogi iocb for @vport |
| 982 | * 1 - failed to issue flogi iocb for @vport |
| 983 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 984 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 985 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 986 | uint8_t retry) |
| 987 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 988 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 989 | struct serv_parm *sp; |
| 990 | IOCB_t *icmd; |
| 991 | struct lpfc_iocbq *elsiocb; |
| 992 | struct lpfc_sli_ring *pring; |
| 993 | uint8_t *pcmd; |
| 994 | uint16_t cmdsize; |
| 995 | uint32_t tmo; |
| 996 | int rc; |
| 997 | |
| 998 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 999 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1000 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1001 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1002 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1003 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1004 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1005 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1006 | |
| 1007 | icmd = &elsiocb->iocb; |
| 1008 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1009 | |
| 1010 | /* For FLOGI request, remainder of payload is service parameters */ |
| 1011 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1012 | pcmd += sizeof(uint32_t); |
| 1013 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1014 | sp = (struct serv_parm *) pcmd; |
| 1015 | |
| 1016 | /* Setup CSPs accordingly for Fabric */ |
| 1017 | sp->cmn.e_d_tov = 0; |
| 1018 | sp->cmn.w2.r_a_tov = 0; |
| 1019 | sp->cls1.classValid = 0; |
| 1020 | sp->cls2.seqDelivery = 1; |
| 1021 | sp->cls3.seqDelivery = 1; |
| 1022 | if (sp->cmn.fcphLow < FC_PH3) |
| 1023 | sp->cmn.fcphLow = FC_PH3; |
| 1024 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1025 | sp->cmn.fcphHigh = FC_PH3; |
| 1026 | |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 1027 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1028 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 1029 | LPFC_SLI_INTF_IF_TYPE_0)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1030 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 1031 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 1032 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 1033 | /* Set the fcfi to the fcfi we registered with */ |
| 1034 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 1035 | } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1036 | sp->cmn.request_multiple_Nport = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1037 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 1038 | icmd->ulpCt_h = 1; |
| 1039 | icmd->ulpCt_l = 0; |
| 1040 | } |
| 1041 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1042 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1043 | icmd->un.elsreq64.myID = 0; |
| 1044 | icmd->un.elsreq64.fl = 1; |
| 1045 | } |
| 1046 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1047 | tmo = phba->fc_ratov; |
| 1048 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1049 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1050 | phba->fc_ratov = tmo; |
| 1051 | |
| 1052 | phba->fc_stat.elsXmitFLOGI++; |
| 1053 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1054 | |
| 1055 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1056 | "Issue FLOGI: opt:x%x", |
| 1057 | phba->sli3_options, 0, 0); |
| 1058 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1059 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1060 | if (rc == IOCB_ERROR) { |
| 1061 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1062 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1063 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1064 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1065 | } |
| 1066 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1067 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1068 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1069 | * @phba: pointer to lpfc hba data structure. |
| 1070 | * |
| 1071 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 1072 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 1073 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 1074 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 1075 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 1076 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 1077 | * |
| 1078 | * Return code |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 1079 | * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1080 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1081 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1082 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1083 | { |
| 1084 | struct lpfc_sli_ring *pring; |
| 1085 | struct lpfc_iocbq *iocb, *next_iocb; |
| 1086 | struct lpfc_nodelist *ndlp; |
| 1087 | IOCB_t *icmd; |
| 1088 | |
| 1089 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 1090 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1091 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 1092 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1093 | |
| 1094 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 1095 | |
| 1096 | /* |
| 1097 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 1098 | * searching for. |
| 1099 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1100 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1101 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 1102 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1103 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR && |
| 1104 | icmd->un.elsreq64.bdl.ulpIoTag32) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1105 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1106 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 1107 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1108 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1109 | } |
| 1110 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1111 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1112 | |
| 1113 | return 0; |
| 1114 | } |
| 1115 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1116 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1117 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1118 | * @vport: pointer to a host virtual N_Port data structure. |
| 1119 | * |
| 1120 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 1121 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1122 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1123 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1124 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 1125 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 1126 | * @vport. |
| 1127 | * |
| 1128 | * Return code |
| 1129 | * 0 - failed to issue initial flogi for @vport |
| 1130 | * 1 - successfully issued initial flogi for @vport |
| 1131 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1132 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1133 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1134 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1135 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1136 | struct lpfc_nodelist *ndlp; |
| 1137 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1138 | vport->port_state = LPFC_FLOGI; |
| 1139 | lpfc_set_disctmo(vport); |
| 1140 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1141 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1142 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1143 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1144 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1145 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1146 | if (!ndlp) |
| 1147 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1148 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1149 | /* Set the node type */ |
| 1150 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1151 | /* Put ndlp onto node list */ |
| 1152 | lpfc_enqueue_node(vport, ndlp); |
| 1153 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1154 | /* re-setup ndlp without removing from node list */ |
| 1155 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1156 | if (!ndlp) |
| 1157 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1158 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1159 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1160 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1161 | /* This decrement of reference count to node shall kick off |
| 1162 | * the release of the node. |
| 1163 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1164 | lpfc_nlp_put(ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1165 | return 0; |
| 1166 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1167 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1168 | } |
| 1169 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1170 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1171 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1172 | * @vport: pointer to a host virtual N_Port data structure. |
| 1173 | * |
| 1174 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 1175 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1176 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1177 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1178 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 1179 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 1180 | * @vport. |
| 1181 | * |
| 1182 | * Return code |
| 1183 | * 0 - failed to issue initial fdisc for @vport |
| 1184 | * 1 - successfully issued initial fdisc for @vport |
| 1185 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1186 | int |
| 1187 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 1188 | { |
| 1189 | struct lpfc_hba *phba = vport->phba; |
| 1190 | struct lpfc_nodelist *ndlp; |
| 1191 | |
| 1192 | /* First look for the Fabric ndlp */ |
| 1193 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1194 | if (!ndlp) { |
| 1195 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 1196 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1197 | if (!ndlp) |
| 1198 | return 0; |
| 1199 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1200 | /* Put ndlp onto node list */ |
| 1201 | lpfc_enqueue_node(vport, ndlp); |
| 1202 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1203 | /* re-setup ndlp without removing from node list */ |
| 1204 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1205 | if (!ndlp) |
| 1206 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1207 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1208 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1209 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1210 | /* decrement node reference count to trigger the release of |
| 1211 | * the node. |
| 1212 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1213 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1214 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1215 | } |
| 1216 | return 1; |
| 1217 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1218 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1219 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1220 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1221 | * @vport: pointer to a host virtual N_Port data structure. |
| 1222 | * |
| 1223 | * This routine checks whether there are more remaining Port Logins |
| 1224 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1225 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1226 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1227 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1228 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1229 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1230 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1231 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1232 | { |
| 1233 | int sentplogi; |
| 1234 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1235 | if (vport->num_disc_nodes) |
| 1236 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1237 | |
| 1238 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1239 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1240 | "0232 Continue discovery with %d PLOGIs to go " |
| 1241 | "Data: x%x x%x x%x\n", |
| 1242 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1243 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1244 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1245 | if (vport->fc_flag & FC_NLP_MORE) |
| 1246 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 1247 | sentplogi = lpfc_els_disc_plogi(vport); |
| 1248 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1249 | return; |
| 1250 | } |
| 1251 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1252 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1253 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1254 | * @phba: pointer to lpfc hba data structure. |
| 1255 | * @prsp: pointer to response IOCB payload. |
| 1256 | * @ndlp: pointer to a node-list data structure. |
| 1257 | * |
| 1258 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1259 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1260 | * The following cases are considered N_Port confirmed: |
| 1261 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1262 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1263 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1264 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1265 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1266 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1267 | * on that node to release the RPI associated with the node; 2) if there is |
| 1268 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1269 | * into, a new node shall be allocated (or activated). In either case, the |
| 1270 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1271 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1272 | * its pointer returned as the confirmed node. |
| 1273 | * |
| 1274 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1275 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1276 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1277 | * into an inactive state on the vport node list and the vport node list |
| 1278 | * management algorithm does not allow two node with a same DID. |
| 1279 | * |
| 1280 | * Return code |
| 1281 | * pointer to the PLOGI N_Port @ndlp |
| 1282 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1283 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1284 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1285 | struct lpfc_nodelist *ndlp) |
| 1286 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1287 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1288 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1289 | struct lpfc_rport_data *rdata; |
| 1290 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1291 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1292 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1293 | uint32_t rc, keepDID = 0; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1294 | int put_node; |
| 1295 | int put_rport; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1296 | struct lpfc_node_rrqs rrq; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1297 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1298 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1299 | * by WWPN. Just return the ndlp that was given to us. |
| 1300 | */ |
| 1301 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1302 | return ndlp; |
| 1303 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1304 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1305 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1306 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1307 | /* 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] | 1308 | * we have for that ndlp. If not, we have some work to do. |
| 1309 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1310 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1311 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1312 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1313 | return ndlp; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1314 | memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1315 | |
| 1316 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1317 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1318 | sizeof(struct lpfc_name)); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1319 | if (!rc) |
| 1320 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1321 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
| 1322 | if (!new_ndlp) |
| 1323 | return ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1324 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1325 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1326 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1327 | sizeof(struct lpfc_name)); |
| 1328 | if (!rc) |
| 1329 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1330 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1331 | NLP_STE_UNUSED_NODE); |
| 1332 | if (!new_ndlp) |
| 1333 | return ndlp; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1334 | keepDID = new_ndlp->nlp_DID; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1335 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1336 | memcpy(&rrq.xri_bitmap, |
| 1337 | &new_ndlp->active_rrqs.xri_bitmap, |
| 1338 | sizeof(new_ndlp->active_rrqs.xri_bitmap)); |
| 1339 | } else { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1340 | keepDID = new_ndlp->nlp_DID; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1341 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1342 | memcpy(&rrq.xri_bitmap, |
| 1343 | &new_ndlp->active_rrqs.xri_bitmap, |
| 1344 | sizeof(new_ndlp->active_rrqs.xri_bitmap)); |
| 1345 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1346 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1347 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1348 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1349 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1350 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1351 | memcpy(new_ndlp->active_rrqs.xri_bitmap, |
| 1352 | &ndlp->active_rrqs.xri_bitmap, |
| 1353 | sizeof(ndlp->active_rrqs.xri_bitmap)); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1354 | |
| 1355 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) |
| 1356 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 1357 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 1358 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1359 | /* 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] | 1360 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1361 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1362 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1363 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1364 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1365 | * to put ndlp on UNUSED list and try to free it. |
| 1366 | */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1367 | |
| 1368 | /* Fix up the rport accordingly */ |
| 1369 | rport = ndlp->rport; |
| 1370 | if (rport) { |
| 1371 | rdata = rport->dd_data; |
| 1372 | if (rdata->pnode == ndlp) { |
| 1373 | lpfc_nlp_put(ndlp); |
| 1374 | ndlp->rport = NULL; |
| 1375 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1376 | new_ndlp->rport = rport; |
| 1377 | } |
| 1378 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1379 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1380 | /* We shall actually free the ndlp with both nlp_DID and |
| 1381 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1382 | * nodelist never to be used. |
| 1383 | */ |
| 1384 | if (ndlp->nlp_DID == 0) { |
| 1385 | spin_lock_irq(&phba->ndlp_lock); |
| 1386 | NLP_SET_FREE_REQ(ndlp); |
| 1387 | spin_unlock_irq(&phba->ndlp_lock); |
| 1388 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1389 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1390 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1391 | ndlp->nlp_DID = keepDID; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1392 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1393 | memcpy(&ndlp->active_rrqs.xri_bitmap, |
| 1394 | &rrq.xri_bitmap, |
| 1395 | sizeof(ndlp->active_rrqs.xri_bitmap)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1396 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1397 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1398 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1399 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1400 | /* Two ndlps cannot have the same did */ |
| 1401 | ndlp->nlp_DID = keepDID; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1402 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1403 | memcpy(&ndlp->active_rrqs.xri_bitmap, |
| 1404 | &rrq.xri_bitmap, |
| 1405 | sizeof(ndlp->active_rrqs.xri_bitmap)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1406 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1407 | /* Since we are swapping the ndlp passed in with the new one |
| 1408 | * and the did has already been swapped, copy over the |
| 1409 | * state and names. |
| 1410 | */ |
| 1411 | memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname, |
| 1412 | sizeof(struct lpfc_name)); |
| 1413 | memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename, |
| 1414 | sizeof(struct lpfc_name)); |
| 1415 | new_ndlp->nlp_state = ndlp->nlp_state; |
| 1416 | /* Fix up the rport accordingly */ |
| 1417 | rport = ndlp->rport; |
| 1418 | if (rport) { |
| 1419 | rdata = rport->dd_data; |
| 1420 | put_node = rdata->pnode != NULL; |
| 1421 | put_rport = ndlp->rport != NULL; |
| 1422 | rdata->pnode = NULL; |
| 1423 | ndlp->rport = NULL; |
| 1424 | if (put_node) |
| 1425 | lpfc_nlp_put(ndlp); |
| 1426 | if (put_rport) |
| 1427 | put_device(&rport->dev); |
| 1428 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1429 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1430 | return new_ndlp; |
| 1431 | } |
| 1432 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1433 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1434 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1435 | * @vport: pointer to a host virtual N_Port data structure. |
| 1436 | * |
| 1437 | * This routine checks whether more Registration State Change |
| 1438 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1439 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1440 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1441 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1442 | * handling the RSCNs. |
| 1443 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1444 | void |
| 1445 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1446 | { |
| 1447 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1448 | |
| 1449 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1450 | /* |
| 1451 | * Check to see if more RSCNs came in while we were |
| 1452 | * processing this one. |
| 1453 | */ |
| 1454 | if (vport->fc_rscn_id_cnt || |
| 1455 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1456 | lpfc_els_handle_rscn(vport); |
| 1457 | else { |
| 1458 | spin_lock_irq(shost->host_lock); |
| 1459 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1460 | spin_unlock_irq(shost->host_lock); |
| 1461 | } |
| 1462 | } |
| 1463 | } |
| 1464 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1465 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1466 | * lpfc_cmpl_els_rrq - Completion handled for els RRQs. |
| 1467 | * @phba: pointer to lpfc hba data structure. |
| 1468 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1469 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1470 | * |
| 1471 | * This routine will call the clear rrq function to free the rrq and |
| 1472 | * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not |
| 1473 | * exist then the clear_rrq is still called because the rrq needs to |
| 1474 | * be freed. |
| 1475 | **/ |
| 1476 | |
| 1477 | static void |
| 1478 | lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1479 | struct lpfc_iocbq *rspiocb) |
| 1480 | { |
| 1481 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1482 | IOCB_t *irsp; |
| 1483 | struct lpfc_nodelist *ndlp; |
| 1484 | struct lpfc_node_rrq *rrq; |
| 1485 | |
| 1486 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1487 | rrq = cmdiocb->context_un.rrq; |
| 1488 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1489 | |
| 1490 | irsp = &rspiocb->iocb; |
| 1491 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1492 | "RRQ cmpl: status:x%x/x%x did:x%x", |
| 1493 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1494 | irsp->un.elsreq64.remoteID); |
| 1495 | |
| 1496 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
| 1497 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) { |
| 1498 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1499 | "2882 RRQ completes to NPort x%x " |
| 1500 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1501 | irsp->un.elsreq64.remoteID, |
| 1502 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1503 | irsp->ulpIoTag); |
| 1504 | goto out; |
| 1505 | } |
| 1506 | |
| 1507 | /* rrq completes to NPort <nlp_DID> */ |
| 1508 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1509 | "2880 RRQ completes to NPort x%x " |
| 1510 | "Data: x%x x%x x%x x%x x%x\n", |
| 1511 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1512 | irsp->ulpTimeout, rrq->xritag, rrq->rxid); |
| 1513 | |
| 1514 | if (irsp->ulpStatus) { |
| 1515 | /* Check for retry */ |
| 1516 | /* RRQ 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, |
| 1522 | "2881 RRQ failure DID:%06X Status:x%x/x%x\n", |
| 1523 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1524 | irsp->un.ulpWord[4]); |
| 1525 | } |
| 1526 | out: |
| 1527 | if (rrq) |
| 1528 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 1529 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1530 | return; |
| 1531 | } |
| 1532 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1533 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1534 | * @phba: pointer to lpfc hba data structure. |
| 1535 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1536 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1537 | * |
| 1538 | * This routine is the completion callback function for issuing the Port |
| 1539 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1540 | * ndlp on the vport node list that matches the remote node ID from the |
| 1541 | * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply |
| 1542 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1543 | * checked for error conditons. If there is error status reported, PLOGI |
| 1544 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1545 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1546 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1547 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1548 | * there are additional N_Port nodes with the vport that need to perform |
| 1549 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1550 | * PLOGIs. |
| 1551 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1552 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1553 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1554 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1555 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1556 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1557 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1558 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1559 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1560 | struct lpfc_dmabuf *prsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1561 | int disc, rc, did, type; |
| 1562 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1563 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1564 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1565 | |
| 1566 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1567 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1568 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1569 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1570 | irsp->un.elsreq64.remoteID); |
| 1571 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1572 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1573 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1574 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1575 | "0136 PLOGI completes to NPort x%x " |
| 1576 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1577 | irsp->un.elsreq64.remoteID, |
| 1578 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1579 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1580 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1581 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1582 | |
| 1583 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1584 | * is being used during discovery. |
| 1585 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1586 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1587 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1588 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1589 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1590 | rc = 0; |
| 1591 | |
| 1592 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1593 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1594 | "0102 PLOGI completes to NPort x%x " |
| 1595 | "Data: x%x x%x x%x x%x x%x\n", |
| 1596 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1597 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1598 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1599 | if (lpfc_els_chk_latt(vport)) { |
| 1600 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1601 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1602 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1603 | goto out; |
| 1604 | } |
| 1605 | |
| 1606 | /* ndlp could be freed in DSM, save these values now */ |
| 1607 | type = ndlp->nlp_type; |
| 1608 | did = ndlp->nlp_DID; |
| 1609 | |
| 1610 | if (irsp->ulpStatus) { |
| 1611 | /* Check for retry */ |
| 1612 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1613 | /* ELS command is being retried */ |
| 1614 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1615 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1616 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1617 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1618 | } |
| 1619 | goto out; |
| 1620 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1621 | /* PLOGI failed Don't print the vport to vport rjts */ |
| 1622 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1623 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1624 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1625 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1626 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1627 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", |
| 1628 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1629 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1630 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1631 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1632 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1633 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1634 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1635 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1636 | } else { |
| 1637 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1638 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1639 | cmdiocb->context2)->list.next, |
| 1640 | struct lpfc_dmabuf, list); |
| 1641 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1642 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1643 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1644 | } |
| 1645 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1646 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1647 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1648 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1649 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1650 | if (vport->num_disc_nodes == 0) { |
| 1651 | spin_lock_irq(shost->host_lock); |
| 1652 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1653 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1654 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1655 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1656 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1657 | } |
| 1658 | } |
| 1659 | |
| 1660 | out: |
| 1661 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1662 | return; |
| 1663 | } |
| 1664 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1665 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1666 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1667 | * @vport: pointer to a host virtual N_Port data structure. |
| 1668 | * @did: destination port identifier. |
| 1669 | * @retry: number of retries to the command IOCB. |
| 1670 | * |
| 1671 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1672 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1673 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1674 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1675 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1676 | * |
| 1677 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1678 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1679 | * will be stored into the context1 field of the IOCB for the completion |
| 1680 | * callback function to the PLOGI ELS command. |
| 1681 | * |
| 1682 | * Return code |
| 1683 | * 0 - Successfully issued a plogi for @vport |
| 1684 | * 1 - failed to issue a plogi for @vport |
| 1685 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1686 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1687 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1688 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1689 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1690 | struct serv_parm *sp; |
| 1691 | IOCB_t *icmd; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1692 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1693 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1694 | struct lpfc_sli *psli; |
| 1695 | uint8_t *pcmd; |
| 1696 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1697 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1698 | |
| 1699 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1700 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1701 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1702 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1703 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1704 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1705 | /* 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] | 1706 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1707 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1708 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1709 | if (!elsiocb) |
| 1710 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1711 | |
| 1712 | icmd = &elsiocb->iocb; |
| 1713 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1714 | |
| 1715 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1716 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1717 | pcmd += sizeof(uint32_t); |
| 1718 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1719 | sp = (struct serv_parm *) pcmd; |
| 1720 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1721 | /* |
| 1722 | * If we are a N-port connected to a Fabric, fix-up paramm's so logins |
| 1723 | * to device on remote loops work. |
| 1724 | */ |
| 1725 | if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP)) |
| 1726 | sp->cmn.altBbCredit = 1; |
| 1727 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1728 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1729 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1730 | |
| 1731 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1732 | sp->cmn.fcphHigh = FC_PH3; |
| 1733 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1734 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1735 | "Issue PLOGI: did:x%x", |
| 1736 | did, 0, 0); |
| 1737 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1738 | phba->fc_stat.elsXmitPLOGI++; |
| 1739 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1740 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1741 | |
| 1742 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1743 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1744 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1745 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1746 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1747 | } |
| 1748 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1749 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1750 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1751 | * @phba: pointer to lpfc hba data structure. |
| 1752 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1753 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1754 | * |
| 1755 | * This routine is the completion callback function for a Process Login |
| 1756 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 1757 | * status. If there is error status reported, PRLI retry shall be attempted |
| 1758 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 1759 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 1760 | * ndlp to mark the PRLI completion. |
| 1761 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1762 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1763 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1764 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1765 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1766 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1767 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1768 | IOCB_t *irsp; |
| 1769 | struct lpfc_sli *psli; |
| 1770 | struct lpfc_nodelist *ndlp; |
| 1771 | |
| 1772 | psli = &phba->sli; |
| 1773 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1774 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1775 | |
| 1776 | irsp = &(rspiocb->iocb); |
| 1777 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1778 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1779 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1780 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1781 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1782 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1783 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 1784 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1785 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1786 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1787 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1788 | "0103 PRLI completes to NPort x%x " |
| 1789 | "Data: x%x x%x x%x x%x\n", |
| 1790 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1791 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1792 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1793 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1794 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1795 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1796 | goto out; |
| 1797 | |
| 1798 | if (irsp->ulpStatus) { |
| 1799 | /* Check for retry */ |
| 1800 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1801 | /* ELS command is being retried */ |
| 1802 | goto out; |
| 1803 | } |
| 1804 | /* PRLI failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1805 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1806 | "2754 PRLI failure DID:%06X Status:x%x/x%x\n", |
| 1807 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1808 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1809 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1810 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1811 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1812 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1813 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1814 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1815 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1816 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1817 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1818 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1819 | out: |
| 1820 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1821 | return; |
| 1822 | } |
| 1823 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1824 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1825 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1826 | * @vport: pointer to a host virtual N_Port data structure. |
| 1827 | * @ndlp: pointer to a node-list data structure. |
| 1828 | * @retry: number of retries to the command IOCB. |
| 1829 | * |
| 1830 | * This routine issues a Process Login (PRLI) ELS command for the |
| 1831 | * @vport. The PRLI service parameters are set up in the payload of the |
| 1832 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 1833 | * is put to the IOCB completion callback func field before invoking the |
| 1834 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 1835 | * |
| 1836 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1837 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1838 | * will be stored into the context1 field of the IOCB for the completion |
| 1839 | * callback function to the PRLI ELS command. |
| 1840 | * |
| 1841 | * Return code |
| 1842 | * 0 - successfully issued prli iocb command for @vport |
| 1843 | * 1 - failed to issue prli iocb command for @vport |
| 1844 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1845 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1846 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1847 | uint8_t retry) |
| 1848 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1849 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1850 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1851 | PRLI *npr; |
| 1852 | IOCB_t *icmd; |
| 1853 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1854 | uint8_t *pcmd; |
| 1855 | uint16_t cmdsize; |
| 1856 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1857 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1858 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1859 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1860 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1861 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1862 | |
| 1863 | icmd = &elsiocb->iocb; |
| 1864 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1865 | |
| 1866 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1867 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1868 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1869 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1870 | |
| 1871 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 1872 | npr = (PRLI *) pcmd; |
| 1873 | /* |
| 1874 | * If our firmware version is 3.20 or later, |
| 1875 | * set the following bits for FC-TAPE support. |
| 1876 | */ |
| 1877 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 1878 | npr->ConfmComplAllowed = 1; |
| 1879 | npr->Retry = 1; |
| 1880 | npr->TaskRetryIdReq = 1; |
| 1881 | } |
| 1882 | npr->estabImagePair = 1; |
| 1883 | npr->readXferRdyDis = 1; |
| 1884 | |
| 1885 | /* For FCP support */ |
| 1886 | npr->prliType = PRLI_FCP_TYPE; |
| 1887 | npr->initiatorFunc = 1; |
| 1888 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1889 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1890 | "Issue PRLI: did:x%x", |
| 1891 | ndlp->nlp_DID, 0, 0); |
| 1892 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1893 | phba->fc_stat.elsXmitPRLI++; |
| 1894 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1895 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1896 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1897 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1898 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 1899 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1900 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1901 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1902 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1903 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1904 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1905 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1906 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1907 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1908 | } |
| 1909 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1910 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1911 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1912 | * @vport: pointer to a host virtual N_Port data structure. |
| 1913 | * |
| 1914 | * This routine performs Registration State Change Notification (RSCN) |
| 1915 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 1916 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 1917 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 1918 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 1919 | * invoked to check and handle possible more RSCN came in during the period |
| 1920 | * of processing the current ones. |
| 1921 | **/ |
| 1922 | static void |
| 1923 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 1924 | { |
| 1925 | lpfc_can_disctmo(vport); |
| 1926 | |
| 1927 | /* RSCN discovery */ |
| 1928 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 1929 | if (vport->fc_npr_cnt) |
| 1930 | if (lpfc_els_disc_plogi(vport)) |
| 1931 | return; |
| 1932 | |
| 1933 | lpfc_end_rscn(vport); |
| 1934 | } |
| 1935 | |
| 1936 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1937 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1938 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 1939 | * |
| 1940 | * This function is called when the final ADISC is completed during discovery. |
| 1941 | * This function handles clearing link attention or issuing reg_vpi depending |
| 1942 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 1943 | * discovery. |
| 1944 | * This function is called with no locks held. |
| 1945 | **/ |
| 1946 | static void |
| 1947 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 1948 | { |
| 1949 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1950 | struct lpfc_hba *phba = vport->phba; |
| 1951 | |
| 1952 | /* |
| 1953 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 1954 | * and continue discovery. |
| 1955 | */ |
| 1956 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1957 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 1958 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1959 | lpfc_issue_reg_vpi(phba, vport); |
| 1960 | return; |
| 1961 | } |
| 1962 | /* |
| 1963 | * For SLI2, we need to set port_state to READY |
| 1964 | * and continue discovery. |
| 1965 | */ |
| 1966 | if (vport->port_state < LPFC_VPORT_READY) { |
| 1967 | /* If we get here, there is nothing to ADISC */ |
| 1968 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1969 | lpfc_issue_clear_la(phba, vport); |
| 1970 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 1971 | vport->num_disc_nodes = 0; |
| 1972 | /* go thru NPR list, issue ELS PLOGIs */ |
| 1973 | if (vport->fc_npr_cnt) |
| 1974 | lpfc_els_disc_plogi(vport); |
| 1975 | if (!vport->num_disc_nodes) { |
| 1976 | spin_lock_irq(shost->host_lock); |
| 1977 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1978 | spin_unlock_irq(shost->host_lock); |
| 1979 | lpfc_can_disctmo(vport); |
| 1980 | lpfc_end_rscn(vport); |
| 1981 | } |
| 1982 | } |
| 1983 | vport->port_state = LPFC_VPORT_READY; |
| 1984 | } else |
| 1985 | lpfc_rscn_disc(vport); |
| 1986 | } |
| 1987 | |
| 1988 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1989 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1990 | * @vport: pointer to a host virtual N_Port data structure. |
| 1991 | * |
| 1992 | * This routine determines whether there are more ndlps on a @vport |
| 1993 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 1994 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 1995 | * remaining nodes which need to have ADISC sent. |
| 1996 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1997 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1998 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1999 | { |
| 2000 | int sentadisc; |
| 2001 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2002 | if (vport->num_disc_nodes) |
| 2003 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2004 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2005 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2006 | "0210 Continue discovery with %d ADISCs to go " |
| 2007 | "Data: x%x x%x x%x\n", |
| 2008 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 2009 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2010 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2011 | if (vport->fc_flag & FC_NLP_MORE) { |
| 2012 | lpfc_set_disctmo(vport); |
| 2013 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 2014 | sentadisc = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2015 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2016 | if (!vport->num_disc_nodes) |
| 2017 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2018 | return; |
| 2019 | } |
| 2020 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2021 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2022 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2023 | * @phba: pointer to lpfc hba data structure. |
| 2024 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2025 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2026 | * |
| 2027 | * This routine is the completion function for issuing the Address Discover |
| 2028 | * (ADISC) command. It first checks to see whether link went down during |
| 2029 | * the discovery process. If so, the node will be marked as node port |
| 2030 | * recovery for issuing discover IOCB by the link attention handler and |
| 2031 | * exit. Otherwise, the response status is checked. If error was reported |
| 2032 | * in the response status, the ADISC command shall be retried by invoking |
| 2033 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 2034 | * the response status, the state machine is invoked to set transition |
| 2035 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 2036 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2037 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2038 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2039 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2040 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2041 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2042 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2043 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2044 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2045 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2046 | |
| 2047 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2048 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2049 | |
| 2050 | irsp = &(rspiocb->iocb); |
| 2051 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2052 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2053 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2054 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 2055 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2056 | ndlp->nlp_DID); |
| 2057 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2058 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 2059 | * is being used during discovery. |
| 2060 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2061 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2062 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2063 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2064 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2065 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2066 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2067 | "0104 ADISC completes to NPort x%x " |
| 2068 | "Data: x%x x%x x%x x%x x%x\n", |
| 2069 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2070 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2071 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2072 | if (lpfc_els_chk_latt(vport)) { |
| 2073 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2074 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2075 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2076 | goto out; |
| 2077 | } |
| 2078 | |
| 2079 | if (irsp->ulpStatus) { |
| 2080 | /* Check for retry */ |
| 2081 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2082 | /* ELS command is being retried */ |
| 2083 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2084 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2085 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2086 | spin_unlock_irq(shost->host_lock); |
| 2087 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2088 | } |
| 2089 | goto out; |
| 2090 | } |
| 2091 | /* ADISC failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2092 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2093 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", |
| 2094 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2095 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2096 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2097 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2098 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2099 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2100 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2101 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2102 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2103 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2104 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2105 | /* Check to see if there are more ADISCs to be sent */ |
| 2106 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2107 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2108 | out: |
| 2109 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2110 | return; |
| 2111 | } |
| 2112 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2113 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2114 | * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2115 | * @vport: pointer to a virtual N_Port data structure. |
| 2116 | * @ndlp: pointer to a node-list data structure. |
| 2117 | * @retry: number of retries to the command IOCB. |
| 2118 | * |
| 2119 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 2120 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 2121 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 2122 | * to issue the ADISC ELS command. |
| 2123 | * |
| 2124 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2125 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2126 | * will be stored into the context1 field of the IOCB for the completion |
| 2127 | * callback function to the ADISC ELS command. |
| 2128 | * |
| 2129 | * Return code |
| 2130 | * 0 - successfully issued adisc |
| 2131 | * 1 - failed to issue adisc |
| 2132 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2133 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2134 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2135 | uint8_t retry) |
| 2136 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2137 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2138 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2139 | ADISC *ap; |
| 2140 | IOCB_t *icmd; |
| 2141 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2142 | uint8_t *pcmd; |
| 2143 | uint16_t cmdsize; |
| 2144 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2145 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2146 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2147 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2148 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2149 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2150 | |
| 2151 | icmd = &elsiocb->iocb; |
| 2152 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2153 | |
| 2154 | /* For ADISC request, remainder of payload is service parameters */ |
| 2155 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2156 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2157 | |
| 2158 | /* Fill in ADISC payload */ |
| 2159 | ap = (ADISC *) pcmd; |
| 2160 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2161 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2162 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2163 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2164 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2165 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2166 | "Issue ADISC: did:x%x", |
| 2167 | ndlp->nlp_DID, 0, 0); |
| 2168 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2169 | phba->fc_stat.elsXmitADISC++; |
| 2170 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2171 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2172 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2173 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2174 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2175 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2176 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2177 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2178 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2179 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2180 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2181 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2182 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2183 | } |
| 2184 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2185 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2186 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2187 | * @phba: pointer to lpfc hba data structure. |
| 2188 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2189 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2190 | * |
| 2191 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 2192 | * command. If no error status was reported from the LOGO response, the |
| 2193 | * state machine of the associated ndlp shall be invoked for transition with |
| 2194 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 2195 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 2196 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2197 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2198 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2199 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2200 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2201 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2202 | struct lpfc_vport *vport = ndlp->vport; |
| 2203 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2204 | IOCB_t *irsp; |
| 2205 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2206 | |
| 2207 | psli = &phba->sli; |
| 2208 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2209 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2210 | |
| 2211 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2212 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2213 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2214 | spin_unlock_irq(shost->host_lock); |
| 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 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 2218 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2219 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2220 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2221 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2222 | "0105 LOGO completes to NPort x%x " |
| 2223 | "Data: x%x x%x x%x x%x\n", |
| 2224 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2225 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2226 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2227 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2228 | goto out; |
| 2229 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2230 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 2231 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 2232 | * which should abort all outstanding IOs. |
| 2233 | */ |
| 2234 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2235 | NLP_EVT_DEVICE_RM); |
| 2236 | goto out; |
| 2237 | } |
| 2238 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2239 | if (irsp->ulpStatus) { |
| 2240 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2241 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2242 | /* ELS command is being retried */ |
| 2243 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2244 | /* LOGO failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2245 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2246 | "2756 LOGO failure DID:%06X Status:x%x/x%x\n", |
| 2247 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2248 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2249 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2250 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2251 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2252 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2253 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2254 | NLP_EVT_CMPL_LOGO); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2255 | } else |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2256 | /* Good status, call state machine. |
| 2257 | * This will unregister the rpi if needed. |
| 2258 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2259 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2260 | NLP_EVT_CMPL_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2261 | out: |
| 2262 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2263 | return; |
| 2264 | } |
| 2265 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2266 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2267 | * 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] | 2268 | * @vport: pointer to a virtual N_Port data structure. |
| 2269 | * @ndlp: pointer to a node-list data structure. |
| 2270 | * @retry: number of retries to the command IOCB. |
| 2271 | * |
| 2272 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2273 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2274 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2275 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2276 | * |
| 2277 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2278 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2279 | * will be stored into the context1 field of the IOCB for the completion |
| 2280 | * callback function to the LOGO ELS command. |
| 2281 | * |
| 2282 | * Return code |
| 2283 | * 0 - successfully issued logo |
| 2284 | * 1 - failed to issue logo |
| 2285 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2286 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2287 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2288 | uint8_t retry) |
| 2289 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2290 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2291 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2292 | IOCB_t *icmd; |
| 2293 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2294 | uint8_t *pcmd; |
| 2295 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2296 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2297 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2298 | spin_lock_irq(shost->host_lock); |
| 2299 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2300 | spin_unlock_irq(shost->host_lock); |
| 2301 | return 0; |
| 2302 | } |
| 2303 | spin_unlock_irq(shost->host_lock); |
| 2304 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2305 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2306 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2307 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2308 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2309 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2310 | |
| 2311 | icmd = &elsiocb->iocb; |
| 2312 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2313 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2314 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2315 | |
| 2316 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2317 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2318 | pcmd += sizeof(uint32_t); |
| 2319 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2320 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2321 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2322 | "Issue LOGO: did:x%x", |
| 2323 | ndlp->nlp_DID, 0, 0); |
| 2324 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2325 | phba->fc_stat.elsXmitLOGO++; |
| 2326 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2327 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2328 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2329 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2330 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2331 | |
| 2332 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2333 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2334 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2335 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2336 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2337 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2338 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2339 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2340 | } |
| 2341 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2342 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2343 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2344 | * @phba: pointer to lpfc hba data structure. |
| 2345 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2346 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2347 | * |
| 2348 | * This routine is a generic completion callback function for ELS commands. |
| 2349 | * Specifically, it is the callback function which does not need to perform |
| 2350 | * any command specific operations. It is currently used by the ELS command |
| 2351 | * issuing routines for the ELS State Change Request (SCR), |
| 2352 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 2353 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2354 | * certain debug loggings, this callback function simply invokes the |
| 2355 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2356 | * discovery process. |
| 2357 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2358 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2359 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2360 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2361 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2362 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2363 | IOCB_t *irsp; |
| 2364 | |
| 2365 | irsp = &rspiocb->iocb; |
| 2366 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2367 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2368 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2369 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2370 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2371 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2372 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2373 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2374 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2375 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2376 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2377 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2378 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2379 | return; |
| 2380 | } |
| 2381 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2382 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2383 | * 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] | 2384 | * @vport: pointer to a host virtual N_Port data structure. |
| 2385 | * @nportid: N_Port identifier to the remote node. |
| 2386 | * @retry: number of retries to the command IOCB. |
| 2387 | * |
| 2388 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2389 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2390 | * first search the @vport node list to find the matching ndlp. If no such |
| 2391 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2392 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2393 | * routine is invoked to send the SCR IOCB. |
| 2394 | * |
| 2395 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2396 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2397 | * will be stored into the context1 field of the IOCB for the completion |
| 2398 | * callback function to the SCR ELS command. |
| 2399 | * |
| 2400 | * Return code |
| 2401 | * 0 - Successfully issued scr command |
| 2402 | * 1 - Failed to issue scr command |
| 2403 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2404 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2405 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2406 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2407 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2408 | IOCB_t *icmd; |
| 2409 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2410 | struct lpfc_sli *psli; |
| 2411 | uint8_t *pcmd; |
| 2412 | uint16_t cmdsize; |
| 2413 | struct lpfc_nodelist *ndlp; |
| 2414 | |
| 2415 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2416 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2417 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2418 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2419 | if (!ndlp) { |
| 2420 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2421 | if (!ndlp) |
| 2422 | return 1; |
| 2423 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2424 | lpfc_enqueue_node(vport, ndlp); |
| 2425 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2426 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2427 | if (!ndlp) |
| 2428 | return 1; |
| 2429 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2430 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2431 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2432 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2433 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2434 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2435 | /* This will trigger the release of the node just |
| 2436 | * allocated |
| 2437 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2438 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2439 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | icmd = &elsiocb->iocb; |
| 2443 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2444 | |
| 2445 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2446 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2447 | |
| 2448 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2449 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2450 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2451 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2452 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2453 | "Issue SCR: did:x%x", |
| 2454 | ndlp->nlp_DID, 0, 0); |
| 2455 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2456 | phba->fc_stat.elsXmitSCR++; |
| 2457 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2458 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2459 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2460 | /* The additional lpfc_nlp_put will cause the following |
| 2461 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2462 | * the node. |
| 2463 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2464 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2465 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2466 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2467 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2468 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2469 | * trigger the release of node. |
| 2470 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2471 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2472 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2473 | } |
| 2474 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2475 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2476 | * 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] | 2477 | * @vport: pointer to a host virtual N_Port data structure. |
| 2478 | * @nportid: N_Port identifier to the remote node. |
| 2479 | * @retry: number of retries to the command IOCB. |
| 2480 | * |
| 2481 | * This routine issues a Fibre Channel Address Resolution Response |
| 2482 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2483 | * is passed into the function. It first search the @vport node list to find |
| 2484 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2485 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2486 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2487 | * |
| 2488 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2489 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2490 | * will be stored into the context1 field of the IOCB for the completion |
| 2491 | * callback function to the PARPR ELS command. |
| 2492 | * |
| 2493 | * Return code |
| 2494 | * 0 - Successfully issued farpr command |
| 2495 | * 1 - Failed to issue farpr command |
| 2496 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2497 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2498 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2499 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2500 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2501 | IOCB_t *icmd; |
| 2502 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2503 | struct lpfc_sli *psli; |
| 2504 | FARP *fp; |
| 2505 | uint8_t *pcmd; |
| 2506 | uint32_t *lp; |
| 2507 | uint16_t cmdsize; |
| 2508 | struct lpfc_nodelist *ondlp; |
| 2509 | struct lpfc_nodelist *ndlp; |
| 2510 | |
| 2511 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2512 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2513 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2514 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2515 | if (!ndlp) { |
| 2516 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2517 | if (!ndlp) |
| 2518 | return 1; |
| 2519 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2520 | lpfc_enqueue_node(vport, ndlp); |
| 2521 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2522 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2523 | if (!ndlp) |
| 2524 | return 1; |
| 2525 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2526 | |
| 2527 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2528 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2529 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2530 | /* This will trigger the release of the node just |
| 2531 | * allocated |
| 2532 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2533 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2534 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2535 | } |
| 2536 | |
| 2537 | icmd = &elsiocb->iocb; |
| 2538 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2539 | |
| 2540 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2541 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2542 | |
| 2543 | /* Fill in FARPR payload */ |
| 2544 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2545 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2546 | lp = (uint32_t *) pcmd; |
| 2547 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2548 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2549 | fp->Rflags = 0; |
| 2550 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2551 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2552 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2553 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2554 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2555 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2556 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2557 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2558 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2559 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2560 | } |
| 2561 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2562 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2563 | "Issue FARPR: did:x%x", |
| 2564 | ndlp->nlp_DID, 0, 0); |
| 2565 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2566 | phba->fc_stat.elsXmitFARPR++; |
| 2567 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2568 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2569 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2570 | /* The additional lpfc_nlp_put will cause the following |
| 2571 | * lpfc_els_free_iocb routine to trigger the release of |
| 2572 | * the node. |
| 2573 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2574 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2575 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2576 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2577 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2578 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2579 | * trigger the release of the node. |
| 2580 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2581 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2582 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2583 | } |
| 2584 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2585 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2586 | * 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] | 2587 | * @vport: pointer to a host virtual N_Port data structure. |
| 2588 | * @nlp: pointer to a node-list data structure. |
| 2589 | * |
| 2590 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2591 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2592 | * removes the ELS retry event if it presents. In addition, if the |
| 2593 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2594 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2595 | * ADISC. |
| 2596 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2597 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2598 | 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] | 2599 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2600 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2601 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2602 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2603 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2604 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2605 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2606 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2607 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2608 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2609 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2610 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2611 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2612 | /* Decrement nlp reference count held for the delayed retry */ |
| 2613 | evtp = &nlp->els_retry_evt; |
| 2614 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2615 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2616 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2617 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2618 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2619 | spin_unlock_irq(shost->host_lock); |
| 2620 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2621 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2622 | /* Check if there are more ADISCs to be sent */ |
| 2623 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2624 | } else { |
| 2625 | /* Check if there are more PLOGIs to be sent */ |
| 2626 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2627 | if (vport->num_disc_nodes == 0) { |
| 2628 | spin_lock_irq(shost->host_lock); |
| 2629 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2630 | spin_unlock_irq(shost->host_lock); |
| 2631 | lpfc_can_disctmo(vport); |
| 2632 | lpfc_end_rscn(vport); |
| 2633 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2634 | } |
| 2635 | } |
| 2636 | } |
| 2637 | return; |
| 2638 | } |
| 2639 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2640 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2641 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2642 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2643 | * |
| 2644 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2645 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2646 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2647 | * adds the delayed events to the HBA work list and invokes the |
| 2648 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2649 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2650 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2651 | * reference to ndlp will still be available when the worker thread gets |
| 2652 | * to the event associated with the ndlp. |
| 2653 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2654 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2655 | lpfc_els_retry_delay(unsigned long ptr) |
| 2656 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2657 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2658 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2659 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2660 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2661 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2662 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2663 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2664 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2665 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2666 | return; |
| 2667 | } |
| 2668 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2669 | /* We need to hold the node by incrementing the reference |
| 2670 | * count until the queued work is done |
| 2671 | */ |
| 2672 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2673 | if (evtp->evt_arg1) { |
| 2674 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2675 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2676 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2677 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2678 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2679 | return; |
| 2680 | } |
| 2681 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2682 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2683 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2684 | * @ndlp: pointer to a node-list data structure. |
| 2685 | * |
| 2686 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 2687 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 2688 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 2689 | * function according to the delayed ELS command to retry the command. |
| 2690 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2691 | void |
| 2692 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 2693 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2694 | struct lpfc_vport *vport = ndlp->vport; |
| 2695 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2696 | uint32_t cmd, did, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2697 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2698 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2699 | did = ndlp->nlp_DID; |
| 2700 | cmd = ndlp->nlp_last_elscmd; |
| 2701 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2702 | |
| 2703 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2704 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2705 | return; |
| 2706 | } |
| 2707 | |
| 2708 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2709 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 2710 | /* |
| 2711 | * If a discovery event readded nlp_delayfunc after timer |
| 2712 | * firing and before processing the timer, cancel the |
| 2713 | * nlp_delayfunc. |
| 2714 | */ |
| 2715 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2716 | retry = ndlp->nlp_retry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 2717 | ndlp->nlp_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2718 | |
| 2719 | switch (cmd) { |
| 2720 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2721 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2722 | break; |
| 2723 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2724 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2725 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2726 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2727 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2728 | break; |
| 2729 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2730 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2731 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2732 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2733 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2734 | break; |
| 2735 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2736 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2737 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2738 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2739 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2740 | break; |
| 2741 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2742 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2743 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2744 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2745 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2746 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2747 | case ELS_CMD_FDISC: |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame^] | 2748 | if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)) |
| 2749 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2750 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2751 | } |
| 2752 | return; |
| 2753 | } |
| 2754 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2755 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2756 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2757 | * @phba: pointer to lpfc hba data structure. |
| 2758 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2759 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2760 | * |
| 2761 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 2762 | * failed. The following ELS IOCBs use this function for retrying the command |
| 2763 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 2764 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 2765 | * returned error status, it makes the decision whether a retry shall be |
| 2766 | * issued for the command, and whether a retry shall be made immediately or |
| 2767 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 2768 | * is called to retry the command. In the later case, the ELS command shall |
| 2769 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 2770 | * ndlp for the delayed command issusing. |
| 2771 | * |
| 2772 | * Return code |
| 2773 | * 0 - No retry of els command is made |
| 2774 | * 1 - Immediate or delayed retry of els command is made |
| 2775 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2776 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2777 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2778 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2779 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2780 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2781 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2782 | IOCB_t *irsp = &rspiocb->iocb; |
| 2783 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2784 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2785 | uint32_t *elscmd; |
| 2786 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2787 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2788 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2789 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2790 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2791 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2792 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2793 | /* Note: context2 may be 0 for internal driver abort |
| 2794 | * of delays ELS command. |
| 2795 | */ |
| 2796 | |
| 2797 | if (pcmd && pcmd->virt) { |
| 2798 | elscmd = (uint32_t *) (pcmd->virt); |
| 2799 | cmd = *elscmd++; |
| 2800 | } |
| 2801 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2802 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2803 | did = ndlp->nlp_DID; |
| 2804 | else { |
| 2805 | /* We should only hit this case for retrying PLOGI */ |
| 2806 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2807 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2808 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 2809 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2810 | return 1; |
| 2811 | } |
| 2812 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2813 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2814 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 2815 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 2816 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2817 | switch (irsp->ulpStatus) { |
| 2818 | case IOSTAT_FCP_RSP_ERROR: |
| 2819 | case IOSTAT_REMOTE_STOP: |
| 2820 | break; |
| 2821 | |
| 2822 | case IOSTAT_LOCAL_REJECT: |
| 2823 | switch ((irsp->un.ulpWord[4] & 0xff)) { |
| 2824 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2825 | if (cmd == ELS_CMD_FLOGI) { |
| 2826 | if (PCI_DEVICE_ID_HORNET == |
| 2827 | phba->pcidev->device) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2828 | phba->fc_topology = LPFC_TOPOLOGY_LOOP; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2829 | phba->pport->fc_myDID = 0; |
| 2830 | phba->alpa_map[0] = 0; |
| 2831 | phba->alpa_map[1] = 0; |
| 2832 | } |
| 2833 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2834 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2835 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2836 | retry = 1; |
| 2837 | break; |
| 2838 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2839 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2840 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2841 | "0124 Retry illegal cmd x%x " |
| 2842 | "retry:x%x delay:x%x\n", |
| 2843 | cmd, cmdiocb->retry, delay); |
| 2844 | retry = 1; |
| 2845 | /* All command's retry policy */ |
| 2846 | maxretry = 8; |
| 2847 | if (cmdiocb->retry > 2) |
| 2848 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2849 | break; |
| 2850 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2851 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2852 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2853 | retry = 1; |
| 2854 | if (cmdiocb->retry > 100) |
| 2855 | delay = 100; |
| 2856 | maxretry = 250; |
| 2857 | break; |
| 2858 | |
| 2859 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2860 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2861 | retry = 1; |
| 2862 | break; |
| 2863 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2864 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2865 | case IOERR_INVALID_RPI: |
| 2866 | retry = 1; |
| 2867 | break; |
| 2868 | } |
| 2869 | break; |
| 2870 | |
| 2871 | case IOSTAT_NPORT_RJT: |
| 2872 | case IOSTAT_FABRIC_RJT: |
| 2873 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 2874 | retry = 1; |
| 2875 | break; |
| 2876 | } |
| 2877 | break; |
| 2878 | |
| 2879 | case IOSTAT_NPORT_BSY: |
| 2880 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2881 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2882 | retry = 1; |
| 2883 | break; |
| 2884 | |
| 2885 | case IOSTAT_LS_RJT: |
| 2886 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 2887 | /* Added for Vendor specifc support |
| 2888 | * Just keep retrying for these Rsn / Exp codes |
| 2889 | */ |
| 2890 | switch (stat.un.b.lsRjtRsnCode) { |
| 2891 | case LSRJT_UNABLE_TPC: |
| 2892 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2893 | LSEXP_CMD_IN_PROGRESS) { |
| 2894 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2895 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2896 | maxretry = 48; |
| 2897 | } |
| 2898 | retry = 1; |
| 2899 | break; |
| 2900 | } |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 2901 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2902 | LSEXP_CANT_GIVE_DATA) { |
| 2903 | if (cmd == ELS_CMD_PLOGI) { |
| 2904 | delay = 1000; |
| 2905 | maxretry = 48; |
| 2906 | } |
| 2907 | retry = 1; |
| 2908 | break; |
| 2909 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2910 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2911 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2912 | maxretry = lpfc_max_els_tries + 1; |
| 2913 | retry = 1; |
| 2914 | break; |
| 2915 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2916 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2917 | (cmd == ELS_CMD_FDISC) && |
| 2918 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2919 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2920 | "0125 FDISC Failed (x%x). " |
| 2921 | "Fabric out of resources\n", |
| 2922 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2923 | lpfc_vport_set_state(vport, |
| 2924 | FC_VPORT_NO_FABRIC_RSCS); |
| 2925 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2926 | break; |
| 2927 | |
| 2928 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2929 | if ((cmd == ELS_CMD_PLOGI) || |
| 2930 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2931 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2932 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2933 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2934 | /* FDISC retry policy */ |
| 2935 | maxretry = 48; |
| 2936 | if (cmdiocb->retry >= 32) |
| 2937 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2938 | } |
| 2939 | retry = 1; |
| 2940 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2941 | |
| 2942 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2943 | /* There are some cases where switches return this |
| 2944 | * error when they are not ready and should be returning |
| 2945 | * Logical Busy. We should delay every time. |
| 2946 | */ |
| 2947 | if (cmd == ELS_CMD_FDISC && |
| 2948 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 2949 | maxretry = 3; |
| 2950 | delay = 1000; |
| 2951 | retry = 1; |
| 2952 | break; |
| 2953 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2954 | case LSRJT_PROTOCOL_ERR: |
| 2955 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2956 | (cmd == ELS_CMD_FDISC) && |
| 2957 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 2958 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 2959 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2960 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2961 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2962 | "Fabric Detected Bad WWN\n", |
| 2963 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2964 | lpfc_vport_set_state(vport, |
| 2965 | FC_VPORT_FABRIC_REJ_WWN); |
| 2966 | } |
| 2967 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2968 | } |
| 2969 | break; |
| 2970 | |
| 2971 | case IOSTAT_INTERMED_RSP: |
| 2972 | case IOSTAT_BA_RJT: |
| 2973 | break; |
| 2974 | |
| 2975 | default: |
| 2976 | break; |
| 2977 | } |
| 2978 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2979 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2980 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2981 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2982 | if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) && |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2983 | (phba->fc_topology != LPFC_TOPOLOGY_LOOP) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 2984 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2985 | /* FLOGI retry policy */ |
| 2986 | retry = 1; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2987 | /* retry forever */ |
| 2988 | maxretry = 0; |
| 2989 | if (cmdiocb->retry >= 100) |
| 2990 | delay = 5000; |
| 2991 | else if (cmdiocb->retry >= 32) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2992 | delay = 1000; |
| 2993 | } |
| 2994 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2995 | cmdiocb->retry++; |
| 2996 | if (maxretry && (cmdiocb->retry >= maxretry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2997 | phba->fc_stat.elsRetryExceeded++; |
| 2998 | retry = 0; |
| 2999 | } |
| 3000 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3001 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 3002 | retry = 0; |
| 3003 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3004 | if (retry) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3005 | if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) { |
| 3006 | /* Stop retrying PLOGI and FDISC if in FCF discovery */ |
| 3007 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 3008 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3009 | "2849 Stop retry ELS command " |
| 3010 | "x%x to remote NPORT x%x, " |
| 3011 | "Data: x%x x%x\n", cmd, did, |
| 3012 | cmdiocb->retry, delay); |
| 3013 | return 0; |
| 3014 | } |
| 3015 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3016 | |
| 3017 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3018 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3019 | "0107 Retry ELS command x%x to remote " |
| 3020 | "NPORT x%x Data: x%x x%x\n", |
| 3021 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3022 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3023 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 3024 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 3025 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { |
| 3026 | /* Don't reset timer for no resources */ |
| 3027 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3028 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3029 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3030 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3031 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3032 | } |
| 3033 | |
| 3034 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3035 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3036 | phba->fc_stat.elsDelayRetry++; |
| 3037 | ndlp->nlp_retry = cmdiocb->retry; |
| 3038 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3039 | /* delay is specified in milliseconds */ |
| 3040 | mod_timer(&ndlp->nlp_delayfunc, |
| 3041 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3042 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3043 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3044 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3045 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3046 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3047 | if (cmd == ELS_CMD_PRLI) |
| 3048 | lpfc_nlp_set_state(vport, ndlp, |
| 3049 | NLP_STE_REG_LOGIN_ISSUE); |
| 3050 | else |
| 3051 | lpfc_nlp_set_state(vport, ndlp, |
| 3052 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3053 | ndlp->nlp_last_elscmd = cmd; |
| 3054 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3055 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3056 | } |
| 3057 | switch (cmd) { |
| 3058 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3059 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3060 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3061 | case ELS_CMD_FDISC: |
| 3062 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 3063 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3064 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3065 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3066 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3067 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3068 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3069 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3070 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3071 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3072 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3073 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3074 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 3075 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3076 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3077 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3078 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3079 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 3080 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3081 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3082 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3083 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3084 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 3085 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3086 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3087 | } |
| 3088 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3089 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3090 | if (logerr) { |
| 3091 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3092 | "0137 No retry ELS command x%x to remote " |
| 3093 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 3094 | cmd, did, irsp->ulpStatus, |
| 3095 | irsp->un.ulpWord[4]); |
| 3096 | } |
| 3097 | else { |
| 3098 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3099 | "0108 No retry ELS command x%x to remote " |
| 3100 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 3101 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 3102 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3103 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3104 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3105 | } |
| 3106 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3107 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3108 | * 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] | 3109 | * @phba: pointer to lpfc hba data structure. |
| 3110 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 3111 | * |
| 3112 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 3113 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 3114 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 3115 | * response of the command IOCB. If so, it will be released before releasing |
| 3116 | * the lpfc DMA buffer associated with the IOCB itself. |
| 3117 | * |
| 3118 | * Return code |
| 3119 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3120 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3121 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3122 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 3123 | { |
| 3124 | struct lpfc_dmabuf *buf_ptr; |
| 3125 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3126 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3127 | if (!list_empty(&buf_ptr1->list)) { |
| 3128 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 3129 | struct lpfc_dmabuf, |
| 3130 | list); |
| 3131 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3132 | kfree(buf_ptr); |
| 3133 | } |
| 3134 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 3135 | kfree(buf_ptr1); |
| 3136 | return 0; |
| 3137 | } |
| 3138 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3139 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3140 | * 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] | 3141 | * @phba: pointer to lpfc hba data structure. |
| 3142 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 3143 | * |
| 3144 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 3145 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 3146 | * pool. |
| 3147 | * |
| 3148 | * Return code |
| 3149 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3150 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3151 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3152 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 3153 | { |
| 3154 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3155 | kfree(buf_ptr); |
| 3156 | return 0; |
| 3157 | } |
| 3158 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3159 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3160 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3161 | * @phba: pointer to lpfc hba data structure. |
| 3162 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 3163 | * |
| 3164 | * This routine frees a command IOCB and its associated resources. The |
| 3165 | * command IOCB data structure contains the reference to various associated |
| 3166 | * resources, these fields must be set to NULL if the associated reference |
| 3167 | * not present: |
| 3168 | * context1 - reference to ndlp |
| 3169 | * context2 - reference to cmd |
| 3170 | * context2->next - reference to rsp |
| 3171 | * context3 - reference to bpl |
| 3172 | * |
| 3173 | * It first properly decrements the reference count held on ndlp for the |
| 3174 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 3175 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 3176 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 3177 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 3178 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 3179 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 3180 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 3181 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 3182 | * |
| 3183 | * Return code |
| 3184 | * 0 - Success (currently, always return 0) |
| 3185 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3186 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3187 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3188 | { |
| 3189 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3190 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3191 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3192 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 3193 | if (ndlp) { |
| 3194 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 3195 | lpfc_nlp_put(ndlp); |
| 3196 | |
| 3197 | /* If the ndlp is not being used by another discovery |
| 3198 | * thread, free it. |
| 3199 | */ |
| 3200 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3201 | /* If ndlp is being used by another discovery |
| 3202 | * thread, just clear NLP_DEFER_RM |
| 3203 | */ |
| 3204 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 3205 | } |
| 3206 | } |
| 3207 | else |
| 3208 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3209 | elsiocb->context1 = NULL; |
| 3210 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3211 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 3212 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3213 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 3214 | /* Firmware could still be in progress of DMAing |
| 3215 | * payload, so don't free data buffer till after |
| 3216 | * a hbeat. |
| 3217 | */ |
| 3218 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 3219 | buf_ptr = elsiocb->context2; |
| 3220 | elsiocb->context2 = NULL; |
| 3221 | if (buf_ptr) { |
| 3222 | buf_ptr1 = NULL; |
| 3223 | spin_lock_irq(&phba->hbalock); |
| 3224 | if (!list_empty(&buf_ptr->list)) { |
| 3225 | list_remove_head(&buf_ptr->list, |
| 3226 | buf_ptr1, struct lpfc_dmabuf, |
| 3227 | list); |
| 3228 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 3229 | list_add_tail(&buf_ptr1->list, |
| 3230 | &phba->elsbuf); |
| 3231 | phba->elsbuf_cnt++; |
| 3232 | } |
| 3233 | INIT_LIST_HEAD(&buf_ptr->list); |
| 3234 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 3235 | phba->elsbuf_cnt++; |
| 3236 | spin_unlock_irq(&phba->hbalock); |
| 3237 | } |
| 3238 | } else { |
| 3239 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 3240 | lpfc_els_free_data(phba, buf_ptr1); |
| 3241 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3242 | } |
| 3243 | |
| 3244 | if (elsiocb->context3) { |
| 3245 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3246 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3247 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3248 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3249 | return 0; |
| 3250 | } |
| 3251 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3252 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3253 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3254 | * @phba: pointer to lpfc hba data structure. |
| 3255 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3256 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3257 | * |
| 3258 | * This routine is the completion callback function to the Logout (LOGO) |
| 3259 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 3260 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 3261 | * release the ndlp if it has the last reference remaining (reference count |
| 3262 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 3263 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 3264 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 3265 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 3266 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 3267 | * IOCB data structure. |
| 3268 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3269 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3270 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3271 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3272 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3273 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3274 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3275 | IOCB_t *irsp; |
| 3276 | |
| 3277 | irsp = &rspiocb->iocb; |
| 3278 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3279 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 3280 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3281 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3282 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3283 | "0109 ACC to LOGO completes to NPort x%x " |
| 3284 | "Data: x%x x%x x%x\n", |
| 3285 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3286 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3287 | |
| 3288 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 3289 | /* NPort Recovery mode or node is just allocated */ |
| 3290 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3291 | /* If the ndlp is being used by another discovery |
| 3292 | * thread, just unregister the RPI. |
| 3293 | */ |
| 3294 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3295 | } else { |
| 3296 | /* Indicate the node has already released, should |
| 3297 | * not reference to it from within lpfc_els_free_iocb. |
| 3298 | */ |
| 3299 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3300 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3301 | } |
| 3302 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3303 | return; |
| 3304 | } |
| 3305 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3306 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3307 | * 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] | 3308 | * @phba: pointer to lpfc hba data structure. |
| 3309 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 3310 | * |
| 3311 | * This routine is the completion callback function for unregister default |
| 3312 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 3313 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 3314 | * decrements the ndlp reference count held for this completion callback |
| 3315 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 3316 | * whether there is only one reference left on the ndlp. If so, it will |
| 3317 | * perform one more decrement and trigger the release of the ndlp. |
| 3318 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3319 | void |
| 3320 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3321 | { |
| 3322 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3323 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3324 | |
| 3325 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3326 | pmb->context2 = NULL; |
| 3327 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3328 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3329 | kfree(mp); |
| 3330 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3331 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3332 | lpfc_nlp_put(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3333 | /* This is the end of the default RPI cleanup logic for this |
| 3334 | * ndlp. If no other discovery threads are using this ndlp. |
| 3335 | * we should free all resources associated with it. |
| 3336 | */ |
| 3337 | lpfc_nlp_not_used(ndlp); |
| 3338 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3339 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3340 | return; |
| 3341 | } |
| 3342 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3343 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3344 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3345 | * @phba: pointer to lpfc hba data structure. |
| 3346 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3347 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3348 | * |
| 3349 | * This routine is the completion callback function for ELS Response IOCB |
| 3350 | * command. In normal case, this callback function just properly sets the |
| 3351 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 3352 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 3353 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 3354 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 3355 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 3356 | * routine shall be invoked trying to release the ndlp if no other threads |
| 3357 | * are currently referring it. |
| 3358 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3359 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3360 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3361 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3362 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3363 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3364 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 3365 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3366 | IOCB_t *irsp; |
| 3367 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3368 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3369 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3370 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3371 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3372 | irsp = &rspiocb->iocb; |
| 3373 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3374 | if (cmdiocb->context_un.mbox) |
| 3375 | mbox = cmdiocb->context_un.mbox; |
| 3376 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3377 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 3378 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 3379 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3380 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3381 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3382 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3383 | /* A LS_RJT associated with Default RPI cleanup has its own |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 3384 | * separate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3385 | */ |
| 3386 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 3387 | ls_rjt = 1; |
| 3388 | } |
| 3389 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3390 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3391 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3392 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3393 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3394 | if (mp) { |
| 3395 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3396 | kfree(mp); |
| 3397 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3398 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3399 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3400 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3401 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3402 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3403 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3404 | /* Indicate the node has already released, |
| 3405 | * should not reference to it from within |
| 3406 | * the routine lpfc_els_free_iocb. |
| 3407 | */ |
| 3408 | cmdiocb->context1 = NULL; |
| 3409 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3410 | goto out; |
| 3411 | } |
| 3412 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3413 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3414 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3415 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3416 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3417 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3418 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3419 | "0110 ELS response tag x%x completes " |
| 3420 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3421 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3422 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3423 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3424 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3425 | if (mbox) { |
| 3426 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3427 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3428 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3429 | /* Increment reference count to ndlp to hold the |
| 3430 | * reference to ndlp for the callback function. |
| 3431 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3432 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3433 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3434 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3435 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3436 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3437 | } |
| 3438 | else { |
| 3439 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3440 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3441 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3442 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3443 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3444 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3445 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3446 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3447 | else |
| 3448 | /* Decrement the ndlp reference count we |
| 3449 | * set for this failed mailbox command. |
| 3450 | */ |
| 3451 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3452 | |
| 3453 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3454 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3455 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3456 | "Data: x%x x%x x%x\n", |
| 3457 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3458 | ndlp->nlp_rpi); |
| 3459 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3460 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3461 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3462 | /* Indicate node has already been released, |
| 3463 | * should not reference to it from within |
| 3464 | * the routine lpfc_els_free_iocb. |
| 3465 | */ |
| 3466 | cmdiocb->context1 = NULL; |
| 3467 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3468 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3469 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3470 | if (!lpfc_error_lost_link(irsp) && |
| 3471 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3472 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3473 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3474 | /* Indicate node has already been |
| 3475 | * released, should not reference |
| 3476 | * to it from within the routine |
| 3477 | * lpfc_els_free_iocb. |
| 3478 | */ |
| 3479 | cmdiocb->context1 = NULL; |
| 3480 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3481 | } |
| 3482 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3483 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3484 | if (mp) { |
| 3485 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3486 | kfree(mp); |
| 3487 | } |
| 3488 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3489 | } |
| 3490 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3491 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3492 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3493 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3494 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3495 | |
| 3496 | /* If the node is not being used by another discovery thread, |
| 3497 | * and we are sending a reject, we are done with it. |
| 3498 | * Release driver reference count here and free associated |
| 3499 | * resources. |
| 3500 | */ |
| 3501 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3502 | if (lpfc_nlp_not_used(ndlp)) |
| 3503 | /* Indicate node has already been released, |
| 3504 | * should not reference to it from within |
| 3505 | * the routine lpfc_els_free_iocb. |
| 3506 | */ |
| 3507 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3508 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3509 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3510 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3511 | return; |
| 3512 | } |
| 3513 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3514 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3515 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3516 | * @vport: pointer to a host virtual N_Port data structure. |
| 3517 | * @flag: the els command code to be accepted. |
| 3518 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3519 | * @ndlp: pointer to a node-list data structure. |
| 3520 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3521 | * |
| 3522 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3523 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3524 | * specific ACC response command to be issued and invokes the |
| 3525 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3526 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3527 | * field of the IOCB for the completion callback function to issue the |
| 3528 | * mailbox command to the HBA later when callback is invoked. |
| 3529 | * |
| 3530 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3531 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3532 | * will be stored into the context1 field of the IOCB for the completion |
| 3533 | * callback function to the corresponding response ELS IOCB command. |
| 3534 | * |
| 3535 | * Return code |
| 3536 | * 0 - Successfully issued acc response |
| 3537 | * 1 - Failed to issue acc response |
| 3538 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3539 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3540 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3541 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3542 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3543 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3544 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3545 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3546 | IOCB_t *icmd; |
| 3547 | IOCB_t *oldcmd; |
| 3548 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3549 | struct lpfc_sli *psli; |
| 3550 | uint8_t *pcmd; |
| 3551 | uint16_t cmdsize; |
| 3552 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3553 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3554 | |
| 3555 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3556 | oldcmd = &oldiocb->iocb; |
| 3557 | |
| 3558 | switch (flag) { |
| 3559 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3560 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3561 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3562 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3563 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3564 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3565 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3566 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3567 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3568 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3569 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3570 | icmd = &elsiocb->iocb; |
| 3571 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3572 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3573 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3574 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3575 | |
| 3576 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3577 | "Issue ACC: did:x%x flg:x%x", |
| 3578 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3579 | break; |
| 3580 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3581 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3582 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3583 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3584 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3585 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3586 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3587 | icmd = &elsiocb->iocb; |
| 3588 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3589 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3590 | |
| 3591 | if (mbox) |
| 3592 | elsiocb->context_un.mbox = mbox; |
| 3593 | |
| 3594 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3595 | pcmd += sizeof(uint32_t); |
| 3596 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3597 | |
| 3598 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3599 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 3600 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3601 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3602 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3603 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3604 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3605 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3606 | if (!elsiocb) |
| 3607 | return 1; |
| 3608 | |
| 3609 | icmd = &elsiocb->iocb; |
| 3610 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3611 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3612 | |
| 3613 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3614 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3615 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 3616 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 3617 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3618 | |
| 3619 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3620 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 3621 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3622 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3623 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3624 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3625 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3626 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3627 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3628 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
| 3629 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", |
| 3630 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3631 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3632 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3633 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3634 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3635 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3636 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3637 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 3638 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3639 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3640 | } |
| 3641 | |
| 3642 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3643 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3644 | if (rc == IOCB_ERROR) { |
| 3645 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3646 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3647 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3648 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3649 | } |
| 3650 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3651 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3652 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3653 | * @vport: pointer to a virtual N_Port data structure. |
| 3654 | * @rejectError: |
| 3655 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3656 | * @ndlp: pointer to a node-list data structure. |
| 3657 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3658 | * |
| 3659 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 3660 | * command. If a @mbox pointer is passed in, it will be put into the |
| 3661 | * context_un.mbox field of the IOCB for the completion callback function |
| 3662 | * to issue to the HBA later. |
| 3663 | * |
| 3664 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3665 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3666 | * will be stored into the context1 field of the IOCB for the completion |
| 3667 | * callback function to the reject response ELS IOCB command. |
| 3668 | * |
| 3669 | * Return code |
| 3670 | * 0 - Successfully issued reject response |
| 3671 | * 1 - Failed to issue reject response |
| 3672 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3673 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3674 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3675 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 3676 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3677 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3678 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3679 | IOCB_t *icmd; |
| 3680 | IOCB_t *oldcmd; |
| 3681 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3682 | struct lpfc_sli *psli; |
| 3683 | uint8_t *pcmd; |
| 3684 | uint16_t cmdsize; |
| 3685 | int rc; |
| 3686 | |
| 3687 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3688 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3689 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3690 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3691 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3692 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3693 | |
| 3694 | icmd = &elsiocb->iocb; |
| 3695 | oldcmd = &oldiocb->iocb; |
| 3696 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3697 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3698 | |
| 3699 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3700 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3701 | *((uint32_t *) (pcmd)) = rejectError; |
| 3702 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3703 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3704 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3705 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3706 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3707 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3708 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 3709 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 3710 | "rpi x%x\n", |
| 3711 | rejectError, elsiocb->iotag, |
| 3712 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 3713 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3714 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3715 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 3716 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 3717 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3718 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3719 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3720 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3721 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3722 | if (rc == IOCB_ERROR) { |
| 3723 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3724 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3725 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3726 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3727 | } |
| 3728 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3729 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3730 | * 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] | 3731 | * @vport: pointer to a virtual N_Port data structure. |
| 3732 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3733 | * @ndlp: pointer to a node-list data structure. |
| 3734 | * |
| 3735 | * This routine prepares and issues an Accept (ACC) response to Address |
| 3736 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 3737 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3738 | * |
| 3739 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3740 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3741 | * will be stored into the context1 field of the IOCB for the completion |
| 3742 | * callback function to the ADISC Accept response ELS IOCB command. |
| 3743 | * |
| 3744 | * Return code |
| 3745 | * 0 - Successfully issued acc adisc response |
| 3746 | * 1 - Failed to issue adisc acc response |
| 3747 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3748 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3749 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 3750 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3751 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3752 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3753 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3754 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3755 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3756 | uint8_t *pcmd; |
| 3757 | uint16_t cmdsize; |
| 3758 | int rc; |
| 3759 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3760 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3761 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3762 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3763 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3764 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3765 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3766 | icmd = &elsiocb->iocb; |
| 3767 | oldcmd = &oldiocb->iocb; |
| 3768 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3769 | |
| 3770 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3771 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3772 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 3773 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 3774 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3775 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3776 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3777 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3778 | |
| 3779 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3780 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3781 | |
| 3782 | ap = (ADISC *) (pcmd); |
| 3783 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3784 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3785 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3786 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3787 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3788 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3789 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 3790 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3791 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3792 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3793 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3794 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3795 | if (rc == IOCB_ERROR) { |
| 3796 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3797 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3798 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3799 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3800 | } |
| 3801 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3802 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3803 | * 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] | 3804 | * @vport: pointer to a virtual N_Port data structure. |
| 3805 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3806 | * @ndlp: pointer to a node-list data structure. |
| 3807 | * |
| 3808 | * This routine prepares and issues an Accept (ACC) response to Process |
| 3809 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 3810 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3811 | * |
| 3812 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3813 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3814 | * will be stored into the context1 field of the IOCB for the completion |
| 3815 | * callback function to the PRLI Accept response ELS IOCB command. |
| 3816 | * |
| 3817 | * Return code |
| 3818 | * 0 - Successfully issued acc prli response |
| 3819 | * 1 - Failed to issue acc prli response |
| 3820 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3821 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3822 | 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] | 3823 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3824 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3825 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3826 | PRLI *npr; |
| 3827 | lpfc_vpd_t *vpd; |
| 3828 | IOCB_t *icmd; |
| 3829 | IOCB_t *oldcmd; |
| 3830 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3831 | struct lpfc_sli *psli; |
| 3832 | uint8_t *pcmd; |
| 3833 | uint16_t cmdsize; |
| 3834 | int rc; |
| 3835 | |
| 3836 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3837 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3838 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3839 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3840 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3841 | if (!elsiocb) |
| 3842 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3843 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3844 | icmd = &elsiocb->iocb; |
| 3845 | oldcmd = &oldiocb->iocb; |
| 3846 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3847 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3848 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3849 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 3850 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 3851 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3852 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3853 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3854 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3855 | |
| 3856 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3857 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3858 | |
| 3859 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3860 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3861 | |
| 3862 | npr = (PRLI *) pcmd; |
| 3863 | vpd = &phba->vpd; |
| 3864 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3865 | * If the remote port is a target and our firmware version is 3.20 or |
| 3866 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3867 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3868 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 3869 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3870 | npr->ConfmComplAllowed = 1; |
| 3871 | npr->Retry = 1; |
| 3872 | npr->TaskRetryIdReq = 1; |
| 3873 | } |
| 3874 | |
| 3875 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 3876 | npr->estabImagePair = 1; |
| 3877 | npr->readXferRdyDis = 1; |
| 3878 | npr->ConfmComplAllowed = 1; |
| 3879 | |
| 3880 | npr->prliType = PRLI_FCP_TYPE; |
| 3881 | npr->initiatorFunc = 1; |
| 3882 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3883 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3884 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 3885 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3886 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3887 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3888 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3889 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3890 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3891 | if (rc == IOCB_ERROR) { |
| 3892 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3893 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3894 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3895 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3896 | } |
| 3897 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3898 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3899 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3900 | * @vport: pointer to a virtual N_Port data structure. |
| 3901 | * @format: rnid command format. |
| 3902 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3903 | * @ndlp: pointer to a node-list data structure. |
| 3904 | * |
| 3905 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 3906 | * (ACC) response. It constructs the RNID ACC response command according to |
| 3907 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 3908 | * issue the response. Note that this command does not need to hold the ndlp |
| 3909 | * reference count for the callback. So, the ndlp reference count taken by |
| 3910 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 3911 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 3912 | * there is no ndlp reference available. |
| 3913 | * |
| 3914 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3915 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3916 | * will be stored into the context1 field of the IOCB for the completion |
| 3917 | * callback function. However, for the RNID Accept Response ELS command, |
| 3918 | * this is undone later by this routine after the IOCB is allocated. |
| 3919 | * |
| 3920 | * Return code |
| 3921 | * 0 - Successfully issued acc rnid response |
| 3922 | * 1 - Failed to issue acc rnid response |
| 3923 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3924 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3925 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3926 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3927 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3928 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3929 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3930 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3931 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3932 | struct lpfc_sli *psli; |
| 3933 | uint8_t *pcmd; |
| 3934 | uint16_t cmdsize; |
| 3935 | int rc; |
| 3936 | |
| 3937 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3938 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 3939 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3940 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3941 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3942 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3943 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3944 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3945 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3946 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3947 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3948 | icmd = &elsiocb->iocb; |
| 3949 | oldcmd = &oldiocb->iocb; |
| 3950 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3951 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3952 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3953 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 3954 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3955 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3956 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3957 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3958 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3959 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3960 | rn = (RNID *) (pcmd); |
| 3961 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3962 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 3963 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3964 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3965 | switch (format) { |
| 3966 | case 0: |
| 3967 | rn->SpecificLen = 0; |
| 3968 | break; |
| 3969 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3970 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3971 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3972 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3973 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 3974 | rn->un.topologyDisc.physPort = 0; |
| 3975 | rn->un.topologyDisc.attachedNodes = 0; |
| 3976 | break; |
| 3977 | default: |
| 3978 | rn->CommonLen = 0; |
| 3979 | rn->SpecificLen = 0; |
| 3980 | break; |
| 3981 | } |
| 3982 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3983 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3984 | "Issue ACC RNID: did:x%x flg:x%x", |
| 3985 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3986 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3987 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3988 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3989 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3990 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 3991 | * it could be freed */ |
| 3992 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3993 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3994 | if (rc == IOCB_ERROR) { |
| 3995 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3996 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3997 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3998 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3999 | } |
| 4000 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4001 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4002 | * lpfc_els_clear_rrq - Clear the rq that this rrq describes. |
| 4003 | * @vport: pointer to a virtual N_Port data structure. |
| 4004 | * @iocb: pointer to the lpfc command iocb data structure. |
| 4005 | * @ndlp: pointer to a node-list data structure. |
| 4006 | * |
| 4007 | * Return |
| 4008 | **/ |
| 4009 | static void |
| 4010 | lpfc_els_clear_rrq(struct lpfc_vport *vport, |
| 4011 | struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp) |
| 4012 | { |
| 4013 | struct lpfc_hba *phba = vport->phba; |
| 4014 | uint8_t *pcmd; |
| 4015 | struct RRQ *rrq; |
| 4016 | uint16_t rxid; |
| 4017 | struct lpfc_node_rrq *prrq; |
| 4018 | |
| 4019 | |
| 4020 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt); |
| 4021 | pcmd += sizeof(uint32_t); |
| 4022 | rrq = (struct RRQ *)pcmd; |
| 4023 | rxid = bf_get(rrq_oxid, rrq); |
| 4024 | |
| 4025 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4026 | "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x" |
| 4027 | " x%x x%x\n", |
| 4028 | bf_get(rrq_did, rrq), |
| 4029 | bf_get(rrq_oxid, rrq), |
| 4030 | rxid, |
| 4031 | iocb->iotag, iocb->iocb.ulpContext); |
| 4032 | |
| 4033 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4034 | "Clear RRQ: did:x%x flg:x%x exchg:x%.08x", |
| 4035 | ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg); |
| 4036 | prrq = lpfc_get_active_rrq(vport, rxid, ndlp->nlp_DID); |
| 4037 | if (prrq) |
| 4038 | lpfc_clr_rrq_active(phba, rxid, prrq); |
| 4039 | return; |
| 4040 | } |
| 4041 | |
| 4042 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4043 | * lpfc_els_rsp_echo_acc - Issue echo acc response |
| 4044 | * @vport: pointer to a virtual N_Port data structure. |
| 4045 | * @data: pointer to echo data to return in the accept. |
| 4046 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4047 | * @ndlp: pointer to a node-list data structure. |
| 4048 | * |
| 4049 | * Return code |
| 4050 | * 0 - Successfully issued acc echo response |
| 4051 | * 1 - Failed to issue acc echo response |
| 4052 | **/ |
| 4053 | static int |
| 4054 | lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data, |
| 4055 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| 4056 | { |
| 4057 | struct lpfc_hba *phba = vport->phba; |
| 4058 | struct lpfc_iocbq *elsiocb; |
| 4059 | struct lpfc_sli *psli; |
| 4060 | uint8_t *pcmd; |
| 4061 | uint16_t cmdsize; |
| 4062 | int rc; |
| 4063 | |
| 4064 | psli = &phba->sli; |
| 4065 | cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len; |
| 4066 | |
| 4067 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4068 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 4069 | if (!elsiocb) |
| 4070 | return 1; |
| 4071 | |
| 4072 | elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri */ |
| 4073 | /* Xmit ECHO ACC response tag <ulpIoTag> */ |
| 4074 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4075 | "2876 Xmit ECHO ACC response tag x%x xri x%x\n", |
| 4076 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| 4077 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4078 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 4079 | pcmd += sizeof(uint32_t); |
| 4080 | memcpy(pcmd, data, cmdsize - sizeof(uint32_t)); |
| 4081 | |
| 4082 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4083 | "Issue ACC ECHO: did:x%x flg:x%x", |
| 4084 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4085 | |
| 4086 | phba->fc_stat.elsXmitACC++; |
| 4087 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 4088 | lpfc_nlp_put(ndlp); |
| 4089 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 4090 | * it could be freed */ |
| 4091 | |
| 4092 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 4093 | if (rc == IOCB_ERROR) { |
| 4094 | lpfc_els_free_iocb(phba, elsiocb); |
| 4095 | return 1; |
| 4096 | } |
| 4097 | return 0; |
| 4098 | } |
| 4099 | |
| 4100 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4101 | * 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] | 4102 | * @vport: pointer to a host virtual N_Port data structure. |
| 4103 | * |
| 4104 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 4105 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 4106 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 4107 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 4108 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 4109 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 4110 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 4111 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 4112 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 4113 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 4114 | * no more ADISC need to be sent. |
| 4115 | * |
| 4116 | * Return code |
| 4117 | * The number of N_Ports with adisc issued. |
| 4118 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4119 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4120 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4121 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4122 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4123 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4124 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4125 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4126 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4127 | 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] | 4128 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4129 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4130 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 4131 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4132 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4133 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4134 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4135 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4136 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4137 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 4138 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4139 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4140 | vport->num_disc_nodes++; |
| 4141 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4142 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4143 | spin_lock_irq(shost->host_lock); |
| 4144 | vport->fc_flag |= FC_NLP_MORE; |
| 4145 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4146 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4147 | } |
| 4148 | } |
| 4149 | } |
| 4150 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4151 | spin_lock_irq(shost->host_lock); |
| 4152 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4153 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4154 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4155 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4156 | } |
| 4157 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4158 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4159 | * 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] | 4160 | * @vport: pointer to a host virtual N_Port data structure. |
| 4161 | * |
| 4162 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 4163 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 4164 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 4165 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 4166 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 4167 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 4168 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 4169 | * later pick up. On the other hand, after walking through all the ndlps with |
| 4170 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 4171 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 4172 | * PLOGI need to be sent. |
| 4173 | * |
| 4174 | * Return code |
| 4175 | * The number of N_Ports with plogi issued. |
| 4176 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4177 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4178 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4179 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4180 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4181 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4182 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4183 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4184 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 4185 | 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] | 4186 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4187 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4188 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 4189 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4190 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 4191 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 4192 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4193 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 4194 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4195 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4196 | vport->num_disc_nodes++; |
| 4197 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4198 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4199 | spin_lock_irq(shost->host_lock); |
| 4200 | vport->fc_flag |= FC_NLP_MORE; |
| 4201 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4202 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4203 | } |
| 4204 | } |
| 4205 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4206 | if (sentplogi) { |
| 4207 | lpfc_set_disctmo(vport); |
| 4208 | } |
| 4209 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4210 | spin_lock_irq(shost->host_lock); |
| 4211 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4212 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4213 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4214 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4215 | } |
| 4216 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4217 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4218 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4219 | * @vport: pointer to a host virtual N_Port data structure. |
| 4220 | * |
| 4221 | * This routine cleans up any Registration State Change Notification |
| 4222 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 4223 | * @vport together with the host_lock is used to prevent multiple thread |
| 4224 | * trying to access the RSCN array on a same @vport at the same time. |
| 4225 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4226 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4227 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4228 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4229 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4230 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4231 | int i; |
| 4232 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4233 | spin_lock_irq(shost->host_lock); |
| 4234 | if (vport->fc_rscn_flush) { |
| 4235 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4236 | spin_unlock_irq(shost->host_lock); |
| 4237 | return; |
| 4238 | } |
| 4239 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 4240 | vport->fc_rscn_flush = 1; |
| 4241 | spin_unlock_irq(shost->host_lock); |
| 4242 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4243 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4244 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4245 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4246 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4247 | spin_lock_irq(shost->host_lock); |
| 4248 | vport->fc_rscn_id_cnt = 0; |
| 4249 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 4250 | spin_unlock_irq(shost->host_lock); |
| 4251 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4252 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 4253 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4254 | } |
| 4255 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4256 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4257 | * 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] | 4258 | * @vport: pointer to a host virtual N_Port data structure. |
| 4259 | * @did: remote destination port identifier. |
| 4260 | * |
| 4261 | * This routine checks whether there is any pending Registration State |
| 4262 | * Configuration Notification (RSCN) to a @did on @vport. |
| 4263 | * |
| 4264 | * Return code |
| 4265 | * None zero - The @did matched with a pending rscn |
| 4266 | * 0 - not able to match @did with a pending rscn |
| 4267 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4268 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4269 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4270 | { |
| 4271 | D_ID ns_did; |
| 4272 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4273 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4274 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4275 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4276 | |
| 4277 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4278 | |
| 4279 | /* Never match fabric nodes for RSCNs */ |
| 4280 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4281 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4282 | |
| 4283 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4284 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4285 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4286 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4287 | spin_lock_irq(shost->host_lock); |
| 4288 | if (vport->fc_rscn_flush) { |
| 4289 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4290 | spin_unlock_irq(shost->host_lock); |
| 4291 | return 0; |
| 4292 | } |
| 4293 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4294 | vport->fc_rscn_flush = 1; |
| 4295 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4296 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4297 | lp = vport->fc_rscn_id_list[i]->virt; |
| 4298 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4299 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4300 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4301 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 4302 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4303 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 4304 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4305 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4306 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 4307 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4308 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4309 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4310 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4311 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4312 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4313 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4314 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4315 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4316 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4317 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4318 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4319 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4320 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4321 | } |
| 4322 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4323 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4324 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4325 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4326 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4327 | return_did_out: |
| 4328 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4329 | vport->fc_rscn_flush = 0; |
| 4330 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4331 | } |
| 4332 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4333 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4334 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4335 | * @vport: pointer to a host virtual N_Port data structure. |
| 4336 | * |
| 4337 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 4338 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 4339 | * State Change Notification). |
| 4340 | * |
| 4341 | * Return code |
| 4342 | * 0 - Successful (currently alway return 0) |
| 4343 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4344 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4345 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4346 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4347 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4348 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4349 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4350 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4351 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4352 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 4353 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4354 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4355 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4356 | NLP_EVT_DEVICE_RECOVERY); |
| 4357 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4358 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4359 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4360 | } |
| 4361 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4362 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4363 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4364 | * @vport: pointer to a host virtual N_Port data structure. |
| 4365 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4366 | * |
| 4367 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 4368 | * applications. |
| 4369 | */ |
| 4370 | static void |
| 4371 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 4372 | struct lpfc_iocbq *cmdiocb) |
| 4373 | { |
| 4374 | struct lpfc_dmabuf *pcmd; |
| 4375 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4376 | uint32_t *payload_ptr; |
| 4377 | uint32_t payload_len; |
| 4378 | struct lpfc_rscn_event_header *rscn_event_data; |
| 4379 | |
| 4380 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4381 | payload_ptr = (uint32_t *) pcmd->virt; |
| 4382 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 4383 | |
| 4384 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 4385 | payload_len, GFP_KERNEL); |
| 4386 | if (!rscn_event_data) { |
| 4387 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4388 | "0147 Failed to allocate memory for RSCN event\n"); |
| 4389 | return; |
| 4390 | } |
| 4391 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 4392 | rscn_event_data->payload_length = payload_len; |
| 4393 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 4394 | payload_len); |
| 4395 | |
| 4396 | fc_host_post_vendor_event(shost, |
| 4397 | fc_get_event_number(), |
| 4398 | sizeof(struct lpfc_els_event_header) + payload_len, |
| 4399 | (char *)rscn_event_data, |
| 4400 | LPFC_NL_VENDOR_ID); |
| 4401 | |
| 4402 | kfree(rscn_event_data); |
| 4403 | } |
| 4404 | |
| 4405 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4406 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4407 | * @vport: pointer to a host virtual N_Port data structure. |
| 4408 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4409 | * @ndlp: pointer to a node-list data structure. |
| 4410 | * |
| 4411 | * This routine processes an unsolicited RSCN (Registration State Change |
| 4412 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 4413 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 4414 | * discover state machine is about to begin discovery, it just accepts the |
| 4415 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 4416 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 4417 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 4418 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 4419 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 4420 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 4421 | * routine is invoked to handle the RSCN event. |
| 4422 | * |
| 4423 | * Return code |
| 4424 | * 0 - Just sent the acc response |
| 4425 | * 1 - Sent the acc response and waited for name server completion |
| 4426 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4427 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4428 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4429 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4430 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4431 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4432 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4433 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4434 | uint32_t *lp, *datap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4435 | IOCB_t *icmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4436 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4437 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4438 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4439 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4440 | |
| 4441 | icmd = &cmdiocb->iocb; |
| 4442 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4443 | lp = (uint32_t *) pcmd->virt; |
| 4444 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4445 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4446 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4447 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4448 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4449 | "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] | 4450 | vport->fc_flag, payload_len, *lp, |
| 4451 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4452 | |
| 4453 | /* Send an RSCN event to the management application */ |
| 4454 | lpfc_send_rscn_event(vport, cmdiocb); |
| 4455 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4456 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4457 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4458 | FCH_EVT_RSCN, lp[i]); |
| 4459 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4460 | /* If we are about to begin discovery, just ACC the RSCN. |
| 4461 | * Discovery processing will satisfy it. |
| 4462 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4463 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4464 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4465 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 4466 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4467 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4468 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4469 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4470 | } |
| 4471 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4472 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 4473 | * just ACC and ignore it. |
| 4474 | */ |
| 4475 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4476 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4477 | i = payload_len; |
| 4478 | datap = lp; |
| 4479 | while (i > 0) { |
| 4480 | nportid = *datap++; |
| 4481 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 4482 | i -= sizeof(uint32_t); |
| 4483 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4484 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 4485 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4486 | } |
| 4487 | if (rscn_id == hba_id) { |
| 4488 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4489 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4490 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4491 | "Data: x%x x%x x%x x%x\n", |
| 4492 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4493 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4494 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4495 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 4496 | ndlp->nlp_DID, vport->port_state, |
| 4497 | ndlp->nlp_flag); |
| 4498 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4499 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4500 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4501 | return 0; |
| 4502 | } |
| 4503 | } |
| 4504 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4505 | spin_lock_irq(shost->host_lock); |
| 4506 | if (vport->fc_rscn_flush) { |
| 4507 | /* Another thread is walking fc_rscn_id_list on this vport */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4508 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 4509 | spin_unlock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4510 | /* Send back ACC */ |
| 4511 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4512 | return 0; |
| 4513 | } |
| 4514 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4515 | vport->fc_rscn_flush = 1; |
| 4516 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4517 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4518 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4519 | /* If we are already processing an RSCN, save the received |
| 4520 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 4521 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4522 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4523 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4524 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 4525 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4526 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4527 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4528 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 4529 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4530 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4531 | vport->fc_flag |= FC_RSCN_MODE; |
| 4532 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4533 | if (rscn_cnt) { |
| 4534 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 4535 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 4536 | } |
| 4537 | if ((rscn_cnt) && |
| 4538 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 4539 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4540 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4541 | memcpy(((uint8_t *)cmd) + length, lp, |
| 4542 | payload_len); |
| 4543 | } else { |
| 4544 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 4545 | vport->fc_rscn_id_cnt++; |
| 4546 | /* If we zero, cmdiocb->context2, the calling |
| 4547 | * routine will not try to free it. |
| 4548 | */ |
| 4549 | cmdiocb->context2 = NULL; |
| 4550 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4551 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4552 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4553 | "0235 Deferred RSCN " |
| 4554 | "Data: x%x x%x x%x\n", |
| 4555 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4556 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4557 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4558 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 4559 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4560 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4561 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4562 | "0234 ReDiscovery RSCN " |
| 4563 | "Data: x%x x%x x%x\n", |
| 4564 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4565 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4566 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4567 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4568 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4569 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4570 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4571 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4572 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4573 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4574 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4575 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4576 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4577 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4578 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4579 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 4580 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4581 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4582 | spin_lock_irq(shost->host_lock); |
| 4583 | vport->fc_flag |= FC_RSCN_MODE; |
| 4584 | spin_unlock_irq(shost->host_lock); |
| 4585 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4586 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4587 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4588 | /* |
| 4589 | * If we zero, cmdiocb->context2, the calling routine will |
| 4590 | * not try to free it. |
| 4591 | */ |
| 4592 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4593 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4594 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4595 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4596 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4597 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4598 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4599 | } |
| 4600 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4601 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4602 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4603 | * @vport: pointer to a host virtual N_Port data structure. |
| 4604 | * |
| 4605 | * This routine handles the Registration State Configuration Notification |
| 4606 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 4607 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 4608 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 4609 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 4610 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 4611 | * RSCN activities with the @vport. |
| 4612 | * |
| 4613 | * Return code |
| 4614 | * 0 - Cleaned up rscn on the @vport |
| 4615 | * 1 - Wait for plogi to name server before proceed |
| 4616 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4617 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4618 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4619 | { |
| 4620 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4621 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4622 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4623 | /* Ignore RSCN if the port is being torn down. */ |
| 4624 | if (vport->load_flag & FC_UNLOADING) { |
| 4625 | lpfc_els_flush_rscn(vport); |
| 4626 | return 0; |
| 4627 | } |
| 4628 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4629 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4630 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4631 | |
| 4632 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4633 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4634 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 4635 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 4636 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4637 | |
| 4638 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4639 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4640 | vport->num_disc_nodes = 0; |
| 4641 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4642 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4643 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 4644 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4645 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4646 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4647 | /* Wait for NameServer query cmpl before we can |
| 4648 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4649 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4650 | } else { |
| 4651 | /* If login to NameServer does not exist, issue one */ |
| 4652 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4653 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4654 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4655 | /* Wait for NameServer login cmpl before we can |
| 4656 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4657 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4658 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4659 | if (ndlp) { |
| 4660 | ndlp = lpfc_enable_node(vport, ndlp, |
| 4661 | NLP_STE_PLOGI_ISSUE); |
| 4662 | if (!ndlp) { |
| 4663 | lpfc_els_flush_rscn(vport); |
| 4664 | return 0; |
| 4665 | } |
| 4666 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4667 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4668 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4669 | if (!ndlp) { |
| 4670 | lpfc_els_flush_rscn(vport); |
| 4671 | return 0; |
| 4672 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4673 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4674 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4675 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4676 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4677 | ndlp->nlp_type |= NLP_FABRIC; |
| 4678 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 4679 | /* Wait for NameServer login cmpl before we can |
| 4680 | * continue |
| 4681 | */ |
| 4682 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4683 | } |
| 4684 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4685 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4686 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4687 | } |
| 4688 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4689 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4690 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4691 | * @vport: pointer to a host virtual N_Port data structure. |
| 4692 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4693 | * @ndlp: pointer to a node-list data structure. |
| 4694 | * |
| 4695 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 4696 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 4697 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 4698 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 4699 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 4700 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 4701 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 4702 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 4703 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 4704 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 4705 | * higher priority (as the winning port) and will initiate PLOGI and |
| 4706 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 4707 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 4708 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 4709 | * |
| 4710 | * Return code |
| 4711 | * 0 - Successfully processed the unsolicited flogi |
| 4712 | * 1 - Failed to process the unsolicited flogi |
| 4713 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4714 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4715 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4716 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4717 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4718 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4719 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4720 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4721 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 4722 | IOCB_t *icmd = &cmdiocb->iocb; |
| 4723 | struct serv_parm *sp; |
| 4724 | LPFC_MBOXQ_t *mbox; |
| 4725 | struct ls_rjt stat; |
| 4726 | uint32_t cmd, did; |
| 4727 | int rc; |
| 4728 | |
| 4729 | cmd = *lp++; |
| 4730 | sp = (struct serv_parm *) lp; |
| 4731 | |
| 4732 | /* FLOGI received */ |
| 4733 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4734 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4735 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4736 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4737 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 4738 | did = icmd->un.elsreq64.remoteID; |
| 4739 | |
| 4740 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 4741 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4742 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4743 | "0113 An FLOGI ELS command x%x was " |
| 4744 | "received from DID x%x in Loop Mode\n", |
| 4745 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4746 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4747 | } |
| 4748 | |
| 4749 | did = Fabric_DID; |
| 4750 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 4751 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4752 | /* For a FLOGI we accept, then if our portname is greater |
| 4753 | * then the remote portname we initiate Nport login. |
| 4754 | */ |
| 4755 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4756 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4757 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4758 | |
| 4759 | if (!rc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4760 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4761 | if (!mbox) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4762 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4763 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4764 | lpfc_linkdown(phba); |
| 4765 | lpfc_init_link(phba, mbox, |
| 4766 | phba->cfg_topology, |
| 4767 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4768 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4769 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4770 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4771 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4772 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4773 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4774 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4775 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4776 | return 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4777 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4778 | spin_lock_irq(shost->host_lock); |
| 4779 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 4780 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4781 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4782 | spin_lock_irq(shost->host_lock); |
| 4783 | vport->fc_flag |= FC_PT2PT; |
| 4784 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 4785 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4786 | } else { |
| 4787 | /* Reject this request because invalid parameters */ |
| 4788 | stat.un.b.lsRjtRsvd0 = 0; |
| 4789 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4790 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 4791 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4792 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4793 | NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4794 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4795 | } |
| 4796 | |
| 4797 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4798 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4799 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4800 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4801 | } |
| 4802 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4803 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4804 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4805 | * @vport: pointer to a host virtual N_Port data structure. |
| 4806 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4807 | * @ndlp: pointer to a node-list data structure. |
| 4808 | * |
| 4809 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 4810 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 4811 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 4812 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 4813 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 4814 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 4815 | * |
| 4816 | * Return code |
| 4817 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 4818 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4819 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4820 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4821 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4822 | { |
| 4823 | struct lpfc_dmabuf *pcmd; |
| 4824 | uint32_t *lp; |
| 4825 | IOCB_t *icmd; |
| 4826 | RNID *rn; |
| 4827 | struct ls_rjt stat; |
| 4828 | uint32_t cmd, did; |
| 4829 | |
| 4830 | icmd = &cmdiocb->iocb; |
| 4831 | did = icmd->un.elsreq64.remoteID; |
| 4832 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4833 | lp = (uint32_t *) pcmd->virt; |
| 4834 | |
| 4835 | cmd = *lp++; |
| 4836 | rn = (RNID *) lp; |
| 4837 | |
| 4838 | /* RNID received */ |
| 4839 | |
| 4840 | switch (rn->Format) { |
| 4841 | case 0: |
| 4842 | case RNID_TOPOLOGY_DISC: |
| 4843 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4844 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4845 | break; |
| 4846 | default: |
| 4847 | /* Reject this request because format not supported */ |
| 4848 | stat.un.b.lsRjtRsvd0 = 0; |
| 4849 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4850 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4851 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4852 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4853 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4854 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4855 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4856 | } |
| 4857 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4858 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4859 | * lpfc_els_rcv_echo - Process an unsolicited echo iocb |
| 4860 | * @vport: pointer to a host virtual N_Port data structure. |
| 4861 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4862 | * @ndlp: pointer to a node-list data structure. |
| 4863 | * |
| 4864 | * Return code |
| 4865 | * 0 - Successfully processed echo iocb (currently always return 0) |
| 4866 | **/ |
| 4867 | static int |
| 4868 | lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4869 | struct lpfc_nodelist *ndlp) |
| 4870 | { |
| 4871 | uint8_t *pcmd; |
| 4872 | |
| 4873 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
| 4874 | |
| 4875 | /* skip over first word of echo command to find echo data */ |
| 4876 | pcmd += sizeof(uint32_t); |
| 4877 | |
| 4878 | lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp); |
| 4879 | return 0; |
| 4880 | } |
| 4881 | |
| 4882 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4883 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4884 | * @vport: pointer to a host virtual N_Port data structure. |
| 4885 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4886 | * @ndlp: pointer to a node-list data structure. |
| 4887 | * |
| 4888 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 4889 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 4890 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 4891 | * |
| 4892 | * Return code |
| 4893 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 4894 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4895 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4896 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4897 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4898 | { |
| 4899 | struct ls_rjt stat; |
| 4900 | |
| 4901 | /* For now, unconditionally reject this command */ |
| 4902 | stat.un.b.lsRjtRsvd0 = 0; |
| 4903 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4904 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4905 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4906 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4907 | return 0; |
| 4908 | } |
| 4909 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4910 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4911 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb |
| 4912 | * @vport: pointer to a host virtual N_Port data structure. |
| 4913 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4914 | * @ndlp: pointer to a node-list data structure. |
| 4915 | * |
| 4916 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB |
| 4917 | * received as an ELS unsolicited event. A request to RRQ shall only |
| 4918 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder |
| 4919 | * Nx_Port N_Port_ID of the target Exchange is the same as the |
| 4920 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is |
| 4921 | * not accepted, an LS_RJT with reason code "Unable to perform |
| 4922 | * command request" and reason code explanation "Invalid Originator |
| 4923 | * S_ID" shall be returned. For now, we just unconditionally accept |
| 4924 | * RRQ from the target. |
| 4925 | **/ |
| 4926 | static void |
| 4927 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4928 | struct lpfc_nodelist *ndlp) |
| 4929 | { |
| 4930 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4931 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 4932 | lpfc_els_clear_rrq(vport, cmdiocb, ndlp); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4933 | } |
| 4934 | |
| 4935 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4936 | * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd |
| 4937 | * @phba: pointer to lpfc hba data structure. |
| 4938 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4939 | * |
| 4940 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 4941 | * mailbox command. This callback function is to actually send the Accept |
| 4942 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 4943 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 4944 | * mailbox command, constructs the RPS response with the link statistics |
| 4945 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 4946 | * response to the RPS. |
| 4947 | * |
| 4948 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4949 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4950 | * will be stored into the context1 field of the IOCB for the completion |
| 4951 | * callback function to the RPS Accept Response ELS IOCB command. |
| 4952 | * |
| 4953 | **/ |
| 4954 | static void |
| 4955 | lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 4956 | { |
| 4957 | MAILBOX_t *mb; |
| 4958 | IOCB_t *icmd; |
| 4959 | struct RLS_RSP *rls_rsp; |
| 4960 | uint8_t *pcmd; |
| 4961 | struct lpfc_iocbq *elsiocb; |
| 4962 | struct lpfc_nodelist *ndlp; |
| 4963 | uint16_t xri; |
| 4964 | uint32_t cmdsize; |
| 4965 | |
| 4966 | mb = &pmb->u.mb; |
| 4967 | |
| 4968 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4969 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
| 4970 | pmb->context1 = NULL; |
| 4971 | pmb->context2 = NULL; |
| 4972 | |
| 4973 | if (mb->mbxStatus) { |
| 4974 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4975 | return; |
| 4976 | } |
| 4977 | |
| 4978 | cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t); |
| 4979 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4980 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 4981 | lpfc_max_els_tries, ndlp, |
| 4982 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 4983 | |
| 4984 | /* Decrement the ndlp reference count from previous mbox command */ |
| 4985 | lpfc_nlp_put(ndlp); |
| 4986 | |
| 4987 | if (!elsiocb) |
| 4988 | return; |
| 4989 | |
| 4990 | icmd = &elsiocb->iocb; |
| 4991 | icmd->ulpContext = xri; |
| 4992 | |
| 4993 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4994 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 4995 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 4996 | rls_rsp = (struct RLS_RSP *)pcmd; |
| 4997 | |
| 4998 | rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 4999 | rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 5000 | rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 5001 | rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 5002 | rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 5003 | rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
| 5004 | |
| 5005 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 5006 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 5007 | "2874 Xmit ELS RLS ACC response tag x%x xri x%x, " |
| 5008 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 5009 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5010 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5011 | ndlp->nlp_rpi); |
| 5012 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5013 | phba->fc_stat.elsXmitACC++; |
| 5014 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 5015 | lpfc_els_free_iocb(phba, elsiocb); |
| 5016 | } |
| 5017 | |
| 5018 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5019 | * 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] | 5020 | * @phba: pointer to lpfc hba data structure. |
| 5021 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 5022 | * |
| 5023 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 5024 | * mailbox command. This callback function is to actually send the Accept |
| 5025 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 5026 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 5027 | * mailbox command, constructs the RPS response with the link statistics |
| 5028 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 5029 | * response to the RPS. |
| 5030 | * |
| 5031 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5032 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5033 | * will be stored into the context1 field of the IOCB for the completion |
| 5034 | * callback function to the RPS Accept Response ELS IOCB command. |
| 5035 | * |
| 5036 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 5037 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5038 | 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] | 5039 | { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5040 | MAILBOX_t *mb; |
| 5041 | IOCB_t *icmd; |
| 5042 | RPS_RSP *rps_rsp; |
| 5043 | uint8_t *pcmd; |
| 5044 | struct lpfc_iocbq *elsiocb; |
| 5045 | struct lpfc_nodelist *ndlp; |
| 5046 | uint16_t xri, status; |
| 5047 | uint32_t cmdsize; |
| 5048 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5049 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5050 | |
| 5051 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 5052 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 5053 | pmb->context1 = NULL; |
| 5054 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5055 | |
| 5056 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5057 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5058 | return; |
| 5059 | } |
| 5060 | |
| 5061 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5062 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5063 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5064 | lpfc_max_els_tries, ndlp, |
| 5065 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5066 | |
| 5067 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5068 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5069 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5070 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5071 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5072 | |
| 5073 | icmd = &elsiocb->iocb; |
| 5074 | icmd->ulpContext = xri; |
| 5075 | |
| 5076 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5077 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5078 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5079 | rps_rsp = (RPS_RSP *)pcmd; |
| 5080 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5081 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5082 | status = 0x10; |
| 5083 | else |
| 5084 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5085 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5086 | status |= 0x4; |
| 5087 | |
| 5088 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5089 | rps_rsp->portStatus = cpu_to_be16(status); |
| 5090 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 5091 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 5092 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 5093 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 5094 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 5095 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5096 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5097 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 5098 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 5099 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 5100 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5101 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5102 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5103 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5104 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5105 | 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] | 5106 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5107 | return; |
| 5108 | } |
| 5109 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5110 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5111 | * lpfc_els_rcv_rls - Process an unsolicited rls iocb |
| 5112 | * @vport: pointer to a host virtual N_Port data structure. |
| 5113 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5114 | * @ndlp: pointer to a node-list data structure. |
| 5115 | * |
| 5116 | * This routine processes Read Port Status (RPL) IOCB received as an |
| 5117 | * ELS unsolicited event. It first checks the remote port state. If the |
| 5118 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 5119 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 5120 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 5121 | * for reading the HBA link statistics. It is for the callback function, |
| 5122 | * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 5123 | * to actually sending out RPL Accept (ACC) response. |
| 5124 | * |
| 5125 | * Return codes |
| 5126 | * 0 - Successfully processed rls iocb (currently always return 0) |
| 5127 | **/ |
| 5128 | static int |
| 5129 | lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5130 | struct lpfc_nodelist *ndlp) |
| 5131 | { |
| 5132 | struct lpfc_hba *phba = vport->phba; |
| 5133 | LPFC_MBOXQ_t *mbox; |
| 5134 | struct lpfc_dmabuf *pcmd; |
| 5135 | struct ls_rjt stat; |
| 5136 | |
| 5137 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 5138 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5139 | /* reject the unsolicited RPS request and done with it */ |
| 5140 | goto reject_out; |
| 5141 | |
| 5142 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5143 | |
| 5144 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 5145 | if (mbox) { |
| 5146 | lpfc_read_lnk_stat(phba, mbox); |
| 5147 | mbox->context1 = |
| 5148 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
| 5149 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 5150 | mbox->vport = vport; |
| 5151 | mbox->mbox_cmpl = lpfc_els_rsp_rls_acc; |
| 5152 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
| 5153 | != MBX_NOT_FINISHED) |
| 5154 | /* Mbox completion will send ELS Response */ |
| 5155 | return 0; |
| 5156 | /* Decrement reference count used for the failed mbox |
| 5157 | * command. |
| 5158 | */ |
| 5159 | lpfc_nlp_put(ndlp); |
| 5160 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5161 | } |
| 5162 | reject_out: |
| 5163 | /* issue rejection response */ |
| 5164 | stat.un.b.lsRjtRsvd0 = 0; |
| 5165 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5166 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5167 | stat.un.b.vendorUnique = 0; |
| 5168 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5169 | return 0; |
| 5170 | } |
| 5171 | |
| 5172 | /** |
| 5173 | * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb |
| 5174 | * @vport: pointer to a host virtual N_Port data structure. |
| 5175 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5176 | * @ndlp: pointer to a node-list data structure. |
| 5177 | * |
| 5178 | * This routine processes Read Timout Value (RTV) IOCB received as an |
| 5179 | * ELS unsolicited event. It first checks the remote port state. If the |
| 5180 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 5181 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 5182 | * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout |
| 5183 | * Value (RTV) unsolicited IOCB event. |
| 5184 | * |
| 5185 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5186 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5187 | * will be stored into the context1 field of the IOCB for the completion |
| 5188 | * callback function to the RPS Accept Response ELS IOCB command. |
| 5189 | * |
| 5190 | * Return codes |
| 5191 | * 0 - Successfully processed rtv iocb (currently always return 0) |
| 5192 | **/ |
| 5193 | static int |
| 5194 | lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5195 | struct lpfc_nodelist *ndlp) |
| 5196 | { |
| 5197 | struct lpfc_hba *phba = vport->phba; |
| 5198 | struct ls_rjt stat; |
| 5199 | struct RTV_RSP *rtv_rsp; |
| 5200 | uint8_t *pcmd; |
| 5201 | struct lpfc_iocbq *elsiocb; |
| 5202 | uint32_t cmdsize; |
| 5203 | |
| 5204 | |
| 5205 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 5206 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5207 | /* reject the unsolicited RPS request and done with it */ |
| 5208 | goto reject_out; |
| 5209 | |
| 5210 | cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t); |
| 5211 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5212 | lpfc_max_els_tries, ndlp, |
| 5213 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 5214 | |
| 5215 | if (!elsiocb) |
| 5216 | return 1; |
| 5217 | |
| 5218 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5219 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 5220 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 5221 | |
| 5222 | /* use the command's xri in the response */ |
| 5223 | elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; |
| 5224 | |
| 5225 | rtv_rsp = (struct RTV_RSP *)pcmd; |
| 5226 | |
| 5227 | /* populate RTV payload */ |
| 5228 | rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */ |
| 5229 | rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov); |
| 5230 | bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0); |
| 5231 | bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */ |
| 5232 | rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov); |
| 5233 | |
| 5234 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 5235 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 5236 | "2875 Xmit ELS RTV ACC response tag x%x xri x%x, " |
| 5237 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, " |
| 5238 | "Data: x%x x%x x%x\n", |
| 5239 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5240 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5241 | ndlp->nlp_rpi, |
| 5242 | rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov); |
| 5243 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5244 | phba->fc_stat.elsXmitACC++; |
| 5245 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 5246 | lpfc_els_free_iocb(phba, elsiocb); |
| 5247 | return 0; |
| 5248 | |
| 5249 | reject_out: |
| 5250 | /* issue rejection response */ |
| 5251 | stat.un.b.lsRjtRsvd0 = 0; |
| 5252 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5253 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5254 | stat.un.b.vendorUnique = 0; |
| 5255 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5256 | return 0; |
| 5257 | } |
| 5258 | |
| 5259 | /* lpfc_els_rcv_rps - Process an unsolicited rps iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5260 | * @vport: pointer to a host virtual N_Port data structure. |
| 5261 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5262 | * @ndlp: pointer to a node-list data structure. |
| 5263 | * |
| 5264 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 5265 | * ELS unsolicited event. It first checks the remote port state. If the |
| 5266 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 5267 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 5268 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 5269 | * for reading the HBA link statistics. It is for the callback function, |
| 5270 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 5271 | * to actually sending out RPS Accept (ACC) response. |
| 5272 | * |
| 5273 | * Return codes |
| 5274 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 5275 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5276 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5277 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5278 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5279 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5280 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5281 | uint32_t *lp; |
| 5282 | uint8_t flag; |
| 5283 | LPFC_MBOXQ_t *mbox; |
| 5284 | struct lpfc_dmabuf *pcmd; |
| 5285 | RPS *rps; |
| 5286 | struct ls_rjt stat; |
| 5287 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5288 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5289 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5290 | /* reject the unsolicited RPS request and done with it */ |
| 5291 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5292 | |
| 5293 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5294 | lp = (uint32_t *) pcmd->virt; |
| 5295 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 5296 | rps = (RPS *) lp; |
| 5297 | |
| 5298 | if ((flag == 0) || |
| 5299 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5300 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5301 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5302 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5303 | printk("Fix me....\n"); |
| 5304 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5305 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 5306 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5307 | lpfc_read_lnk_stat(phba, mbox); |
| 5308 | mbox->context1 = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5309 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5310 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5311 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5312 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5313 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5314 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5315 | /* Mbox completion will send ELS Response */ |
| 5316 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5317 | /* Decrement reference count used for the failed mbox |
| 5318 | * command. |
| 5319 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5320 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5321 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5322 | } |
| 5323 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5324 | |
| 5325 | reject_out: |
| 5326 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5327 | stat.un.b.lsRjtRsvd0 = 0; |
| 5328 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5329 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5330 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5331 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5332 | return 0; |
| 5333 | } |
| 5334 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5335 | /* lpfc_issue_els_rrq - Process an unsolicited rps iocb |
| 5336 | * @vport: pointer to a host virtual N_Port data structure. |
| 5337 | * @ndlp: pointer to a node-list data structure. |
| 5338 | * @did: DID of the target. |
| 5339 | * @rrq: Pointer to the rrq struct. |
| 5340 | * |
| 5341 | * Build a ELS RRQ command and send it to the target. If the issue_iocb is |
| 5342 | * Successful the the completion handler will clear the RRQ. |
| 5343 | * |
| 5344 | * Return codes |
| 5345 | * 0 - Successfully sent rrq els iocb. |
| 5346 | * 1 - Failed to send rrq els iocb. |
| 5347 | **/ |
| 5348 | static int |
| 5349 | lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 5350 | uint32_t did, struct lpfc_node_rrq *rrq) |
| 5351 | { |
| 5352 | struct lpfc_hba *phba = vport->phba; |
| 5353 | struct RRQ *els_rrq; |
| 5354 | IOCB_t *icmd; |
| 5355 | struct lpfc_iocbq *elsiocb; |
| 5356 | uint8_t *pcmd; |
| 5357 | uint16_t cmdsize; |
| 5358 | int ret; |
| 5359 | |
| 5360 | |
| 5361 | if (ndlp != rrq->ndlp) |
| 5362 | ndlp = rrq->ndlp; |
| 5363 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 5364 | return 1; |
| 5365 | |
| 5366 | /* If ndlp is not NULL, we will bump the reference count on it */ |
| 5367 | cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ)); |
| 5368 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did, |
| 5369 | ELS_CMD_RRQ); |
| 5370 | if (!elsiocb) |
| 5371 | return 1; |
| 5372 | |
| 5373 | icmd = &elsiocb->iocb; |
| 5374 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5375 | |
| 5376 | /* For RRQ request, remainder of payload is Exchange IDs */ |
| 5377 | *((uint32_t *) (pcmd)) = ELS_CMD_RRQ; |
| 5378 | pcmd += sizeof(uint32_t); |
| 5379 | els_rrq = (struct RRQ *) pcmd; |
| 5380 | |
| 5381 | bf_set(rrq_oxid, els_rrq, rrq->xritag); |
| 5382 | bf_set(rrq_rxid, els_rrq, rrq->rxid); |
| 5383 | bf_set(rrq_did, els_rrq, vport->fc_myDID); |
| 5384 | els_rrq->rrq = cpu_to_be32(els_rrq->rrq); |
| 5385 | els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg); |
| 5386 | |
| 5387 | |
| 5388 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 5389 | "Issue RRQ: did:x%x", |
| 5390 | did, rrq->xritag, rrq->rxid); |
| 5391 | elsiocb->context_un.rrq = rrq; |
| 5392 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq; |
| 5393 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5394 | |
| 5395 | if (ret == IOCB_ERROR) { |
| 5396 | lpfc_els_free_iocb(phba, elsiocb); |
| 5397 | return 1; |
| 5398 | } |
| 5399 | return 0; |
| 5400 | } |
| 5401 | |
| 5402 | /** |
| 5403 | * lpfc_send_rrq - Sends ELS RRQ if needed. |
| 5404 | * @phba: pointer to lpfc hba data structure. |
| 5405 | * @rrq: pointer to the active rrq. |
| 5406 | * |
| 5407 | * This routine will call the lpfc_issue_els_rrq if the rrq is |
| 5408 | * still active for the xri. If this function returns a failure then |
| 5409 | * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq. |
| 5410 | * |
| 5411 | * Returns 0 Success. |
| 5412 | * 1 Failure. |
| 5413 | **/ |
| 5414 | int |
| 5415 | lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq) |
| 5416 | { |
| 5417 | struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport, |
| 5418 | rrq->nlp_DID); |
| 5419 | if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag)) |
| 5420 | return lpfc_issue_els_rrq(rrq->vport, ndlp, |
| 5421 | rrq->nlp_DID, rrq); |
| 5422 | else |
| 5423 | return 1; |
| 5424 | } |
| 5425 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5426 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5427 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5428 | * @vport: pointer to a host virtual N_Port data structure. |
| 5429 | * @cmdsize: size of the ELS command. |
| 5430 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 5431 | * @ndlp: pointer to a node-list data structure. |
| 5432 | * |
| 5433 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 5434 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 5435 | * |
| 5436 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5437 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5438 | * will be stored into the context1 field of the IOCB for the completion |
| 5439 | * callback function to the RPL Accept Response ELS command. |
| 5440 | * |
| 5441 | * Return code |
| 5442 | * 0 - Successfully issued ACC RPL ELS command |
| 5443 | * 1 - Failed to issue ACC RPL ELS command |
| 5444 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 5445 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5446 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 5447 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5448 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5449 | struct lpfc_hba *phba = vport->phba; |
| 5450 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5451 | RPL_RSP rpl_rsp; |
| 5452 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5453 | uint8_t *pcmd; |
| 5454 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5455 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 5456 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5457 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5458 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5459 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5460 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5461 | icmd = &elsiocb->iocb; |
| 5462 | oldcmd = &oldiocb->iocb; |
| 5463 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 5464 | |
| 5465 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5466 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5467 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5468 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 5469 | pcmd += sizeof(uint16_t); |
| 5470 | |
| 5471 | /* Setup the RPL ACC payload */ |
| 5472 | rpl_rsp.listLen = be32_to_cpu(1); |
| 5473 | rpl_rsp.index = 0; |
| 5474 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5475 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 5476 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5477 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5478 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5479 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5480 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5481 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 5482 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 5483 | "rpi x%x\n", |
| 5484 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5485 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5486 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5487 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5488 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5489 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 5490 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5491 | lpfc_els_free_iocb(phba, elsiocb); |
| 5492 | return 1; |
| 5493 | } |
| 5494 | return 0; |
| 5495 | } |
| 5496 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5497 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5498 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5499 | * @vport: pointer to a host virtual N_Port data structure. |
| 5500 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5501 | * @ndlp: pointer to a node-list data structure. |
| 5502 | * |
| 5503 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 5504 | * unsolicited event. It first checks the remote port state. If the remote |
| 5505 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 5506 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 5507 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 5508 | * to accept the RPL. |
| 5509 | * |
| 5510 | * Return code |
| 5511 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 5512 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5513 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5514 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5515 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5516 | { |
| 5517 | struct lpfc_dmabuf *pcmd; |
| 5518 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5519 | uint32_t maxsize; |
| 5520 | uint16_t cmdsize; |
| 5521 | RPL *rpl; |
| 5522 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5523 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5524 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 5525 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5526 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5527 | stat.un.b.lsRjtRsvd0 = 0; |
| 5528 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5529 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5530 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5531 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 5532 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5533 | /* rejected the unsolicited RPL request and done with it */ |
| 5534 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5535 | } |
| 5536 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5537 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5538 | lp = (uint32_t *) pcmd->virt; |
| 5539 | rpl = (RPL *) (lp + 1); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5540 | maxsize = be32_to_cpu(rpl->maxsize); |
| 5541 | |
| 5542 | /* We support only one port */ |
| 5543 | if ((rpl->index == 0) && |
| 5544 | ((maxsize == 0) || |
| 5545 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 5546 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5547 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5548 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 5549 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5550 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5551 | |
| 5552 | return 0; |
| 5553 | } |
| 5554 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5555 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5556 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5557 | * @vport: pointer to a virtual N_Port data structure. |
| 5558 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5559 | * @ndlp: pointer to a node-list data structure. |
| 5560 | * |
| 5561 | * This routine processes Fibre Channel Address Resolution Protocol |
| 5562 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 5563 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 5564 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 5565 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 5566 | * remote PortName is compared against the FC PortName stored in the @vport |
| 5567 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 5568 | * compared against the FC NodeName stored in the @vport data structure. |
| 5569 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 5570 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 5571 | * invoked to send out FARP Response to the remote node. Before sending the |
| 5572 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 5573 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 5574 | * routine is invoked to log into the remote port first. |
| 5575 | * |
| 5576 | * Return code |
| 5577 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 5578 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5579 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5580 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5581 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5582 | { |
| 5583 | struct lpfc_dmabuf *pcmd; |
| 5584 | uint32_t *lp; |
| 5585 | IOCB_t *icmd; |
| 5586 | FARP *fp; |
| 5587 | uint32_t cmd, cnt, did; |
| 5588 | |
| 5589 | icmd = &cmdiocb->iocb; |
| 5590 | did = icmd->un.elsreq64.remoteID; |
| 5591 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5592 | lp = (uint32_t *) pcmd->virt; |
| 5593 | |
| 5594 | cmd = *lp++; |
| 5595 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5596 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5597 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5598 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5599 | /* We will only support match on WWPN or WWNN */ |
| 5600 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5601 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5602 | } |
| 5603 | |
| 5604 | cnt = 0; |
| 5605 | /* If this FARP command is searching for my portname */ |
| 5606 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5607 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5608 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5609 | cnt = 1; |
| 5610 | } |
| 5611 | |
| 5612 | /* If this FARP command is searching for my nodename */ |
| 5613 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5614 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5615 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5616 | cnt = 1; |
| 5617 | } |
| 5618 | |
| 5619 | if (cnt) { |
| 5620 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 5621 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 5622 | /* Log back into the node before sending the FARP. */ |
| 5623 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5624 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5625 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 5626 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5627 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5628 | } |
| 5629 | |
| 5630 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5631 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 5632 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5633 | } |
| 5634 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5635 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5636 | } |
| 5637 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5638 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5639 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5640 | * @vport: pointer to a host virtual N_Port data structure. |
| 5641 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5642 | * @ndlp: pointer to a node-list data structure. |
| 5643 | * |
| 5644 | * This routine processes Fibre Channel Address Resolution Protocol |
| 5645 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 5646 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 5647 | * the FARP response request. |
| 5648 | * |
| 5649 | * Return code |
| 5650 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 5651 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5652 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5653 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5654 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5655 | { |
| 5656 | struct lpfc_dmabuf *pcmd; |
| 5657 | uint32_t *lp; |
| 5658 | IOCB_t *icmd; |
| 5659 | uint32_t cmd, did; |
| 5660 | |
| 5661 | icmd = &cmdiocb->iocb; |
| 5662 | did = icmd->un.elsreq64.remoteID; |
| 5663 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5664 | lp = (uint32_t *) pcmd->virt; |
| 5665 | |
| 5666 | cmd = *lp++; |
| 5667 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5668 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5669 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5670 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5671 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5672 | |
| 5673 | return 0; |
| 5674 | } |
| 5675 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5676 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5677 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5678 | * @vport: pointer to a host virtual N_Port data structure. |
| 5679 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5680 | * @fan_ndlp: pointer to a node-list data structure. |
| 5681 | * |
| 5682 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 5683 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 5684 | * only be processed on a physical port (i.e., the @vport represents the |
| 5685 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 5686 | * compared against those in the phba data structure. If any of those is |
| 5687 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 5688 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 5689 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 5690 | * is invoked to register login to the fabric. |
| 5691 | * |
| 5692 | * Return code |
| 5693 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 5694 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5695 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5696 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5697 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5698 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5699 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5700 | uint32_t *lp; |
| 5701 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5702 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5703 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 5704 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 5705 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5706 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5707 | if ((vport == phba->pport) && |
| 5708 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5709 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5710 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5711 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5712 | sizeof(struct lpfc_name)))) { |
| 5713 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5714 | lpfc_issue_init_vfi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5715 | } else { |
| 5716 | /* FAN verified - skip FLOGI */ |
| 5717 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5718 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5719 | lpfc_issue_fabric_reglogin(vport); |
| 5720 | else |
| 5721 | lpfc_issue_reg_vfi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5722 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5723 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5724 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5725 | } |
| 5726 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5727 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5728 | * lpfc_els_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5729 | * @ptr: holder for the timer function associated data. |
| 5730 | * |
| 5731 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 5732 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 5733 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 5734 | * up the worker thread. It is for the worker thread to invoke the routine |
| 5735 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 5736 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5737 | void |
| 5738 | lpfc_els_timeout(unsigned long ptr) |
| 5739 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5740 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 5741 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5742 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5743 | unsigned long iflag; |
| 5744 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5745 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5746 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
| 5747 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5748 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5749 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5750 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5751 | if (!tmo_posted) |
| 5752 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5753 | return; |
| 5754 | } |
| 5755 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5756 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5757 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5758 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5759 | * @vport: pointer to a virtual N_Port data structure. |
| 5760 | * |
| 5761 | * This routine is the actual handler function that processes an ELS timeout |
| 5762 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 5763 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 5764 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5765 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5766 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5767 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5768 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5769 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5770 | struct lpfc_sli_ring *pring; |
| 5771 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5772 | IOCB_t *cmd = NULL; |
| 5773 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5774 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5775 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5776 | uint32_t remote_ID = 0xffffffff; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5777 | LIST_HEAD(txcmplq_completions); |
| 5778 | LIST_HEAD(abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5779 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5780 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5781 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 5782 | |
| 5783 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5784 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5785 | spin_lock_irq(&phba->hbalock); |
| 5786 | list_splice_init(&pring->txcmplq, &txcmplq_completions); |
| 5787 | spin_unlock_irq(&phba->hbalock); |
| 5788 | |
| 5789 | list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5790 | cmd = &piocb->iocb; |
| 5791 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5792 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 5793 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 5794 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5795 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5796 | |
| 5797 | if (piocb->vport != vport) |
| 5798 | continue; |
| 5799 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5800 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5801 | if (pcmd) |
| 5802 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5803 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5804 | if (els_command == ELS_CMD_FARP || |
| 5805 | els_command == ELS_CMD_FARPR || |
| 5806 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5807 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5808 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5809 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5810 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5811 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5812 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5813 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5814 | continue; |
| 5815 | } |
| 5816 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5817 | remote_ID = 0xffffffff; |
| 5818 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5819 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5820 | else { |
| 5821 | struct lpfc_nodelist *ndlp; |
| 5822 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5823 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5824 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5825 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5826 | list_add_tail(&piocb->dlist, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5827 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5828 | spin_lock_irq(&phba->hbalock); |
| 5829 | list_splice(&txcmplq_completions, &pring->txcmplq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5830 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 5831 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5832 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
| 5833 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5834 | "0127 ELS timeout Data: x%x x%x x%x " |
| 5835 | "x%x\n", els_command, |
| 5836 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
| 5837 | spin_lock_irq(&phba->hbalock); |
| 5838 | list_del_init(&piocb->dlist); |
| 5839 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5840 | spin_unlock_irq(&phba->hbalock); |
| 5841 | } |
| 5842 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5843 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
| 5844 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5845 | } |
| 5846 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5847 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5848 | * 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] | 5849 | * @vport: pointer to a host virtual N_Port data structure. |
| 5850 | * |
| 5851 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5852 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 5853 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5854 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5855 | * the IOCBs with a non-NULL completion callback function, the callback |
| 5856 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5857 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 5858 | * callback function, the IOCB will simply be released. Finally, it walks |
| 5859 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 5860 | * completion queue IOCB that is associated with the @vport and is not |
| 5861 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 5862 | * part of the discovery state machine) out to HBA by invoking the |
| 5863 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 5864 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 5865 | * the IOCBs are aborted when this function returns. |
| 5866 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5867 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5868 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5869 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5870 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5871 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5872 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5873 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5874 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5875 | |
| 5876 | lpfc_fabric_abort_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5877 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5878 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5879 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5880 | cmd = &piocb->iocb; |
| 5881 | |
| 5882 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5883 | continue; |
| 5884 | } |
| 5885 | |
| 5886 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5887 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5888 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5889 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5890 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5891 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5892 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5893 | if (piocb->vport != vport) |
| 5894 | continue; |
| 5895 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5896 | list_move_tail(&piocb->list, &completions); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5897 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5898 | } |
| 5899 | |
| 5900 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5901 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5902 | continue; |
| 5903 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5904 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5905 | if (piocb->vport != vport) |
| 5906 | continue; |
| 5907 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5908 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5909 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5910 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5911 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5912 | /* Cancell all the IOCBs from the completions list */ |
| 5913 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5914 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5915 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5916 | return; |
| 5917 | } |
| 5918 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5919 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5920 | * lpfc_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] | 5921 | * @phba: pointer to lpfc hba data structure. |
| 5922 | * |
| 5923 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5924 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 5925 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5926 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5927 | * the IOCBs with the completion callback function associated, the callback |
| 5928 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5929 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 5930 | * callback function associated, the IOCB will simply be released. Finally, |
| 5931 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 5932 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 5933 | * management plane IOCBs that are not part of the discovery state machine) |
| 5934 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5935 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5936 | void |
| 5937 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 5938 | { |
| 5939 | LIST_HEAD(completions); |
| 5940 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 5941 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5942 | IOCB_t *cmd = NULL; |
| 5943 | |
| 5944 | lpfc_fabric_abort_hba(phba); |
| 5945 | spin_lock_irq(&phba->hbalock); |
| 5946 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5947 | cmd = &piocb->iocb; |
| 5948 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5949 | continue; |
| 5950 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
| 5951 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5952 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5953 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5954 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| 5955 | continue; |
| 5956 | list_move_tail(&piocb->list, &completions); |
| 5957 | pring->txq_cnt--; |
| 5958 | } |
| 5959 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5960 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5961 | continue; |
| 5962 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5963 | } |
| 5964 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5965 | |
| 5966 | /* Cancel all the IOCBs from the completions list */ |
| 5967 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5968 | IOERR_SLI_ABORTED); |
| 5969 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5970 | return; |
| 5971 | } |
| 5972 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5973 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5974 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5975 | * @phba: Pointer to hba context object. |
| 5976 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 5977 | * @rspiocbp: Pointer to response iocb which reported error. |
| 5978 | * |
| 5979 | * This function sends an event when there is an ELS command |
| 5980 | * failure. |
| 5981 | **/ |
| 5982 | void |
| 5983 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 5984 | struct lpfc_iocbq *cmdiocbp, |
| 5985 | struct lpfc_iocbq *rspiocbp) |
| 5986 | { |
| 5987 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 5988 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5989 | struct lpfc_lsrjt_event lsrjt_event; |
| 5990 | struct lpfc_fabric_event_header fabric_event; |
| 5991 | struct ls_rjt stat; |
| 5992 | struct lpfc_nodelist *ndlp; |
| 5993 | uint32_t *pcmd; |
| 5994 | |
| 5995 | ndlp = cmdiocbp->context1; |
| 5996 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 5997 | return; |
| 5998 | |
| 5999 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 6000 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 6001 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 6002 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 6003 | sizeof(struct lpfc_name)); |
| 6004 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 6005 | sizeof(struct lpfc_name)); |
| 6006 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 6007 | cmdiocbp->context2)->virt); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6008 | lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6009 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 6010 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 6011 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 6012 | fc_host_post_vendor_event(shost, |
| 6013 | fc_get_event_number(), |
| 6014 | sizeof(lsrjt_event), |
| 6015 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6016 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6017 | return; |
| 6018 | } |
| 6019 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 6020 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 6021 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 6022 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 6023 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 6024 | else |
| 6025 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 6026 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 6027 | sizeof(struct lpfc_name)); |
| 6028 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 6029 | sizeof(struct lpfc_name)); |
| 6030 | fc_host_post_vendor_event(shost, |
| 6031 | fc_get_event_number(), |
| 6032 | sizeof(fabric_event), |
| 6033 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6034 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6035 | return; |
| 6036 | } |
| 6037 | |
| 6038 | } |
| 6039 | |
| 6040 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6041 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6042 | * @vport: Pointer to vport object. |
| 6043 | * @ndlp: Pointer FC node object. |
| 6044 | * @cmd: ELS command code. |
| 6045 | * |
| 6046 | * This function posts an event when there is an incoming |
| 6047 | * unsolicited ELS command. |
| 6048 | **/ |
| 6049 | static void |
| 6050 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 6051 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6052 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6053 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6054 | struct lpfc_els_event_header *els_data = NULL; |
| 6055 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6056 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6057 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6058 | if (*payload == ELS_CMD_LOGO) { |
| 6059 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 6060 | if (!logo_data) { |
| 6061 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6062 | "0148 Failed to allocate memory " |
| 6063 | "for LOGO event\n"); |
| 6064 | return; |
| 6065 | } |
| 6066 | els_data = &logo_data->header; |
| 6067 | } else { |
| 6068 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 6069 | GFP_KERNEL); |
| 6070 | if (!els_data) { |
| 6071 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6072 | "0149 Failed to allocate memory " |
| 6073 | "for ELS event\n"); |
| 6074 | return; |
| 6075 | } |
| 6076 | } |
| 6077 | els_data->event_type = FC_REG_ELS_EVENT; |
| 6078 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6079 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6080 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6081 | break; |
| 6082 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6083 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6084 | break; |
| 6085 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6086 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 6087 | break; |
| 6088 | case ELS_CMD_LOGO: |
| 6089 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 6090 | /* Copy the WWPN in the LOGO payload */ |
| 6091 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 6092 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6093 | break; |
| 6094 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 6095 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6096 | return; |
| 6097 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6098 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 6099 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 6100 | if (*payload == ELS_CMD_LOGO) { |
| 6101 | fc_host_post_vendor_event(shost, |
| 6102 | fc_get_event_number(), |
| 6103 | sizeof(struct lpfc_logo_event), |
| 6104 | (char *)logo_data, |
| 6105 | LPFC_NL_VENDOR_ID); |
| 6106 | kfree(logo_data); |
| 6107 | } else { |
| 6108 | fc_host_post_vendor_event(shost, |
| 6109 | fc_get_event_number(), |
| 6110 | sizeof(struct lpfc_els_event_header), |
| 6111 | (char *)els_data, |
| 6112 | LPFC_NL_VENDOR_ID); |
| 6113 | kfree(els_data); |
| 6114 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6115 | |
| 6116 | return; |
| 6117 | } |
| 6118 | |
| 6119 | |
| 6120 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6121 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6122 | * @phba: pointer to lpfc hba data structure. |
| 6123 | * @pring: pointer to a SLI ring. |
| 6124 | * @vport: pointer to a host virtual N_Port data structure. |
| 6125 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 6126 | * |
| 6127 | * This routine is used for processing the IOCB associated with a unsolicited |
| 6128 | * event. It first determines whether there is an existing ndlp that matches |
| 6129 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 6130 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 6131 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 6132 | * of the discovery state machine. |
| 6133 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6134 | static void |
| 6135 | 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] | 6136 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6137 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6138 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6139 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6140 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6141 | uint32_t *payload; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6142 | uint32_t cmd, did, newnode, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6143 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6144 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6145 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6146 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6147 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6148 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6149 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 6150 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6151 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 6152 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6153 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6154 | did = icmd->un.rcvels.remoteID; |
| 6155 | if (icmd->ulpStatus) { |
| 6156 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6157 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 6158 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6159 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6160 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6161 | |
| 6162 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6163 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6164 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6165 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 6166 | /* Ignore traffic received during vport shutdown. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6167 | if (vport->load_flag & FC_UNLOADING) |
| 6168 | goto dropit; |
| 6169 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6170 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6171 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6172 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6173 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6174 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6175 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6176 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6177 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6178 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6179 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6180 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6181 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6182 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 6183 | ndlp = lpfc_enable_node(vport, ndlp, |
| 6184 | NLP_STE_UNUSED_NODE); |
| 6185 | if (!ndlp) |
| 6186 | goto dropit; |
| 6187 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 6188 | newnode = 1; |
| 6189 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 6190 | ndlp->nlp_type |= NLP_FABRIC; |
| 6191 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 6192 | /* This is similar to the new node path */ |
| 6193 | ndlp = lpfc_nlp_get(ndlp); |
| 6194 | if (!ndlp) |
| 6195 | goto dropit; |
| 6196 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 6197 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6198 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6199 | |
| 6200 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6201 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6202 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6203 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6204 | |
| 6205 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 6206 | cmd &= ELS_CMD_MASK; |
| 6207 | } |
| 6208 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6209 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6210 | "0112 ELS command x%x received from NPORT x%x " |
| 6211 | "Data: x%x\n", cmd, did, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6212 | switch (cmd) { |
| 6213 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6214 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6215 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 6216 | did, vport->port_state, ndlp->nlp_flag); |
| 6217 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6218 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6219 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
| 6220 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6221 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6222 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 6223 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 6224 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 6225 | rjt_err = LSRJT_UNABLE_TPC; |
| 6226 | break; |
| 6227 | } |
| 6228 | /* We get here, and drop thru, if we are PT2PT with |
| 6229 | * another NPort and the other side has initiated |
| 6230 | * the PLOGI before responding to our FLOGI. |
| 6231 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6232 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6233 | |
| 6234 | shost = lpfc_shost_from_vport(vport); |
| 6235 | spin_lock_irq(shost->host_lock); |
| 6236 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 6237 | spin_unlock_irq(shost->host_lock); |
| 6238 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6239 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 6240 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6241 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6242 | break; |
| 6243 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6244 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6245 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 6246 | did, vport->port_state, ndlp->nlp_flag); |
| 6247 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6248 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6249 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6250 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6251 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6252 | break; |
| 6253 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6254 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6255 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 6256 | did, vport->port_state, ndlp->nlp_flag); |
| 6257 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6258 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6259 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6260 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6261 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6262 | break; |
| 6263 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6264 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6265 | break; |
| 6266 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6267 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6268 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 6269 | did, vport->port_state, ndlp->nlp_flag); |
| 6270 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6271 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6272 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6273 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6274 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6275 | break; |
| 6276 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6277 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6278 | break; |
| 6279 | case ELS_CMD_RSCN: |
| 6280 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6281 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6282 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6283 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6284 | break; |
| 6285 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6286 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6287 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 6288 | did, vport->port_state, ndlp->nlp_flag); |
| 6289 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6290 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6291 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6292 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6293 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6294 | break; |
| 6295 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6296 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 6297 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6298 | break; |
| 6299 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6300 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6301 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 6302 | did, vport->port_state, ndlp->nlp_flag); |
| 6303 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6304 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6305 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6306 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6307 | break; |
| 6308 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6309 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 6310 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6311 | break; |
| 6312 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6313 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6314 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 6315 | did, vport->port_state, ndlp->nlp_flag); |
| 6316 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6317 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6318 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6319 | break; |
| 6320 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6321 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6322 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 6323 | did, vport->port_state, ndlp->nlp_flag); |
| 6324 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6325 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6326 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6327 | break; |
| 6328 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6329 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6330 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 6331 | did, vport->port_state, ndlp->nlp_flag); |
| 6332 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6333 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6334 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6335 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6336 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6337 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6338 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 6339 | did, vport->port_state, ndlp->nlp_flag); |
| 6340 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6341 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6342 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6343 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6344 | break; |
| 6345 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6346 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6347 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6348 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6349 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6350 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 6351 | did, vport->port_state, ndlp->nlp_flag); |
| 6352 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6353 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6354 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6355 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6356 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6357 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6358 | case ELS_CMD_RLS: |
| 6359 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6360 | "RCV RLS: did:x%x/ste:x%x flg:x%x", |
| 6361 | did, vport->port_state, ndlp->nlp_flag); |
| 6362 | |
| 6363 | phba->fc_stat.elsRcvRLS++; |
| 6364 | lpfc_els_rcv_rls(vport, elsiocb, ndlp); |
| 6365 | if (newnode) |
| 6366 | lpfc_nlp_put(ndlp); |
| 6367 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6368 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6369 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6370 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 6371 | did, vport->port_state, ndlp->nlp_flag); |
| 6372 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6373 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6374 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6375 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6376 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6377 | break; |
| 6378 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6379 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6380 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 6381 | did, vport->port_state, ndlp->nlp_flag); |
| 6382 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6383 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6384 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6385 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6386 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6387 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6388 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6389 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6390 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 6391 | did, vport->port_state, ndlp->nlp_flag); |
| 6392 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6393 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6394 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6395 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6396 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6397 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6398 | case ELS_CMD_RTV: |
| 6399 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6400 | "RCV RTV: did:x%x/ste:x%x flg:x%x", |
| 6401 | did, vport->port_state, ndlp->nlp_flag); |
| 6402 | phba->fc_stat.elsRcvRTV++; |
| 6403 | lpfc_els_rcv_rtv(vport, elsiocb, ndlp); |
| 6404 | if (newnode) |
| 6405 | lpfc_nlp_put(ndlp); |
| 6406 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6407 | case ELS_CMD_RRQ: |
| 6408 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6409 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", |
| 6410 | did, vport->port_state, ndlp->nlp_flag); |
| 6411 | |
| 6412 | phba->fc_stat.elsRcvRRQ++; |
| 6413 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); |
| 6414 | if (newnode) |
| 6415 | lpfc_nlp_put(ndlp); |
| 6416 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6417 | case ELS_CMD_ECHO: |
| 6418 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6419 | "RCV ECHO: did:x%x/ste:x%x flg:x%x", |
| 6420 | did, vport->port_state, ndlp->nlp_flag); |
| 6421 | |
| 6422 | phba->fc_stat.elsRcvECHO++; |
| 6423 | lpfc_els_rcv_echo(vport, elsiocb, ndlp); |
| 6424 | if (newnode) |
| 6425 | lpfc_nlp_put(ndlp); |
| 6426 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6427 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6428 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6429 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 6430 | cmd, did, vport->port_state); |
| 6431 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6432 | /* Unsupported ELS command, reject */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6433 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6434 | |
| 6435 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6436 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6437 | "0115 Unknown ELS command x%x " |
| 6438 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6439 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6440 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6441 | break; |
| 6442 | } |
| 6443 | |
| 6444 | /* check if need to LS_RJT received ELS cmd */ |
| 6445 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6446 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6447 | stat.un.b.lsRjtRsnCode = rjt_err; |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 6448 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6449 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 6450 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6451 | } |
| 6452 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6453 | lpfc_nlp_put(elsiocb->context1); |
| 6454 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6455 | return; |
| 6456 | |
| 6457 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6458 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6459 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6460 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6461 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6462 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6463 | phba->fc_stat.elsRcvDrop++; |
| 6464 | } |
| 6465 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6466 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6467 | * 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] | 6468 | * @phba: pointer to lpfc hba data structure. |
| 6469 | * @vpi: host virtual N_Port identifier. |
| 6470 | * |
| 6471 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 6472 | * @vpi. The function walks the HBA's vport list and returns the address |
| 6473 | * of the vport with the matching @vpi. |
| 6474 | * |
| 6475 | * Return code |
| 6476 | * NULL - No vport with the matching @vpi found |
| 6477 | * Otherwise - Address to the vport with the matching @vpi. |
| 6478 | **/ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 6479 | struct lpfc_vport * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6480 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 6481 | { |
| 6482 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6483 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6484 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6485 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6486 | list_for_each_entry(vport, &phba->port_list, listentry) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6487 | if (vport->vpi == vpi) { |
| 6488 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6489 | return vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6490 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6491 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6492 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6493 | return NULL; |
| 6494 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6495 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6496 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6497 | * 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] | 6498 | * @phba: pointer to lpfc hba data structure. |
| 6499 | * @pring: pointer to a SLI ring. |
| 6500 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 6501 | * |
| 6502 | * This routine is used to process an unsolicited event received from a SLI |
| 6503 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 6504 | * associated with the unsolicited event is done by invoking the routine |
| 6505 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 6506 | * SLI ring on which the unsolicited event was received. |
| 6507 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6508 | void |
| 6509 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 6510 | struct lpfc_iocbq *elsiocb) |
| 6511 | { |
| 6512 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6513 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6514 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6515 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 6516 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6517 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6518 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6519 | elsiocb->context2 = NULL; |
| 6520 | elsiocb->context3 = NULL; |
| 6521 | |
| 6522 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 6523 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 6524 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 6525 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6526 | phba->fc_stat.NoRcvBuf++; |
| 6527 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6528 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 6529 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6530 | return; |
| 6531 | } |
| 6532 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6533 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 6534 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 6535 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 6536 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 6537 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6538 | else |
| 6539 | vport = lpfc_find_vport_by_vpid(phba, |
| 6540 | icmd->unsli3.rcvsli3.vpi - phba->vpi_base); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6541 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6542 | /* If there are no BDEs associated |
| 6543 | * with this IOCB, there is nothing to do. |
| 6544 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6545 | if (icmd->ulpBdeCount == 0) |
| 6546 | return; |
| 6547 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6548 | /* type of ELS cmd is first 32bit word |
| 6549 | * in packet |
| 6550 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6551 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6552 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6553 | } else { |
| 6554 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 6555 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6556 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 6557 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6558 | } |
| 6559 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6560 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 6561 | /* |
| 6562 | * The different unsolicited event handlers would tell us |
| 6563 | * if they are done with "mp" by setting context2 to NULL. |
| 6564 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6565 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6566 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 6567 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6568 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6569 | |
| 6570 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6571 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6572 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6573 | elsiocb->context2 = bdeBuf2; |
| 6574 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6575 | /* free mp if we are done with it */ |
| 6576 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6577 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 6578 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6579 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6580 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6581 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6582 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6583 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6584 | * lpfc_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] | 6585 | * @phba: pointer to lpfc hba data structure. |
| 6586 | * @vport: pointer to a virtual N_Port data structure. |
| 6587 | * |
| 6588 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 6589 | * State Change Request (SCR) for a @vport. This routine will create an |
| 6590 | * ndlp for the Name Server associated to the @vport if such node does |
| 6591 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 6592 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 6593 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 6594 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 6595 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6596 | void |
| 6597 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 6598 | { |
| 6599 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
| 6600 | |
| 6601 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 6602 | if (!ndlp) { |
| 6603 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 6604 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6605 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6606 | lpfc_disc_start(vport); |
| 6607 | return; |
| 6608 | } |
| 6609 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6610 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6611 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6612 | return; |
| 6613 | } |
| 6614 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6615 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 6616 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 6617 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6618 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6619 | lpfc_disc_start(vport); |
| 6620 | return; |
| 6621 | } |
| 6622 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6623 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6624 | "0348 NameServer login: node freed\n"); |
| 6625 | return; |
| 6626 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6627 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6628 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6629 | |
| 6630 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 6631 | |
| 6632 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 6633 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6634 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6635 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6636 | return; |
| 6637 | } |
| 6638 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6639 | if (vport->cfg_fdmi_on) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6640 | /* If this is the first time, allocate an ndlp and initialize |
| 6641 | * it. Otherwise, make sure the node is enabled and then do the |
| 6642 | * login. |
| 6643 | */ |
| 6644 | ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID); |
| 6645 | if (!ndlp_fdmi) { |
| 6646 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 6647 | GFP_KERNEL); |
| 6648 | if (ndlp_fdmi) { |
| 6649 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 6650 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
| 6651 | } else |
| 6652 | return; |
| 6653 | } |
| 6654 | if (!NLP_CHK_NODE_ACT(ndlp_fdmi)) |
| 6655 | ndlp_fdmi = lpfc_enable_node(vport, |
| 6656 | ndlp_fdmi, |
| 6657 | NLP_STE_NPR_NODE); |
| 6658 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6659 | if (ndlp_fdmi) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6660 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6661 | NLP_STE_PLOGI_ISSUE); |
| 6662 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6663 | } |
| 6664 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6665 | } |
| 6666 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6667 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6668 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6669 | * @phba: pointer to lpfc hba data structure. |
| 6670 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 6671 | * |
| 6672 | * This routine is the completion callback function to register new vport |
| 6673 | * mailbox command. If the new vport mailbox command completes successfully, |
| 6674 | * the fabric registration login shall be performed on physical port (the |
| 6675 | * new vport created is actually a physical port, with VPI 0) or the port |
| 6676 | * login to Name Server for State Change Request (SCR) will be performed |
| 6677 | * on virtual port (real virtual port, with VPI greater than 0). |
| 6678 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6679 | static void |
| 6680 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6681 | { |
| 6682 | struct lpfc_vport *vport = pmb->vport; |
| 6683 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6684 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6685 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6686 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6687 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6688 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6689 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6690 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6691 | |
| 6692 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6693 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6694 | "0915 Register VPI failed : Status: x%x" |
| 6695 | " upd bit: x%x \n", mb->mbxStatus, |
| 6696 | mb->un.varRegVpi.upd); |
| 6697 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 6698 | mb->un.varRegVpi.upd) |
| 6699 | goto mbox_err_exit ; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6700 | |
| 6701 | switch (mb->mbxStatus) { |
| 6702 | case 0x11: /* unsupported feature */ |
| 6703 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6704 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6705 | /* giving up on vport registration */ |
| 6706 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6707 | spin_lock_irq(shost->host_lock); |
| 6708 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 6709 | spin_unlock_irq(shost->host_lock); |
| 6710 | lpfc_can_disctmo(vport); |
| 6711 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6712 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
| 6713 | case 0x20: |
| 6714 | spin_lock_irq(shost->host_lock); |
| 6715 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 6716 | spin_unlock_irq(shost->host_lock); |
| 6717 | lpfc_init_vpi(phba, pmb, vport->vpi); |
| 6718 | pmb->vport = vport; |
| 6719 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 6720 | rc = lpfc_sli_issue_mbox(phba, pmb, |
| 6721 | MBX_NOWAIT); |
| 6722 | if (rc == MBX_NOT_FINISHED) { |
| 6723 | lpfc_printf_vlog(vport, |
| 6724 | KERN_ERR, LOG_MBOX, |
| 6725 | "2732 Failed to issue INIT_VPI" |
| 6726 | " mailbox command\n"); |
| 6727 | } else { |
| 6728 | lpfc_nlp_put(ndlp); |
| 6729 | return; |
| 6730 | } |
| 6731 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6732 | default: |
| 6733 | /* Try to recover from this error */ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 6734 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6735 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6736 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6737 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6738 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6739 | spin_unlock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6740 | if (vport->port_type == LPFC_PHYSICAL_PORT |
| 6741 | && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6742 | lpfc_issue_init_vfi(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6743 | else |
| 6744 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6745 | break; |
| 6746 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6747 | } else { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6748 | spin_lock_irq(shost->host_lock); |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 6749 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6750 | spin_unlock_irq(shost->host_lock); |
| 6751 | if (vport == phba->pport) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6752 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 6753 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6754 | else { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6755 | /* |
| 6756 | * If the physical port is instantiated using |
| 6757 | * FDISC, do not start vport discovery. |
| 6758 | */ |
| 6759 | if (vport->port_state != LPFC_FDISC) |
| 6760 | lpfc_start_fdiscs(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6761 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6762 | } |
| 6763 | } else |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6764 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6765 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6766 | mbox_err_exit: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6767 | /* Now, we decrement the ndlp reference count held for this |
| 6768 | * callback function |
| 6769 | */ |
| 6770 | lpfc_nlp_put(ndlp); |
| 6771 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6772 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6773 | return; |
| 6774 | } |
| 6775 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6776 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6777 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6778 | * @phba: pointer to lpfc hba data structure. |
| 6779 | * @vport: pointer to a host virtual N_Port data structure. |
| 6780 | * @ndlp: pointer to a node-list data structure. |
| 6781 | * |
| 6782 | * This routine registers the @vport as a new virtual port with a HBA. |
| 6783 | * It is done through a registering vpi mailbox command. |
| 6784 | **/ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6785 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6786 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 6787 | struct lpfc_nodelist *ndlp) |
| 6788 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6789 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6790 | LPFC_MBOXQ_t *mbox; |
| 6791 | |
| 6792 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6793 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6794 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6795 | mbox->vport = vport; |
| 6796 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 6797 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 6798 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6799 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6800 | /* mailbox command not success, decrement ndlp |
| 6801 | * reference count for this command |
| 6802 | */ |
| 6803 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6804 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6805 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6806 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6807 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6808 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6809 | } |
| 6810 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6811 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6812 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6813 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6814 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6815 | return; |
| 6816 | |
| 6817 | mbox_err_exit: |
| 6818 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6819 | spin_lock_irq(shost->host_lock); |
| 6820 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 6821 | spin_unlock_irq(shost->host_lock); |
| 6822 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6823 | } |
| 6824 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6825 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6826 | * 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] | 6827 | * @phba: pointer to lpfc hba data structure. |
| 6828 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6829 | * This routine cancels the retry delay timers to all the vports. |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6830 | **/ |
| 6831 | void |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6832 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6833 | { |
| 6834 | struct lpfc_vport **vports; |
| 6835 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6836 | uint32_t link_state; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6837 | int i; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6838 | |
| 6839 | /* Treat this failure as linkdown for all vports */ |
| 6840 | link_state = phba->link_state; |
| 6841 | lpfc_linkdown(phba); |
| 6842 | phba->link_state = link_state; |
| 6843 | |
| 6844 | vports = lpfc_create_vport_work_array(phba); |
| 6845 | |
| 6846 | if (vports) { |
| 6847 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 6848 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 6849 | if (ndlp) |
| 6850 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
| 6851 | lpfc_els_flush_cmd(vports[i]); |
| 6852 | } |
| 6853 | lpfc_destroy_vport_work_array(phba, vports); |
| 6854 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6855 | } |
| 6856 | |
| 6857 | /** |
| 6858 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. |
| 6859 | * @phba: pointer to lpfc hba data structure. |
| 6860 | * |
| 6861 | * This routine abort all pending discovery commands and |
| 6862 | * start a timer to retry FLOGI for the physical port |
| 6863 | * discovery. |
| 6864 | **/ |
| 6865 | void |
| 6866 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) |
| 6867 | { |
| 6868 | struct lpfc_nodelist *ndlp; |
| 6869 | struct Scsi_Host *shost; |
| 6870 | |
| 6871 | /* Cancel the all vports retry delay retry timers */ |
| 6872 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6873 | |
| 6874 | /* If fabric require FLOGI, then re-instantiate physical login */ |
| 6875 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 6876 | if (!ndlp) |
| 6877 | return; |
| 6878 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6879 | shost = lpfc_shost_from_vport(phba->pport); |
| 6880 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); |
| 6881 | spin_lock_irq(shost->host_lock); |
| 6882 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 6883 | spin_unlock_irq(shost->host_lock); |
| 6884 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; |
| 6885 | phba->pport->port_state = LPFC_FLOGI; |
| 6886 | return; |
| 6887 | } |
| 6888 | |
| 6889 | /** |
| 6890 | * lpfc_fabric_login_reqd - Check if FLOGI required. |
| 6891 | * @phba: pointer to lpfc hba data structure. |
| 6892 | * @cmdiocb: pointer to FDISC command iocb. |
| 6893 | * @rspiocb: pointer to FDISC response iocb. |
| 6894 | * |
| 6895 | * This routine checks if a FLOGI is reguired for FDISC |
| 6896 | * to succeed. |
| 6897 | **/ |
| 6898 | static int |
| 6899 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, |
| 6900 | struct lpfc_iocbq *cmdiocb, |
| 6901 | struct lpfc_iocbq *rspiocb) |
| 6902 | { |
| 6903 | |
| 6904 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || |
| 6905 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) |
| 6906 | return 0; |
| 6907 | else |
| 6908 | return 1; |
| 6909 | } |
| 6910 | |
| 6911 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6912 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6913 | * @phba: pointer to lpfc hba data structure. |
| 6914 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6915 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6916 | * |
| 6917 | * This routine is the completion callback function to a Fabric Discover |
| 6918 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 6919 | * single threaded, each FDISC completion callback function will reset |
| 6920 | * the discovery timer for all vports such that the timers will not get |
| 6921 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 6922 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 6923 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 6924 | * assigned to the vport has been changed with the completion of the FDISC |
| 6925 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 6926 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 6927 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 6928 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 6929 | * Server for State Change Request (SCR). |
| 6930 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6931 | static void |
| 6932 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6933 | struct lpfc_iocbq *rspiocb) |
| 6934 | { |
| 6935 | struct lpfc_vport *vport = cmdiocb->vport; |
| 6936 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6937 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 6938 | struct lpfc_nodelist *np; |
| 6939 | struct lpfc_nodelist *next_np; |
| 6940 | IOCB_t *irsp = &rspiocb->iocb; |
| 6941 | struct lpfc_iocbq *piocb; |
| 6942 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6943 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6944 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 6945 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 6946 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6947 | /* Since all FDISCs are being single threaded, we |
| 6948 | * must reset the discovery timer for ALL vports |
| 6949 | * waiting to send FDISC when one completes. |
| 6950 | */ |
| 6951 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 6952 | lpfc_set_disctmo(piocb->vport); |
| 6953 | } |
| 6954 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6955 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6956 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 6957 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 6958 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6959 | if (irsp->ulpStatus) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6960 | |
| 6961 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { |
| 6962 | lpfc_retry_pport_discovery(phba); |
| 6963 | goto out; |
| 6964 | } |
| 6965 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6966 | /* Check for retry */ |
| 6967 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 6968 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6969 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6970 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6971 | "0126 FDISC failed. (%d/%d)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6972 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6973 | goto fdisc_failed; |
| 6974 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6975 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6976 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6977 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6978 | vport->fc_flag |= FC_FABRIC; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6979 | if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6980 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 6981 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6982 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6983 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 6984 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
| 6985 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 6986 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 6987 | /* If our NportID changed, we need to ensure all |
| 6988 | * remaining NPORTs get unreg_login'ed so we can |
| 6989 | * issue unreg_vpi. |
| 6990 | */ |
| 6991 | list_for_each_entry_safe(np, next_np, |
| 6992 | &vport->fc_nodes, nlp_listp) { |
| 6993 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 6994 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 6995 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 6996 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6997 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6998 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6999 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7000 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7001 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 7002 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 7003 | |
| 7004 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7005 | lpfc_sli4_unreg_all_rpis(vport); |
| 7006 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7007 | lpfc_mbx_unreg_vpi(vport); |
| 7008 | spin_lock_irq(shost->host_lock); |
| 7009 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7010 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7011 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 7012 | else |
| 7013 | vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7014 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 7015 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 7016 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 7017 | /* |
| 7018 | * Driver needs to re-reg VPI in order for f/w |
| 7019 | * to update the MAC address. |
| 7020 | */ |
| 7021 | lpfc_register_new_vport(phba, vport, ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 7022 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7023 | } |
| 7024 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 7025 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
| 7026 | lpfc_issue_init_vpi(vport); |
| 7027 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7028 | lpfc_register_new_vport(phba, vport, ndlp); |
| 7029 | else |
| 7030 | lpfc_do_scr_ns_plogi(phba, vport); |
| 7031 | goto out; |
| 7032 | fdisc_failed: |
| 7033 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 7034 | /* Cancel discovery timer */ |
| 7035 | lpfc_can_disctmo(vport); |
| 7036 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7037 | out: |
| 7038 | lpfc_els_free_iocb(phba, cmdiocb); |
| 7039 | } |
| 7040 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7041 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7042 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7043 | * @vport: pointer to a virtual N_Port data structure. |
| 7044 | * @ndlp: pointer to a node-list data structure. |
| 7045 | * @retry: number of retries to the command IOCB. |
| 7046 | * |
| 7047 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 7048 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 7049 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 7050 | * IOCB will be sent off HBA at any given time. |
| 7051 | * |
| 7052 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 7053 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 7054 | * will be stored into the context1 field of the IOCB for the completion |
| 7055 | * callback function to the FDISC ELS command. |
| 7056 | * |
| 7057 | * Return code |
| 7058 | * 0 - Successfully issued fdisc iocb command |
| 7059 | * 1 - Failed to issue fdisc iocb command |
| 7060 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 7061 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7062 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 7063 | uint8_t retry) |
| 7064 | { |
| 7065 | struct lpfc_hba *phba = vport->phba; |
| 7066 | IOCB_t *icmd; |
| 7067 | struct lpfc_iocbq *elsiocb; |
| 7068 | struct serv_parm *sp; |
| 7069 | uint8_t *pcmd; |
| 7070 | uint16_t cmdsize; |
| 7071 | int did = ndlp->nlp_DID; |
| 7072 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7073 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7074 | vport->port_state = LPFC_FDISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7075 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 7076 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 7077 | ELS_CMD_FDISC); |
| 7078 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7079 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7080 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7081 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7082 | return 1; |
| 7083 | } |
| 7084 | |
| 7085 | icmd = &elsiocb->iocb; |
| 7086 | icmd->un.elsreq64.myID = 0; |
| 7087 | icmd->un.elsreq64.fl = 1; |
| 7088 | |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 7089 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 7090 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 7091 | LPFC_SLI_INTF_IF_TYPE_0)) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7092 | /* FDISC needs to be 1 for WQE VPI */ |
| 7093 | elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1; |
| 7094 | elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ; |
| 7095 | /* Set the ulpContext to the vpi */ |
| 7096 | elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base; |
| 7097 | } else { |
| 7098 | /* For FDISC, Let FDISC rsp set the NPortID for this VPI */ |
| 7099 | icmd->ulpCt_h = 1; |
| 7100 | icmd->ulpCt_l = 0; |
| 7101 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7102 | |
| 7103 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 7104 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 7105 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 7106 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 7107 | sp = (struct serv_parm *) pcmd; |
| 7108 | /* Setup CSPs accordingly for Fabric */ |
| 7109 | sp->cmn.e_d_tov = 0; |
| 7110 | sp->cmn.w2.r_a_tov = 0; |
| 7111 | sp->cls1.classValid = 0; |
| 7112 | sp->cls2.seqDelivery = 1; |
| 7113 | sp->cls3.seqDelivery = 1; |
| 7114 | |
| 7115 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 7116 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 7117 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 7118 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 7119 | memcpy(pcmd, &vport->fc_portname, 8); |
| 7120 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 7121 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 7122 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 7123 | |
| 7124 | lpfc_set_disctmo(vport); |
| 7125 | |
| 7126 | phba->fc_stat.elsXmitFDISC++; |
| 7127 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 7128 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7129 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 7130 | "Issue FDISC: did:x%x", |
| 7131 | did, 0, 0); |
| 7132 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7133 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 7134 | if (rc == IOCB_ERROR) { |
| 7135 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7136 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7137 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7138 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7139 | return 1; |
| 7140 | } |
| 7141 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7142 | return 0; |
| 7143 | } |
| 7144 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7145 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7146 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7147 | * @phba: pointer to lpfc hba data structure. |
| 7148 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7149 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 7150 | * |
| 7151 | * This routine is the completion callback function to the issuing of a LOGO |
| 7152 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 7153 | * reference count held on ndlp for this completion function, indicating that |
| 7154 | * the reference to the ndlp is no long needed. Note that the |
| 7155 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 7156 | * callback function and an additional explicit ndlp reference decrementation |
| 7157 | * will trigger the actual release of the ndlp. |
| 7158 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7159 | static void |
| 7160 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 7161 | struct lpfc_iocbq *rspiocb) |
| 7162 | { |
| 7163 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7164 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7165 | struct lpfc_nodelist *ndlp; |
| 7166 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7167 | |
| 7168 | irsp = &rspiocb->iocb; |
| 7169 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 7170 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 7171 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7172 | |
| 7173 | lpfc_els_free_iocb(phba, cmdiocb); |
| 7174 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7175 | |
| 7176 | /* Trigger the release of the ndlp after logo */ |
| 7177 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 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_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7182 | * @vport: pointer to a virtual N_Port data structure. |
| 7183 | * @ndlp: pointer to a node-list data structure. |
| 7184 | * |
| 7185 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 7186 | * |
| 7187 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 7188 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 7189 | * will be stored into the context1 field of the IOCB for the completion |
| 7190 | * callback function to the LOGO ELS command. |
| 7191 | * |
| 7192 | * Return codes |
| 7193 | * 0 - Successfully issued logo off the @vport |
| 7194 | * 1 - Failed to issue logo off the @vport |
| 7195 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7196 | int |
| 7197 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 7198 | { |
| 7199 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7200 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7201 | IOCB_t *icmd; |
| 7202 | struct lpfc_iocbq *elsiocb; |
| 7203 | uint8_t *pcmd; |
| 7204 | uint16_t cmdsize; |
| 7205 | |
| 7206 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 7207 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 7208 | ELS_CMD_LOGO); |
| 7209 | if (!elsiocb) |
| 7210 | return 1; |
| 7211 | |
| 7212 | icmd = &elsiocb->iocb; |
| 7213 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 7214 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 7215 | pcmd += sizeof(uint32_t); |
| 7216 | |
| 7217 | /* Fill in LOGO payload */ |
| 7218 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 7219 | pcmd += sizeof(uint32_t); |
| 7220 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 7221 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7222 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 7223 | "Issue LOGO npiv did:x%x flg:x%x", |
| 7224 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 7225 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7226 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 7227 | spin_lock_irq(shost->host_lock); |
| 7228 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 7229 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7230 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 7231 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7232 | spin_lock_irq(shost->host_lock); |
| 7233 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 7234 | spin_unlock_irq(shost->host_lock); |
| 7235 | lpfc_els_free_iocb(phba, elsiocb); |
| 7236 | return 1; |
| 7237 | } |
| 7238 | return 0; |
| 7239 | } |
| 7240 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7241 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7242 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7243 | * @ptr: holder for the timer function associated data. |
| 7244 | * |
| 7245 | * This routine is invoked by the fabric iocb block timer after |
| 7246 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 7247 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 7248 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 7249 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 7250 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 7251 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7252 | void |
| 7253 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 7254 | { |
| 7255 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 7256 | unsigned long iflags; |
| 7257 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7258 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7259 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 7260 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 7261 | if (!tmo_posted) |
| 7262 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 7263 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 7264 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7265 | if (!tmo_posted) |
| 7266 | lpfc_worker_wake_up(phba); |
| 7267 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7268 | } |
| 7269 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7270 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7271 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7272 | * @phba: pointer to lpfc hba data structure. |
| 7273 | * |
| 7274 | * This routine issues one fabric iocb from the driver internal list to |
| 7275 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 7276 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 7277 | * remove one pending fabric iocb from the driver internal list and invokes |
| 7278 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 7279 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7280 | static void |
| 7281 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 7282 | { |
| 7283 | struct lpfc_iocbq *iocb; |
| 7284 | unsigned long iflags; |
| 7285 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7286 | IOCB_t *cmd; |
| 7287 | |
| 7288 | repeat: |
| 7289 | iocb = NULL; |
| 7290 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7291 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7292 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 7293 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 7294 | list); |
| 7295 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7296 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7297 | atomic_inc(&phba->fabric_iocb_count); |
| 7298 | } |
| 7299 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7300 | if (iocb) { |
| 7301 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 7302 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 7303 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 7304 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7305 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 7306 | "Fabric sched1: ste:x%x", |
| 7307 | iocb->vport->port_state, 0, 0); |
| 7308 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7309 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7310 | |
| 7311 | if (ret == IOCB_ERROR) { |
| 7312 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 7313 | iocb->fabric_iocb_cmpl = NULL; |
| 7314 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 7315 | cmd = &iocb->iocb; |
| 7316 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 7317 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 7318 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 7319 | |
| 7320 | atomic_dec(&phba->fabric_iocb_count); |
| 7321 | goto repeat; |
| 7322 | } |
| 7323 | } |
| 7324 | |
| 7325 | return; |
| 7326 | } |
| 7327 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7328 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7329 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7330 | * @phba: pointer to lpfc hba data structure. |
| 7331 | * |
| 7332 | * This routine unblocks the issuing fabric iocb command. The function |
| 7333 | * will clear the fabric iocb block bit and then invoke the routine |
| 7334 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 7335 | * from the driver internal fabric iocb list. |
| 7336 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7337 | void |
| 7338 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 7339 | { |
| 7340 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 7341 | |
| 7342 | lpfc_resume_fabric_iocbs(phba); |
| 7343 | return; |
| 7344 | } |
| 7345 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7346 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7347 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7348 | * @phba: pointer to lpfc hba data structure. |
| 7349 | * |
| 7350 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 7351 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 7352 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 7353 | * fabric iocb will be issued out of the HBA. |
| 7354 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7355 | static void |
| 7356 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 7357 | { |
| 7358 | int blocked; |
| 7359 | |
| 7360 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7361 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7362 | if (!blocked) |
| 7363 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); |
| 7364 | |
| 7365 | return; |
| 7366 | } |
| 7367 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7368 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7369 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7370 | * @phba: pointer to lpfc hba data structure. |
| 7371 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7372 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 7373 | * |
| 7374 | * This routine is the callback function that is put to the fabric iocb's |
| 7375 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 7376 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 7377 | * function first restores and invokes the original iocb's callback function |
| 7378 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 7379 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 7380 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7381 | static void |
| 7382 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 7383 | struct lpfc_iocbq *rspiocb) |
| 7384 | { |
| 7385 | struct ls_rjt stat; |
| 7386 | |
| 7387 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 7388 | BUG(); |
| 7389 | |
| 7390 | switch (rspiocb->iocb.ulpStatus) { |
| 7391 | case IOSTAT_NPORT_RJT: |
| 7392 | case IOSTAT_FABRIC_RJT: |
| 7393 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 7394 | lpfc_block_fabric_iocbs(phba); |
| 7395 | } |
| 7396 | break; |
| 7397 | |
| 7398 | case IOSTAT_NPORT_BSY: |
| 7399 | case IOSTAT_FABRIC_BSY: |
| 7400 | lpfc_block_fabric_iocbs(phba); |
| 7401 | break; |
| 7402 | |
| 7403 | case IOSTAT_LS_RJT: |
| 7404 | stat.un.lsRjtError = |
| 7405 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 7406 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 7407 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 7408 | lpfc_block_fabric_iocbs(phba); |
| 7409 | break; |
| 7410 | } |
| 7411 | |
| 7412 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 7413 | BUG(); |
| 7414 | |
| 7415 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 7416 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 7417 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 7418 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 7419 | |
| 7420 | atomic_dec(&phba->fabric_iocb_count); |
| 7421 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7422 | /* Post any pending iocbs to HBA */ |
| 7423 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7424 | } |
| 7425 | } |
| 7426 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7427 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7428 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7429 | * @phba: pointer to lpfc hba data structure. |
| 7430 | * @iocb: pointer to lpfc command iocb data structure. |
| 7431 | * |
| 7432 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 7433 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 7434 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 7435 | * any given time. As such, this function will first check to see whether there |
| 7436 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 7437 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 7438 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 7439 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 7440 | * |
| 7441 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 7442 | * order. The problem is caused by the construction of the "ready" boolen does |
| 7443 | * not include the condition that the internal fabric IOCB list is empty. As |
| 7444 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 7445 | * ahead of the fabric IOCBs in the internal list. |
| 7446 | * |
| 7447 | * Return code |
| 7448 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 7449 | * IOCB_ERROR - failed to issue fabric iocb |
| 7450 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 7451 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7452 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 7453 | { |
| 7454 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7455 | int ready; |
| 7456 | int ret; |
| 7457 | |
| 7458 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 7459 | BUG(); |
| 7460 | |
| 7461 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7462 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 7463 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 7464 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7465 | if (ready) |
| 7466 | /* Increment fabric iocb count to hold the position */ |
| 7467 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7468 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7469 | if (ready) { |
| 7470 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 7471 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 7472 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 7473 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7474 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 7475 | "Fabric sched2: ste:x%x", |
| 7476 | iocb->vport->port_state, 0, 0); |
| 7477 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7478 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7479 | |
| 7480 | if (ret == IOCB_ERROR) { |
| 7481 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 7482 | iocb->fabric_iocb_cmpl = NULL; |
| 7483 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 7484 | atomic_dec(&phba->fabric_iocb_count); |
| 7485 | } |
| 7486 | } else { |
| 7487 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7488 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 7489 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7490 | ret = IOCB_SUCCESS; |
| 7491 | } |
| 7492 | return ret; |
| 7493 | } |
| 7494 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7495 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7496 | * 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] | 7497 | * @vport: pointer to a virtual N_Port data structure. |
| 7498 | * |
| 7499 | * This routine aborts all the IOCBs associated with a @vport from the |
| 7500 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 7501 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 7502 | * list, removes each IOCB associated with the @vport off the list, set the |
| 7503 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 7504 | * associated with the IOCB. |
| 7505 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 7506 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7507 | { |
| 7508 | LIST_HEAD(completions); |
| 7509 | struct lpfc_hba *phba = vport->phba; |
| 7510 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7511 | |
| 7512 | spin_lock_irq(&phba->hbalock); |
| 7513 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 7514 | list) { |
| 7515 | |
| 7516 | if (piocb->vport != vport) |
| 7517 | continue; |
| 7518 | |
| 7519 | list_move_tail(&piocb->list, &completions); |
| 7520 | } |
| 7521 | spin_unlock_irq(&phba->hbalock); |
| 7522 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7523 | /* Cancel all the IOCBs from the completions list */ |
| 7524 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 7525 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7526 | } |
| 7527 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7528 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7529 | * 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] | 7530 | * @ndlp: pointer to a node-list data structure. |
| 7531 | * |
| 7532 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 7533 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 7534 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 7535 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 7536 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 7537 | * associated with the IOCB. |
| 7538 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7539 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 7540 | { |
| 7541 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7542 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7543 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 7544 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7545 | |
| 7546 | spin_lock_irq(&phba->hbalock); |
| 7547 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 7548 | list) { |
| 7549 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 7550 | |
| 7551 | list_move_tail(&piocb->list, &completions); |
| 7552 | } |
| 7553 | } |
| 7554 | spin_unlock_irq(&phba->hbalock); |
| 7555 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7556 | /* Cancel all the IOCBs from the completions list */ |
| 7557 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 7558 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7559 | } |
| 7560 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7561 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7562 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7563 | * @phba: pointer to lpfc hba data structure. |
| 7564 | * |
| 7565 | * This routine aborts all the IOCBs currently on the driver internal |
| 7566 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 7567 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 7568 | * list, removes IOCBs off the list, set the status feild to |
| 7569 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 7570 | * the IOCB. |
| 7571 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7572 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 7573 | { |
| 7574 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7575 | |
| 7576 | spin_lock_irq(&phba->hbalock); |
| 7577 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 7578 | spin_unlock_irq(&phba->hbalock); |
| 7579 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7580 | /* Cancel all the IOCBs from the completions list */ |
| 7581 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 7582 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7583 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7584 | |
| 7585 | /** |
| 7586 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 7587 | * @phba: pointer to lpfc hba data structure. |
| 7588 | * @axri: pointer to the els xri abort wcqe structure. |
| 7589 | * |
| 7590 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 7591 | * ELS aborted xri. |
| 7592 | **/ |
| 7593 | void |
| 7594 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 7595 | struct sli4_wcqe_xri_aborted *axri) |
| 7596 | { |
| 7597 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7598 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
| 7599 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7600 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 7601 | unsigned long iflag = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7602 | struct lpfc_nodelist *ndlp; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 7603 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7604 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7605 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7606 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7607 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 7608 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 7609 | if (sglq_entry->sli4_xritag == xri) { |
| 7610 | list_del(&sglq_entry->list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7611 | ndlp = sglq_entry->ndlp; |
| 7612 | sglq_entry->ndlp = NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7613 | list_add_tail(&sglq_entry->list, |
| 7614 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7615 | sglq_entry->state = SGL_FREED; |
| 7616 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7617 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7618 | lpfc_set_rrq_active(phba, ndlp, xri, rxid, 1); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 7619 | |
| 7620 | /* Check if TXQ queue needs to be serviced */ |
| 7621 | if (pring->txq_cnt) |
| 7622 | lpfc_worker_wake_up(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7623 | return; |
| 7624 | } |
| 7625 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7626 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 7627 | sglq_entry = __lpfc_get_active_sglq(phba, xri); |
| 7628 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { |
| 7629 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7630 | return; |
| 7631 | } |
| 7632 | sglq_entry->state = SGL_XRI_ABORTED; |
| 7633 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7634 | return; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7635 | } |