| 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 | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 378 | rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, 0); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 379 | if (rc) { |
| 380 | err = 5; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 381 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 382 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 383 | |
| 384 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; |
| 385 | mbox->vport = vport; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 386 | /* increment the reference count on ndlp to hold reference |
| 387 | * for the callback routine. |
| 388 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 389 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 390 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 391 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 392 | if (rc == MBX_NOT_FINISHED) { |
| 393 | err = 6; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 394 | goto fail_issue_reg_login; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 395 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 396 | |
| 397 | return 0; |
| 398 | |
| 399 | fail_issue_reg_login: |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 400 | /* decrement the reference count on ndlp just incremented |
| 401 | * for the failed mbox command. |
| 402 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 403 | lpfc_nlp_put(ndlp); |
| 404 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 405 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 406 | kfree(mp); |
| 407 | fail_free_mbox: |
| 408 | mempool_free(mbox, phba->mbox_mem_pool); |
| 409 | |
| 410 | fail: |
| 411 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 412 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 413 | "0249 Cannot issue Register Fabric login: Err %d\n", err); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 414 | return -ENXIO; |
| 415 | } |
| 416 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 417 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 418 | * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login |
| 419 | * @vport: pointer to a host virtual N_Port data structure. |
| 420 | * |
| 421 | * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for |
| 422 | * the @vport. This mailbox command is necessary for FCoE only. |
| 423 | * |
| 424 | * Return code |
| 425 | * 0 - successfully issued REG_VFI for @vport |
| 426 | * A failure code otherwise. |
| 427 | **/ |
| 428 | static int |
| 429 | lpfc_issue_reg_vfi(struct lpfc_vport *vport) |
| 430 | { |
| 431 | struct lpfc_hba *phba = vport->phba; |
| 432 | LPFC_MBOXQ_t *mboxq; |
| 433 | struct lpfc_nodelist *ndlp; |
| 434 | struct serv_parm *sp; |
| 435 | struct lpfc_dmabuf *dmabuf; |
| 436 | int rc = 0; |
| 437 | |
| 438 | sp = &phba->fc_fabparam; |
| 439 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 440 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
| 441 | rc = -ENODEV; |
| 442 | goto fail; |
| 443 | } |
| 444 | |
| 445 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 446 | if (!dmabuf) { |
| 447 | rc = -ENOMEM; |
| 448 | goto fail; |
| 449 | } |
| 450 | dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys); |
| 451 | if (!dmabuf->virt) { |
| 452 | rc = -ENOMEM; |
| 453 | goto fail_free_dmabuf; |
| 454 | } |
| 455 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 456 | if (!mboxq) { |
| 457 | rc = -ENOMEM; |
| 458 | goto fail_free_coherent; |
| 459 | } |
| 460 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 461 | memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam)); |
| 462 | lpfc_reg_vfi(mboxq, vport, dmabuf->phys); |
| 463 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi; |
| 464 | mboxq->vport = vport; |
| 465 | mboxq->context1 = dmabuf; |
| 466 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 467 | if (rc == MBX_NOT_FINISHED) { |
| 468 | rc = -ENXIO; |
| 469 | goto fail_free_mbox; |
| 470 | } |
| 471 | return 0; |
| 472 | |
| 473 | fail_free_mbox: |
| 474 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 475 | fail_free_coherent: |
| 476 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 477 | fail_free_dmabuf: |
| 478 | kfree(dmabuf); |
| 479 | fail: |
| 480 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 481 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 482 | "0289 Issue Register VFI failed: Err %d\n", rc); |
| 483 | return rc; |
| 484 | } |
| 485 | |
| 486 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 487 | * 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] | 488 | * @vport: pointer to a host virtual N_Port data structure. |
| 489 | * @ndlp: pointer to a node-list data structure. |
| 490 | * @sp: pointer to service parameter data structure. |
| 491 | * @irsp: pointer to the IOCB within the lpfc response IOCB. |
| 492 | * |
| 493 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 494 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric |
| 495 | * port in a fabric topology. It properly sets up the parameters to the @ndlp |
| 496 | * from the IOCB response. It also check the newly assigned N_Port ID to the |
| 497 | * @vport against the previously assigned N_Port ID. If it is different from |
| 498 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine |
| 499 | * is invoked on all the remaining nodes with the @vport to unregister the |
| 500 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() |
| 501 | * is invoked to register login to the fabric. |
| 502 | * |
| 503 | * Return code |
| 504 | * 0 - Success (currently, always return 0) |
| 505 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 506 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 507 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 508 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 509 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 510 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 511 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 512 | struct lpfc_nodelist *np; |
| 513 | struct lpfc_nodelist *next_np; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 514 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 515 | spin_lock_irq(shost->host_lock); |
| 516 | vport->fc_flag |= FC_FABRIC; |
| 517 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 518 | |
| 519 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 520 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 521 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 522 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 523 | phba->fc_edtovResol = sp->cmn.edtovResolution; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 524 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 525 | |
| 526 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 527 | spin_lock_irq(shost->host_lock); |
| 528 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 529 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 530 | } |
| 531 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 532 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 533 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 534 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 535 | ndlp->nlp_class_sup = 0; |
| 536 | if (sp->cls1.classValid) |
| 537 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 538 | if (sp->cls2.classValid) |
| 539 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 540 | if (sp->cls3.classValid) |
| 541 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 542 | if (sp->cls4.classValid) |
| 543 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 544 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 545 | sp->cmn.bbRcvSizeLsb; |
| 546 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 547 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 548 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 549 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 550 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 551 | LOG_ELS | LOG_VPORT, |
| 552 | "1816 FLOGI NPIV supported, " |
| 553 | "response data 0x%x\n", |
| 554 | sp->cmn.response_multiple_NPort); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 555 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 556 | } else { |
| 557 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 558 | to call reg_vnpid atleast for the physcial host */ |
| 559 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 560 | LOG_ELS | LOG_VPORT, |
| 561 | "1817 Fabric does not support NPIV " |
| 562 | "- configuring single port mode.\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 563 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 568 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 569 | |
| 570 | /* If our NportID changed, we need to ensure all |
| 571 | * remaining NPORTs get unreg_login'ed. |
| 572 | */ |
| 573 | list_for_each_entry_safe(np, next_np, |
| 574 | &vport->fc_nodes, nlp_listp) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 575 | if (!NLP_CHK_NODE_ACT(np)) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 576 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 577 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 578 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 579 | continue; |
| 580 | spin_lock_irq(shost->host_lock); |
| 581 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 582 | spin_unlock_irq(shost->host_lock); |
| 583 | lpfc_unreg_rpi(vport, np); |
| 584 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 585 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 586 | |
| 587 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 588 | lpfc_sli4_unreg_all_rpis(vport); |
| 589 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 590 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 591 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 592 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 593 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 594 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 595 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 596 | /* |
| 597 | * If VPI is unreged, driver need to do INIT_VPI |
| 598 | * before re-registering |
| 599 | */ |
| 600 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 601 | spin_lock_irq(shost->host_lock); |
| 602 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 603 | spin_unlock_irq(shost->host_lock); |
| 604 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 605 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 606 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 607 | /* |
| 608 | * Driver needs to re-reg VPI in order for f/w |
| 609 | * to update the MAC address. |
| 610 | */ |
| 611 | lpfc_register_new_vport(phba, vport, ndlp); |
| 612 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 613 | } |
| 614 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 615 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 616 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
| 617 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 618 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 619 | lpfc_register_new_vport(phba, vport, ndlp); |
| 620 | else |
| 621 | lpfc_issue_fabric_reglogin(vport); |
| 622 | } else { |
| 623 | ndlp->nlp_type |= NLP_FABRIC; |
| 624 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 625 | if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) && |
| 626 | (vport->vpi_state & LPFC_VPI_REGISTERED)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 627 | lpfc_start_fdiscs(phba); |
| 628 | lpfc_do_scr_ns_plogi(phba, vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 629 | } else if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 630 | lpfc_issue_init_vpi(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 631 | else |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 632 | lpfc_issue_reg_vfi(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 633 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 634 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 635 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 636 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 637 | * 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] | 638 | * @vport: pointer to a host virtual N_Port data structure. |
| 639 | * @ndlp: pointer to a node-list data structure. |
| 640 | * @sp: pointer to service parameter data structure. |
| 641 | * |
| 642 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 643 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 644 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 645 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 646 | * the received N_Port Name lexicographically, this node shall assign local |
| 647 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 648 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 649 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 650 | * N_Port IDs. |
| 651 | * |
| 652 | * Return code |
| 653 | * 0 - Success |
| 654 | * -ENXIO - Fail |
| 655 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 656 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 657 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 658 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 659 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 660 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 661 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 662 | LPFC_MBOXQ_t *mbox; |
| 663 | int rc; |
| 664 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 665 | spin_lock_irq(shost->host_lock); |
| 666 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 667 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 668 | |
| 669 | phba->fc_edtov = FF_DEF_EDTOV; |
| 670 | phba->fc_ratov = FF_DEF_RATOV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 671 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 672 | sizeof(vport->fc_portname)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 673 | if (rc >= 0) { |
| 674 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 675 | spin_lock_irq(shost->host_lock); |
| 676 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 677 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 678 | |
| 679 | /* |
| 680 | * N_Port ID cannot be 0, set our to LocalID the other |
| 681 | * side will be RemoteID. |
| 682 | */ |
| 683 | |
| 684 | /* not equal */ |
| 685 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 686 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 687 | |
| 688 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 689 | if (!mbox) |
| 690 | goto fail; |
| 691 | |
| 692 | lpfc_config_link(phba, mbox); |
| 693 | |
| 694 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 695 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 696 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 697 | if (rc == MBX_NOT_FINISHED) { |
| 698 | mempool_free(mbox, phba->mbox_mem_pool); |
| 699 | goto fail; |
| 700 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 701 | /* Decrement ndlp reference count indicating that ndlp can be |
| 702 | * safely released when other references to it are done. |
| 703 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 704 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 705 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 706 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 707 | if (!ndlp) { |
| 708 | /* |
| 709 | * Cannot find existing Fabric ndlp, so allocate a |
| 710 | * new one |
| 711 | */ |
| 712 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 713 | if (!ndlp) |
| 714 | goto fail; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 715 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 716 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 717 | ndlp = lpfc_enable_node(vport, ndlp, |
| 718 | NLP_STE_UNUSED_NODE); |
| 719 | if(!ndlp) |
| 720 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 724 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 725 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 726 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 727 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 728 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 729 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 730 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 731 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 732 | } else |
| 733 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 734 | * count indicating that ndlp can be released when other |
| 735 | * references to it are done. |
| 736 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 737 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 738 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 739 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 740 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 741 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 742 | spin_lock_irq(shost->host_lock); |
| 743 | vport->fc_flag |= FC_PT2PT; |
| 744 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 745 | |
| 746 | /* Start discovery - this should just do CLEAR_LA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 747 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 748 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 749 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 750 | return -ENXIO; |
| 751 | } |
| 752 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 753 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 754 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 755 | * @phba: pointer to lpfc hba data structure. |
| 756 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 757 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 758 | * |
| 759 | * This routine is the top-level completion callback function for issuing |
| 760 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 761 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 762 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 763 | * returning 1), the command IOCB will be released and function returned. |
| 764 | * If the retry attempt has been given up (possibly reach the maximum |
| 765 | * number of retries), one additional decrement of ndlp reference shall be |
| 766 | * invoked before going out after releasing the command IOCB. This will |
| 767 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 768 | * invoke one decrement of ndlp reference count). If no error reported in |
| 769 | * the IOCB status, the command Port ID field is used to determine whether |
| 770 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 771 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 772 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 773 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 774 | * specific topology completion conditions. |
| 775 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 776 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 777 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 778 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 779 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 780 | struct lpfc_vport *vport = cmdiocb->vport; |
| 781 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 782 | IOCB_t *irsp = &rspiocb->iocb; |
| 783 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 784 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 785 | struct serv_parm *sp; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 786 | uint16_t fcf_index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 787 | int rc; |
| 788 | |
| 789 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 790 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 791 | /* One additional decrement on node reference count to |
| 792 | * trigger the release of the node |
| 793 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 794 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 795 | goto out; |
| 796 | } |
| 797 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 798 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 799 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 800 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 801 | vport->port_state); |
| 802 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 803 | if (irsp->ulpStatus) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 804 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 805 | * In case of FIP mode, perform roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 806 | * due to new FCF discovery |
| 807 | */ |
| 808 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 809 | (phba->fcf.fcf_flag & FCF_DISCOVERY) && |
| 810 | (irsp->ulpStatus != IOSTAT_LOCAL_REJECT) && |
| 811 | (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 812 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 813 | "2611 FLOGI failed on FCF (x%x), " |
| 814 | "status:x%x/x%x, tmo:x%x, perform " |
| 815 | "roundrobin FCF failover\n", |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 816 | phba->fcf.current_rec.fcf_indx, |
| 817 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 818 | irsp->ulpTimeout); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 819 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 820 | rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index); |
| 821 | if (rc) |
| 822 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 823 | } |
| 824 | |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 825 | /* FLOGI failure */ |
| 826 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 827 | "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
| 828 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 829 | irsp->ulpTimeout); |
| 830 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 831 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 832 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 833 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 834 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 835 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 836 | spin_lock_irq(shost->host_lock); |
| 837 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 838 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 839 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 840 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 841 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 842 | * alpa map would take too long otherwise. |
| 843 | */ |
| 844 | if (phba->alpa_map[0] == 0) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 845 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | /* FLOGI failure */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 849 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 850 | "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 851 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 852 | irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 853 | goto flogifail; |
| 854 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 855 | spin_lock_irq(shost->host_lock); |
| 856 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 857 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 858 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 859 | |
| 860 | /* |
| 861 | * The FLogI succeeded. Sync the data for the CPU before |
| 862 | * accessing it. |
| 863 | */ |
| 864 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 865 | |
| 866 | sp = prsp->virt + sizeof(uint32_t); |
| 867 | |
| 868 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 869 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 870 | "0101 FLOGI completes successfully " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 871 | "Data: x%x x%x x%x x%x\n", |
| 872 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
| 873 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 874 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 875 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 876 | /* |
| 877 | * If Common Service Parameters indicate Nport |
| 878 | * we are point to point, if Fport we are Fabric. |
| 879 | */ |
| 880 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 881 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 882 | else if (!(phba->hba_flag & HBA_FCOE_SUPPORT)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 883 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 884 | else { |
| 885 | lpfc_printf_vlog(vport, KERN_ERR, |
| 886 | LOG_FIP | LOG_ELS, |
| 887 | "2831 FLOGI response with cleared Fabric " |
| 888 | "bit fcf_index 0x%x " |
| 889 | "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x " |
| 890 | "Fabric Name " |
| 891 | "%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 892 | phba->fcf.current_rec.fcf_indx, |
| 893 | phba->fcf.current_rec.switch_name[0], |
| 894 | phba->fcf.current_rec.switch_name[1], |
| 895 | phba->fcf.current_rec.switch_name[2], |
| 896 | phba->fcf.current_rec.switch_name[3], |
| 897 | phba->fcf.current_rec.switch_name[4], |
| 898 | phba->fcf.current_rec.switch_name[5], |
| 899 | phba->fcf.current_rec.switch_name[6], |
| 900 | phba->fcf.current_rec.switch_name[7], |
| 901 | phba->fcf.current_rec.fabric_name[0], |
| 902 | phba->fcf.current_rec.fabric_name[1], |
| 903 | phba->fcf.current_rec.fabric_name[2], |
| 904 | phba->fcf.current_rec.fabric_name[3], |
| 905 | phba->fcf.current_rec.fabric_name[4], |
| 906 | phba->fcf.current_rec.fabric_name[5], |
| 907 | phba->fcf.current_rec.fabric_name[6], |
| 908 | phba->fcf.current_rec.fabric_name[7]); |
| 909 | lpfc_nlp_put(ndlp); |
| 910 | spin_lock_irq(&phba->hbalock); |
| 911 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 912 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 913 | spin_unlock_irq(&phba->hbalock); |
| 914 | goto out; |
| 915 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 916 | if (!rc) { |
| 917 | /* Mark the FCF discovery process done */ |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 918 | if (phba->hba_flag & HBA_FIP_SUPPORT) |
| 919 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | |
| 920 | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 921 | "2769 FLOGI to FCF (x%x) " |
| 922 | "completed successfully\n", |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 923 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 924 | spin_lock_irq(&phba->hbalock); |
| 925 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 926 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 927 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 928 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 929 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | flogifail: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 933 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 934 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 935 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 936 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 937 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 938 | |
| 939 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 940 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 941 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 942 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && |
| 943 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) && |
| 944 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 945 | /* If FLOGI failed enable link interrupt. */ |
| 946 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 947 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 948 | out: |
| 949 | lpfc_els_free_iocb(phba, cmdiocb); |
| 950 | } |
| 951 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 952 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 953 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 954 | * @vport: pointer to a host virtual N_Port data structure. |
| 955 | * @ndlp: pointer to a node-list data structure. |
| 956 | * @retry: number of retries to the command IOCB. |
| 957 | * |
| 958 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 959 | * for a @vport. The initiator service parameters are put into the payload |
| 960 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 961 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 962 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 963 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 964 | * |
| 965 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 966 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 967 | * will be stored into the context1 field of the IOCB for the completion |
| 968 | * callback function to the FLOGI ELS command. |
| 969 | * |
| 970 | * Return code |
| 971 | * 0 - successfully issued flogi iocb for @vport |
| 972 | * 1 - failed to issue flogi iocb for @vport |
| 973 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 974 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 975 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 976 | uint8_t retry) |
| 977 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 978 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 979 | struct serv_parm *sp; |
| 980 | IOCB_t *icmd; |
| 981 | struct lpfc_iocbq *elsiocb; |
| 982 | struct lpfc_sli_ring *pring; |
| 983 | uint8_t *pcmd; |
| 984 | uint16_t cmdsize; |
| 985 | uint32_t tmo; |
| 986 | int rc; |
| 987 | |
| 988 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 989 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 990 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 991 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 992 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 993 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 994 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 995 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 996 | |
| 997 | icmd = &elsiocb->iocb; |
| 998 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 999 | |
| 1000 | /* For FLOGI request, remainder of payload is service parameters */ |
| 1001 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1002 | pcmd += sizeof(uint32_t); |
| 1003 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1004 | sp = (struct serv_parm *) pcmd; |
| 1005 | |
| 1006 | /* Setup CSPs accordingly for Fabric */ |
| 1007 | sp->cmn.e_d_tov = 0; |
| 1008 | sp->cmn.w2.r_a_tov = 0; |
| 1009 | sp->cls1.classValid = 0; |
| 1010 | sp->cls2.seqDelivery = 1; |
| 1011 | sp->cls3.seqDelivery = 1; |
| 1012 | if (sp->cmn.fcphLow < FC_PH3) |
| 1013 | sp->cmn.fcphLow = FC_PH3; |
| 1014 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1015 | sp->cmn.fcphHigh = FC_PH3; |
| 1016 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1017 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1018 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 1019 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 1020 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 1021 | /* Set the fcfi to the fcfi we registered with */ |
| 1022 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 1023 | } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1024 | sp->cmn.request_multiple_Nport = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1025 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 1026 | icmd->ulpCt_h = 1; |
| 1027 | icmd->ulpCt_l = 0; |
| 1028 | } |
| 1029 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1030 | if (phba->fc_topology != TOPOLOGY_LOOP) { |
| 1031 | icmd->un.elsreq64.myID = 0; |
| 1032 | icmd->un.elsreq64.fl = 1; |
| 1033 | } |
| 1034 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1035 | tmo = phba->fc_ratov; |
| 1036 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1037 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1038 | phba->fc_ratov = tmo; |
| 1039 | |
| 1040 | phba->fc_stat.elsXmitFLOGI++; |
| 1041 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1042 | |
| 1043 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1044 | "Issue FLOGI: opt:x%x", |
| 1045 | phba->sli3_options, 0, 0); |
| 1046 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1047 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1048 | if (rc == IOCB_ERROR) { |
| 1049 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1050 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1051 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1052 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1053 | } |
| 1054 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1055 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1056 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1057 | * @phba: pointer to lpfc hba data structure. |
| 1058 | * |
| 1059 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 1060 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 1061 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 1062 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 1063 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 1064 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 1065 | * |
| 1066 | * Return code |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 1067 | * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1068 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1069 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1070 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1071 | { |
| 1072 | struct lpfc_sli_ring *pring; |
| 1073 | struct lpfc_iocbq *iocb, *next_iocb; |
| 1074 | struct lpfc_nodelist *ndlp; |
| 1075 | IOCB_t *icmd; |
| 1076 | |
| 1077 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 1078 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1079 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 1080 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1081 | |
| 1082 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 1083 | |
| 1084 | /* |
| 1085 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 1086 | * searching for. |
| 1087 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1088 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1089 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 1090 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1091 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR && |
| 1092 | icmd->un.elsreq64.bdl.ulpIoTag32) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1093 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1094 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 1095 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1096 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1097 | } |
| 1098 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1099 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1100 | |
| 1101 | return 0; |
| 1102 | } |
| 1103 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1104 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1105 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1106 | * @vport: pointer to a host virtual N_Port data structure. |
| 1107 | * |
| 1108 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 1109 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1110 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1111 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1112 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 1113 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 1114 | * @vport. |
| 1115 | * |
| 1116 | * Return code |
| 1117 | * 0 - failed to issue initial flogi for @vport |
| 1118 | * 1 - successfully issued initial flogi for @vport |
| 1119 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1120 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1121 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1122 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1123 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1124 | struct lpfc_nodelist *ndlp; |
| 1125 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1126 | vport->port_state = LPFC_FLOGI; |
| 1127 | lpfc_set_disctmo(vport); |
| 1128 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1129 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1130 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1131 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1132 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1133 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1134 | if (!ndlp) |
| 1135 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1136 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1137 | /* Set the node type */ |
| 1138 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1139 | /* Put ndlp onto node list */ |
| 1140 | lpfc_enqueue_node(vport, ndlp); |
| 1141 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1142 | /* re-setup ndlp without removing from node list */ |
| 1143 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1144 | if (!ndlp) |
| 1145 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1146 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1147 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1148 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1149 | /* This decrement of reference count to node shall kick off |
| 1150 | * the release of the node. |
| 1151 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1152 | lpfc_nlp_put(ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1153 | return 0; |
| 1154 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1155 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1156 | } |
| 1157 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1158 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1159 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1160 | * @vport: pointer to a host virtual N_Port data structure. |
| 1161 | * |
| 1162 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 1163 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1164 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1165 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1166 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 1167 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 1168 | * @vport. |
| 1169 | * |
| 1170 | * Return code |
| 1171 | * 0 - failed to issue initial fdisc for @vport |
| 1172 | * 1 - successfully issued initial fdisc for @vport |
| 1173 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1174 | int |
| 1175 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 1176 | { |
| 1177 | struct lpfc_hba *phba = vport->phba; |
| 1178 | struct lpfc_nodelist *ndlp; |
| 1179 | |
| 1180 | /* First look for the Fabric ndlp */ |
| 1181 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1182 | if (!ndlp) { |
| 1183 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 1184 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1185 | if (!ndlp) |
| 1186 | return 0; |
| 1187 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1188 | /* Put ndlp onto node list */ |
| 1189 | lpfc_enqueue_node(vport, ndlp); |
| 1190 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1191 | /* re-setup ndlp without removing from node list */ |
| 1192 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1193 | if (!ndlp) |
| 1194 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1195 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1196 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1197 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1198 | /* decrement node reference count to trigger the release of |
| 1199 | * the node. |
| 1200 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1201 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1202 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1203 | } |
| 1204 | return 1; |
| 1205 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1206 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1207 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1208 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1209 | * @vport: pointer to a host virtual N_Port data structure. |
| 1210 | * |
| 1211 | * This routine checks whether there are more remaining Port Logins |
| 1212 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1213 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1214 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1215 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1216 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1217 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1218 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1219 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1220 | { |
| 1221 | int sentplogi; |
| 1222 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1223 | if (vport->num_disc_nodes) |
| 1224 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1225 | |
| 1226 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1227 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1228 | "0232 Continue discovery with %d PLOGIs to go " |
| 1229 | "Data: x%x x%x x%x\n", |
| 1230 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1231 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1232 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1233 | if (vport->fc_flag & FC_NLP_MORE) |
| 1234 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 1235 | sentplogi = lpfc_els_disc_plogi(vport); |
| 1236 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1237 | return; |
| 1238 | } |
| 1239 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1240 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1241 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1242 | * @phba: pointer to lpfc hba data structure. |
| 1243 | * @prsp: pointer to response IOCB payload. |
| 1244 | * @ndlp: pointer to a node-list data structure. |
| 1245 | * |
| 1246 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1247 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1248 | * The following cases are considered N_Port confirmed: |
| 1249 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1250 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1251 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1252 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1253 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1254 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1255 | * on that node to release the RPI associated with the node; 2) if there is |
| 1256 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1257 | * into, a new node shall be allocated (or activated). In either case, the |
| 1258 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1259 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1260 | * its pointer returned as the confirmed node. |
| 1261 | * |
| 1262 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1263 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1264 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1265 | * into an inactive state on the vport node list and the vport node list |
| 1266 | * management algorithm does not allow two node with a same DID. |
| 1267 | * |
| 1268 | * Return code |
| 1269 | * pointer to the PLOGI N_Port @ndlp |
| 1270 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1271 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1272 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1273 | struct lpfc_nodelist *ndlp) |
| 1274 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1275 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1276 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1277 | struct lpfc_rport_data *rdata; |
| 1278 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1279 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1280 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1281 | uint32_t rc, keepDID = 0; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1282 | int put_node; |
| 1283 | int put_rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1284 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1285 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1286 | * by WWPN. Just return the ndlp that was given to us. |
| 1287 | */ |
| 1288 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1289 | return ndlp; |
| 1290 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1291 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1292 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1293 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1294 | /* 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] | 1295 | * we have for that ndlp. If not, we have some work to do. |
| 1296 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1297 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1298 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1299 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1300 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1301 | |
| 1302 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1303 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1304 | sizeof(struct lpfc_name)); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1305 | if (!rc) |
| 1306 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1307 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
| 1308 | if (!new_ndlp) |
| 1309 | return ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1310 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1311 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1312 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1313 | sizeof(struct lpfc_name)); |
| 1314 | if (!rc) |
| 1315 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1316 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1317 | NLP_STE_UNUSED_NODE); |
| 1318 | if (!new_ndlp) |
| 1319 | return ndlp; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1320 | keepDID = new_ndlp->nlp_DID; |
| 1321 | } else |
| 1322 | keepDID = new_ndlp->nlp_DID; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1323 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1324 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1325 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1326 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1327 | |
| 1328 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) |
| 1329 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 1330 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 1331 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1332 | /* 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] | 1333 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1334 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1335 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1336 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1337 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1338 | * to put ndlp on UNUSED list and try to free it. |
| 1339 | */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1340 | |
| 1341 | /* Fix up the rport accordingly */ |
| 1342 | rport = ndlp->rport; |
| 1343 | if (rport) { |
| 1344 | rdata = rport->dd_data; |
| 1345 | if (rdata->pnode == ndlp) { |
| 1346 | lpfc_nlp_put(ndlp); |
| 1347 | ndlp->rport = NULL; |
| 1348 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1349 | new_ndlp->rport = rport; |
| 1350 | } |
| 1351 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1352 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1353 | /* We shall actually free the ndlp with both nlp_DID and |
| 1354 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1355 | * nodelist never to be used. |
| 1356 | */ |
| 1357 | if (ndlp->nlp_DID == 0) { |
| 1358 | spin_lock_irq(&phba->ndlp_lock); |
| 1359 | NLP_SET_FREE_REQ(ndlp); |
| 1360 | spin_unlock_irq(&phba->ndlp_lock); |
| 1361 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1362 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1363 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1364 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1365 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1366 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1367 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1368 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1369 | /* Two ndlps cannot have the same did */ |
| 1370 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1371 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1372 | /* Since we are swapping the ndlp passed in with the new one |
| 1373 | * and the did has already been swapped, copy over the |
| 1374 | * state and names. |
| 1375 | */ |
| 1376 | memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname, |
| 1377 | sizeof(struct lpfc_name)); |
| 1378 | memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename, |
| 1379 | sizeof(struct lpfc_name)); |
| 1380 | new_ndlp->nlp_state = ndlp->nlp_state; |
| 1381 | /* Fix up the rport accordingly */ |
| 1382 | rport = ndlp->rport; |
| 1383 | if (rport) { |
| 1384 | rdata = rport->dd_data; |
| 1385 | put_node = rdata->pnode != NULL; |
| 1386 | put_rport = ndlp->rport != NULL; |
| 1387 | rdata->pnode = NULL; |
| 1388 | ndlp->rport = NULL; |
| 1389 | if (put_node) |
| 1390 | lpfc_nlp_put(ndlp); |
| 1391 | if (put_rport) |
| 1392 | put_device(&rport->dev); |
| 1393 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1394 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1395 | return new_ndlp; |
| 1396 | } |
| 1397 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1398 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1399 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1400 | * @vport: pointer to a host virtual N_Port data structure. |
| 1401 | * |
| 1402 | * This routine checks whether more Registration State Change |
| 1403 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1404 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1405 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1406 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1407 | * handling the RSCNs. |
| 1408 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1409 | void |
| 1410 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1411 | { |
| 1412 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1413 | |
| 1414 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1415 | /* |
| 1416 | * Check to see if more RSCNs came in while we were |
| 1417 | * processing this one. |
| 1418 | */ |
| 1419 | if (vport->fc_rscn_id_cnt || |
| 1420 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1421 | lpfc_els_handle_rscn(vport); |
| 1422 | else { |
| 1423 | spin_lock_irq(shost->host_lock); |
| 1424 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1425 | spin_unlock_irq(shost->host_lock); |
| 1426 | } |
| 1427 | } |
| 1428 | } |
| 1429 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1430 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1431 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1432 | * @phba: pointer to lpfc hba data structure. |
| 1433 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1434 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1435 | * |
| 1436 | * This routine is the completion callback function for issuing the Port |
| 1437 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1438 | * ndlp on the vport node list that matches the remote node ID from the |
| 1439 | * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply |
| 1440 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1441 | * checked for error conditons. If there is error status reported, PLOGI |
| 1442 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1443 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1444 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1445 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1446 | * there are additional N_Port nodes with the vport that need to perform |
| 1447 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1448 | * PLOGIs. |
| 1449 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1450 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1451 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1452 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1453 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1454 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1455 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1456 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1457 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1458 | struct lpfc_dmabuf *prsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1459 | int disc, rc, did, type; |
| 1460 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1461 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1462 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1463 | |
| 1464 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1465 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1466 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1467 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1468 | irsp->un.elsreq64.remoteID); |
| 1469 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1470 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1471 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1472 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1473 | "0136 PLOGI completes to NPort x%x " |
| 1474 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1475 | irsp->un.elsreq64.remoteID, |
| 1476 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1477 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1478 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1479 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1480 | |
| 1481 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1482 | * is being used during discovery. |
| 1483 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1484 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1485 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1486 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1487 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1488 | rc = 0; |
| 1489 | |
| 1490 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1491 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1492 | "0102 PLOGI completes to NPort x%x " |
| 1493 | "Data: x%x x%x x%x x%x x%x\n", |
| 1494 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1495 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1496 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1497 | if (lpfc_els_chk_latt(vport)) { |
| 1498 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1499 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1500 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1501 | goto out; |
| 1502 | } |
| 1503 | |
| 1504 | /* ndlp could be freed in DSM, save these values now */ |
| 1505 | type = ndlp->nlp_type; |
| 1506 | did = ndlp->nlp_DID; |
| 1507 | |
| 1508 | if (irsp->ulpStatus) { |
| 1509 | /* Check for retry */ |
| 1510 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1511 | /* ELS command is being retried */ |
| 1512 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1513 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1514 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1515 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1516 | } |
| 1517 | goto out; |
| 1518 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1519 | /* PLOGI failed Don't print the vport to vport rjts */ |
| 1520 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1521 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1522 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1523 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1524 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1525 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", |
| 1526 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1527 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1528 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1529 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1530 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1531 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1532 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1533 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1534 | } else { |
| 1535 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1536 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1537 | cmdiocb->context2)->list.next, |
| 1538 | struct lpfc_dmabuf, list); |
| 1539 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1540 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1541 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1542 | } |
| 1543 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1544 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1545 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1546 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1547 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1548 | if (vport->num_disc_nodes == 0) { |
| 1549 | spin_lock_irq(shost->host_lock); |
| 1550 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1551 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1552 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1553 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1554 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1555 | } |
| 1556 | } |
| 1557 | |
| 1558 | out: |
| 1559 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1560 | return; |
| 1561 | } |
| 1562 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1563 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1564 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1565 | * @vport: pointer to a host virtual N_Port data structure. |
| 1566 | * @did: destination port identifier. |
| 1567 | * @retry: number of retries to the command IOCB. |
| 1568 | * |
| 1569 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1570 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1571 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1572 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1573 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1574 | * |
| 1575 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1576 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1577 | * will be stored into the context1 field of the IOCB for the completion |
| 1578 | * callback function to the PLOGI ELS command. |
| 1579 | * |
| 1580 | * Return code |
| 1581 | * 0 - Successfully issued a plogi for @vport |
| 1582 | * 1 - failed to issue a plogi for @vport |
| 1583 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1584 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1585 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1586 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1587 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1588 | struct serv_parm *sp; |
| 1589 | IOCB_t *icmd; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1590 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1591 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1592 | struct lpfc_sli *psli; |
| 1593 | uint8_t *pcmd; |
| 1594 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1595 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1596 | |
| 1597 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1598 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1599 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1600 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1601 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1602 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1603 | /* 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] | 1604 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1605 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1606 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1607 | if (!elsiocb) |
| 1608 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1609 | |
| 1610 | icmd = &elsiocb->iocb; |
| 1611 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1612 | |
| 1613 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1614 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1615 | pcmd += sizeof(uint32_t); |
| 1616 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1617 | sp = (struct serv_parm *) pcmd; |
| 1618 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1619 | /* |
| 1620 | * If we are a N-port connected to a Fabric, fix-up paramm's so logins |
| 1621 | * to device on remote loops work. |
| 1622 | */ |
| 1623 | if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP)) |
| 1624 | sp->cmn.altBbCredit = 1; |
| 1625 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1626 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1627 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1628 | |
| 1629 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1630 | sp->cmn.fcphHigh = FC_PH3; |
| 1631 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1632 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1633 | "Issue PLOGI: did:x%x", |
| 1634 | did, 0, 0); |
| 1635 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1636 | phba->fc_stat.elsXmitPLOGI++; |
| 1637 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1638 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1639 | |
| 1640 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1641 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1642 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1643 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1644 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1645 | } |
| 1646 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1647 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1648 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1649 | * @phba: pointer to lpfc hba data structure. |
| 1650 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1651 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1652 | * |
| 1653 | * This routine is the completion callback function for a Process Login |
| 1654 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 1655 | * status. If there is error status reported, PRLI retry shall be attempted |
| 1656 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 1657 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 1658 | * ndlp to mark the PRLI completion. |
| 1659 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1660 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1661 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1662 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1663 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1664 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1665 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1666 | IOCB_t *irsp; |
| 1667 | struct lpfc_sli *psli; |
| 1668 | struct lpfc_nodelist *ndlp; |
| 1669 | |
| 1670 | psli = &phba->sli; |
| 1671 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1672 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1673 | |
| 1674 | irsp = &(rspiocb->iocb); |
| 1675 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1676 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1677 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1678 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1679 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1680 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1681 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 1682 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1683 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1684 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1685 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1686 | "0103 PRLI completes to NPort x%x " |
| 1687 | "Data: x%x x%x x%x x%x\n", |
| 1688 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1689 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1690 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1691 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1692 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1693 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1694 | goto out; |
| 1695 | |
| 1696 | if (irsp->ulpStatus) { |
| 1697 | /* Check for retry */ |
| 1698 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1699 | /* ELS command is being retried */ |
| 1700 | goto out; |
| 1701 | } |
| 1702 | /* PRLI failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1703 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1704 | "2754 PRLI failure DID:%06X Status:x%x/x%x\n", |
| 1705 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1706 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1707 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1708 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1709 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1710 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1711 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1712 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1713 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1714 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1715 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1716 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1717 | out: |
| 1718 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1719 | return; |
| 1720 | } |
| 1721 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1722 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1723 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1724 | * @vport: pointer to a host virtual N_Port data structure. |
| 1725 | * @ndlp: pointer to a node-list data structure. |
| 1726 | * @retry: number of retries to the command IOCB. |
| 1727 | * |
| 1728 | * This routine issues a Process Login (PRLI) ELS command for the |
| 1729 | * @vport. The PRLI service parameters are set up in the payload of the |
| 1730 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 1731 | * is put to the IOCB completion callback func field before invoking the |
| 1732 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 1733 | * |
| 1734 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1735 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1736 | * will be stored into the context1 field of the IOCB for the completion |
| 1737 | * callback function to the PRLI ELS command. |
| 1738 | * |
| 1739 | * Return code |
| 1740 | * 0 - successfully issued prli iocb command for @vport |
| 1741 | * 1 - failed to issue prli iocb command for @vport |
| 1742 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1743 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1744 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1745 | uint8_t retry) |
| 1746 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1747 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1748 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1749 | PRLI *npr; |
| 1750 | IOCB_t *icmd; |
| 1751 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1752 | uint8_t *pcmd; |
| 1753 | uint16_t cmdsize; |
| 1754 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1755 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1756 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1757 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1758 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1759 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1760 | |
| 1761 | icmd = &elsiocb->iocb; |
| 1762 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1763 | |
| 1764 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1765 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1766 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1767 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1768 | |
| 1769 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 1770 | npr = (PRLI *) pcmd; |
| 1771 | /* |
| 1772 | * If our firmware version is 3.20 or later, |
| 1773 | * set the following bits for FC-TAPE support. |
| 1774 | */ |
| 1775 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 1776 | npr->ConfmComplAllowed = 1; |
| 1777 | npr->Retry = 1; |
| 1778 | npr->TaskRetryIdReq = 1; |
| 1779 | } |
| 1780 | npr->estabImagePair = 1; |
| 1781 | npr->readXferRdyDis = 1; |
| 1782 | |
| 1783 | /* For FCP support */ |
| 1784 | npr->prliType = PRLI_FCP_TYPE; |
| 1785 | npr->initiatorFunc = 1; |
| 1786 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1787 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1788 | "Issue PRLI: did:x%x", |
| 1789 | ndlp->nlp_DID, 0, 0); |
| 1790 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1791 | phba->fc_stat.elsXmitPRLI++; |
| 1792 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1793 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1794 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1795 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1796 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 1797 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1798 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1799 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1800 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1801 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1802 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1803 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1804 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1805 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1806 | } |
| 1807 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1808 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1809 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1810 | * @vport: pointer to a host virtual N_Port data structure. |
| 1811 | * |
| 1812 | * This routine performs Registration State Change Notification (RSCN) |
| 1813 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 1814 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 1815 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 1816 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 1817 | * invoked to check and handle possible more RSCN came in during the period |
| 1818 | * of processing the current ones. |
| 1819 | **/ |
| 1820 | static void |
| 1821 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 1822 | { |
| 1823 | lpfc_can_disctmo(vport); |
| 1824 | |
| 1825 | /* RSCN discovery */ |
| 1826 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 1827 | if (vport->fc_npr_cnt) |
| 1828 | if (lpfc_els_disc_plogi(vport)) |
| 1829 | return; |
| 1830 | |
| 1831 | lpfc_end_rscn(vport); |
| 1832 | } |
| 1833 | |
| 1834 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1835 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1836 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 1837 | * |
| 1838 | * This function is called when the final ADISC is completed during discovery. |
| 1839 | * This function handles clearing link attention or issuing reg_vpi depending |
| 1840 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 1841 | * discovery. |
| 1842 | * This function is called with no locks held. |
| 1843 | **/ |
| 1844 | static void |
| 1845 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 1846 | { |
| 1847 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1848 | struct lpfc_hba *phba = vport->phba; |
| 1849 | |
| 1850 | /* |
| 1851 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 1852 | * and continue discovery. |
| 1853 | */ |
| 1854 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1855 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 1856 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1857 | lpfc_issue_reg_vpi(phba, vport); |
| 1858 | return; |
| 1859 | } |
| 1860 | /* |
| 1861 | * For SLI2, we need to set port_state to READY |
| 1862 | * and continue discovery. |
| 1863 | */ |
| 1864 | if (vport->port_state < LPFC_VPORT_READY) { |
| 1865 | /* If we get here, there is nothing to ADISC */ |
| 1866 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1867 | lpfc_issue_clear_la(phba, vport); |
| 1868 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 1869 | vport->num_disc_nodes = 0; |
| 1870 | /* go thru NPR list, issue ELS PLOGIs */ |
| 1871 | if (vport->fc_npr_cnt) |
| 1872 | lpfc_els_disc_plogi(vport); |
| 1873 | if (!vport->num_disc_nodes) { |
| 1874 | spin_lock_irq(shost->host_lock); |
| 1875 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1876 | spin_unlock_irq(shost->host_lock); |
| 1877 | lpfc_can_disctmo(vport); |
| 1878 | lpfc_end_rscn(vport); |
| 1879 | } |
| 1880 | } |
| 1881 | vport->port_state = LPFC_VPORT_READY; |
| 1882 | } else |
| 1883 | lpfc_rscn_disc(vport); |
| 1884 | } |
| 1885 | |
| 1886 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1887 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1888 | * @vport: pointer to a host virtual N_Port data structure. |
| 1889 | * |
| 1890 | * This routine determines whether there are more ndlps on a @vport |
| 1891 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 1892 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 1893 | * remaining nodes which need to have ADISC sent. |
| 1894 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1895 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1896 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1897 | { |
| 1898 | int sentadisc; |
| 1899 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1900 | if (vport->num_disc_nodes) |
| 1901 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1902 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1903 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1904 | "0210 Continue discovery with %d ADISCs to go " |
| 1905 | "Data: x%x x%x x%x\n", |
| 1906 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 1907 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1908 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1909 | if (vport->fc_flag & FC_NLP_MORE) { |
| 1910 | lpfc_set_disctmo(vport); |
| 1911 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 1912 | sentadisc = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1913 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1914 | if (!vport->num_disc_nodes) |
| 1915 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1916 | return; |
| 1917 | } |
| 1918 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1919 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1920 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1921 | * @phba: pointer to lpfc hba data structure. |
| 1922 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1923 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1924 | * |
| 1925 | * This routine is the completion function for issuing the Address Discover |
| 1926 | * (ADISC) command. It first checks to see whether link went down during |
| 1927 | * the discovery process. If so, the node will be marked as node port |
| 1928 | * recovery for issuing discover IOCB by the link attention handler and |
| 1929 | * exit. Otherwise, the response status is checked. If error was reported |
| 1930 | * in the response status, the ADISC command shall be retried by invoking |
| 1931 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 1932 | * the response status, the state machine is invoked to set transition |
| 1933 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 1934 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1935 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1936 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1937 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1938 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1939 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1940 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1941 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1942 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1943 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1944 | |
| 1945 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1946 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1947 | |
| 1948 | irsp = &(rspiocb->iocb); |
| 1949 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1950 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1951 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1952 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 1953 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1954 | ndlp->nlp_DID); |
| 1955 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1956 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1957 | * is being used during discovery. |
| 1958 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1959 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1960 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1961 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1962 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1963 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1964 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1965 | "0104 ADISC completes to NPort x%x " |
| 1966 | "Data: x%x x%x x%x x%x x%x\n", |
| 1967 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1968 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1969 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1970 | if (lpfc_els_chk_latt(vport)) { |
| 1971 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1972 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1973 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1974 | goto out; |
| 1975 | } |
| 1976 | |
| 1977 | if (irsp->ulpStatus) { |
| 1978 | /* Check for retry */ |
| 1979 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1980 | /* ELS command is being retried */ |
| 1981 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1982 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1983 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1984 | spin_unlock_irq(shost->host_lock); |
| 1985 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1986 | } |
| 1987 | goto out; |
| 1988 | } |
| 1989 | /* ADISC failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1990 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1991 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", |
| 1992 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1993 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1994 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1995 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1996 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1997 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1998 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1999 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2000 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2001 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2002 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2003 | /* Check to see if there are more ADISCs to be sent */ |
| 2004 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2005 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2006 | out: |
| 2007 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2008 | return; |
| 2009 | } |
| 2010 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2011 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2012 | * 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] | 2013 | * @vport: pointer to a virtual N_Port data structure. |
| 2014 | * @ndlp: pointer to a node-list data structure. |
| 2015 | * @retry: number of retries to the command IOCB. |
| 2016 | * |
| 2017 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 2018 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 2019 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 2020 | * to issue the ADISC ELS command. |
| 2021 | * |
| 2022 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2023 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2024 | * will be stored into the context1 field of the IOCB for the completion |
| 2025 | * callback function to the ADISC ELS command. |
| 2026 | * |
| 2027 | * Return code |
| 2028 | * 0 - successfully issued adisc |
| 2029 | * 1 - failed to issue adisc |
| 2030 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2031 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2032 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2033 | uint8_t retry) |
| 2034 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2035 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2036 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2037 | ADISC *ap; |
| 2038 | IOCB_t *icmd; |
| 2039 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2040 | uint8_t *pcmd; |
| 2041 | uint16_t cmdsize; |
| 2042 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2043 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2044 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2045 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2046 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2047 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2048 | |
| 2049 | icmd = &elsiocb->iocb; |
| 2050 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2051 | |
| 2052 | /* For ADISC request, remainder of payload is service parameters */ |
| 2053 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2054 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2055 | |
| 2056 | /* Fill in ADISC payload */ |
| 2057 | ap = (ADISC *) pcmd; |
| 2058 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2059 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2060 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2061 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2062 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2063 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2064 | "Issue ADISC: did:x%x", |
| 2065 | ndlp->nlp_DID, 0, 0); |
| 2066 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2067 | phba->fc_stat.elsXmitADISC++; |
| 2068 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2069 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2070 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2071 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2072 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2073 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2074 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2075 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2076 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2077 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2078 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2079 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2080 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2081 | } |
| 2082 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2083 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2084 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2085 | * @phba: pointer to lpfc hba data structure. |
| 2086 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2087 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2088 | * |
| 2089 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 2090 | * command. If no error status was reported from the LOGO response, the |
| 2091 | * state machine of the associated ndlp shall be invoked for transition with |
| 2092 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 2093 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 2094 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2095 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2096 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2097 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2098 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2099 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2100 | struct lpfc_vport *vport = ndlp->vport; |
| 2101 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2102 | IOCB_t *irsp; |
| 2103 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2104 | |
| 2105 | psli = &phba->sli; |
| 2106 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2107 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2108 | |
| 2109 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2110 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2111 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2112 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2113 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2114 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2115 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 2116 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2117 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2118 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2119 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2120 | "0105 LOGO completes to NPort x%x " |
| 2121 | "Data: x%x x%x x%x x%x\n", |
| 2122 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2123 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2124 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2125 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2126 | goto out; |
| 2127 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2128 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 2129 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 2130 | * which should abort all outstanding IOs. |
| 2131 | */ |
| 2132 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2133 | NLP_EVT_DEVICE_RM); |
| 2134 | goto out; |
| 2135 | } |
| 2136 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2137 | if (irsp->ulpStatus) { |
| 2138 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2139 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2140 | /* ELS command is being retried */ |
| 2141 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2142 | /* LOGO failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2143 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2144 | "2756 LOGO failure DID:%06X Status:x%x/x%x\n", |
| 2145 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2146 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2147 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2148 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2149 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2150 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2151 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2152 | NLP_EVT_CMPL_LOGO); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2153 | } else |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2154 | /* Good status, call state machine. |
| 2155 | * This will unregister the rpi if needed. |
| 2156 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2157 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2158 | NLP_EVT_CMPL_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2159 | out: |
| 2160 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2161 | return; |
| 2162 | } |
| 2163 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2164 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2165 | * 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] | 2166 | * @vport: pointer to a virtual N_Port data structure. |
| 2167 | * @ndlp: pointer to a node-list data structure. |
| 2168 | * @retry: number of retries to the command IOCB. |
| 2169 | * |
| 2170 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2171 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2172 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2173 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2174 | * |
| 2175 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2176 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2177 | * will be stored into the context1 field of the IOCB for the completion |
| 2178 | * callback function to the LOGO ELS command. |
| 2179 | * |
| 2180 | * Return code |
| 2181 | * 0 - successfully issued logo |
| 2182 | * 1 - failed to issue logo |
| 2183 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2184 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2185 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2186 | uint8_t retry) |
| 2187 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2188 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2189 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2190 | IOCB_t *icmd; |
| 2191 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2192 | uint8_t *pcmd; |
| 2193 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2194 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2195 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2196 | spin_lock_irq(shost->host_lock); |
| 2197 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2198 | spin_unlock_irq(shost->host_lock); |
| 2199 | return 0; |
| 2200 | } |
| 2201 | spin_unlock_irq(shost->host_lock); |
| 2202 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2203 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2204 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2205 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2206 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2207 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2208 | |
| 2209 | icmd = &elsiocb->iocb; |
| 2210 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2211 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2212 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2213 | |
| 2214 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2215 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2216 | pcmd += sizeof(uint32_t); |
| 2217 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2218 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2219 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2220 | "Issue LOGO: did:x%x", |
| 2221 | ndlp->nlp_DID, 0, 0); |
| 2222 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2223 | phba->fc_stat.elsXmitLOGO++; |
| 2224 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2225 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2226 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2227 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2228 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2229 | |
| 2230 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2231 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2232 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2233 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2234 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2235 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2236 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2237 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2238 | } |
| 2239 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2240 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2241 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2242 | * @phba: pointer to lpfc hba data structure. |
| 2243 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2244 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2245 | * |
| 2246 | * This routine is a generic completion callback function for ELS commands. |
| 2247 | * Specifically, it is the callback function which does not need to perform |
| 2248 | * any command specific operations. It is currently used by the ELS command |
| 2249 | * issuing routines for the ELS State Change Request (SCR), |
| 2250 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 2251 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2252 | * certain debug loggings, this callback function simply invokes the |
| 2253 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2254 | * discovery process. |
| 2255 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2256 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2257 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2258 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2259 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2260 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2261 | IOCB_t *irsp; |
| 2262 | |
| 2263 | irsp = &rspiocb->iocb; |
| 2264 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2265 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2266 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2267 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2268 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2269 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2270 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2271 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2272 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2273 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2274 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2275 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2276 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2277 | return; |
| 2278 | } |
| 2279 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2280 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2281 | * 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] | 2282 | * @vport: pointer to a host virtual N_Port data structure. |
| 2283 | * @nportid: N_Port identifier to the remote node. |
| 2284 | * @retry: number of retries to the command IOCB. |
| 2285 | * |
| 2286 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2287 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2288 | * first search the @vport node list to find the matching ndlp. If no such |
| 2289 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2290 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2291 | * routine is invoked to send the SCR IOCB. |
| 2292 | * |
| 2293 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2294 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2295 | * will be stored into the context1 field of the IOCB for the completion |
| 2296 | * callback function to the SCR ELS command. |
| 2297 | * |
| 2298 | * Return code |
| 2299 | * 0 - Successfully issued scr command |
| 2300 | * 1 - Failed to issue scr command |
| 2301 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2302 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2303 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2304 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2305 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2306 | IOCB_t *icmd; |
| 2307 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2308 | struct lpfc_sli *psli; |
| 2309 | uint8_t *pcmd; |
| 2310 | uint16_t cmdsize; |
| 2311 | struct lpfc_nodelist *ndlp; |
| 2312 | |
| 2313 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2314 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2315 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2316 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2317 | if (!ndlp) { |
| 2318 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2319 | if (!ndlp) |
| 2320 | return 1; |
| 2321 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2322 | lpfc_enqueue_node(vport, ndlp); |
| 2323 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2324 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2325 | if (!ndlp) |
| 2326 | return 1; |
| 2327 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2328 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2329 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2330 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2331 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2332 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2333 | /* This will trigger the release of the node just |
| 2334 | * allocated |
| 2335 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2336 | lpfc_nlp_put(ndlp); |
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 | } |
| 2339 | |
| 2340 | icmd = &elsiocb->iocb; |
| 2341 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2342 | |
| 2343 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2344 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2345 | |
| 2346 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2347 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2348 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2349 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2350 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2351 | "Issue SCR: did:x%x", |
| 2352 | ndlp->nlp_DID, 0, 0); |
| 2353 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2354 | phba->fc_stat.elsXmitSCR++; |
| 2355 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2356 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2357 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2358 | /* The additional lpfc_nlp_put will cause the following |
| 2359 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2360 | * the node. |
| 2361 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2362 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2363 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2364 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2365 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2366 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2367 | * trigger the release of node. |
| 2368 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2369 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2370 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2371 | } |
| 2372 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2373 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2374 | * 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] | 2375 | * @vport: pointer to a host virtual N_Port data structure. |
| 2376 | * @nportid: N_Port identifier to the remote node. |
| 2377 | * @retry: number of retries to the command IOCB. |
| 2378 | * |
| 2379 | * This routine issues a Fibre Channel Address Resolution Response |
| 2380 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2381 | * is passed into the function. It first search the @vport node list to find |
| 2382 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2383 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2384 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2385 | * |
| 2386 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2387 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2388 | * will be stored into the context1 field of the IOCB for the completion |
| 2389 | * callback function to the PARPR ELS command. |
| 2390 | * |
| 2391 | * Return code |
| 2392 | * 0 - Successfully issued farpr command |
| 2393 | * 1 - Failed to issue farpr command |
| 2394 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2395 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2396 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2397 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2398 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2399 | IOCB_t *icmd; |
| 2400 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2401 | struct lpfc_sli *psli; |
| 2402 | FARP *fp; |
| 2403 | uint8_t *pcmd; |
| 2404 | uint32_t *lp; |
| 2405 | uint16_t cmdsize; |
| 2406 | struct lpfc_nodelist *ondlp; |
| 2407 | struct lpfc_nodelist *ndlp; |
| 2408 | |
| 2409 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2410 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2411 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2412 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2413 | if (!ndlp) { |
| 2414 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2415 | if (!ndlp) |
| 2416 | return 1; |
| 2417 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2418 | lpfc_enqueue_node(vport, ndlp); |
| 2419 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2420 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2421 | if (!ndlp) |
| 2422 | return 1; |
| 2423 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2424 | |
| 2425 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2426 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2427 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2428 | /* This will trigger the release of the node just |
| 2429 | * allocated |
| 2430 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2431 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2432 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2433 | } |
| 2434 | |
| 2435 | icmd = &elsiocb->iocb; |
| 2436 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2437 | |
| 2438 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2439 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2440 | |
| 2441 | /* Fill in FARPR payload */ |
| 2442 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2443 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2444 | lp = (uint32_t *) pcmd; |
| 2445 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2446 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2447 | fp->Rflags = 0; |
| 2448 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2449 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2450 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2451 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2452 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2453 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2454 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2455 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2456 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2457 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2458 | } |
| 2459 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2460 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2461 | "Issue FARPR: did:x%x", |
| 2462 | ndlp->nlp_DID, 0, 0); |
| 2463 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2464 | phba->fc_stat.elsXmitFARPR++; |
| 2465 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2466 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2467 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2468 | /* The additional lpfc_nlp_put will cause the following |
| 2469 | * lpfc_els_free_iocb routine to trigger the release of |
| 2470 | * the node. |
| 2471 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2472 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2473 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2474 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2475 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2476 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2477 | * trigger the release of the node. |
| 2478 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2479 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2480 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2481 | } |
| 2482 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2483 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2484 | * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2485 | * @vport: pointer to a host virtual N_Port data structure. |
| 2486 | * @nlp: pointer to a node-list data structure. |
| 2487 | * |
| 2488 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2489 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2490 | * removes the ELS retry event if it presents. In addition, if the |
| 2491 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2492 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2493 | * ADISC. |
| 2494 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2495 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2496 | 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] | 2497 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2498 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2499 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2500 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2501 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2502 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2503 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2504 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2505 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2506 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2507 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2508 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2509 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2510 | /* Decrement nlp reference count held for the delayed retry */ |
| 2511 | evtp = &nlp->els_retry_evt; |
| 2512 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2513 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2514 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2515 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2516 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2517 | spin_unlock_irq(shost->host_lock); |
| 2518 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2519 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2520 | /* Check if there are more ADISCs to be sent */ |
| 2521 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2522 | } else { |
| 2523 | /* Check if there are more PLOGIs to be sent */ |
| 2524 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2525 | if (vport->num_disc_nodes == 0) { |
| 2526 | spin_lock_irq(shost->host_lock); |
| 2527 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2528 | spin_unlock_irq(shost->host_lock); |
| 2529 | lpfc_can_disctmo(vport); |
| 2530 | lpfc_end_rscn(vport); |
| 2531 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2532 | } |
| 2533 | } |
| 2534 | } |
| 2535 | return; |
| 2536 | } |
| 2537 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2538 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2539 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2540 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2541 | * |
| 2542 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2543 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2544 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2545 | * adds the delayed events to the HBA work list and invokes the |
| 2546 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2547 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2548 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2549 | * reference to ndlp will still be available when the worker thread gets |
| 2550 | * to the event associated with the ndlp. |
| 2551 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2552 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2553 | lpfc_els_retry_delay(unsigned long ptr) |
| 2554 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2555 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2556 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2557 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2558 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2559 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2560 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2561 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2562 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2563 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2564 | return; |
| 2565 | } |
| 2566 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2567 | /* We need to hold the node by incrementing the reference |
| 2568 | * count until the queued work is done |
| 2569 | */ |
| 2570 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2571 | if (evtp->evt_arg1) { |
| 2572 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2573 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2574 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2575 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2576 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2577 | return; |
| 2578 | } |
| 2579 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2580 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2581 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2582 | * @ndlp: pointer to a node-list data structure. |
| 2583 | * |
| 2584 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 2585 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 2586 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 2587 | * function according to the delayed ELS command to retry the command. |
| 2588 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2589 | void |
| 2590 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 2591 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2592 | struct lpfc_vport *vport = ndlp->vport; |
| 2593 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2594 | uint32_t cmd, did, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2595 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2596 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2597 | did = ndlp->nlp_DID; |
| 2598 | cmd = ndlp->nlp_last_elscmd; |
| 2599 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2600 | |
| 2601 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2602 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2603 | return; |
| 2604 | } |
| 2605 | |
| 2606 | ndlp->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 | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 2608 | /* |
| 2609 | * If a discovery event readded nlp_delayfunc after timer |
| 2610 | * firing and before processing the timer, cancel the |
| 2611 | * nlp_delayfunc. |
| 2612 | */ |
| 2613 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2614 | retry = ndlp->nlp_retry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 2615 | ndlp->nlp_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2616 | |
| 2617 | switch (cmd) { |
| 2618 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2619 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2620 | break; |
| 2621 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2622 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2623 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2624 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2625 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2626 | break; |
| 2627 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2628 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2629 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2630 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2631 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2632 | break; |
| 2633 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2634 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2635 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2636 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2637 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2638 | break; |
| 2639 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2640 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2641 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2642 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2643 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2644 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2645 | case ELS_CMD_FDISC: |
| 2646 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
| 2647 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2648 | } |
| 2649 | return; |
| 2650 | } |
| 2651 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2652 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2653 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2654 | * @phba: pointer to lpfc hba data structure. |
| 2655 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2656 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2657 | * |
| 2658 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 2659 | * failed. The following ELS IOCBs use this function for retrying the command |
| 2660 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 2661 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 2662 | * returned error status, it makes the decision whether a retry shall be |
| 2663 | * issued for the command, and whether a retry shall be made immediately or |
| 2664 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 2665 | * is called to retry the command. In the later case, the ELS command shall |
| 2666 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 2667 | * ndlp for the delayed command issusing. |
| 2668 | * |
| 2669 | * Return code |
| 2670 | * 0 - No retry of els command is made |
| 2671 | * 1 - Immediate or delayed retry of els command is made |
| 2672 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2673 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2674 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2675 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2676 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2677 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2678 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2679 | IOCB_t *irsp = &rspiocb->iocb; |
| 2680 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2681 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2682 | uint32_t *elscmd; |
| 2683 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2684 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2685 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2686 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2687 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2688 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2689 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2690 | /* Note: context2 may be 0 for internal driver abort |
| 2691 | * of delays ELS command. |
| 2692 | */ |
| 2693 | |
| 2694 | if (pcmd && pcmd->virt) { |
| 2695 | elscmd = (uint32_t *) (pcmd->virt); |
| 2696 | cmd = *elscmd++; |
| 2697 | } |
| 2698 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2699 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2700 | did = ndlp->nlp_DID; |
| 2701 | else { |
| 2702 | /* We should only hit this case for retrying PLOGI */ |
| 2703 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2704 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2705 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 2706 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2707 | return 1; |
| 2708 | } |
| 2709 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2710 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2711 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 2712 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 2713 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2714 | switch (irsp->ulpStatus) { |
| 2715 | case IOSTAT_FCP_RSP_ERROR: |
| 2716 | case IOSTAT_REMOTE_STOP: |
| 2717 | break; |
| 2718 | |
| 2719 | case IOSTAT_LOCAL_REJECT: |
| 2720 | switch ((irsp->un.ulpWord[4] & 0xff)) { |
| 2721 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2722 | if (cmd == ELS_CMD_FLOGI) { |
| 2723 | if (PCI_DEVICE_ID_HORNET == |
| 2724 | phba->pcidev->device) { |
| 2725 | phba->fc_topology = TOPOLOGY_LOOP; |
| 2726 | phba->pport->fc_myDID = 0; |
| 2727 | phba->alpa_map[0] = 0; |
| 2728 | phba->alpa_map[1] = 0; |
| 2729 | } |
| 2730 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2731 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2732 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2733 | retry = 1; |
| 2734 | break; |
| 2735 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2736 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2737 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2738 | "0124 Retry illegal cmd x%x " |
| 2739 | "retry:x%x delay:x%x\n", |
| 2740 | cmd, cmdiocb->retry, delay); |
| 2741 | retry = 1; |
| 2742 | /* All command's retry policy */ |
| 2743 | maxretry = 8; |
| 2744 | if (cmdiocb->retry > 2) |
| 2745 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2746 | break; |
| 2747 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2748 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2749 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2750 | retry = 1; |
| 2751 | if (cmdiocb->retry > 100) |
| 2752 | delay = 100; |
| 2753 | maxretry = 250; |
| 2754 | break; |
| 2755 | |
| 2756 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2757 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2758 | retry = 1; |
| 2759 | break; |
| 2760 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2761 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2762 | case IOERR_INVALID_RPI: |
| 2763 | retry = 1; |
| 2764 | break; |
| 2765 | } |
| 2766 | break; |
| 2767 | |
| 2768 | case IOSTAT_NPORT_RJT: |
| 2769 | case IOSTAT_FABRIC_RJT: |
| 2770 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 2771 | retry = 1; |
| 2772 | break; |
| 2773 | } |
| 2774 | break; |
| 2775 | |
| 2776 | case IOSTAT_NPORT_BSY: |
| 2777 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2778 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2779 | retry = 1; |
| 2780 | break; |
| 2781 | |
| 2782 | case IOSTAT_LS_RJT: |
| 2783 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 2784 | /* Added for Vendor specifc support |
| 2785 | * Just keep retrying for these Rsn / Exp codes |
| 2786 | */ |
| 2787 | switch (stat.un.b.lsRjtRsnCode) { |
| 2788 | case LSRJT_UNABLE_TPC: |
| 2789 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2790 | LSEXP_CMD_IN_PROGRESS) { |
| 2791 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2792 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2793 | maxretry = 48; |
| 2794 | } |
| 2795 | retry = 1; |
| 2796 | break; |
| 2797 | } |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 2798 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2799 | LSEXP_CANT_GIVE_DATA) { |
| 2800 | if (cmd == ELS_CMD_PLOGI) { |
| 2801 | delay = 1000; |
| 2802 | maxretry = 48; |
| 2803 | } |
| 2804 | retry = 1; |
| 2805 | break; |
| 2806 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2807 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2808 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2809 | maxretry = lpfc_max_els_tries + 1; |
| 2810 | retry = 1; |
| 2811 | break; |
| 2812 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2813 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2814 | (cmd == ELS_CMD_FDISC) && |
| 2815 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2816 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2817 | "0125 FDISC Failed (x%x). " |
| 2818 | "Fabric out of resources\n", |
| 2819 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2820 | lpfc_vport_set_state(vport, |
| 2821 | FC_VPORT_NO_FABRIC_RSCS); |
| 2822 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2823 | break; |
| 2824 | |
| 2825 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2826 | if ((cmd == ELS_CMD_PLOGI) || |
| 2827 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2828 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2829 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2830 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2831 | /* FDISC retry policy */ |
| 2832 | maxretry = 48; |
| 2833 | if (cmdiocb->retry >= 32) |
| 2834 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2835 | } |
| 2836 | retry = 1; |
| 2837 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2838 | |
| 2839 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2840 | /* There are some cases where switches return this |
| 2841 | * error when they are not ready and should be returning |
| 2842 | * Logical Busy. We should delay every time. |
| 2843 | */ |
| 2844 | if (cmd == ELS_CMD_FDISC && |
| 2845 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 2846 | maxretry = 3; |
| 2847 | delay = 1000; |
| 2848 | retry = 1; |
| 2849 | break; |
| 2850 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2851 | case LSRJT_PROTOCOL_ERR: |
| 2852 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2853 | (cmd == ELS_CMD_FDISC) && |
| 2854 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 2855 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 2856 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2857 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2858 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2859 | "Fabric Detected Bad WWN\n", |
| 2860 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2861 | lpfc_vport_set_state(vport, |
| 2862 | FC_VPORT_FABRIC_REJ_WWN); |
| 2863 | } |
| 2864 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2865 | } |
| 2866 | break; |
| 2867 | |
| 2868 | case IOSTAT_INTERMED_RSP: |
| 2869 | case IOSTAT_BA_RJT: |
| 2870 | break; |
| 2871 | |
| 2872 | default: |
| 2873 | break; |
| 2874 | } |
| 2875 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2876 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2877 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2878 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2879 | if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 2880 | (phba->fc_topology != TOPOLOGY_LOOP) && |
| 2881 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2882 | /* FLOGI retry policy */ |
| 2883 | retry = 1; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2884 | /* retry forever */ |
| 2885 | maxretry = 0; |
| 2886 | if (cmdiocb->retry >= 100) |
| 2887 | delay = 5000; |
| 2888 | else if (cmdiocb->retry >= 32) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2889 | delay = 1000; |
| 2890 | } |
| 2891 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2892 | cmdiocb->retry++; |
| 2893 | if (maxretry && (cmdiocb->retry >= maxretry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2894 | phba->fc_stat.elsRetryExceeded++; |
| 2895 | retry = 0; |
| 2896 | } |
| 2897 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2898 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 2899 | retry = 0; |
| 2900 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2901 | if (retry) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 2902 | if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) { |
| 2903 | /* Stop retrying PLOGI and FDISC if in FCF discovery */ |
| 2904 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 2905 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2906 | "2849 Stop retry ELS command " |
| 2907 | "x%x to remote NPORT x%x, " |
| 2908 | "Data: x%x x%x\n", cmd, did, |
| 2909 | cmdiocb->retry, delay); |
| 2910 | return 0; |
| 2911 | } |
| 2912 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2913 | |
| 2914 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2915 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2916 | "0107 Retry ELS command x%x to remote " |
| 2917 | "NPORT x%x Data: x%x x%x\n", |
| 2918 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2919 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2920 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 2921 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 2922 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { |
| 2923 | /* Don't reset timer for no resources */ |
| 2924 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2925 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2926 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2927 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2928 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2929 | } |
| 2930 | |
| 2931 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2932 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2933 | phba->fc_stat.elsDelayRetry++; |
| 2934 | ndlp->nlp_retry = cmdiocb->retry; |
| 2935 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2936 | /* delay is specified in milliseconds */ |
| 2937 | mod_timer(&ndlp->nlp_delayfunc, |
| 2938 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2939 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2940 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2941 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2942 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2943 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2944 | if (cmd == ELS_CMD_PRLI) |
| 2945 | lpfc_nlp_set_state(vport, ndlp, |
| 2946 | NLP_STE_REG_LOGIN_ISSUE); |
| 2947 | else |
| 2948 | lpfc_nlp_set_state(vport, ndlp, |
| 2949 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2950 | ndlp->nlp_last_elscmd = cmd; |
| 2951 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2952 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2953 | } |
| 2954 | switch (cmd) { |
| 2955 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2956 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2957 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2958 | case ELS_CMD_FDISC: |
| 2959 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 2960 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2961 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2962 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2963 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2964 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2965 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2966 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2967 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2968 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2969 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2970 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2971 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 2972 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2973 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2974 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2975 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2976 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 2977 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2978 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2979 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2980 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2981 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 2982 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2983 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2984 | } |
| 2985 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2986 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2987 | if (logerr) { |
| 2988 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2989 | "0137 No retry ELS command x%x to remote " |
| 2990 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 2991 | cmd, did, irsp->ulpStatus, |
| 2992 | irsp->un.ulpWord[4]); |
| 2993 | } |
| 2994 | else { |
| 2995 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2996 | "0108 No retry ELS command x%x to remote " |
| 2997 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 2998 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 2999 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3000 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3001 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3002 | } |
| 3003 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3004 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3005 | * 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] | 3006 | * @phba: pointer to lpfc hba data structure. |
| 3007 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 3008 | * |
| 3009 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 3010 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 3011 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 3012 | * response of the command IOCB. If so, it will be released before releasing |
| 3013 | * the lpfc DMA buffer associated with the IOCB itself. |
| 3014 | * |
| 3015 | * Return code |
| 3016 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3017 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3018 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3019 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 3020 | { |
| 3021 | struct lpfc_dmabuf *buf_ptr; |
| 3022 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3023 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3024 | if (!list_empty(&buf_ptr1->list)) { |
| 3025 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 3026 | struct lpfc_dmabuf, |
| 3027 | list); |
| 3028 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3029 | kfree(buf_ptr); |
| 3030 | } |
| 3031 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 3032 | kfree(buf_ptr1); |
| 3033 | return 0; |
| 3034 | } |
| 3035 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3036 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3037 | * 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] | 3038 | * @phba: pointer to lpfc hba data structure. |
| 3039 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 3040 | * |
| 3041 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 3042 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 3043 | * pool. |
| 3044 | * |
| 3045 | * Return code |
| 3046 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3047 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3048 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3049 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 3050 | { |
| 3051 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3052 | kfree(buf_ptr); |
| 3053 | return 0; |
| 3054 | } |
| 3055 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3056 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3057 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3058 | * @phba: pointer to lpfc hba data structure. |
| 3059 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 3060 | * |
| 3061 | * This routine frees a command IOCB and its associated resources. The |
| 3062 | * command IOCB data structure contains the reference to various associated |
| 3063 | * resources, these fields must be set to NULL if the associated reference |
| 3064 | * not present: |
| 3065 | * context1 - reference to ndlp |
| 3066 | * context2 - reference to cmd |
| 3067 | * context2->next - reference to rsp |
| 3068 | * context3 - reference to bpl |
| 3069 | * |
| 3070 | * It first properly decrements the reference count held on ndlp for the |
| 3071 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 3072 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 3073 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 3074 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 3075 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 3076 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 3077 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 3078 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 3079 | * |
| 3080 | * Return code |
| 3081 | * 0 - Success (currently, always return 0) |
| 3082 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3083 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3084 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3085 | { |
| 3086 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3087 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3088 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3089 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 3090 | if (ndlp) { |
| 3091 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 3092 | lpfc_nlp_put(ndlp); |
| 3093 | |
| 3094 | /* If the ndlp is not being used by another discovery |
| 3095 | * thread, free it. |
| 3096 | */ |
| 3097 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3098 | /* If ndlp is being used by another discovery |
| 3099 | * thread, just clear NLP_DEFER_RM |
| 3100 | */ |
| 3101 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 3102 | } |
| 3103 | } |
| 3104 | else |
| 3105 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3106 | elsiocb->context1 = NULL; |
| 3107 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3108 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 3109 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3110 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 3111 | /* Firmware could still be in progress of DMAing |
| 3112 | * payload, so don't free data buffer till after |
| 3113 | * a hbeat. |
| 3114 | */ |
| 3115 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 3116 | buf_ptr = elsiocb->context2; |
| 3117 | elsiocb->context2 = NULL; |
| 3118 | if (buf_ptr) { |
| 3119 | buf_ptr1 = NULL; |
| 3120 | spin_lock_irq(&phba->hbalock); |
| 3121 | if (!list_empty(&buf_ptr->list)) { |
| 3122 | list_remove_head(&buf_ptr->list, |
| 3123 | buf_ptr1, struct lpfc_dmabuf, |
| 3124 | list); |
| 3125 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 3126 | list_add_tail(&buf_ptr1->list, |
| 3127 | &phba->elsbuf); |
| 3128 | phba->elsbuf_cnt++; |
| 3129 | } |
| 3130 | INIT_LIST_HEAD(&buf_ptr->list); |
| 3131 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 3132 | phba->elsbuf_cnt++; |
| 3133 | spin_unlock_irq(&phba->hbalock); |
| 3134 | } |
| 3135 | } else { |
| 3136 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 3137 | lpfc_els_free_data(phba, buf_ptr1); |
| 3138 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3139 | } |
| 3140 | |
| 3141 | if (elsiocb->context3) { |
| 3142 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3143 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3144 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3145 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3146 | return 0; |
| 3147 | } |
| 3148 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3149 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3150 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3151 | * @phba: pointer to lpfc hba data structure. |
| 3152 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3153 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3154 | * |
| 3155 | * This routine is the completion callback function to the Logout (LOGO) |
| 3156 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 3157 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 3158 | * release the ndlp if it has the last reference remaining (reference count |
| 3159 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 3160 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 3161 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 3162 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 3163 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 3164 | * IOCB data structure. |
| 3165 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3166 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3167 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3168 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3169 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3170 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3171 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3172 | IOCB_t *irsp; |
| 3173 | |
| 3174 | irsp = &rspiocb->iocb; |
| 3175 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3176 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 3177 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3178 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3179 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3180 | "0109 ACC to LOGO completes to NPort x%x " |
| 3181 | "Data: x%x x%x x%x\n", |
| 3182 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3183 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3184 | |
| 3185 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 3186 | /* NPort Recovery mode or node is just allocated */ |
| 3187 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3188 | /* If the ndlp is being used by another discovery |
| 3189 | * thread, just unregister the RPI. |
| 3190 | */ |
| 3191 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3192 | } else { |
| 3193 | /* Indicate the node has already released, should |
| 3194 | * not reference to it from within lpfc_els_free_iocb. |
| 3195 | */ |
| 3196 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3197 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3198 | } |
| 3199 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3200 | return; |
| 3201 | } |
| 3202 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3203 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3204 | * 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] | 3205 | * @phba: pointer to lpfc hba data structure. |
| 3206 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 3207 | * |
| 3208 | * This routine is the completion callback function for unregister default |
| 3209 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 3210 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 3211 | * decrements the ndlp reference count held for this completion callback |
| 3212 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 3213 | * whether there is only one reference left on the ndlp. If so, it will |
| 3214 | * perform one more decrement and trigger the release of the ndlp. |
| 3215 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3216 | void |
| 3217 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3218 | { |
| 3219 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3220 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3221 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3222 | /* |
| 3223 | * This routine is used to register and unregister in previous SLI |
| 3224 | * modes. |
| 3225 | */ |
| 3226 | if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) && |
| 3227 | (phba->sli_rev == LPFC_SLI_REV4)) |
| 3228 | lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi); |
| 3229 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3230 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3231 | pmb->context2 = NULL; |
| 3232 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3233 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3234 | kfree(mp); |
| 3235 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3236 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3237 | lpfc_nlp_put(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3238 | /* This is the end of the default RPI cleanup logic for this |
| 3239 | * ndlp. If no other discovery threads are using this ndlp. |
| 3240 | * we should free all resources associated with it. |
| 3241 | */ |
| 3242 | lpfc_nlp_not_used(ndlp); |
| 3243 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3244 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3245 | return; |
| 3246 | } |
| 3247 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3248 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3249 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3250 | * @phba: pointer to lpfc hba data structure. |
| 3251 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3252 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3253 | * |
| 3254 | * This routine is the completion callback function for ELS Response IOCB |
| 3255 | * command. In normal case, this callback function just properly sets the |
| 3256 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 3257 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 3258 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 3259 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 3260 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 3261 | * routine shall be invoked trying to release the ndlp if no other threads |
| 3262 | * are currently referring it. |
| 3263 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3264 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3265 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3266 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3267 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3268 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3269 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 3270 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3271 | IOCB_t *irsp; |
| 3272 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3273 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3274 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3275 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3276 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3277 | irsp = &rspiocb->iocb; |
| 3278 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3279 | if (cmdiocb->context_un.mbox) |
| 3280 | mbox = cmdiocb->context_un.mbox; |
| 3281 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3282 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 3283 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 3284 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3285 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3286 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3287 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3288 | /* A LS_RJT associated with Default RPI cleanup has its own |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 3289 | * separate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3290 | */ |
| 3291 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 3292 | ls_rjt = 1; |
| 3293 | } |
| 3294 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3295 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3296 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3297 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3298 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3299 | if (mp) { |
| 3300 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3301 | kfree(mp); |
| 3302 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3303 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3304 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3305 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3306 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3307 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3308 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3309 | /* Indicate the node has already released, |
| 3310 | * should not reference to it from within |
| 3311 | * the routine lpfc_els_free_iocb. |
| 3312 | */ |
| 3313 | cmdiocb->context1 = NULL; |
| 3314 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3315 | goto out; |
| 3316 | } |
| 3317 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3318 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3319 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3320 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3321 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3322 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3323 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3324 | "0110 ELS response tag x%x completes " |
| 3325 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3326 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3327 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3328 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3329 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3330 | if (mbox) { |
| 3331 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3332 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3333 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3334 | /* Increment reference count to ndlp to hold the |
| 3335 | * reference to ndlp for the callback function. |
| 3336 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3337 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3338 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3339 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3340 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3341 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3342 | } |
| 3343 | else { |
| 3344 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3345 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3346 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3347 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3348 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3349 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3350 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3351 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3352 | else |
| 3353 | /* Decrement the ndlp reference count we |
| 3354 | * set for this failed mailbox command. |
| 3355 | */ |
| 3356 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3357 | |
| 3358 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3359 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3360 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3361 | "Data: x%x x%x x%x\n", |
| 3362 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3363 | ndlp->nlp_rpi); |
| 3364 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3365 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3366 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3367 | /* Indicate node has already been released, |
| 3368 | * should not reference to it from within |
| 3369 | * the routine lpfc_els_free_iocb. |
| 3370 | */ |
| 3371 | cmdiocb->context1 = NULL; |
| 3372 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3373 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3374 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3375 | if (!lpfc_error_lost_link(irsp) && |
| 3376 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3377 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3378 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3379 | /* Indicate node has already been |
| 3380 | * released, should not reference |
| 3381 | * to it from within the routine |
| 3382 | * lpfc_els_free_iocb. |
| 3383 | */ |
| 3384 | cmdiocb->context1 = NULL; |
| 3385 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3386 | } |
| 3387 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3388 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3389 | if (mp) { |
| 3390 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3391 | kfree(mp); |
| 3392 | } |
| 3393 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3394 | } |
| 3395 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3396 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3397 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3398 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3399 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3400 | |
| 3401 | /* If the node is not being used by another discovery thread, |
| 3402 | * and we are sending a reject, we are done with it. |
| 3403 | * Release driver reference count here and free associated |
| 3404 | * resources. |
| 3405 | */ |
| 3406 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3407 | if (lpfc_nlp_not_used(ndlp)) |
| 3408 | /* Indicate node has already been released, |
| 3409 | * should not reference to it from within |
| 3410 | * the routine lpfc_els_free_iocb. |
| 3411 | */ |
| 3412 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3413 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3414 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3415 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3416 | return; |
| 3417 | } |
| 3418 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3419 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3420 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3421 | * @vport: pointer to a host virtual N_Port data structure. |
| 3422 | * @flag: the els command code to be accepted. |
| 3423 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3424 | * @ndlp: pointer to a node-list data structure. |
| 3425 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3426 | * |
| 3427 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3428 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3429 | * specific ACC response command to be issued and invokes the |
| 3430 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3431 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3432 | * field of the IOCB for the completion callback function to issue the |
| 3433 | * mailbox command to the HBA later when callback is invoked. |
| 3434 | * |
| 3435 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3436 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3437 | * will be stored into the context1 field of the IOCB for the completion |
| 3438 | * callback function to the corresponding response ELS IOCB command. |
| 3439 | * |
| 3440 | * Return code |
| 3441 | * 0 - Successfully issued acc response |
| 3442 | * 1 - Failed to issue acc response |
| 3443 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3444 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3445 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3446 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3447 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3448 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3449 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3450 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3451 | IOCB_t *icmd; |
| 3452 | IOCB_t *oldcmd; |
| 3453 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3454 | struct lpfc_sli *psli; |
| 3455 | uint8_t *pcmd; |
| 3456 | uint16_t cmdsize; |
| 3457 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3458 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3459 | |
| 3460 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3461 | oldcmd = &oldiocb->iocb; |
| 3462 | |
| 3463 | switch (flag) { |
| 3464 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3465 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3466 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3467 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3468 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3469 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3470 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3471 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3472 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3473 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3474 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3475 | icmd = &elsiocb->iocb; |
| 3476 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3477 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3478 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3479 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3480 | |
| 3481 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3482 | "Issue ACC: did:x%x flg:x%x", |
| 3483 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3484 | break; |
| 3485 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3486 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3487 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3488 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3489 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3490 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3491 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3492 | icmd = &elsiocb->iocb; |
| 3493 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3494 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3495 | |
| 3496 | if (mbox) |
| 3497 | elsiocb->context_un.mbox = mbox; |
| 3498 | |
| 3499 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3500 | pcmd += sizeof(uint32_t); |
| 3501 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3502 | |
| 3503 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3504 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 3505 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3506 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3507 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3508 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3509 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3510 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3511 | if (!elsiocb) |
| 3512 | return 1; |
| 3513 | |
| 3514 | icmd = &elsiocb->iocb; |
| 3515 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3516 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3517 | |
| 3518 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3519 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3520 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 3521 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 3522 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3523 | |
| 3524 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3525 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 3526 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3527 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3528 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3529 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3530 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3531 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3532 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3533 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
| 3534 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", |
| 3535 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3536 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3537 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3538 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3539 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3540 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3541 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3542 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 3543 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3544 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3545 | } |
| 3546 | |
| 3547 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3548 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3549 | if (rc == IOCB_ERROR) { |
| 3550 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3551 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3552 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3553 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3554 | } |
| 3555 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3556 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3557 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3558 | * @vport: pointer to a virtual N_Port data structure. |
| 3559 | * @rejectError: |
| 3560 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3561 | * @ndlp: pointer to a node-list data structure. |
| 3562 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3563 | * |
| 3564 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 3565 | * command. If a @mbox pointer is passed in, it will be put into the |
| 3566 | * context_un.mbox field of the IOCB for the completion callback function |
| 3567 | * to issue to the HBA later. |
| 3568 | * |
| 3569 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3570 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3571 | * will be stored into the context1 field of the IOCB for the completion |
| 3572 | * callback function to the reject response ELS IOCB command. |
| 3573 | * |
| 3574 | * Return code |
| 3575 | * 0 - Successfully issued reject response |
| 3576 | * 1 - Failed to issue reject response |
| 3577 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3578 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3579 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3580 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 3581 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3582 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3583 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3584 | IOCB_t *icmd; |
| 3585 | IOCB_t *oldcmd; |
| 3586 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3587 | struct lpfc_sli *psli; |
| 3588 | uint8_t *pcmd; |
| 3589 | uint16_t cmdsize; |
| 3590 | int rc; |
| 3591 | |
| 3592 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3593 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3594 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3595 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3596 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3597 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3598 | |
| 3599 | icmd = &elsiocb->iocb; |
| 3600 | oldcmd = &oldiocb->iocb; |
| 3601 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3602 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3603 | |
| 3604 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3605 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3606 | *((uint32_t *) (pcmd)) = rejectError; |
| 3607 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3608 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3609 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3610 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3611 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3612 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3613 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 3614 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 3615 | "rpi x%x\n", |
| 3616 | rejectError, elsiocb->iotag, |
| 3617 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 3618 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3619 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3620 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 3621 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 3622 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3623 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3624 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3625 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3626 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3627 | if (rc == IOCB_ERROR) { |
| 3628 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3629 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3630 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3631 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3632 | } |
| 3633 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3634 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3635 | * 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] | 3636 | * @vport: pointer to a virtual N_Port data structure. |
| 3637 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3638 | * @ndlp: pointer to a node-list data structure. |
| 3639 | * |
| 3640 | * This routine prepares and issues an Accept (ACC) response to Address |
| 3641 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 3642 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3643 | * |
| 3644 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3645 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3646 | * will be stored into the context1 field of the IOCB for the completion |
| 3647 | * callback function to the ADISC Accept response ELS IOCB command. |
| 3648 | * |
| 3649 | * Return code |
| 3650 | * 0 - Successfully issued acc adisc response |
| 3651 | * 1 - Failed to issue adisc acc response |
| 3652 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3653 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3654 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 3655 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3656 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3657 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3658 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3659 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3660 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3661 | uint8_t *pcmd; |
| 3662 | uint16_t cmdsize; |
| 3663 | int rc; |
| 3664 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3665 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3666 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3667 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3668 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3669 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3670 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3671 | icmd = &elsiocb->iocb; |
| 3672 | oldcmd = &oldiocb->iocb; |
| 3673 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3674 | |
| 3675 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3676 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3677 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 3678 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 3679 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3680 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3681 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3682 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3683 | |
| 3684 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3685 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3686 | |
| 3687 | ap = (ADISC *) (pcmd); |
| 3688 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3689 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3690 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3691 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3692 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3693 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3694 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 3695 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3696 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3697 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3698 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3699 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3700 | if (rc == IOCB_ERROR) { |
| 3701 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3702 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3703 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3704 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3705 | } |
| 3706 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3707 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3708 | * 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] | 3709 | * @vport: pointer to a virtual N_Port data structure. |
| 3710 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3711 | * @ndlp: pointer to a node-list data structure. |
| 3712 | * |
| 3713 | * This routine prepares and issues an Accept (ACC) response to Process |
| 3714 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 3715 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3716 | * |
| 3717 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3718 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3719 | * will be stored into the context1 field of the IOCB for the completion |
| 3720 | * callback function to the PRLI Accept response ELS IOCB command. |
| 3721 | * |
| 3722 | * Return code |
| 3723 | * 0 - Successfully issued acc prli response |
| 3724 | * 1 - Failed to issue acc prli response |
| 3725 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3726 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3727 | 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] | 3728 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3729 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3730 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3731 | PRLI *npr; |
| 3732 | lpfc_vpd_t *vpd; |
| 3733 | IOCB_t *icmd; |
| 3734 | IOCB_t *oldcmd; |
| 3735 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3736 | struct lpfc_sli *psli; |
| 3737 | uint8_t *pcmd; |
| 3738 | uint16_t cmdsize; |
| 3739 | int rc; |
| 3740 | |
| 3741 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3742 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3743 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3744 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3745 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3746 | if (!elsiocb) |
| 3747 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3748 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3749 | icmd = &elsiocb->iocb; |
| 3750 | oldcmd = &oldiocb->iocb; |
| 3751 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3752 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3753 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3754 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 3755 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 3756 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3757 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3758 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3759 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3760 | |
| 3761 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3762 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3763 | |
| 3764 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3765 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3766 | |
| 3767 | npr = (PRLI *) pcmd; |
| 3768 | vpd = &phba->vpd; |
| 3769 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3770 | * If the remote port is a target and our firmware version is 3.20 or |
| 3771 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3772 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3773 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 3774 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3775 | npr->ConfmComplAllowed = 1; |
| 3776 | npr->Retry = 1; |
| 3777 | npr->TaskRetryIdReq = 1; |
| 3778 | } |
| 3779 | |
| 3780 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 3781 | npr->estabImagePair = 1; |
| 3782 | npr->readXferRdyDis = 1; |
| 3783 | npr->ConfmComplAllowed = 1; |
| 3784 | |
| 3785 | npr->prliType = PRLI_FCP_TYPE; |
| 3786 | npr->initiatorFunc = 1; |
| 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 PRLI: 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; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3794 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3795 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3796 | if (rc == IOCB_ERROR) { |
| 3797 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3798 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3799 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3800 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3801 | } |
| 3802 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3803 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3804 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3805 | * @vport: pointer to a virtual N_Port data structure. |
| 3806 | * @format: rnid command format. |
| 3807 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3808 | * @ndlp: pointer to a node-list data structure. |
| 3809 | * |
| 3810 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 3811 | * (ACC) response. It constructs the RNID ACC response command according to |
| 3812 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 3813 | * issue the response. Note that this command does not need to hold the ndlp |
| 3814 | * reference count for the callback. So, the ndlp reference count taken by |
| 3815 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 3816 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 3817 | * there is no ndlp reference available. |
| 3818 | * |
| 3819 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3820 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3821 | * will be stored into the context1 field of the IOCB for the completion |
| 3822 | * callback function. However, for the RNID Accept Response ELS command, |
| 3823 | * this is undone later by this routine after the IOCB is allocated. |
| 3824 | * |
| 3825 | * Return code |
| 3826 | * 0 - Successfully issued acc rnid response |
| 3827 | * 1 - Failed to issue acc rnid response |
| 3828 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3829 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3830 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3831 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3832 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3833 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3834 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3835 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3836 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3837 | struct lpfc_sli *psli; |
| 3838 | uint8_t *pcmd; |
| 3839 | uint16_t cmdsize; |
| 3840 | int rc; |
| 3841 | |
| 3842 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3843 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 3844 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3845 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3846 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3847 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3848 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3849 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3850 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3851 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3852 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3853 | icmd = &elsiocb->iocb; |
| 3854 | oldcmd = &oldiocb->iocb; |
| 3855 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3856 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3857 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3858 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 3859 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3860 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3861 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3862 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3863 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3864 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3865 | rn = (RNID *) (pcmd); |
| 3866 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3867 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 3868 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3869 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3870 | switch (format) { |
| 3871 | case 0: |
| 3872 | rn->SpecificLen = 0; |
| 3873 | break; |
| 3874 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3875 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3876 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3877 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3878 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 3879 | rn->un.topologyDisc.physPort = 0; |
| 3880 | rn->un.topologyDisc.attachedNodes = 0; |
| 3881 | break; |
| 3882 | default: |
| 3883 | rn->CommonLen = 0; |
| 3884 | rn->SpecificLen = 0; |
| 3885 | break; |
| 3886 | } |
| 3887 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3888 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3889 | "Issue ACC RNID: did:x%x flg:x%x", |
| 3890 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3891 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3892 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3893 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3894 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3895 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 3896 | * it could be freed */ |
| 3897 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3898 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3899 | if (rc == IOCB_ERROR) { |
| 3900 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3901 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3902 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3903 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3904 | } |
| 3905 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3906 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 3907 | * lpfc_els_rsp_echo_acc - Issue echo acc response |
| 3908 | * @vport: pointer to a virtual N_Port data structure. |
| 3909 | * @data: pointer to echo data to return in the accept. |
| 3910 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3911 | * @ndlp: pointer to a node-list data structure. |
| 3912 | * |
| 3913 | * Return code |
| 3914 | * 0 - Successfully issued acc echo response |
| 3915 | * 1 - Failed to issue acc echo response |
| 3916 | **/ |
| 3917 | static int |
| 3918 | lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data, |
| 3919 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| 3920 | { |
| 3921 | struct lpfc_hba *phba = vport->phba; |
| 3922 | struct lpfc_iocbq *elsiocb; |
| 3923 | struct lpfc_sli *psli; |
| 3924 | uint8_t *pcmd; |
| 3925 | uint16_t cmdsize; |
| 3926 | int rc; |
| 3927 | |
| 3928 | psli = &phba->sli; |
| 3929 | cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len; |
| 3930 | |
| 3931 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3932 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 3933 | if (!elsiocb) |
| 3934 | return 1; |
| 3935 | |
| 3936 | elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri */ |
| 3937 | /* Xmit ECHO ACC response tag <ulpIoTag> */ |
| 3938 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3939 | "2876 Xmit ECHO ACC response tag x%x xri x%x\n", |
| 3940 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| 3941 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3942 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 3943 | pcmd += sizeof(uint32_t); |
| 3944 | memcpy(pcmd, data, cmdsize - sizeof(uint32_t)); |
| 3945 | |
| 3946 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3947 | "Issue ACC ECHO: did:x%x flg:x%x", |
| 3948 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3949 | |
| 3950 | phba->fc_stat.elsXmitACC++; |
| 3951 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 3952 | lpfc_nlp_put(ndlp); |
| 3953 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 3954 | * it could be freed */ |
| 3955 | |
| 3956 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 3957 | if (rc == IOCB_ERROR) { |
| 3958 | lpfc_els_free_iocb(phba, elsiocb); |
| 3959 | return 1; |
| 3960 | } |
| 3961 | return 0; |
| 3962 | } |
| 3963 | |
| 3964 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3965 | * 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] | 3966 | * @vport: pointer to a host virtual N_Port data structure. |
| 3967 | * |
| 3968 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 3969 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 3970 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 3971 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 3972 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 3973 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 3974 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 3975 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 3976 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 3977 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 3978 | * no more ADISC need to be sent. |
| 3979 | * |
| 3980 | * Return code |
| 3981 | * The number of N_Ports with adisc issued. |
| 3982 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3983 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3984 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3985 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3986 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3987 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3988 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3989 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3990 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3991 | 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] | 3992 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3993 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3994 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3995 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3996 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3997 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3998 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3999 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4000 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4001 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 4002 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4003 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4004 | vport->num_disc_nodes++; |
| 4005 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4006 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4007 | spin_lock_irq(shost->host_lock); |
| 4008 | vport->fc_flag |= FC_NLP_MORE; |
| 4009 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4010 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4011 | } |
| 4012 | } |
| 4013 | } |
| 4014 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4015 | spin_lock_irq(shost->host_lock); |
| 4016 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4017 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4018 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4019 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4020 | } |
| 4021 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4022 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4023 | * 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] | 4024 | * @vport: pointer to a host virtual N_Port data structure. |
| 4025 | * |
| 4026 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 4027 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 4028 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 4029 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 4030 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 4031 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 4032 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 4033 | * later pick up. On the other hand, after walking through all the ndlps with |
| 4034 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 4035 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 4036 | * PLOGI need to be sent. |
| 4037 | * |
| 4038 | * Return code |
| 4039 | * The number of N_Ports with plogi issued. |
| 4040 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4041 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4042 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4043 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4044 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4045 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4046 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4047 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4048 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 4049 | 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] | 4050 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4051 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4052 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 4053 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4054 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 4055 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 4056 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4057 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 4058 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4059 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4060 | vport->num_disc_nodes++; |
| 4061 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4062 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4063 | spin_lock_irq(shost->host_lock); |
| 4064 | vport->fc_flag |= FC_NLP_MORE; |
| 4065 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4066 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4067 | } |
| 4068 | } |
| 4069 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4070 | if (sentplogi) { |
| 4071 | lpfc_set_disctmo(vport); |
| 4072 | } |
| 4073 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4074 | spin_lock_irq(shost->host_lock); |
| 4075 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4076 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4077 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4078 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4079 | } |
| 4080 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4081 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4082 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4083 | * @vport: pointer to a host virtual N_Port data structure. |
| 4084 | * |
| 4085 | * This routine cleans up any Registration State Change Notification |
| 4086 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 4087 | * @vport together with the host_lock is used to prevent multiple thread |
| 4088 | * trying to access the RSCN array on a same @vport at the same time. |
| 4089 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4090 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4091 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4092 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4093 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4094 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4095 | int i; |
| 4096 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4097 | spin_lock_irq(shost->host_lock); |
| 4098 | if (vport->fc_rscn_flush) { |
| 4099 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4100 | spin_unlock_irq(shost->host_lock); |
| 4101 | return; |
| 4102 | } |
| 4103 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 4104 | vport->fc_rscn_flush = 1; |
| 4105 | spin_unlock_irq(shost->host_lock); |
| 4106 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4107 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4108 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4109 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4110 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4111 | spin_lock_irq(shost->host_lock); |
| 4112 | vport->fc_rscn_id_cnt = 0; |
| 4113 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 4114 | spin_unlock_irq(shost->host_lock); |
| 4115 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4116 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 4117 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4118 | } |
| 4119 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4120 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4121 | * 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] | 4122 | * @vport: pointer to a host virtual N_Port data structure. |
| 4123 | * @did: remote destination port identifier. |
| 4124 | * |
| 4125 | * This routine checks whether there is any pending Registration State |
| 4126 | * Configuration Notification (RSCN) to a @did on @vport. |
| 4127 | * |
| 4128 | * Return code |
| 4129 | * None zero - The @did matched with a pending rscn |
| 4130 | * 0 - not able to match @did with a pending rscn |
| 4131 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4132 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4133 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4134 | { |
| 4135 | D_ID ns_did; |
| 4136 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4137 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4138 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4139 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4140 | |
| 4141 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4142 | |
| 4143 | /* Never match fabric nodes for RSCNs */ |
| 4144 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4145 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4146 | |
| 4147 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4148 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4149 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4150 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4151 | spin_lock_irq(shost->host_lock); |
| 4152 | if (vport->fc_rscn_flush) { |
| 4153 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4154 | spin_unlock_irq(shost->host_lock); |
| 4155 | return 0; |
| 4156 | } |
| 4157 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4158 | vport->fc_rscn_flush = 1; |
| 4159 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4160 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4161 | lp = vport->fc_rscn_id_list[i]->virt; |
| 4162 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4163 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4164 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4165 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 4166 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4167 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 4168 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4169 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4170 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 4171 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4172 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4173 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4174 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4175 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4176 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4177 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4178 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4179 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4180 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4181 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4182 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4183 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4184 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4185 | } |
| 4186 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4187 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4188 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4189 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4190 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4191 | return_did_out: |
| 4192 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4193 | vport->fc_rscn_flush = 0; |
| 4194 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4195 | } |
| 4196 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4197 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4198 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4199 | * @vport: pointer to a host virtual N_Port data structure. |
| 4200 | * |
| 4201 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 4202 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 4203 | * State Change Notification). |
| 4204 | * |
| 4205 | * Return code |
| 4206 | * 0 - Successful (currently alway return 0) |
| 4207 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4208 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4209 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4210 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4211 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4212 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4213 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4214 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4215 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4216 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 4217 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4218 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4219 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4220 | NLP_EVT_DEVICE_RECOVERY); |
| 4221 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4222 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4223 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4224 | } |
| 4225 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4226 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4227 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4228 | * @vport: pointer to a host virtual N_Port data structure. |
| 4229 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4230 | * |
| 4231 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 4232 | * applications. |
| 4233 | */ |
| 4234 | static void |
| 4235 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 4236 | struct lpfc_iocbq *cmdiocb) |
| 4237 | { |
| 4238 | struct lpfc_dmabuf *pcmd; |
| 4239 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4240 | uint32_t *payload_ptr; |
| 4241 | uint32_t payload_len; |
| 4242 | struct lpfc_rscn_event_header *rscn_event_data; |
| 4243 | |
| 4244 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4245 | payload_ptr = (uint32_t *) pcmd->virt; |
| 4246 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 4247 | |
| 4248 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 4249 | payload_len, GFP_KERNEL); |
| 4250 | if (!rscn_event_data) { |
| 4251 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4252 | "0147 Failed to allocate memory for RSCN event\n"); |
| 4253 | return; |
| 4254 | } |
| 4255 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 4256 | rscn_event_data->payload_length = payload_len; |
| 4257 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 4258 | payload_len); |
| 4259 | |
| 4260 | fc_host_post_vendor_event(shost, |
| 4261 | fc_get_event_number(), |
| 4262 | sizeof(struct lpfc_els_event_header) + payload_len, |
| 4263 | (char *)rscn_event_data, |
| 4264 | LPFC_NL_VENDOR_ID); |
| 4265 | |
| 4266 | kfree(rscn_event_data); |
| 4267 | } |
| 4268 | |
| 4269 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4270 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4271 | * @vport: pointer to a host virtual N_Port data structure. |
| 4272 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4273 | * @ndlp: pointer to a node-list data structure. |
| 4274 | * |
| 4275 | * This routine processes an unsolicited RSCN (Registration State Change |
| 4276 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 4277 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 4278 | * discover state machine is about to begin discovery, it just accepts the |
| 4279 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 4280 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 4281 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 4282 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 4283 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 4284 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 4285 | * routine is invoked to handle the RSCN event. |
| 4286 | * |
| 4287 | * Return code |
| 4288 | * 0 - Just sent the acc response |
| 4289 | * 1 - Sent the acc response and waited for name server completion |
| 4290 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4291 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4292 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4293 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4294 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4295 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4296 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4297 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4298 | uint32_t *lp, *datap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4299 | IOCB_t *icmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4300 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4301 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4302 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4303 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4304 | |
| 4305 | icmd = &cmdiocb->iocb; |
| 4306 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4307 | lp = (uint32_t *) pcmd->virt; |
| 4308 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4309 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4310 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4311 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4312 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4313 | "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] | 4314 | vport->fc_flag, payload_len, *lp, |
| 4315 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4316 | |
| 4317 | /* Send an RSCN event to the management application */ |
| 4318 | lpfc_send_rscn_event(vport, cmdiocb); |
| 4319 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4320 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4321 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4322 | FCH_EVT_RSCN, lp[i]); |
| 4323 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4324 | /* If we are about to begin discovery, just ACC the RSCN. |
| 4325 | * Discovery processing will satisfy it. |
| 4326 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4327 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4328 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4329 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 4330 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4331 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4332 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4333 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4334 | } |
| 4335 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4336 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 4337 | * just ACC and ignore it. |
| 4338 | */ |
| 4339 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4340 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4341 | i = payload_len; |
| 4342 | datap = lp; |
| 4343 | while (i > 0) { |
| 4344 | nportid = *datap++; |
| 4345 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 4346 | i -= sizeof(uint32_t); |
| 4347 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4348 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 4349 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4350 | } |
| 4351 | if (rscn_id == hba_id) { |
| 4352 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4353 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4354 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4355 | "Data: x%x x%x x%x x%x\n", |
| 4356 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4357 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4358 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4359 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 4360 | ndlp->nlp_DID, vport->port_state, |
| 4361 | ndlp->nlp_flag); |
| 4362 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4363 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4364 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4365 | return 0; |
| 4366 | } |
| 4367 | } |
| 4368 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4369 | spin_lock_irq(shost->host_lock); |
| 4370 | if (vport->fc_rscn_flush) { |
| 4371 | /* Another thread is walking fc_rscn_id_list on this vport */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4372 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 4373 | spin_unlock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4374 | /* Send back ACC */ |
| 4375 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4376 | return 0; |
| 4377 | } |
| 4378 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4379 | vport->fc_rscn_flush = 1; |
| 4380 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4381 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4382 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4383 | /* If we are already processing an RSCN, save the received |
| 4384 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 4385 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4386 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4387 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4388 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 4389 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4390 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4391 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4392 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 4393 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4394 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4395 | vport->fc_flag |= FC_RSCN_MODE; |
| 4396 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4397 | if (rscn_cnt) { |
| 4398 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 4399 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 4400 | } |
| 4401 | if ((rscn_cnt) && |
| 4402 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 4403 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4404 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4405 | memcpy(((uint8_t *)cmd) + length, lp, |
| 4406 | payload_len); |
| 4407 | } else { |
| 4408 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 4409 | vport->fc_rscn_id_cnt++; |
| 4410 | /* If we zero, cmdiocb->context2, the calling |
| 4411 | * routine will not try to free it. |
| 4412 | */ |
| 4413 | cmdiocb->context2 = NULL; |
| 4414 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4415 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4416 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4417 | "0235 Deferred RSCN " |
| 4418 | "Data: x%x x%x x%x\n", |
| 4419 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4420 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4421 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4422 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 4423 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4424 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4425 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4426 | "0234 ReDiscovery RSCN " |
| 4427 | "Data: x%x x%x x%x\n", |
| 4428 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4429 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4430 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4431 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4432 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4433 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4434 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4435 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4436 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4437 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4438 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4439 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4440 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4441 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4442 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4443 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 4444 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4445 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4446 | spin_lock_irq(shost->host_lock); |
| 4447 | vport->fc_flag |= FC_RSCN_MODE; |
| 4448 | spin_unlock_irq(shost->host_lock); |
| 4449 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4450 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4451 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4452 | /* |
| 4453 | * If we zero, cmdiocb->context2, the calling routine will |
| 4454 | * not try to free it. |
| 4455 | */ |
| 4456 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4457 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4458 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4459 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4460 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4461 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4462 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4463 | } |
| 4464 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4465 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4466 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4467 | * @vport: pointer to a host virtual N_Port data structure. |
| 4468 | * |
| 4469 | * This routine handles the Registration State Configuration Notification |
| 4470 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 4471 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 4472 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 4473 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 4474 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 4475 | * RSCN activities with the @vport. |
| 4476 | * |
| 4477 | * Return code |
| 4478 | * 0 - Cleaned up rscn on the @vport |
| 4479 | * 1 - Wait for plogi to name server before proceed |
| 4480 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4481 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4482 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4483 | { |
| 4484 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4485 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4486 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4487 | /* Ignore RSCN if the port is being torn down. */ |
| 4488 | if (vport->load_flag & FC_UNLOADING) { |
| 4489 | lpfc_els_flush_rscn(vport); |
| 4490 | return 0; |
| 4491 | } |
| 4492 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4493 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4494 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4495 | |
| 4496 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4497 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4498 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 4499 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 4500 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4501 | |
| 4502 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4503 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4504 | vport->num_disc_nodes = 0; |
| 4505 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4506 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4507 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 4508 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4509 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4510 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4511 | /* Wait for NameServer query cmpl before we can |
| 4512 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4513 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4514 | } else { |
| 4515 | /* If login to NameServer does not exist, issue one */ |
| 4516 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4517 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4518 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4519 | /* Wait for NameServer login cmpl before we can |
| 4520 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4521 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4522 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4523 | if (ndlp) { |
| 4524 | ndlp = lpfc_enable_node(vport, ndlp, |
| 4525 | NLP_STE_PLOGI_ISSUE); |
| 4526 | if (!ndlp) { |
| 4527 | lpfc_els_flush_rscn(vport); |
| 4528 | return 0; |
| 4529 | } |
| 4530 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4531 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4532 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4533 | if (!ndlp) { |
| 4534 | lpfc_els_flush_rscn(vport); |
| 4535 | return 0; |
| 4536 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4537 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4538 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4539 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4540 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4541 | ndlp->nlp_type |= NLP_FABRIC; |
| 4542 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 4543 | /* Wait for NameServer login cmpl before we can |
| 4544 | * continue |
| 4545 | */ |
| 4546 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4547 | } |
| 4548 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4549 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4550 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4551 | } |
| 4552 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4553 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4554 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4555 | * @vport: pointer to a host virtual N_Port data structure. |
| 4556 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4557 | * @ndlp: pointer to a node-list data structure. |
| 4558 | * |
| 4559 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 4560 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 4561 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 4562 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 4563 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 4564 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 4565 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 4566 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 4567 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 4568 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 4569 | * higher priority (as the winning port) and will initiate PLOGI and |
| 4570 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 4571 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 4572 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 4573 | * |
| 4574 | * Return code |
| 4575 | * 0 - Successfully processed the unsolicited flogi |
| 4576 | * 1 - Failed to process the unsolicited flogi |
| 4577 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4578 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4579 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4580 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4581 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4582 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4583 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4584 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4585 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 4586 | IOCB_t *icmd = &cmdiocb->iocb; |
| 4587 | struct serv_parm *sp; |
| 4588 | LPFC_MBOXQ_t *mbox; |
| 4589 | struct ls_rjt stat; |
| 4590 | uint32_t cmd, did; |
| 4591 | int rc; |
| 4592 | |
| 4593 | cmd = *lp++; |
| 4594 | sp = (struct serv_parm *) lp; |
| 4595 | |
| 4596 | /* FLOGI received */ |
| 4597 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4598 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4599 | |
| 4600 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 4601 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 4602 | did = icmd->un.elsreq64.remoteID; |
| 4603 | |
| 4604 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 4605 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4606 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4607 | "0113 An FLOGI ELS command x%x was " |
| 4608 | "received from DID x%x in Loop Mode\n", |
| 4609 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4610 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4611 | } |
| 4612 | |
| 4613 | did = Fabric_DID; |
| 4614 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 4615 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4616 | /* For a FLOGI we accept, then if our portname is greater |
| 4617 | * then the remote portname we initiate Nport login. |
| 4618 | */ |
| 4619 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4620 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4621 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4622 | |
| 4623 | if (!rc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4624 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4625 | if (!mbox) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4626 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4627 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4628 | lpfc_linkdown(phba); |
| 4629 | lpfc_init_link(phba, mbox, |
| 4630 | phba->cfg_topology, |
| 4631 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4632 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4633 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4634 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4635 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4636 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4637 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4638 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4639 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4640 | return 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4641 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4642 | spin_lock_irq(shost->host_lock); |
| 4643 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 4644 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4645 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4646 | spin_lock_irq(shost->host_lock); |
| 4647 | vport->fc_flag |= FC_PT2PT; |
| 4648 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 4649 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4650 | } else { |
| 4651 | /* Reject this request because invalid parameters */ |
| 4652 | stat.un.b.lsRjtRsvd0 = 0; |
| 4653 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4654 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 4655 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4656 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4657 | NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4658 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4659 | } |
| 4660 | |
| 4661 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4662 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4663 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4664 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4665 | } |
| 4666 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4667 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4668 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4669 | * @vport: pointer to a host virtual N_Port data structure. |
| 4670 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4671 | * @ndlp: pointer to a node-list data structure. |
| 4672 | * |
| 4673 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 4674 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 4675 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 4676 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 4677 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 4678 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 4679 | * |
| 4680 | * Return code |
| 4681 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 4682 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4683 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4684 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4685 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4686 | { |
| 4687 | struct lpfc_dmabuf *pcmd; |
| 4688 | uint32_t *lp; |
| 4689 | IOCB_t *icmd; |
| 4690 | RNID *rn; |
| 4691 | struct ls_rjt stat; |
| 4692 | uint32_t cmd, did; |
| 4693 | |
| 4694 | icmd = &cmdiocb->iocb; |
| 4695 | did = icmd->un.elsreq64.remoteID; |
| 4696 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4697 | lp = (uint32_t *) pcmd->virt; |
| 4698 | |
| 4699 | cmd = *lp++; |
| 4700 | rn = (RNID *) lp; |
| 4701 | |
| 4702 | /* RNID received */ |
| 4703 | |
| 4704 | switch (rn->Format) { |
| 4705 | case 0: |
| 4706 | case RNID_TOPOLOGY_DISC: |
| 4707 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4708 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4709 | break; |
| 4710 | default: |
| 4711 | /* Reject this request because format not supported */ |
| 4712 | stat.un.b.lsRjtRsvd0 = 0; |
| 4713 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4714 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4715 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4716 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4717 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4718 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4719 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4720 | } |
| 4721 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4722 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4723 | * lpfc_els_rcv_echo - Process an unsolicited echo iocb |
| 4724 | * @vport: pointer to a host virtual N_Port data structure. |
| 4725 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4726 | * @ndlp: pointer to a node-list data structure. |
| 4727 | * |
| 4728 | * Return code |
| 4729 | * 0 - Successfully processed echo iocb (currently always return 0) |
| 4730 | **/ |
| 4731 | static int |
| 4732 | lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4733 | struct lpfc_nodelist *ndlp) |
| 4734 | { |
| 4735 | uint8_t *pcmd; |
| 4736 | |
| 4737 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
| 4738 | |
| 4739 | /* skip over first word of echo command to find echo data */ |
| 4740 | pcmd += sizeof(uint32_t); |
| 4741 | |
| 4742 | lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp); |
| 4743 | return 0; |
| 4744 | } |
| 4745 | |
| 4746 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4747 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4748 | * @vport: pointer to a host virtual N_Port data structure. |
| 4749 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4750 | * @ndlp: pointer to a node-list data structure. |
| 4751 | * |
| 4752 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 4753 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 4754 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 4755 | * |
| 4756 | * Return code |
| 4757 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 4758 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4759 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4760 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4761 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4762 | { |
| 4763 | struct ls_rjt stat; |
| 4764 | |
| 4765 | /* For now, unconditionally reject this command */ |
| 4766 | stat.un.b.lsRjtRsvd0 = 0; |
| 4767 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4768 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4769 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4770 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4771 | return 0; |
| 4772 | } |
| 4773 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4774 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4775 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb |
| 4776 | * @vport: pointer to a host virtual N_Port data structure. |
| 4777 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4778 | * @ndlp: pointer to a node-list data structure. |
| 4779 | * |
| 4780 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB |
| 4781 | * received as an ELS unsolicited event. A request to RRQ shall only |
| 4782 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder |
| 4783 | * Nx_Port N_Port_ID of the target Exchange is the same as the |
| 4784 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is |
| 4785 | * not accepted, an LS_RJT with reason code "Unable to perform |
| 4786 | * command request" and reason code explanation "Invalid Originator |
| 4787 | * S_ID" shall be returned. For now, we just unconditionally accept |
| 4788 | * RRQ from the target. |
| 4789 | **/ |
| 4790 | static void |
| 4791 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4792 | struct lpfc_nodelist *ndlp) |
| 4793 | { |
| 4794 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| 4795 | } |
| 4796 | |
| 4797 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4798 | * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd |
| 4799 | * @phba: pointer to lpfc hba data structure. |
| 4800 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4801 | * |
| 4802 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 4803 | * mailbox command. This callback function is to actually send the Accept |
| 4804 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 4805 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 4806 | * mailbox command, constructs the RPS response with the link statistics |
| 4807 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 4808 | * response to the RPS. |
| 4809 | * |
| 4810 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4811 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4812 | * will be stored into the context1 field of the IOCB for the completion |
| 4813 | * callback function to the RPS Accept Response ELS IOCB command. |
| 4814 | * |
| 4815 | **/ |
| 4816 | static void |
| 4817 | lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 4818 | { |
| 4819 | MAILBOX_t *mb; |
| 4820 | IOCB_t *icmd; |
| 4821 | struct RLS_RSP *rls_rsp; |
| 4822 | uint8_t *pcmd; |
| 4823 | struct lpfc_iocbq *elsiocb; |
| 4824 | struct lpfc_nodelist *ndlp; |
| 4825 | uint16_t xri; |
| 4826 | uint32_t cmdsize; |
| 4827 | |
| 4828 | mb = &pmb->u.mb; |
| 4829 | |
| 4830 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4831 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
| 4832 | pmb->context1 = NULL; |
| 4833 | pmb->context2 = NULL; |
| 4834 | |
| 4835 | if (mb->mbxStatus) { |
| 4836 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4837 | return; |
| 4838 | } |
| 4839 | |
| 4840 | cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t); |
| 4841 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4842 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 4843 | lpfc_max_els_tries, ndlp, |
| 4844 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 4845 | |
| 4846 | /* Decrement the ndlp reference count from previous mbox command */ |
| 4847 | lpfc_nlp_put(ndlp); |
| 4848 | |
| 4849 | if (!elsiocb) |
| 4850 | return; |
| 4851 | |
| 4852 | icmd = &elsiocb->iocb; |
| 4853 | icmd->ulpContext = xri; |
| 4854 | |
| 4855 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4856 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 4857 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 4858 | rls_rsp = (struct RLS_RSP *)pcmd; |
| 4859 | |
| 4860 | rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 4861 | rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 4862 | rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 4863 | rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 4864 | rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 4865 | rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
| 4866 | |
| 4867 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 4868 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 4869 | "2874 Xmit ELS RLS ACC response tag x%x xri x%x, " |
| 4870 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4871 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4872 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4873 | ndlp->nlp_rpi); |
| 4874 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 4875 | phba->fc_stat.elsXmitACC++; |
| 4876 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 4877 | lpfc_els_free_iocb(phba, elsiocb); |
| 4878 | } |
| 4879 | |
| 4880 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4881 | * 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] | 4882 | * @phba: pointer to lpfc hba data structure. |
| 4883 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4884 | * |
| 4885 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 4886 | * mailbox command. This callback function is to actually send the Accept |
| 4887 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 4888 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 4889 | * mailbox command, constructs the RPS response with the link statistics |
| 4890 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 4891 | * response to the RPS. |
| 4892 | * |
| 4893 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4894 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4895 | * will be stored into the context1 field of the IOCB for the completion |
| 4896 | * callback function to the RPS Accept Response ELS IOCB command. |
| 4897 | * |
| 4898 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4899 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4900 | 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] | 4901 | { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4902 | MAILBOX_t *mb; |
| 4903 | IOCB_t *icmd; |
| 4904 | RPS_RSP *rps_rsp; |
| 4905 | uint8_t *pcmd; |
| 4906 | struct lpfc_iocbq *elsiocb; |
| 4907 | struct lpfc_nodelist *ndlp; |
| 4908 | uint16_t xri, status; |
| 4909 | uint32_t cmdsize; |
| 4910 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4911 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4912 | |
| 4913 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4914 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 4915 | pmb->context1 = NULL; |
| 4916 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4917 | |
| 4918 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4919 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4920 | return; |
| 4921 | } |
| 4922 | |
| 4923 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4924 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4925 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 4926 | lpfc_max_els_tries, ndlp, |
| 4927 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4928 | |
| 4929 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4930 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4931 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4932 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4933 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4934 | |
| 4935 | icmd = &elsiocb->iocb; |
| 4936 | icmd->ulpContext = xri; |
| 4937 | |
| 4938 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4939 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4940 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4941 | rps_rsp = (RPS_RSP *)pcmd; |
| 4942 | |
| 4943 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| 4944 | status = 0x10; |
| 4945 | else |
| 4946 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4947 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4948 | status |= 0x4; |
| 4949 | |
| 4950 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4951 | rps_rsp->portStatus = cpu_to_be16(status); |
| 4952 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 4953 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 4954 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 4955 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 4956 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 4957 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4958 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4959 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 4960 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 4961 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4962 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4963 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4964 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4965 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4966 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4967 | 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] | 4968 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4969 | return; |
| 4970 | } |
| 4971 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4972 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4973 | * lpfc_els_rcv_rls - Process an unsolicited rls iocb |
| 4974 | * @vport: pointer to a host virtual N_Port data structure. |
| 4975 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4976 | * @ndlp: pointer to a node-list data structure. |
| 4977 | * |
| 4978 | * This routine processes Read Port Status (RPL) IOCB received as an |
| 4979 | * ELS unsolicited event. It first checks the remote port state. If the |
| 4980 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 4981 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 4982 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 4983 | * for reading the HBA link statistics. It is for the callback function, |
| 4984 | * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 4985 | * to actually sending out RPL Accept (ACC) response. |
| 4986 | * |
| 4987 | * Return codes |
| 4988 | * 0 - Successfully processed rls iocb (currently always return 0) |
| 4989 | **/ |
| 4990 | static int |
| 4991 | lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4992 | struct lpfc_nodelist *ndlp) |
| 4993 | { |
| 4994 | struct lpfc_hba *phba = vport->phba; |
| 4995 | LPFC_MBOXQ_t *mbox; |
| 4996 | struct lpfc_dmabuf *pcmd; |
| 4997 | struct ls_rjt stat; |
| 4998 | |
| 4999 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 5000 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5001 | /* reject the unsolicited RPS request and done with it */ |
| 5002 | goto reject_out; |
| 5003 | |
| 5004 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5005 | |
| 5006 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 5007 | if (mbox) { |
| 5008 | lpfc_read_lnk_stat(phba, mbox); |
| 5009 | mbox->context1 = |
| 5010 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
| 5011 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 5012 | mbox->vport = vport; |
| 5013 | mbox->mbox_cmpl = lpfc_els_rsp_rls_acc; |
| 5014 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
| 5015 | != MBX_NOT_FINISHED) |
| 5016 | /* Mbox completion will send ELS Response */ |
| 5017 | return 0; |
| 5018 | /* Decrement reference count used for the failed mbox |
| 5019 | * command. |
| 5020 | */ |
| 5021 | lpfc_nlp_put(ndlp); |
| 5022 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5023 | } |
| 5024 | reject_out: |
| 5025 | /* issue rejection response */ |
| 5026 | stat.un.b.lsRjtRsvd0 = 0; |
| 5027 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5028 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5029 | stat.un.b.vendorUnique = 0; |
| 5030 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5031 | return 0; |
| 5032 | } |
| 5033 | |
| 5034 | /** |
| 5035 | * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb |
| 5036 | * @vport: pointer to a host virtual N_Port data structure. |
| 5037 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5038 | * @ndlp: pointer to a node-list data structure. |
| 5039 | * |
| 5040 | * This routine processes Read Timout Value (RTV) IOCB received as an |
| 5041 | * ELS unsolicited event. It first checks the remote port state. If the |
| 5042 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 5043 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 5044 | * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout |
| 5045 | * Value (RTV) unsolicited IOCB event. |
| 5046 | * |
| 5047 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5048 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5049 | * will be stored into the context1 field of the IOCB for the completion |
| 5050 | * callback function to the RPS Accept Response ELS IOCB command. |
| 5051 | * |
| 5052 | * Return codes |
| 5053 | * 0 - Successfully processed rtv iocb (currently always return 0) |
| 5054 | **/ |
| 5055 | static int |
| 5056 | lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5057 | struct lpfc_nodelist *ndlp) |
| 5058 | { |
| 5059 | struct lpfc_hba *phba = vport->phba; |
| 5060 | struct ls_rjt stat; |
| 5061 | struct RTV_RSP *rtv_rsp; |
| 5062 | uint8_t *pcmd; |
| 5063 | struct lpfc_iocbq *elsiocb; |
| 5064 | uint32_t cmdsize; |
| 5065 | |
| 5066 | |
| 5067 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 5068 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5069 | /* reject the unsolicited RPS request and done with it */ |
| 5070 | goto reject_out; |
| 5071 | |
| 5072 | cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t); |
| 5073 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5074 | lpfc_max_els_tries, ndlp, |
| 5075 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 5076 | |
| 5077 | if (!elsiocb) |
| 5078 | return 1; |
| 5079 | |
| 5080 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5081 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 5082 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 5083 | |
| 5084 | /* use the command's xri in the response */ |
| 5085 | elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; |
| 5086 | |
| 5087 | rtv_rsp = (struct RTV_RSP *)pcmd; |
| 5088 | |
| 5089 | /* populate RTV payload */ |
| 5090 | rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */ |
| 5091 | rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov); |
| 5092 | bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0); |
| 5093 | bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */ |
| 5094 | rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov); |
| 5095 | |
| 5096 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 5097 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 5098 | "2875 Xmit ELS RTV ACC response tag x%x xri x%x, " |
| 5099 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, " |
| 5100 | "Data: x%x x%x x%x\n", |
| 5101 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5102 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5103 | ndlp->nlp_rpi, |
| 5104 | rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov); |
| 5105 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5106 | phba->fc_stat.elsXmitACC++; |
| 5107 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 5108 | lpfc_els_free_iocb(phba, elsiocb); |
| 5109 | return 0; |
| 5110 | |
| 5111 | reject_out: |
| 5112 | /* issue rejection response */ |
| 5113 | stat.un.b.lsRjtRsvd0 = 0; |
| 5114 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5115 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5116 | stat.un.b.vendorUnique = 0; |
| 5117 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5118 | return 0; |
| 5119 | } |
| 5120 | |
| 5121 | /* lpfc_els_rcv_rps - Process an unsolicited rps iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5122 | * @vport: pointer to a host virtual N_Port data structure. |
| 5123 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5124 | * @ndlp: pointer to a node-list data structure. |
| 5125 | * |
| 5126 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 5127 | * ELS unsolicited event. It first checks the remote port state. If the |
| 5128 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 5129 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 5130 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 5131 | * for reading the HBA link statistics. It is for the callback function, |
| 5132 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 5133 | * to actually sending out RPS Accept (ACC) response. |
| 5134 | * |
| 5135 | * Return codes |
| 5136 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 5137 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5138 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5139 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5140 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5141 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5142 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5143 | uint32_t *lp; |
| 5144 | uint8_t flag; |
| 5145 | LPFC_MBOXQ_t *mbox; |
| 5146 | struct lpfc_dmabuf *pcmd; |
| 5147 | RPS *rps; |
| 5148 | struct ls_rjt stat; |
| 5149 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5150 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5151 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5152 | /* reject the unsolicited RPS request and done with it */ |
| 5153 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5154 | |
| 5155 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5156 | lp = (uint32_t *) pcmd->virt; |
| 5157 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 5158 | rps = (RPS *) lp; |
| 5159 | |
| 5160 | if ((flag == 0) || |
| 5161 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5162 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5163 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5164 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5165 | printk("Fix me....\n"); |
| 5166 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5167 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 5168 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5169 | lpfc_read_lnk_stat(phba, mbox); |
| 5170 | mbox->context1 = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5171 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5172 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5173 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5174 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5175 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5176 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5177 | /* Mbox completion will send ELS Response */ |
| 5178 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5179 | /* Decrement reference count used for the failed mbox |
| 5180 | * command. |
| 5181 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5182 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5183 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5184 | } |
| 5185 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5186 | |
| 5187 | reject_out: |
| 5188 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5189 | stat.un.b.lsRjtRsvd0 = 0; |
| 5190 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5191 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5192 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5193 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5194 | return 0; |
| 5195 | } |
| 5196 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5197 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5198 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5199 | * @vport: pointer to a host virtual N_Port data structure. |
| 5200 | * @cmdsize: size of the ELS command. |
| 5201 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 5202 | * @ndlp: pointer to a node-list data structure. |
| 5203 | * |
| 5204 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 5205 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 5206 | * |
| 5207 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5208 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5209 | * will be stored into the context1 field of the IOCB for the completion |
| 5210 | * callback function to the RPL Accept Response ELS command. |
| 5211 | * |
| 5212 | * Return code |
| 5213 | * 0 - Successfully issued ACC RPL ELS command |
| 5214 | * 1 - Failed to issue ACC RPL ELS command |
| 5215 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 5216 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5217 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 5218 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5219 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5220 | struct lpfc_hba *phba = vport->phba; |
| 5221 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5222 | RPL_RSP rpl_rsp; |
| 5223 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5224 | uint8_t *pcmd; |
| 5225 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5226 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 5227 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5228 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5229 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5230 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5231 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5232 | icmd = &elsiocb->iocb; |
| 5233 | oldcmd = &oldiocb->iocb; |
| 5234 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 5235 | |
| 5236 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5237 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5238 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5239 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 5240 | pcmd += sizeof(uint16_t); |
| 5241 | |
| 5242 | /* Setup the RPL ACC payload */ |
| 5243 | rpl_rsp.listLen = be32_to_cpu(1); |
| 5244 | rpl_rsp.index = 0; |
| 5245 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5246 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 5247 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5248 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5249 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5250 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5251 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5252 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 5253 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 5254 | "rpi x%x\n", |
| 5255 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5256 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5257 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5258 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5259 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5260 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 5261 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5262 | lpfc_els_free_iocb(phba, elsiocb); |
| 5263 | return 1; |
| 5264 | } |
| 5265 | return 0; |
| 5266 | } |
| 5267 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5268 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5269 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5270 | * @vport: pointer to a host virtual N_Port data structure. |
| 5271 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5272 | * @ndlp: pointer to a node-list data structure. |
| 5273 | * |
| 5274 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 5275 | * unsolicited event. It first checks the remote port state. If the remote |
| 5276 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 5277 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 5278 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 5279 | * to accept the RPL. |
| 5280 | * |
| 5281 | * Return code |
| 5282 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 5283 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5284 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5285 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5286 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5287 | { |
| 5288 | struct lpfc_dmabuf *pcmd; |
| 5289 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5290 | uint32_t maxsize; |
| 5291 | uint16_t cmdsize; |
| 5292 | RPL *rpl; |
| 5293 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5294 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5295 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 5296 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5297 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5298 | stat.un.b.lsRjtRsvd0 = 0; |
| 5299 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5300 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5301 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5302 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 5303 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5304 | /* rejected the unsolicited RPL request and done with it */ |
| 5305 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5306 | } |
| 5307 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5308 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5309 | lp = (uint32_t *) pcmd->virt; |
| 5310 | rpl = (RPL *) (lp + 1); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5311 | maxsize = be32_to_cpu(rpl->maxsize); |
| 5312 | |
| 5313 | /* We support only one port */ |
| 5314 | if ((rpl->index == 0) && |
| 5315 | ((maxsize == 0) || |
| 5316 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 5317 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5318 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5319 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 5320 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5321 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5322 | |
| 5323 | return 0; |
| 5324 | } |
| 5325 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5326 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5327 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5328 | * @vport: pointer to a virtual N_Port data structure. |
| 5329 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5330 | * @ndlp: pointer to a node-list data structure. |
| 5331 | * |
| 5332 | * This routine processes Fibre Channel Address Resolution Protocol |
| 5333 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 5334 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 5335 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 5336 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 5337 | * remote PortName is compared against the FC PortName stored in the @vport |
| 5338 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 5339 | * compared against the FC NodeName stored in the @vport data structure. |
| 5340 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 5341 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 5342 | * invoked to send out FARP Response to the remote node. Before sending the |
| 5343 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 5344 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 5345 | * routine is invoked to log into the remote port first. |
| 5346 | * |
| 5347 | * Return code |
| 5348 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 5349 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5350 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5351 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5352 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5353 | { |
| 5354 | struct lpfc_dmabuf *pcmd; |
| 5355 | uint32_t *lp; |
| 5356 | IOCB_t *icmd; |
| 5357 | FARP *fp; |
| 5358 | uint32_t cmd, cnt, did; |
| 5359 | |
| 5360 | icmd = &cmdiocb->iocb; |
| 5361 | did = icmd->un.elsreq64.remoteID; |
| 5362 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5363 | lp = (uint32_t *) pcmd->virt; |
| 5364 | |
| 5365 | cmd = *lp++; |
| 5366 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5367 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5368 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5369 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5370 | /* We will only support match on WWPN or WWNN */ |
| 5371 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5372 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5373 | } |
| 5374 | |
| 5375 | cnt = 0; |
| 5376 | /* If this FARP command is searching for my portname */ |
| 5377 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5378 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5379 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5380 | cnt = 1; |
| 5381 | } |
| 5382 | |
| 5383 | /* If this FARP command is searching for my nodename */ |
| 5384 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5385 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5386 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5387 | cnt = 1; |
| 5388 | } |
| 5389 | |
| 5390 | if (cnt) { |
| 5391 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 5392 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 5393 | /* Log back into the node before sending the FARP. */ |
| 5394 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5395 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5396 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 5397 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5398 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5399 | } |
| 5400 | |
| 5401 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5402 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 5403 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5404 | } |
| 5405 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5406 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5407 | } |
| 5408 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5409 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5410 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5411 | * @vport: pointer to a host virtual N_Port data structure. |
| 5412 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5413 | * @ndlp: pointer to a node-list data structure. |
| 5414 | * |
| 5415 | * This routine processes Fibre Channel Address Resolution Protocol |
| 5416 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 5417 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 5418 | * the FARP response request. |
| 5419 | * |
| 5420 | * Return code |
| 5421 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 5422 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5423 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5424 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5425 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5426 | { |
| 5427 | struct lpfc_dmabuf *pcmd; |
| 5428 | uint32_t *lp; |
| 5429 | IOCB_t *icmd; |
| 5430 | uint32_t cmd, did; |
| 5431 | |
| 5432 | icmd = &cmdiocb->iocb; |
| 5433 | did = icmd->un.elsreq64.remoteID; |
| 5434 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5435 | lp = (uint32_t *) pcmd->virt; |
| 5436 | |
| 5437 | cmd = *lp++; |
| 5438 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5439 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5440 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5441 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5442 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5443 | |
| 5444 | return 0; |
| 5445 | } |
| 5446 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5447 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5448 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5449 | * @vport: pointer to a host virtual N_Port data structure. |
| 5450 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5451 | * @fan_ndlp: pointer to a node-list data structure. |
| 5452 | * |
| 5453 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 5454 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 5455 | * only be processed on a physical port (i.e., the @vport represents the |
| 5456 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 5457 | * compared against those in the phba data structure. If any of those is |
| 5458 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 5459 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 5460 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 5461 | * is invoked to register login to the fabric. |
| 5462 | * |
| 5463 | * Return code |
| 5464 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 5465 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5466 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5467 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5468 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5469 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5470 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5471 | uint32_t *lp; |
| 5472 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5473 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5474 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 5475 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 5476 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5477 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5478 | if ((vport == phba->pport) && |
| 5479 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5480 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5481 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5482 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5483 | sizeof(struct lpfc_name)))) { |
| 5484 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5485 | lpfc_initial_flogi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5486 | } else { |
| 5487 | /* FAN verified - skip FLOGI */ |
| 5488 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5489 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5490 | lpfc_issue_fabric_reglogin(vport); |
| 5491 | else |
| 5492 | lpfc_issue_reg_vfi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5493 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5494 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5495 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5496 | } |
| 5497 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5498 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5499 | * lpfc_els_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5500 | * @ptr: holder for the timer function associated data. |
| 5501 | * |
| 5502 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 5503 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 5504 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 5505 | * up the worker thread. It is for the worker thread to invoke the routine |
| 5506 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 5507 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5508 | void |
| 5509 | lpfc_els_timeout(unsigned long ptr) |
| 5510 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5511 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 5512 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5513 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5514 | unsigned long iflag; |
| 5515 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5516 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5517 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
| 5518 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5519 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5520 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5521 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5522 | if (!tmo_posted) |
| 5523 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5524 | return; |
| 5525 | } |
| 5526 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5527 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5528 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5529 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5530 | * @vport: pointer to a virtual N_Port data structure. |
| 5531 | * |
| 5532 | * This routine is the actual handler function that processes an ELS timeout |
| 5533 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 5534 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 5535 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5536 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5537 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5538 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5539 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5540 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5541 | struct lpfc_sli_ring *pring; |
| 5542 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5543 | IOCB_t *cmd = NULL; |
| 5544 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5545 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5546 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5547 | uint32_t remote_ID = 0xffffffff; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5548 | LIST_HEAD(txcmplq_completions); |
| 5549 | LIST_HEAD(abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5550 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5551 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5552 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 5553 | |
| 5554 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5555 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5556 | spin_lock_irq(&phba->hbalock); |
| 5557 | list_splice_init(&pring->txcmplq, &txcmplq_completions); |
| 5558 | spin_unlock_irq(&phba->hbalock); |
| 5559 | |
| 5560 | list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5561 | cmd = &piocb->iocb; |
| 5562 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5563 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 5564 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 5565 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5566 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5567 | |
| 5568 | if (piocb->vport != vport) |
| 5569 | continue; |
| 5570 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5571 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5572 | if (pcmd) |
| 5573 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5574 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5575 | if (els_command == ELS_CMD_FARP || |
| 5576 | els_command == ELS_CMD_FARPR || |
| 5577 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5578 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5579 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5580 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5581 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5582 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5583 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5584 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5585 | continue; |
| 5586 | } |
| 5587 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5588 | remote_ID = 0xffffffff; |
| 5589 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5590 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5591 | else { |
| 5592 | struct lpfc_nodelist *ndlp; |
| 5593 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5594 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5595 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5596 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5597 | list_add_tail(&piocb->dlist, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5598 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5599 | spin_lock_irq(&phba->hbalock); |
| 5600 | list_splice(&txcmplq_completions, &pring->txcmplq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5601 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 5602 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5603 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
| 5604 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5605 | "0127 ELS timeout Data: x%x x%x x%x " |
| 5606 | "x%x\n", els_command, |
| 5607 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
| 5608 | spin_lock_irq(&phba->hbalock); |
| 5609 | list_del_init(&piocb->dlist); |
| 5610 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5611 | spin_unlock_irq(&phba->hbalock); |
| 5612 | } |
| 5613 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5614 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
| 5615 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5616 | } |
| 5617 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5618 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5619 | * 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] | 5620 | * @vport: pointer to a host virtual N_Port data structure. |
| 5621 | * |
| 5622 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5623 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 5624 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5625 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5626 | * the IOCBs with a non-NULL completion callback function, the callback |
| 5627 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5628 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 5629 | * callback function, the IOCB will simply be released. Finally, it walks |
| 5630 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 5631 | * completion queue IOCB that is associated with the @vport and is not |
| 5632 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 5633 | * part of the discovery state machine) out to HBA by invoking the |
| 5634 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 5635 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 5636 | * the IOCBs are aborted when this function returns. |
| 5637 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5638 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5639 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5640 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5641 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5642 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5643 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5644 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5645 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5646 | |
| 5647 | lpfc_fabric_abort_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5648 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5649 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5650 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5651 | cmd = &piocb->iocb; |
| 5652 | |
| 5653 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5654 | continue; |
| 5655 | } |
| 5656 | |
| 5657 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5658 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5659 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5660 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5661 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5662 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5663 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5664 | if (piocb->vport != vport) |
| 5665 | continue; |
| 5666 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5667 | list_move_tail(&piocb->list, &completions); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5668 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5669 | } |
| 5670 | |
| 5671 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5672 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5673 | continue; |
| 5674 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5675 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5676 | if (piocb->vport != vport) |
| 5677 | continue; |
| 5678 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5679 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5680 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5681 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5682 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5683 | /* Cancell all the IOCBs from the completions list */ |
| 5684 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5685 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5686 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5687 | return; |
| 5688 | } |
| 5689 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5690 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5691 | * 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] | 5692 | * @phba: pointer to lpfc hba data structure. |
| 5693 | * |
| 5694 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5695 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 5696 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5697 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5698 | * the IOCBs with the completion callback function associated, the callback |
| 5699 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5700 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 5701 | * callback function associated, the IOCB will simply be released. Finally, |
| 5702 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 5703 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 5704 | * management plane IOCBs that are not part of the discovery state machine) |
| 5705 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5706 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5707 | void |
| 5708 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 5709 | { |
| 5710 | LIST_HEAD(completions); |
| 5711 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 5712 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5713 | IOCB_t *cmd = NULL; |
| 5714 | |
| 5715 | lpfc_fabric_abort_hba(phba); |
| 5716 | spin_lock_irq(&phba->hbalock); |
| 5717 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5718 | cmd = &piocb->iocb; |
| 5719 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5720 | continue; |
| 5721 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
| 5722 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5723 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5724 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5725 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| 5726 | continue; |
| 5727 | list_move_tail(&piocb->list, &completions); |
| 5728 | pring->txq_cnt--; |
| 5729 | } |
| 5730 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5731 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5732 | continue; |
| 5733 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5734 | } |
| 5735 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5736 | |
| 5737 | /* Cancel all the IOCBs from the completions list */ |
| 5738 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5739 | IOERR_SLI_ABORTED); |
| 5740 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5741 | return; |
| 5742 | } |
| 5743 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5744 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5745 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5746 | * @phba: Pointer to hba context object. |
| 5747 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 5748 | * @rspiocbp: Pointer to response iocb which reported error. |
| 5749 | * |
| 5750 | * This function sends an event when there is an ELS command |
| 5751 | * failure. |
| 5752 | **/ |
| 5753 | void |
| 5754 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 5755 | struct lpfc_iocbq *cmdiocbp, |
| 5756 | struct lpfc_iocbq *rspiocbp) |
| 5757 | { |
| 5758 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 5759 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5760 | struct lpfc_lsrjt_event lsrjt_event; |
| 5761 | struct lpfc_fabric_event_header fabric_event; |
| 5762 | struct ls_rjt stat; |
| 5763 | struct lpfc_nodelist *ndlp; |
| 5764 | uint32_t *pcmd; |
| 5765 | |
| 5766 | ndlp = cmdiocbp->context1; |
| 5767 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 5768 | return; |
| 5769 | |
| 5770 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 5771 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 5772 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 5773 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 5774 | sizeof(struct lpfc_name)); |
| 5775 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 5776 | sizeof(struct lpfc_name)); |
| 5777 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 5778 | cmdiocbp->context2)->virt); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 5779 | lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5780 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 5781 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 5782 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 5783 | fc_host_post_vendor_event(shost, |
| 5784 | fc_get_event_number(), |
| 5785 | sizeof(lsrjt_event), |
| 5786 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5787 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5788 | return; |
| 5789 | } |
| 5790 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 5791 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 5792 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 5793 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 5794 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 5795 | else |
| 5796 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 5797 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 5798 | sizeof(struct lpfc_name)); |
| 5799 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 5800 | sizeof(struct lpfc_name)); |
| 5801 | fc_host_post_vendor_event(shost, |
| 5802 | fc_get_event_number(), |
| 5803 | sizeof(fabric_event), |
| 5804 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5805 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5806 | return; |
| 5807 | } |
| 5808 | |
| 5809 | } |
| 5810 | |
| 5811 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5812 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5813 | * @vport: Pointer to vport object. |
| 5814 | * @ndlp: Pointer FC node object. |
| 5815 | * @cmd: ELS command code. |
| 5816 | * |
| 5817 | * This function posts an event when there is an incoming |
| 5818 | * unsolicited ELS command. |
| 5819 | **/ |
| 5820 | static void |
| 5821 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 5822 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5823 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5824 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5825 | struct lpfc_els_event_header *els_data = NULL; |
| 5826 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5827 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5828 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5829 | if (*payload == ELS_CMD_LOGO) { |
| 5830 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 5831 | if (!logo_data) { |
| 5832 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5833 | "0148 Failed to allocate memory " |
| 5834 | "for LOGO event\n"); |
| 5835 | return; |
| 5836 | } |
| 5837 | els_data = &logo_data->header; |
| 5838 | } else { |
| 5839 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 5840 | GFP_KERNEL); |
| 5841 | if (!els_data) { |
| 5842 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5843 | "0149 Failed to allocate memory " |
| 5844 | "for ELS event\n"); |
| 5845 | return; |
| 5846 | } |
| 5847 | } |
| 5848 | els_data->event_type = FC_REG_ELS_EVENT; |
| 5849 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5850 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5851 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5852 | break; |
| 5853 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5854 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5855 | break; |
| 5856 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5857 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 5858 | break; |
| 5859 | case ELS_CMD_LOGO: |
| 5860 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 5861 | /* Copy the WWPN in the LOGO payload */ |
| 5862 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 5863 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5864 | break; |
| 5865 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 5866 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5867 | return; |
| 5868 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5869 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 5870 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 5871 | if (*payload == ELS_CMD_LOGO) { |
| 5872 | fc_host_post_vendor_event(shost, |
| 5873 | fc_get_event_number(), |
| 5874 | sizeof(struct lpfc_logo_event), |
| 5875 | (char *)logo_data, |
| 5876 | LPFC_NL_VENDOR_ID); |
| 5877 | kfree(logo_data); |
| 5878 | } else { |
| 5879 | fc_host_post_vendor_event(shost, |
| 5880 | fc_get_event_number(), |
| 5881 | sizeof(struct lpfc_els_event_header), |
| 5882 | (char *)els_data, |
| 5883 | LPFC_NL_VENDOR_ID); |
| 5884 | kfree(els_data); |
| 5885 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5886 | |
| 5887 | return; |
| 5888 | } |
| 5889 | |
| 5890 | |
| 5891 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5892 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5893 | * @phba: pointer to lpfc hba data structure. |
| 5894 | * @pring: pointer to a SLI ring. |
| 5895 | * @vport: pointer to a host virtual N_Port data structure. |
| 5896 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 5897 | * |
| 5898 | * This routine is used for processing the IOCB associated with a unsolicited |
| 5899 | * event. It first determines whether there is an existing ndlp that matches |
| 5900 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 5901 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 5902 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 5903 | * of the discovery state machine. |
| 5904 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5905 | static void |
| 5906 | 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] | 5907 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5908 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5909 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5910 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5911 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5912 | uint32_t *payload; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5913 | uint32_t cmd, did, newnode, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5914 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5915 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5916 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5917 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5918 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5919 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5920 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 5921 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5922 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5923 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5924 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5925 | did = icmd->un.rcvels.remoteID; |
| 5926 | if (icmd->ulpStatus) { |
| 5927 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5928 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 5929 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5930 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5931 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5932 | |
| 5933 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5934 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5935 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5936 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 5937 | /* Ignore traffic received during vport shutdown. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5938 | if (vport->load_flag & FC_UNLOADING) |
| 5939 | goto dropit; |
| 5940 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5941 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5942 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5943 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5944 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5945 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5946 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5947 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5948 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5949 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5950 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5951 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5952 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5953 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5954 | ndlp = lpfc_enable_node(vport, ndlp, |
| 5955 | NLP_STE_UNUSED_NODE); |
| 5956 | if (!ndlp) |
| 5957 | goto dropit; |
| 5958 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5959 | newnode = 1; |
| 5960 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 5961 | ndlp->nlp_type |= NLP_FABRIC; |
| 5962 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 5963 | /* This is similar to the new node path */ |
| 5964 | ndlp = lpfc_nlp_get(ndlp); |
| 5965 | if (!ndlp) |
| 5966 | goto dropit; |
| 5967 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5968 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5969 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5970 | |
| 5971 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5972 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5973 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5974 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5975 | |
| 5976 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 5977 | cmd &= ELS_CMD_MASK; |
| 5978 | } |
| 5979 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5980 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5981 | "0112 ELS command x%x received from NPORT x%x " |
| 5982 | "Data: x%x\n", cmd, did, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5983 | switch (cmd) { |
| 5984 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5985 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5986 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 5987 | did, vport->port_state, ndlp->nlp_flag); |
| 5988 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5989 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5990 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
| 5991 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5992 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5993 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5994 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 5995 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 5996 | rjt_err = LSRJT_UNABLE_TPC; |
| 5997 | break; |
| 5998 | } |
| 5999 | /* We get here, and drop thru, if we are PT2PT with |
| 6000 | * another NPort and the other side has initiated |
| 6001 | * the PLOGI before responding to our FLOGI. |
| 6002 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6003 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6004 | |
| 6005 | shost = lpfc_shost_from_vport(vport); |
| 6006 | spin_lock_irq(shost->host_lock); |
| 6007 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 6008 | spin_unlock_irq(shost->host_lock); |
| 6009 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6010 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 6011 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6012 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6013 | break; |
| 6014 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6015 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6016 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 6017 | did, vport->port_state, ndlp->nlp_flag); |
| 6018 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6019 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6020 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6021 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6022 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6023 | break; |
| 6024 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6025 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6026 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 6027 | did, vport->port_state, ndlp->nlp_flag); |
| 6028 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6029 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6030 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6031 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6032 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6033 | break; |
| 6034 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6035 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6036 | break; |
| 6037 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6038 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6039 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 6040 | did, vport->port_state, ndlp->nlp_flag); |
| 6041 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6042 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6043 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6044 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6045 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6046 | break; |
| 6047 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6048 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6049 | break; |
| 6050 | case ELS_CMD_RSCN: |
| 6051 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6052 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6053 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6054 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6055 | break; |
| 6056 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6057 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6058 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 6059 | did, vport->port_state, ndlp->nlp_flag); |
| 6060 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6061 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6062 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6063 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6064 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6065 | break; |
| 6066 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6067 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 6068 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6069 | break; |
| 6070 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6071 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6072 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 6073 | did, vport->port_state, ndlp->nlp_flag); |
| 6074 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6075 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6076 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6077 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6078 | break; |
| 6079 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6080 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 6081 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6082 | break; |
| 6083 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6084 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6085 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 6086 | did, vport->port_state, ndlp->nlp_flag); |
| 6087 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6088 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6089 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6090 | break; |
| 6091 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6092 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6093 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 6094 | did, vport->port_state, ndlp->nlp_flag); |
| 6095 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6096 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6097 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6098 | break; |
| 6099 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6100 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6101 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 6102 | did, vport->port_state, ndlp->nlp_flag); |
| 6103 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6104 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6105 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6106 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6107 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6108 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6109 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 6110 | did, vport->port_state, ndlp->nlp_flag); |
| 6111 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6112 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6113 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6114 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6115 | break; |
| 6116 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6117 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6118 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6119 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6120 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6121 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 6122 | did, vport->port_state, ndlp->nlp_flag); |
| 6123 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6124 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6125 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6126 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6127 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6128 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6129 | case ELS_CMD_RLS: |
| 6130 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6131 | "RCV RLS: did:x%x/ste:x%x flg:x%x", |
| 6132 | did, vport->port_state, ndlp->nlp_flag); |
| 6133 | |
| 6134 | phba->fc_stat.elsRcvRLS++; |
| 6135 | lpfc_els_rcv_rls(vport, elsiocb, ndlp); |
| 6136 | if (newnode) |
| 6137 | lpfc_nlp_put(ndlp); |
| 6138 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6139 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6140 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6141 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 6142 | did, vport->port_state, ndlp->nlp_flag); |
| 6143 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6144 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6145 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6146 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6147 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6148 | break; |
| 6149 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6150 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6151 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 6152 | did, vport->port_state, ndlp->nlp_flag); |
| 6153 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6154 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6155 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6156 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6157 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6158 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6159 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6160 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6161 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 6162 | did, vport->port_state, ndlp->nlp_flag); |
| 6163 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6164 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6165 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6166 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6167 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6168 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6169 | case ELS_CMD_RTV: |
| 6170 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6171 | "RCV RTV: did:x%x/ste:x%x flg:x%x", |
| 6172 | did, vport->port_state, ndlp->nlp_flag); |
| 6173 | phba->fc_stat.elsRcvRTV++; |
| 6174 | lpfc_els_rcv_rtv(vport, elsiocb, ndlp); |
| 6175 | if (newnode) |
| 6176 | lpfc_nlp_put(ndlp); |
| 6177 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6178 | case ELS_CMD_RRQ: |
| 6179 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6180 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", |
| 6181 | did, vport->port_state, ndlp->nlp_flag); |
| 6182 | |
| 6183 | phba->fc_stat.elsRcvRRQ++; |
| 6184 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); |
| 6185 | if (newnode) |
| 6186 | lpfc_nlp_put(ndlp); |
| 6187 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6188 | case ELS_CMD_ECHO: |
| 6189 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6190 | "RCV ECHO: did:x%x/ste:x%x flg:x%x", |
| 6191 | did, vport->port_state, ndlp->nlp_flag); |
| 6192 | |
| 6193 | phba->fc_stat.elsRcvECHO++; |
| 6194 | lpfc_els_rcv_echo(vport, elsiocb, ndlp); |
| 6195 | if (newnode) |
| 6196 | lpfc_nlp_put(ndlp); |
| 6197 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6198 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6199 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6200 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 6201 | cmd, did, vport->port_state); |
| 6202 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6203 | /* Unsupported ELS command, reject */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6204 | rjt_err = LSRJT_INVALID_CMD; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6205 | |
| 6206 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6207 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6208 | "0115 Unknown ELS command x%x " |
| 6209 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6210 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6211 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6212 | break; |
| 6213 | } |
| 6214 | |
| 6215 | /* check if need to LS_RJT received ELS cmd */ |
| 6216 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6217 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6218 | stat.un.b.lsRjtRsnCode = rjt_err; |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 6219 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6220 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 6221 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6222 | } |
| 6223 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6224 | lpfc_nlp_put(elsiocb->context1); |
| 6225 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6226 | return; |
| 6227 | |
| 6228 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6229 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6230 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6231 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6232 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6233 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6234 | phba->fc_stat.elsRcvDrop++; |
| 6235 | } |
| 6236 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6237 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6238 | * 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] | 6239 | * @phba: pointer to lpfc hba data structure. |
| 6240 | * @vpi: host virtual N_Port identifier. |
| 6241 | * |
| 6242 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 6243 | * @vpi. The function walks the HBA's vport list and returns the address |
| 6244 | * of the vport with the matching @vpi. |
| 6245 | * |
| 6246 | * Return code |
| 6247 | * NULL - No vport with the matching @vpi found |
| 6248 | * Otherwise - Address to the vport with the matching @vpi. |
| 6249 | **/ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 6250 | struct lpfc_vport * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6251 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 6252 | { |
| 6253 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6254 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6255 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6256 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6257 | list_for_each_entry(vport, &phba->port_list, listentry) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6258 | if (vport->vpi == vpi) { |
| 6259 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6260 | return vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6261 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6262 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6263 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6264 | return NULL; |
| 6265 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6266 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6267 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6268 | * 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] | 6269 | * @phba: pointer to lpfc hba data structure. |
| 6270 | * @pring: pointer to a SLI ring. |
| 6271 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 6272 | * |
| 6273 | * This routine is used to process an unsolicited event received from a SLI |
| 6274 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 6275 | * associated with the unsolicited event is done by invoking the routine |
| 6276 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 6277 | * SLI ring on which the unsolicited event was received. |
| 6278 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6279 | void |
| 6280 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 6281 | struct lpfc_iocbq *elsiocb) |
| 6282 | { |
| 6283 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6284 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6285 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6286 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 6287 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6288 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6289 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6290 | elsiocb->context2 = NULL; |
| 6291 | elsiocb->context3 = NULL; |
| 6292 | |
| 6293 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 6294 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 6295 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 6296 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6297 | phba->fc_stat.NoRcvBuf++; |
| 6298 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6299 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 6300 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6301 | return; |
| 6302 | } |
| 6303 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6304 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 6305 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 6306 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 6307 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 6308 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6309 | else |
| 6310 | vport = lpfc_find_vport_by_vpid(phba, |
| 6311 | icmd->unsli3.rcvsli3.vpi - phba->vpi_base); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6312 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6313 | /* If there are no BDEs associated |
| 6314 | * with this IOCB, there is nothing to do. |
| 6315 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6316 | if (icmd->ulpBdeCount == 0) |
| 6317 | return; |
| 6318 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6319 | /* type of ELS cmd is first 32bit word |
| 6320 | * in packet |
| 6321 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6322 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6323 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6324 | } else { |
| 6325 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 6326 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6327 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 6328 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6329 | } |
| 6330 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6331 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 6332 | /* |
| 6333 | * The different unsolicited event handlers would tell us |
| 6334 | * if they are done with "mp" by setting context2 to NULL. |
| 6335 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6336 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6337 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 6338 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6339 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6340 | |
| 6341 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6342 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6343 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6344 | elsiocb->context2 = bdeBuf2; |
| 6345 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6346 | /* free mp if we are done with it */ |
| 6347 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6348 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 6349 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6350 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6351 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6352 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6353 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6354 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6355 | * 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] | 6356 | * @phba: pointer to lpfc hba data structure. |
| 6357 | * @vport: pointer to a virtual N_Port data structure. |
| 6358 | * |
| 6359 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 6360 | * State Change Request (SCR) for a @vport. This routine will create an |
| 6361 | * ndlp for the Name Server associated to the @vport if such node does |
| 6362 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 6363 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 6364 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 6365 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 6366 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6367 | void |
| 6368 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 6369 | { |
| 6370 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
| 6371 | |
| 6372 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 6373 | if (!ndlp) { |
| 6374 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 6375 | if (!ndlp) { |
| 6376 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 6377 | lpfc_disc_start(vport); |
| 6378 | return; |
| 6379 | } |
| 6380 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6381 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6382 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6383 | return; |
| 6384 | } |
| 6385 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6386 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 6387 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 6388 | if (!ndlp) { |
| 6389 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 6390 | lpfc_disc_start(vport); |
| 6391 | return; |
| 6392 | } |
| 6393 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6394 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6395 | "0348 NameServer login: node freed\n"); |
| 6396 | return; |
| 6397 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6398 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6399 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6400 | |
| 6401 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 6402 | |
| 6403 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 6404 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6405 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6406 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6407 | return; |
| 6408 | } |
| 6409 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6410 | if (vport->cfg_fdmi_on) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6411 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 6412 | GFP_KERNEL); |
| 6413 | if (ndlp_fdmi) { |
| 6414 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 6415 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6416 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
| 6417 | NLP_STE_PLOGI_ISSUE); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6418 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, |
| 6419 | 0); |
| 6420 | } |
| 6421 | } |
| 6422 | return; |
| 6423 | } |
| 6424 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6425 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6426 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6427 | * @phba: pointer to lpfc hba data structure. |
| 6428 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 6429 | * |
| 6430 | * This routine is the completion callback function to register new vport |
| 6431 | * mailbox command. If the new vport mailbox command completes successfully, |
| 6432 | * the fabric registration login shall be performed on physical port (the |
| 6433 | * new vport created is actually a physical port, with VPI 0) or the port |
| 6434 | * login to Name Server for State Change Request (SCR) will be performed |
| 6435 | * on virtual port (real virtual port, with VPI greater than 0). |
| 6436 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6437 | static void |
| 6438 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6439 | { |
| 6440 | struct lpfc_vport *vport = pmb->vport; |
| 6441 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6442 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6443 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6444 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6445 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6446 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6447 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6448 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6449 | |
| 6450 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6451 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6452 | "0915 Register VPI failed : Status: x%x" |
| 6453 | " upd bit: x%x \n", mb->mbxStatus, |
| 6454 | mb->un.varRegVpi.upd); |
| 6455 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 6456 | mb->un.varRegVpi.upd) |
| 6457 | goto mbox_err_exit ; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6458 | |
| 6459 | switch (mb->mbxStatus) { |
| 6460 | case 0x11: /* unsupported feature */ |
| 6461 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6462 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6463 | /* giving up on vport registration */ |
| 6464 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6465 | spin_lock_irq(shost->host_lock); |
| 6466 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 6467 | spin_unlock_irq(shost->host_lock); |
| 6468 | lpfc_can_disctmo(vport); |
| 6469 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6470 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
| 6471 | case 0x20: |
| 6472 | spin_lock_irq(shost->host_lock); |
| 6473 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 6474 | spin_unlock_irq(shost->host_lock); |
| 6475 | lpfc_init_vpi(phba, pmb, vport->vpi); |
| 6476 | pmb->vport = vport; |
| 6477 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 6478 | rc = lpfc_sli_issue_mbox(phba, pmb, |
| 6479 | MBX_NOWAIT); |
| 6480 | if (rc == MBX_NOT_FINISHED) { |
| 6481 | lpfc_printf_vlog(vport, |
| 6482 | KERN_ERR, LOG_MBOX, |
| 6483 | "2732 Failed to issue INIT_VPI" |
| 6484 | " mailbox command\n"); |
| 6485 | } else { |
| 6486 | lpfc_nlp_put(ndlp); |
| 6487 | return; |
| 6488 | } |
| 6489 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6490 | default: |
| 6491 | /* Try to recover from this error */ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 6492 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6493 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6494 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6495 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6496 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6497 | spin_unlock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6498 | if (vport->port_type == LPFC_PHYSICAL_PORT |
| 6499 | && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6500 | lpfc_initial_flogi(vport); |
| 6501 | else |
| 6502 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6503 | break; |
| 6504 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6505 | } else { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6506 | spin_lock_irq(shost->host_lock); |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 6507 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6508 | spin_unlock_irq(shost->host_lock); |
| 6509 | if (vport == phba->pport) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6510 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 6511 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6512 | else { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6513 | /* |
| 6514 | * If the physical port is instantiated using |
| 6515 | * FDISC, do not start vport discovery. |
| 6516 | */ |
| 6517 | if (vport->port_state != LPFC_FDISC) |
| 6518 | lpfc_start_fdiscs(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6519 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6520 | } |
| 6521 | } else |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6522 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6523 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6524 | mbox_err_exit: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6525 | /* Now, we decrement the ndlp reference count held for this |
| 6526 | * callback function |
| 6527 | */ |
| 6528 | lpfc_nlp_put(ndlp); |
| 6529 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6530 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6531 | return; |
| 6532 | } |
| 6533 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6534 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6535 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6536 | * @phba: pointer to lpfc hba data structure. |
| 6537 | * @vport: pointer to a host virtual N_Port data structure. |
| 6538 | * @ndlp: pointer to a node-list data structure. |
| 6539 | * |
| 6540 | * This routine registers the @vport as a new virtual port with a HBA. |
| 6541 | * It is done through a registering vpi mailbox command. |
| 6542 | **/ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6543 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6544 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 6545 | struct lpfc_nodelist *ndlp) |
| 6546 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6547 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6548 | LPFC_MBOXQ_t *mbox; |
| 6549 | |
| 6550 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6551 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6552 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6553 | mbox->vport = vport; |
| 6554 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 6555 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 6556 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6557 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6558 | /* mailbox command not success, decrement ndlp |
| 6559 | * reference count for this command |
| 6560 | */ |
| 6561 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6562 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6563 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6564 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6565 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6566 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6567 | } |
| 6568 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6569 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6570 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6571 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6572 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6573 | return; |
| 6574 | |
| 6575 | mbox_err_exit: |
| 6576 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6577 | spin_lock_irq(shost->host_lock); |
| 6578 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 6579 | spin_unlock_irq(shost->host_lock); |
| 6580 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6581 | } |
| 6582 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6583 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6584 | * 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] | 6585 | * @phba: pointer to lpfc hba data structure. |
| 6586 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6587 | * This routine cancels the retry delay timers to all the vports. |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6588 | **/ |
| 6589 | void |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6590 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6591 | { |
| 6592 | struct lpfc_vport **vports; |
| 6593 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6594 | uint32_t link_state; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6595 | int i; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6596 | |
| 6597 | /* Treat this failure as linkdown for all vports */ |
| 6598 | link_state = phba->link_state; |
| 6599 | lpfc_linkdown(phba); |
| 6600 | phba->link_state = link_state; |
| 6601 | |
| 6602 | vports = lpfc_create_vport_work_array(phba); |
| 6603 | |
| 6604 | if (vports) { |
| 6605 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 6606 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 6607 | if (ndlp) |
| 6608 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
| 6609 | lpfc_els_flush_cmd(vports[i]); |
| 6610 | } |
| 6611 | lpfc_destroy_vport_work_array(phba, vports); |
| 6612 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6613 | } |
| 6614 | |
| 6615 | /** |
| 6616 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. |
| 6617 | * @phba: pointer to lpfc hba data structure. |
| 6618 | * |
| 6619 | * This routine abort all pending discovery commands and |
| 6620 | * start a timer to retry FLOGI for the physical port |
| 6621 | * discovery. |
| 6622 | **/ |
| 6623 | void |
| 6624 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) |
| 6625 | { |
| 6626 | struct lpfc_nodelist *ndlp; |
| 6627 | struct Scsi_Host *shost; |
| 6628 | |
| 6629 | /* Cancel the all vports retry delay retry timers */ |
| 6630 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6631 | |
| 6632 | /* If fabric require FLOGI, then re-instantiate physical login */ |
| 6633 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 6634 | if (!ndlp) |
| 6635 | return; |
| 6636 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6637 | shost = lpfc_shost_from_vport(phba->pport); |
| 6638 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); |
| 6639 | spin_lock_irq(shost->host_lock); |
| 6640 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 6641 | spin_unlock_irq(shost->host_lock); |
| 6642 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; |
| 6643 | phba->pport->port_state = LPFC_FLOGI; |
| 6644 | return; |
| 6645 | } |
| 6646 | |
| 6647 | /** |
| 6648 | * lpfc_fabric_login_reqd - Check if FLOGI required. |
| 6649 | * @phba: pointer to lpfc hba data structure. |
| 6650 | * @cmdiocb: pointer to FDISC command iocb. |
| 6651 | * @rspiocb: pointer to FDISC response iocb. |
| 6652 | * |
| 6653 | * This routine checks if a FLOGI is reguired for FDISC |
| 6654 | * to succeed. |
| 6655 | **/ |
| 6656 | static int |
| 6657 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, |
| 6658 | struct lpfc_iocbq *cmdiocb, |
| 6659 | struct lpfc_iocbq *rspiocb) |
| 6660 | { |
| 6661 | |
| 6662 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || |
| 6663 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) |
| 6664 | return 0; |
| 6665 | else |
| 6666 | return 1; |
| 6667 | } |
| 6668 | |
| 6669 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6670 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6671 | * @phba: pointer to lpfc hba data structure. |
| 6672 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6673 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6674 | * |
| 6675 | * This routine is the completion callback function to a Fabric Discover |
| 6676 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 6677 | * single threaded, each FDISC completion callback function will reset |
| 6678 | * the discovery timer for all vports such that the timers will not get |
| 6679 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 6680 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 6681 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 6682 | * assigned to the vport has been changed with the completion of the FDISC |
| 6683 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 6684 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 6685 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 6686 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 6687 | * Server for State Change Request (SCR). |
| 6688 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6689 | static void |
| 6690 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6691 | struct lpfc_iocbq *rspiocb) |
| 6692 | { |
| 6693 | struct lpfc_vport *vport = cmdiocb->vport; |
| 6694 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6695 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 6696 | struct lpfc_nodelist *np; |
| 6697 | struct lpfc_nodelist *next_np; |
| 6698 | IOCB_t *irsp = &rspiocb->iocb; |
| 6699 | struct lpfc_iocbq *piocb; |
| 6700 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6701 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6702 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 6703 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 6704 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6705 | /* Since all FDISCs are being single threaded, we |
| 6706 | * must reset the discovery timer for ALL vports |
| 6707 | * waiting to send FDISC when one completes. |
| 6708 | */ |
| 6709 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 6710 | lpfc_set_disctmo(piocb->vport); |
| 6711 | } |
| 6712 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6713 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6714 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 6715 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 6716 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6717 | if (irsp->ulpStatus) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6718 | |
| 6719 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { |
| 6720 | lpfc_retry_pport_discovery(phba); |
| 6721 | goto out; |
| 6722 | } |
| 6723 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6724 | /* Check for retry */ |
| 6725 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 6726 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6727 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6728 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6729 | "0126 FDISC failed. (%d/%d)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6730 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6731 | goto fdisc_failed; |
| 6732 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6733 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6734 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6735 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6736 | vport->fc_flag |= FC_FABRIC; |
| 6737 | if (vport->phba->fc_topology == TOPOLOGY_LOOP) |
| 6738 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 6739 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6740 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6741 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 6742 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
| 6743 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 6744 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 6745 | /* If our NportID changed, we need to ensure all |
| 6746 | * remaining NPORTs get unreg_login'ed so we can |
| 6747 | * issue unreg_vpi. |
| 6748 | */ |
| 6749 | list_for_each_entry_safe(np, next_np, |
| 6750 | &vport->fc_nodes, nlp_listp) { |
| 6751 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 6752 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 6753 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 6754 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6755 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6756 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6757 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6758 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6759 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 6760 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 6761 | |
| 6762 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6763 | lpfc_sli4_unreg_all_rpis(vport); |
| 6764 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6765 | lpfc_mbx_unreg_vpi(vport); |
| 6766 | spin_lock_irq(shost->host_lock); |
| 6767 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 6768 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6769 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6770 | else |
| 6771 | vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6772 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6773 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 6774 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 6775 | /* |
| 6776 | * Driver needs to re-reg VPI in order for f/w |
| 6777 | * to update the MAC address. |
| 6778 | */ |
| 6779 | lpfc_register_new_vport(phba, vport, ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 6780 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6781 | } |
| 6782 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6783 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
| 6784 | lpfc_issue_init_vpi(vport); |
| 6785 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6786 | lpfc_register_new_vport(phba, vport, ndlp); |
| 6787 | else |
| 6788 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6789 | goto out; |
| 6790 | fdisc_failed: |
| 6791 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6792 | /* Cancel discovery timer */ |
| 6793 | lpfc_can_disctmo(vport); |
| 6794 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6795 | out: |
| 6796 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6797 | } |
| 6798 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6799 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6800 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6801 | * @vport: pointer to a virtual N_Port data structure. |
| 6802 | * @ndlp: pointer to a node-list data structure. |
| 6803 | * @retry: number of retries to the command IOCB. |
| 6804 | * |
| 6805 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 6806 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 6807 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 6808 | * IOCB will be sent off HBA at any given time. |
| 6809 | * |
| 6810 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6811 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6812 | * will be stored into the context1 field of the IOCB for the completion |
| 6813 | * callback function to the FDISC ELS command. |
| 6814 | * |
| 6815 | * Return code |
| 6816 | * 0 - Successfully issued fdisc iocb command |
| 6817 | * 1 - Failed to issue fdisc iocb command |
| 6818 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6819 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6820 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 6821 | uint8_t retry) |
| 6822 | { |
| 6823 | struct lpfc_hba *phba = vport->phba; |
| 6824 | IOCB_t *icmd; |
| 6825 | struct lpfc_iocbq *elsiocb; |
| 6826 | struct serv_parm *sp; |
| 6827 | uint8_t *pcmd; |
| 6828 | uint16_t cmdsize; |
| 6829 | int did = ndlp->nlp_DID; |
| 6830 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6831 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6832 | vport->port_state = LPFC_FDISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6833 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 6834 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 6835 | ELS_CMD_FDISC); |
| 6836 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6837 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6838 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6839 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6840 | return 1; |
| 6841 | } |
| 6842 | |
| 6843 | icmd = &elsiocb->iocb; |
| 6844 | icmd->un.elsreq64.myID = 0; |
| 6845 | icmd->un.elsreq64.fl = 1; |
| 6846 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6847 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 6848 | /* FDISC needs to be 1 for WQE VPI */ |
| 6849 | elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1; |
| 6850 | elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ; |
| 6851 | /* Set the ulpContext to the vpi */ |
| 6852 | elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base; |
| 6853 | } else { |
| 6854 | /* For FDISC, Let FDISC rsp set the NPortID for this VPI */ |
| 6855 | icmd->ulpCt_h = 1; |
| 6856 | icmd->ulpCt_l = 0; |
| 6857 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6858 | |
| 6859 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6860 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 6861 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 6862 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 6863 | sp = (struct serv_parm *) pcmd; |
| 6864 | /* Setup CSPs accordingly for Fabric */ |
| 6865 | sp->cmn.e_d_tov = 0; |
| 6866 | sp->cmn.w2.r_a_tov = 0; |
| 6867 | sp->cls1.classValid = 0; |
| 6868 | sp->cls2.seqDelivery = 1; |
| 6869 | sp->cls3.seqDelivery = 1; |
| 6870 | |
| 6871 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 6872 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 6873 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 6874 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 6875 | memcpy(pcmd, &vport->fc_portname, 8); |
| 6876 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6877 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6878 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 6879 | |
| 6880 | lpfc_set_disctmo(vport); |
| 6881 | |
| 6882 | phba->fc_stat.elsXmitFDISC++; |
| 6883 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 6884 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6885 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6886 | "Issue FDISC: did:x%x", |
| 6887 | did, 0, 0); |
| 6888 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6889 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 6890 | if (rc == IOCB_ERROR) { |
| 6891 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6892 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6893 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6894 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6895 | return 1; |
| 6896 | } |
| 6897 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6898 | return 0; |
| 6899 | } |
| 6900 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6901 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6902 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6903 | * @phba: pointer to lpfc hba data structure. |
| 6904 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6905 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6906 | * |
| 6907 | * This routine is the completion callback function to the issuing of a LOGO |
| 6908 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 6909 | * reference count held on ndlp for this completion function, indicating that |
| 6910 | * the reference to the ndlp is no long needed. Note that the |
| 6911 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 6912 | * callback function and an additional explicit ndlp reference decrementation |
| 6913 | * will trigger the actual release of the ndlp. |
| 6914 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6915 | static void |
| 6916 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6917 | struct lpfc_iocbq *rspiocb) |
| 6918 | { |
| 6919 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6920 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6921 | struct lpfc_nodelist *ndlp; |
| 6922 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6923 | |
| 6924 | irsp = &rspiocb->iocb; |
| 6925 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6926 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 6927 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6928 | |
| 6929 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6930 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6931 | |
| 6932 | /* Trigger the release of the ndlp after logo */ |
| 6933 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6934 | } |
| 6935 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6936 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6937 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6938 | * @vport: pointer to a virtual N_Port data structure. |
| 6939 | * @ndlp: pointer to a node-list data structure. |
| 6940 | * |
| 6941 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 6942 | * |
| 6943 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6944 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6945 | * will be stored into the context1 field of the IOCB for the completion |
| 6946 | * callback function to the LOGO ELS command. |
| 6947 | * |
| 6948 | * Return codes |
| 6949 | * 0 - Successfully issued logo off the @vport |
| 6950 | * 1 - Failed to issue logo off the @vport |
| 6951 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6952 | int |
| 6953 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 6954 | { |
| 6955 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6956 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6957 | IOCB_t *icmd; |
| 6958 | struct lpfc_iocbq *elsiocb; |
| 6959 | uint8_t *pcmd; |
| 6960 | uint16_t cmdsize; |
| 6961 | |
| 6962 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 6963 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 6964 | ELS_CMD_LOGO); |
| 6965 | if (!elsiocb) |
| 6966 | return 1; |
| 6967 | |
| 6968 | icmd = &elsiocb->iocb; |
| 6969 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6970 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 6971 | pcmd += sizeof(uint32_t); |
| 6972 | |
| 6973 | /* Fill in LOGO payload */ |
| 6974 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 6975 | pcmd += sizeof(uint32_t); |
| 6976 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 6977 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6978 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6979 | "Issue LOGO npiv did:x%x flg:x%x", |
| 6980 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 6981 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6982 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 6983 | spin_lock_irq(shost->host_lock); |
| 6984 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 6985 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6986 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 6987 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6988 | spin_lock_irq(shost->host_lock); |
| 6989 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 6990 | spin_unlock_irq(shost->host_lock); |
| 6991 | lpfc_els_free_iocb(phba, elsiocb); |
| 6992 | return 1; |
| 6993 | } |
| 6994 | return 0; |
| 6995 | } |
| 6996 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6997 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6998 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6999 | * @ptr: holder for the timer function associated data. |
| 7000 | * |
| 7001 | * This routine is invoked by the fabric iocb block timer after |
| 7002 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 7003 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 7004 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 7005 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 7006 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 7007 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7008 | void |
| 7009 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 7010 | { |
| 7011 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 7012 | unsigned long iflags; |
| 7013 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7014 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7015 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 7016 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 7017 | if (!tmo_posted) |
| 7018 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 7019 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 7020 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7021 | if (!tmo_posted) |
| 7022 | lpfc_worker_wake_up(phba); |
| 7023 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7024 | } |
| 7025 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7026 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7027 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7028 | * @phba: pointer to lpfc hba data structure. |
| 7029 | * |
| 7030 | * This routine issues one fabric iocb from the driver internal list to |
| 7031 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 7032 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 7033 | * remove one pending fabric iocb from the driver internal list and invokes |
| 7034 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 7035 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7036 | static void |
| 7037 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 7038 | { |
| 7039 | struct lpfc_iocbq *iocb; |
| 7040 | unsigned long iflags; |
| 7041 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7042 | IOCB_t *cmd; |
| 7043 | |
| 7044 | repeat: |
| 7045 | iocb = NULL; |
| 7046 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7047 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7048 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 7049 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 7050 | list); |
| 7051 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7052 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7053 | atomic_inc(&phba->fabric_iocb_count); |
| 7054 | } |
| 7055 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7056 | if (iocb) { |
| 7057 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 7058 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 7059 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 7060 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7061 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 7062 | "Fabric sched1: ste:x%x", |
| 7063 | iocb->vport->port_state, 0, 0); |
| 7064 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7065 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7066 | |
| 7067 | if (ret == IOCB_ERROR) { |
| 7068 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 7069 | iocb->fabric_iocb_cmpl = NULL; |
| 7070 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 7071 | cmd = &iocb->iocb; |
| 7072 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 7073 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 7074 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 7075 | |
| 7076 | atomic_dec(&phba->fabric_iocb_count); |
| 7077 | goto repeat; |
| 7078 | } |
| 7079 | } |
| 7080 | |
| 7081 | return; |
| 7082 | } |
| 7083 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7084 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7085 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7086 | * @phba: pointer to lpfc hba data structure. |
| 7087 | * |
| 7088 | * This routine unblocks the issuing fabric iocb command. The function |
| 7089 | * will clear the fabric iocb block bit and then invoke the routine |
| 7090 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 7091 | * from the driver internal fabric iocb list. |
| 7092 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7093 | void |
| 7094 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 7095 | { |
| 7096 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 7097 | |
| 7098 | lpfc_resume_fabric_iocbs(phba); |
| 7099 | return; |
| 7100 | } |
| 7101 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7102 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7103 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7104 | * @phba: pointer to lpfc hba data structure. |
| 7105 | * |
| 7106 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 7107 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 7108 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 7109 | * fabric iocb will be issued out of the HBA. |
| 7110 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7111 | static void |
| 7112 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 7113 | { |
| 7114 | int blocked; |
| 7115 | |
| 7116 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7117 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7118 | if (!blocked) |
| 7119 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); |
| 7120 | |
| 7121 | return; |
| 7122 | } |
| 7123 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7124 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7125 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7126 | * @phba: pointer to lpfc hba data structure. |
| 7127 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7128 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 7129 | * |
| 7130 | * This routine is the callback function that is put to the fabric iocb's |
| 7131 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 7132 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 7133 | * function first restores and invokes the original iocb's callback function |
| 7134 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 7135 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 7136 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7137 | static void |
| 7138 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 7139 | struct lpfc_iocbq *rspiocb) |
| 7140 | { |
| 7141 | struct ls_rjt stat; |
| 7142 | |
| 7143 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 7144 | BUG(); |
| 7145 | |
| 7146 | switch (rspiocb->iocb.ulpStatus) { |
| 7147 | case IOSTAT_NPORT_RJT: |
| 7148 | case IOSTAT_FABRIC_RJT: |
| 7149 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 7150 | lpfc_block_fabric_iocbs(phba); |
| 7151 | } |
| 7152 | break; |
| 7153 | |
| 7154 | case IOSTAT_NPORT_BSY: |
| 7155 | case IOSTAT_FABRIC_BSY: |
| 7156 | lpfc_block_fabric_iocbs(phba); |
| 7157 | break; |
| 7158 | |
| 7159 | case IOSTAT_LS_RJT: |
| 7160 | stat.un.lsRjtError = |
| 7161 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 7162 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 7163 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 7164 | lpfc_block_fabric_iocbs(phba); |
| 7165 | break; |
| 7166 | } |
| 7167 | |
| 7168 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 7169 | BUG(); |
| 7170 | |
| 7171 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 7172 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 7173 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 7174 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 7175 | |
| 7176 | atomic_dec(&phba->fabric_iocb_count); |
| 7177 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7178 | /* Post any pending iocbs to HBA */ |
| 7179 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7180 | } |
| 7181 | } |
| 7182 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7183 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7184 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7185 | * @phba: pointer to lpfc hba data structure. |
| 7186 | * @iocb: pointer to lpfc command iocb data structure. |
| 7187 | * |
| 7188 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 7189 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 7190 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 7191 | * any given time. As such, this function will first check to see whether there |
| 7192 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 7193 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 7194 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 7195 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 7196 | * |
| 7197 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 7198 | * order. The problem is caused by the construction of the "ready" boolen does |
| 7199 | * not include the condition that the internal fabric IOCB list is empty. As |
| 7200 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 7201 | * ahead of the fabric IOCBs in the internal list. |
| 7202 | * |
| 7203 | * Return code |
| 7204 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 7205 | * IOCB_ERROR - failed to issue fabric iocb |
| 7206 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 7207 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7208 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 7209 | { |
| 7210 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7211 | int ready; |
| 7212 | int ret; |
| 7213 | |
| 7214 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 7215 | BUG(); |
| 7216 | |
| 7217 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7218 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 7219 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 7220 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7221 | if (ready) |
| 7222 | /* Increment fabric iocb count to hold the position */ |
| 7223 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7224 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7225 | if (ready) { |
| 7226 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 7227 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 7228 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 7229 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7230 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 7231 | "Fabric sched2: ste:x%x", |
| 7232 | iocb->vport->port_state, 0, 0); |
| 7233 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7234 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7235 | |
| 7236 | if (ret == IOCB_ERROR) { |
| 7237 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 7238 | iocb->fabric_iocb_cmpl = NULL; |
| 7239 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 7240 | atomic_dec(&phba->fabric_iocb_count); |
| 7241 | } |
| 7242 | } else { |
| 7243 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7244 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 7245 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7246 | ret = IOCB_SUCCESS; |
| 7247 | } |
| 7248 | return ret; |
| 7249 | } |
| 7250 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7251 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7252 | * 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] | 7253 | * @vport: pointer to a virtual N_Port data structure. |
| 7254 | * |
| 7255 | * This routine aborts all the IOCBs associated with a @vport from the |
| 7256 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 7257 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 7258 | * list, removes each IOCB associated with the @vport off the list, set the |
| 7259 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 7260 | * associated with the IOCB. |
| 7261 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 7262 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7263 | { |
| 7264 | LIST_HEAD(completions); |
| 7265 | struct lpfc_hba *phba = vport->phba; |
| 7266 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7267 | |
| 7268 | spin_lock_irq(&phba->hbalock); |
| 7269 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 7270 | list) { |
| 7271 | |
| 7272 | if (piocb->vport != vport) |
| 7273 | continue; |
| 7274 | |
| 7275 | list_move_tail(&piocb->list, &completions); |
| 7276 | } |
| 7277 | spin_unlock_irq(&phba->hbalock); |
| 7278 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7279 | /* Cancel all the IOCBs from the completions list */ |
| 7280 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 7281 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7282 | } |
| 7283 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7284 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7285 | * 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] | 7286 | * @ndlp: pointer to a node-list data structure. |
| 7287 | * |
| 7288 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 7289 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 7290 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 7291 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 7292 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 7293 | * associated with the IOCB. |
| 7294 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7295 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 7296 | { |
| 7297 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7298 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7299 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 7300 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7301 | |
| 7302 | spin_lock_irq(&phba->hbalock); |
| 7303 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 7304 | list) { |
| 7305 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 7306 | |
| 7307 | list_move_tail(&piocb->list, &completions); |
| 7308 | } |
| 7309 | } |
| 7310 | spin_unlock_irq(&phba->hbalock); |
| 7311 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7312 | /* Cancel all the IOCBs from the completions list */ |
| 7313 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 7314 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7315 | } |
| 7316 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7317 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7318 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7319 | * @phba: pointer to lpfc hba data structure. |
| 7320 | * |
| 7321 | * This routine aborts all the IOCBs currently on the driver internal |
| 7322 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 7323 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 7324 | * list, removes IOCBs off the list, set the status feild to |
| 7325 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 7326 | * the IOCB. |
| 7327 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7328 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 7329 | { |
| 7330 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7331 | |
| 7332 | spin_lock_irq(&phba->hbalock); |
| 7333 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 7334 | spin_unlock_irq(&phba->hbalock); |
| 7335 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7336 | /* Cancel all the IOCBs from the completions list */ |
| 7337 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 7338 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7339 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7340 | |
| 7341 | /** |
| 7342 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 7343 | * @phba: pointer to lpfc hba data structure. |
| 7344 | * @axri: pointer to the els xri abort wcqe structure. |
| 7345 | * |
| 7346 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 7347 | * ELS aborted xri. |
| 7348 | **/ |
| 7349 | void |
| 7350 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 7351 | struct sli4_wcqe_xri_aborted *axri) |
| 7352 | { |
| 7353 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
| 7354 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 7355 | unsigned long iflag = 0; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 7356 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7357 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7358 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7359 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7360 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 7361 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 7362 | if (sglq_entry->sli4_xritag == xri) { |
| 7363 | list_del(&sglq_entry->list); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7364 | list_add_tail(&sglq_entry->list, |
| 7365 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7366 | sglq_entry->state = SGL_FREED; |
| 7367 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7368 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 7369 | |
| 7370 | /* Check if TXQ queue needs to be serviced */ |
| 7371 | if (pring->txq_cnt) |
| 7372 | lpfc_worker_wake_up(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7373 | return; |
| 7374 | } |
| 7375 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7376 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 7377 | sglq_entry = __lpfc_get_active_sglq(phba, xri); |
| 7378 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { |
| 7379 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7380 | return; |
| 7381 | } |
| 7382 | sglq_entry->state = SGL_XRI_ABORTED; |
| 7383 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7384 | return; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7385 | } |