| 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 | d4379ac | 2012-03-01 22:37:07 -0500 | [diff] [blame] | 4 | * Copyright (C) 2004-2012 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 */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 92 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 93 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 94 | |
| 95 | if (!(ha_copy & HA_LATT)) |
| 96 | return 0; |
| 97 | |
| 98 | /* Pending Link Event during Discovery */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 99 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 100 | "0237 Pending Link Event during " |
| 101 | "Discovery: State x%x\n", |
| 102 | phba->pport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 103 | |
| 104 | /* CLEAR_LA should re-enable link attention events and |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 105 | * we should then immediately take a LATT event. The |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 106 | * LATT processing should call lpfc_linkdown() which |
| 107 | * will cleanup any left over in-progress discovery |
| 108 | * events. |
| 109 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 110 | spin_lock_irq(shost->host_lock); |
| 111 | vport->fc_flag |= FC_ABORT_DISCOVERY; |
| 112 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 113 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 114 | if (phba->link_state != LPFC_CLEAR_LA) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 115 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 116 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 117 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 118 | } |
| 119 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 120 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 121 | * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 122 | * @vport: pointer to a host virtual N_Port data structure. |
| 123 | * @expectRsp: flag indicating whether response is expected. |
| 124 | * @cmdSize: size of the ELS command. |
| 125 | * @retry: number of retries to the command IOCB when it fails. |
| 126 | * @ndlp: pointer to a node-list data structure. |
| 127 | * @did: destination identifier. |
| 128 | * @elscmd: the ELS command code. |
| 129 | * |
| 130 | * This routine is used for allocating a lpfc-IOCB data structure from |
| 131 | * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters |
| 132 | * passed into the routine for discovery state machine to issue an Extended |
| 133 | * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation |
| 134 | * and preparation routine that is used by all the discovery state machine |
| 135 | * routines and the ELS command-specific fields will be later set up by |
| 136 | * the individual discovery machine routines after calling this routine |
| 137 | * allocating and preparing a generic IOCB data structure. It fills in the |
| 138 | * Buffer Descriptor Entries (BDEs), allocates buffers for both command |
| 139 | * payload and response payload (if expected). The reference count on the |
| 140 | * ndlp is incremented by 1 and the reference to the ndlp is put into |
| 141 | * context1 of the IOCB data structure for this IOCB to hold the ndlp |
| 142 | * reference for the command's callback function to access later. |
| 143 | * |
| 144 | * Return code |
| 145 | * Pointer to the newly allocated/prepared els iocb data structure |
| 146 | * NULL - when els iocb data structure allocation/preparation failed |
| 147 | **/ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 148 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 149 | lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, |
| 150 | uint16_t cmdSize, uint8_t retry, |
| 151 | struct lpfc_nodelist *ndlp, uint32_t did, |
| 152 | uint32_t elscmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 153 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 154 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 155 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 156 | struct lpfc_dmabuf *pcmd, *prsp, *pbuflist; |
| 157 | struct ulp_bde64 *bpl; |
| 158 | IOCB_t *icmd; |
| 159 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 160 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 161 | if (!lpfc_is_link_up(phba)) |
| 162 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 163 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 164 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 165 | elsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 166 | |
| 167 | if (elsiocb == NULL) |
| 168 | return NULL; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 169 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 170 | /* |
| 171 | * If this command is for fabric controller and HBA running |
| 172 | * in FIP mode send FLOGI, FDISC and LOGO as FIP frames. |
| 173 | */ |
| 174 | if ((did == Fabric_DID) && |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 175 | (phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 176 | ((elscmd == ELS_CMD_FLOGI) || |
| 177 | (elscmd == ELS_CMD_FDISC) || |
| 178 | (elscmd == ELS_CMD_LOGO))) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 179 | switch (elscmd) { |
| 180 | case ELS_CMD_FLOGI: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 181 | elsiocb->iocb_flag |= |
| 182 | ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 183 | & LPFC_FIP_ELS_ID_MASK); |
| 184 | break; |
| 185 | case ELS_CMD_FDISC: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 186 | elsiocb->iocb_flag |= |
| 187 | ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 188 | & LPFC_FIP_ELS_ID_MASK); |
| 189 | break; |
| 190 | case ELS_CMD_LOGO: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 191 | elsiocb->iocb_flag |= |
| 192 | ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 193 | & LPFC_FIP_ELS_ID_MASK); |
| 194 | break; |
| 195 | } |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 196 | else |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 197 | elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 198 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 199 | icmd = &elsiocb->iocb; |
| 200 | |
| 201 | /* fill in BDEs for command */ |
| 202 | /* Allocate buffer for command payload */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 203 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 204 | if (pcmd) |
| 205 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 206 | if (!pcmd || !pcmd->virt) |
| 207 | goto els_iocb_free_pcmb_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 208 | |
| 209 | INIT_LIST_HEAD(&pcmd->list); |
| 210 | |
| 211 | /* Allocate buffer for response payload */ |
| 212 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 213 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 214 | if (prsp) |
| 215 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 216 | &prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 217 | if (!prsp || !prsp->virt) |
| 218 | goto els_iocb_free_prsp_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 219 | INIT_LIST_HEAD(&prsp->list); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 220 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 221 | prsp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 222 | |
| 223 | /* Allocate buffer for Buffer ptr list */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 224 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 225 | if (pbuflist) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 226 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 227 | &pbuflist->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 228 | if (!pbuflist || !pbuflist->virt) |
| 229 | goto els_iocb_free_pbuf_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 230 | |
| 231 | INIT_LIST_HEAD(&pbuflist->list); |
| 232 | |
| 233 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 234 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 235 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 236 | icmd->un.elsreq64.remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 237 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 238 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 239 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 240 | icmd->ulpTimeout = phba->fc_ratov * 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 241 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 242 | icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 243 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; |
| 244 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 245 | icmd->ulpBdeCount = 1; |
| 246 | icmd->ulpLe = 1; |
| 247 | icmd->ulpClass = CLASS3; |
| 248 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 249 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 250 | icmd->un.elsreq64.myID = vport->fc_myDID; |
| 251 | |
| 252 | /* For ELS_REQUEST64_CR, use the VPI by default */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 253 | icmd->ulpContext = phba->vpi_ids[vport->vpi]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 254 | icmd->ulpCt_h = 0; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 255 | /* The CT field must be 0=INVALID_RPI for the ECHO cmd */ |
| 256 | if (elscmd == ELS_CMD_ECHO) |
| 257 | icmd->ulpCt_l = 0; /* context = invalid RPI */ |
| 258 | else |
| 259 | icmd->ulpCt_l = 1; /* context = VPI */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 260 | } |
| 261 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 262 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
| 263 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); |
| 264 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); |
| 265 | bpl->tus.f.bdeSize = cmdSize; |
| 266 | bpl->tus.f.bdeFlags = 0; |
| 267 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 268 | |
| 269 | if (expectRsp) { |
| 270 | bpl++; |
| 271 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); |
| 272 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); |
| 273 | bpl->tus.f.bdeSize = FCELSSIZE; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 274 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 275 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 276 | } |
| 277 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 278 | /* prevent preparing iocb with NULL ndlp reference */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 279 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 280 | if (!elsiocb->context1) |
| 281 | goto els_iocb_free_pbuf_exit; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 282 | elsiocb->context2 = pcmd; |
| 283 | elsiocb->context3 = pbuflist; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 284 | elsiocb->retry = retry; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 285 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 286 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
| 287 | |
| 288 | if (prsp) { |
| 289 | list_add(&prsp->list, &pcmd->list); |
| 290 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 291 | if (expectRsp) { |
| 292 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 293 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 294 | "0116 Xmit ELS command x%x to remote " |
| 295 | "NPORT x%x I/O tag: x%x, port state: x%x\n", |
| 296 | elscmd, did, elsiocb->iotag, |
| 297 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 298 | } else { |
| 299 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 300 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 301 | "0117 Xmit ELS response x%x to remote " |
| 302 | "NPORT x%x I/O tag: x%x, size: x%x\n", |
| 303 | elscmd, ndlp->nlp_DID, elsiocb->iotag, |
| 304 | cmdSize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 305 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 306 | return elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 307 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 308 | els_iocb_free_pbuf_exit: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 309 | if (expectRsp) |
| 310 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 311 | kfree(pbuflist); |
| 312 | |
| 313 | els_iocb_free_prsp_exit: |
| 314 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 315 | kfree(prsp); |
| 316 | |
| 317 | els_iocb_free_pcmb_exit: |
| 318 | kfree(pcmd); |
| 319 | lpfc_sli_release_iocbq(phba, elsiocb); |
| 320 | return NULL; |
| 321 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 322 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 323 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 324 | * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 325 | * @vport: pointer to a host virtual N_Port data structure. |
| 326 | * |
| 327 | * This routine issues a fabric registration login for a @vport. An |
| 328 | * active ndlp node with Fabric_DID must already exist for this @vport. |
| 329 | * The routine invokes two mailbox commands to carry out fabric registration |
| 330 | * login through the HBA firmware: the first mailbox command requests the |
| 331 | * HBA to perform link configuration for the @vport; and the second mailbox |
| 332 | * command requests the HBA to perform the actual fabric registration login |
| 333 | * with the @vport. |
| 334 | * |
| 335 | * Return code |
| 336 | * 0 - successfully issued fabric registration login for @vport |
| 337 | * -ENXIO -- failed to issue fabric registration login for @vport |
| 338 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 339 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 340 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
| 341 | { |
| 342 | struct lpfc_hba *phba = vport->phba; |
| 343 | LPFC_MBOXQ_t *mbox; |
| 344 | struct lpfc_dmabuf *mp; |
| 345 | struct lpfc_nodelist *ndlp; |
| 346 | struct serv_parm *sp; |
| 347 | int rc; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 348 | int err = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 349 | |
| 350 | sp = &phba->fc_fabparam; |
| 351 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 352 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 353 | err = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 354 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 355 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 356 | |
| 357 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 358 | if (!mbox) { |
| 359 | err = 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 360 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 361 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 362 | |
| 363 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 364 | lpfc_config_link(phba, mbox); |
| 365 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 366 | mbox->vport = vport; |
| 367 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 368 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 369 | if (rc == MBX_NOT_FINISHED) { |
| 370 | err = 3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 371 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 372 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 373 | |
| 374 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 375 | if (!mbox) { |
| 376 | err = 4; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 377 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 378 | } |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 379 | rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, |
| 380 | ndlp->nlp_rpi); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 381 | if (rc) { |
| 382 | err = 5; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 383 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 384 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 385 | |
| 386 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; |
| 387 | mbox->vport = vport; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 388 | /* increment the reference count on ndlp to hold reference |
| 389 | * for the callback routine. |
| 390 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 391 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 392 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 393 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 394 | if (rc == MBX_NOT_FINISHED) { |
| 395 | err = 6; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 396 | goto fail_issue_reg_login; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 397 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 398 | |
| 399 | return 0; |
| 400 | |
| 401 | fail_issue_reg_login: |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 402 | /* decrement the reference count on ndlp just incremented |
| 403 | * for the failed mbox command. |
| 404 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 405 | lpfc_nlp_put(ndlp); |
| 406 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 407 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 408 | kfree(mp); |
| 409 | fail_free_mbox: |
| 410 | mempool_free(mbox, phba->mbox_mem_pool); |
| 411 | |
| 412 | fail: |
| 413 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 414 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 415 | "0249 Cannot issue Register Fabric login: Err %d\n", err); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 416 | return -ENXIO; |
| 417 | } |
| 418 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 419 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 420 | * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login |
| 421 | * @vport: pointer to a host virtual N_Port data structure. |
| 422 | * |
| 423 | * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 424 | * the @vport. This mailbox command is necessary for SLI4 port only. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 425 | * |
| 426 | * Return code |
| 427 | * 0 - successfully issued REG_VFI for @vport |
| 428 | * A failure code otherwise. |
| 429 | **/ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 430 | int |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 431 | lpfc_issue_reg_vfi(struct lpfc_vport *vport) |
| 432 | { |
| 433 | struct lpfc_hba *phba = vport->phba; |
| 434 | LPFC_MBOXQ_t *mboxq; |
| 435 | struct lpfc_nodelist *ndlp; |
| 436 | struct serv_parm *sp; |
| 437 | struct lpfc_dmabuf *dmabuf; |
| 438 | int rc = 0; |
| 439 | |
| 440 | sp = &phba->fc_fabparam; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 441 | /* move forward in case of SLI4 FC port loopback test */ |
| 442 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 443 | !(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 444 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 445 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
| 446 | rc = -ENODEV; |
| 447 | goto fail; |
| 448 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 452 | if (!dmabuf) { |
| 453 | rc = -ENOMEM; |
| 454 | goto fail; |
| 455 | } |
| 456 | dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys); |
| 457 | if (!dmabuf->virt) { |
| 458 | rc = -ENOMEM; |
| 459 | goto fail_free_dmabuf; |
| 460 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 461 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 462 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 463 | if (!mboxq) { |
| 464 | rc = -ENOMEM; |
| 465 | goto fail_free_coherent; |
| 466 | } |
| 467 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 468 | memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam)); |
| 469 | lpfc_reg_vfi(mboxq, vport, dmabuf->phys); |
| 470 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi; |
| 471 | mboxq->vport = vport; |
| 472 | mboxq->context1 = dmabuf; |
| 473 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 474 | if (rc == MBX_NOT_FINISHED) { |
| 475 | rc = -ENXIO; |
| 476 | goto fail_free_mbox; |
| 477 | } |
| 478 | return 0; |
| 479 | |
| 480 | fail_free_mbox: |
| 481 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 482 | fail_free_coherent: |
| 483 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 484 | fail_free_dmabuf: |
| 485 | kfree(dmabuf); |
| 486 | fail: |
| 487 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 488 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 489 | "0289 Issue Register VFI failed: Err %d\n", rc); |
| 490 | return rc; |
| 491 | } |
| 492 | |
| 493 | /** |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 494 | * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login |
| 495 | * @vport: pointer to a host virtual N_Port data structure. |
| 496 | * |
| 497 | * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for |
| 498 | * the @vport. This mailbox command is necessary for SLI4 port only. |
| 499 | * |
| 500 | * Return code |
| 501 | * 0 - successfully issued REG_VFI for @vport |
| 502 | * A failure code otherwise. |
| 503 | **/ |
| 504 | int |
| 505 | lpfc_issue_unreg_vfi(struct lpfc_vport *vport) |
| 506 | { |
| 507 | struct lpfc_hba *phba = vport->phba; |
| 508 | struct Scsi_Host *shost; |
| 509 | LPFC_MBOXQ_t *mboxq; |
| 510 | int rc; |
| 511 | |
| 512 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 513 | if (!mboxq) { |
| 514 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 515 | "2556 UNREG_VFI mbox allocation failed" |
| 516 | "HBA state x%x\n", phba->pport->port_state); |
| 517 | return -ENOMEM; |
| 518 | } |
| 519 | |
| 520 | lpfc_unreg_vfi(mboxq, vport); |
| 521 | mboxq->vport = vport; |
| 522 | mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl; |
| 523 | |
| 524 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 525 | if (rc == MBX_NOT_FINISHED) { |
| 526 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
| 527 | "2557 UNREG_VFI issue mbox failed rc x%x " |
| 528 | "HBA state x%x\n", |
| 529 | rc, phba->pport->port_state); |
| 530 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 531 | return -EIO; |
| 532 | } |
| 533 | |
| 534 | shost = lpfc_shost_from_vport(vport); |
| 535 | spin_lock_irq(shost->host_lock); |
| 536 | vport->fc_flag &= ~FC_VFI_REGISTERED; |
| 537 | spin_unlock_irq(shost->host_lock); |
| 538 | return 0; |
| 539 | } |
| 540 | |
| 541 | /** |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 542 | * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean. |
| 543 | * @vport: pointer to a host virtual N_Port data structure. |
| 544 | * @sp: pointer to service parameter data structure. |
| 545 | * |
| 546 | * This routine is called from FLOGI/FDISC completion handler functions. |
| 547 | * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric |
| 548 | * node nodename is changed in the completion service parameter else return |
| 549 | * 0. This function also set flag in the vport data structure to delay |
| 550 | * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit |
| 551 | * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric |
| 552 | * node nodename is changed in the completion service parameter. |
| 553 | * |
| 554 | * Return code |
| 555 | * 0 - FCID and Fabric Nodename and Fabric portname is not changed. |
| 556 | * 1 - FCID or Fabric Nodename or Fabric portname is changed. |
| 557 | * |
| 558 | **/ |
| 559 | static uint8_t |
| 560 | lpfc_check_clean_addr_bit(struct lpfc_vport *vport, |
| 561 | struct serv_parm *sp) |
| 562 | { |
| 563 | uint8_t fabric_param_changed = 0; |
| 564 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 565 | |
| 566 | if ((vport->fc_prevDID != vport->fc_myDID) || |
| 567 | memcmp(&vport->fabric_portname, &sp->portName, |
| 568 | sizeof(struct lpfc_name)) || |
| 569 | memcmp(&vport->fabric_nodename, &sp->nodeName, |
| 570 | sizeof(struct lpfc_name))) |
| 571 | fabric_param_changed = 1; |
| 572 | |
| 573 | /* |
| 574 | * Word 1 Bit 31 in common service parameter is overloaded. |
| 575 | * Word 1 Bit 31 in FLOGI request is multiple NPort request |
| 576 | * Word 1 Bit 31 in FLOGI response is clean address bit |
| 577 | * |
| 578 | * If fabric parameter is changed and clean address bit is |
| 579 | * cleared delay nport discovery if |
| 580 | * - vport->fc_prevDID != 0 (not initial discovery) OR |
| 581 | * - lpfc_delay_discovery module parameter is set. |
| 582 | */ |
| 583 | if (fabric_param_changed && !sp->cmn.clean_address_bit && |
| 584 | (vport->fc_prevDID || lpfc_delay_discovery)) { |
| 585 | spin_lock_irq(shost->host_lock); |
| 586 | vport->fc_flag |= FC_DISC_DELAYED; |
| 587 | spin_unlock_irq(shost->host_lock); |
| 588 | } |
| 589 | |
| 590 | return fabric_param_changed; |
| 591 | } |
| 592 | |
| 593 | |
| 594 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 595 | * 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] | 596 | * @vport: pointer to a host virtual N_Port data structure. |
| 597 | * @ndlp: pointer to a node-list data structure. |
| 598 | * @sp: pointer to service parameter data structure. |
| 599 | * @irsp: pointer to the IOCB within the lpfc response IOCB. |
| 600 | * |
| 601 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 602 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric |
| 603 | * port in a fabric topology. It properly sets up the parameters to the @ndlp |
| 604 | * from the IOCB response. It also check the newly assigned N_Port ID to the |
| 605 | * @vport against the previously assigned N_Port ID. If it is different from |
| 606 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine |
| 607 | * is invoked on all the remaining nodes with the @vport to unregister the |
| 608 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() |
| 609 | * is invoked to register login to the fabric. |
| 610 | * |
| 611 | * Return code |
| 612 | * 0 - Success (currently, always return 0) |
| 613 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 614 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 615 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 616 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 617 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 618 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 619 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 620 | struct lpfc_nodelist *np; |
| 621 | struct lpfc_nodelist *next_np; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 622 | uint8_t fabric_param_changed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 623 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 624 | spin_lock_irq(shost->host_lock); |
| 625 | vport->fc_flag |= FC_FABRIC; |
| 626 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 627 | |
| 628 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 629 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 630 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 631 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 632 | phba->fc_edtovResol = sp->cmn.edtovResolution; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 633 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 634 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 635 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 636 | spin_lock_irq(shost->host_lock); |
| 637 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 638 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 639 | } |
| 640 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 641 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 642 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 643 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 644 | ndlp->nlp_class_sup = 0; |
| 645 | if (sp->cls1.classValid) |
| 646 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 647 | if (sp->cls2.classValid) |
| 648 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 649 | if (sp->cls3.classValid) |
| 650 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 651 | if (sp->cls4.classValid) |
| 652 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 653 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 654 | sp->cmn.bbRcvSizeLsb; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 655 | |
| 656 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); |
| 657 | memcpy(&vport->fabric_portname, &sp->portName, |
| 658 | sizeof(struct lpfc_name)); |
| 659 | memcpy(&vport->fabric_nodename, &sp->nodeName, |
| 660 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 661 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 662 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 663 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 664 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 665 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 666 | LOG_ELS | LOG_VPORT, |
| 667 | "1816 FLOGI NPIV supported, " |
| 668 | "response data 0x%x\n", |
| 669 | sp->cmn.response_multiple_NPort); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 670 | spin_lock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 671 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 672 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 673 | } else { |
| 674 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 675 | to call reg_vnpid atleast for the physcial host */ |
| 676 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 677 | LOG_ELS | LOG_VPORT, |
| 678 | "1817 Fabric does not support NPIV " |
| 679 | "- configuring single port mode.\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 680 | spin_lock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 681 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 682 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 683 | } |
| 684 | } |
| 685 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 686 | if (fabric_param_changed && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 687 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 688 | |
| 689 | /* If our NportID changed, we need to ensure all |
| 690 | * remaining NPORTs get unreg_login'ed. |
| 691 | */ |
| 692 | list_for_each_entry_safe(np, next_np, |
| 693 | &vport->fc_nodes, nlp_listp) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 694 | if (!NLP_CHK_NODE_ACT(np)) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 695 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 696 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 697 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 698 | continue; |
| 699 | spin_lock_irq(shost->host_lock); |
| 700 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 701 | spin_unlock_irq(shost->host_lock); |
| 702 | lpfc_unreg_rpi(vport, np); |
| 703 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 704 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 705 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 706 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 707 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 708 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 709 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 710 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 711 | /* |
| 712 | * If VPI is unreged, driver need to do INIT_VPI |
| 713 | * before re-registering |
| 714 | */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 715 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 716 | spin_unlock_irq(shost->host_lock); |
| 717 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 718 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 719 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 720 | /* |
| 721 | * Driver needs to re-reg VPI in order for f/w |
| 722 | * to update the MAC address. |
| 723 | */ |
James Smart | 9589b06 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 724 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 725 | lpfc_register_new_vport(phba, vport, ndlp); |
| 726 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 727 | } |
| 728 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 729 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 730 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
| 731 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 732 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 733 | lpfc_register_new_vport(phba, vport, ndlp); |
| 734 | else |
| 735 | lpfc_issue_fabric_reglogin(vport); |
| 736 | } else { |
| 737 | ndlp->nlp_type |= NLP_FABRIC; |
| 738 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 739 | if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) && |
| 740 | (vport->vpi_state & LPFC_VPI_REGISTERED)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 741 | lpfc_start_fdiscs(phba); |
| 742 | lpfc_do_scr_ns_plogi(phba, vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 743 | } else if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 744 | lpfc_issue_init_vpi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 745 | else { |
| 746 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 747 | "3135 Need register VFI: (x%x/%x)\n", |
| 748 | vport->fc_prevDID, vport->fc_myDID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 749 | lpfc_issue_reg_vfi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 750 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 751 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 752 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 753 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 754 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 755 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 756 | * 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] | 757 | * @vport: pointer to a host virtual N_Port data structure. |
| 758 | * @ndlp: pointer to a node-list data structure. |
| 759 | * @sp: pointer to service parameter data structure. |
| 760 | * |
| 761 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 762 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 763 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 764 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 765 | * the received N_Port Name lexicographically, this node shall assign local |
| 766 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 767 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 768 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 769 | * N_Port IDs. |
| 770 | * |
| 771 | * Return code |
| 772 | * 0 - Success |
| 773 | * -ENXIO - Fail |
| 774 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 775 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 776 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 777 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 778 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 779 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 780 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 781 | LPFC_MBOXQ_t *mbox; |
| 782 | int rc; |
| 783 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 784 | spin_lock_irq(shost->host_lock); |
| 785 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 786 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 787 | |
| 788 | phba->fc_edtov = FF_DEF_EDTOV; |
| 789 | phba->fc_ratov = FF_DEF_RATOV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 790 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 791 | sizeof(vport->fc_portname)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 792 | if (rc >= 0) { |
| 793 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 794 | spin_lock_irq(shost->host_lock); |
| 795 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 796 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 797 | |
| 798 | /* |
| 799 | * N_Port ID cannot be 0, set our to LocalID the other |
| 800 | * side will be RemoteID. |
| 801 | */ |
| 802 | |
| 803 | /* not equal */ |
| 804 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 805 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 806 | |
| 807 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 808 | if (!mbox) |
| 809 | goto fail; |
| 810 | |
| 811 | lpfc_config_link(phba, mbox); |
| 812 | |
| 813 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 814 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 815 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 816 | if (rc == MBX_NOT_FINISHED) { |
| 817 | mempool_free(mbox, phba->mbox_mem_pool); |
| 818 | goto fail; |
| 819 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 820 | /* Decrement ndlp reference count indicating that ndlp can be |
| 821 | * safely released when other references to it are done. |
| 822 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 823 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 824 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 825 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 826 | if (!ndlp) { |
| 827 | /* |
| 828 | * Cannot find existing Fabric ndlp, so allocate a |
| 829 | * new one |
| 830 | */ |
| 831 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 832 | if (!ndlp) |
| 833 | goto fail; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 834 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 835 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 836 | ndlp = lpfc_enable_node(vport, ndlp, |
| 837 | NLP_STE_UNUSED_NODE); |
| 838 | if(!ndlp) |
| 839 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 843 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 844 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 845 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 846 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 847 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 848 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 849 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 850 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 851 | } else |
| 852 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 853 | * count indicating that ndlp can be released when other |
| 854 | * references to it are done. |
| 855 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 856 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 857 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 858 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 859 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 860 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 861 | spin_lock_irq(shost->host_lock); |
| 862 | vport->fc_flag |= FC_PT2PT; |
| 863 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 864 | |
| 865 | /* Start discovery - this should just do CLEAR_LA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 866 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 867 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 868 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 869 | return -ENXIO; |
| 870 | } |
| 871 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 872 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 873 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 874 | * @phba: pointer to lpfc hba data structure. |
| 875 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 876 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 877 | * |
| 878 | * This routine is the top-level completion callback function for issuing |
| 879 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 880 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 881 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 882 | * returning 1), the command IOCB will be released and function returned. |
| 883 | * If the retry attempt has been given up (possibly reach the maximum |
| 884 | * number of retries), one additional decrement of ndlp reference shall be |
| 885 | * invoked before going out after releasing the command IOCB. This will |
| 886 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 887 | * invoke one decrement of ndlp reference count). If no error reported in |
| 888 | * the IOCB status, the command Port ID field is used to determine whether |
| 889 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 890 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 891 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 892 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 893 | * specific topology completion conditions. |
| 894 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 895 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 896 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 897 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 898 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 899 | struct lpfc_vport *vport = cmdiocb->vport; |
| 900 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 901 | IOCB_t *irsp = &rspiocb->iocb; |
| 902 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 903 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 904 | struct serv_parm *sp; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 905 | uint16_t fcf_index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 906 | int rc; |
| 907 | |
| 908 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 909 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 910 | /* One additional decrement on node reference count to |
| 911 | * trigger the release of the node |
| 912 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 913 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 914 | goto out; |
| 915 | } |
| 916 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 917 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 918 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 919 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 920 | vport->port_state); |
| 921 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 922 | if (irsp->ulpStatus) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 923 | /* |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 924 | * In case of FIP mode, perform roundrobin FCF failover |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 925 | * due to new FCF discovery |
| 926 | */ |
| 927 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 928 | (phba->fcf.fcf_flag & FCF_DISCOVERY)) { |
| 929 | if (phba->link_state < LPFC_LINK_UP) |
| 930 | goto stop_rr_fcf_flogi; |
| 931 | if ((phba->fcoe_cvl_eventtag_attn == |
| 932 | phba->fcoe_cvl_eventtag) && |
| 933 | (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 934 | (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)) |
| 935 | goto stop_rr_fcf_flogi; |
| 936 | else |
| 937 | phba->fcoe_cvl_eventtag_attn = |
| 938 | phba->fcoe_cvl_eventtag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 939 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 940 | "2611 FLOGI failed on FCF (x%x), " |
| 941 | "status:x%x/x%x, tmo:x%x, perform " |
| 942 | "roundrobin FCF failover\n", |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 943 | phba->fcf.current_rec.fcf_indx, |
| 944 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 945 | irsp->ulpTimeout); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 946 | lpfc_sli4_set_fcf_flogi_fail(phba, |
| 947 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 948 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 949 | rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index); |
| 950 | if (rc) |
| 951 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 952 | } |
| 953 | |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 954 | stop_rr_fcf_flogi: |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 955 | /* FLOGI failure */ |
| 956 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 957 | "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
| 958 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 959 | irsp->ulpTimeout); |
| 960 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 961 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 962 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 963 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 964 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 965 | /* FLOGI failure */ |
| 966 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 967 | "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
| 968 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 969 | irsp->ulpTimeout); |
| 970 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 971 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 972 | spin_lock_irq(shost->host_lock); |
| 973 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 974 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 975 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 976 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 977 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 978 | * alpa map would take too long otherwise. |
| 979 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 980 | if (phba->alpa_map[0] == 0) |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 981 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 982 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 983 | (!(vport->fc_flag & FC_VFI_REGISTERED) || |
| 984 | (vport->fc_prevDID != vport->fc_myDID))) { |
| 985 | if (vport->fc_flag & FC_VFI_REGISTERED) |
| 986 | lpfc_sli4_unreg_all_rpis(vport); |
| 987 | lpfc_issue_reg_vfi(vport); |
| 988 | lpfc_nlp_put(ndlp); |
| 989 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 990 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 991 | goto flogifail; |
| 992 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 993 | spin_lock_irq(shost->host_lock); |
| 994 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 995 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 996 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 997 | |
| 998 | /* |
| 999 | * The FLogI succeeded. Sync the data for the CPU before |
| 1000 | * accessing it. |
| 1001 | */ |
| 1002 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 1003 | |
| 1004 | sp = prsp->virt + sizeof(uint32_t); |
| 1005 | |
| 1006 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1007 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1008 | "0101 FLOGI completes successfully " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1009 | "Data: x%x x%x x%x x%x\n", |
| 1010 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
| 1011 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1012 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1013 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1014 | /* |
| 1015 | * If Common Service Parameters indicate Nport |
| 1016 | * we are point to point, if Fport we are Fabric. |
| 1017 | */ |
| 1018 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1019 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1020 | else if (!(phba->hba_flag & HBA_FCOE_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1021 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1022 | else { |
| 1023 | lpfc_printf_vlog(vport, KERN_ERR, |
| 1024 | LOG_FIP | LOG_ELS, |
| 1025 | "2831 FLOGI response with cleared Fabric " |
| 1026 | "bit fcf_index 0x%x " |
| 1027 | "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x " |
| 1028 | "Fabric Name " |
| 1029 | "%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 1030 | phba->fcf.current_rec.fcf_indx, |
| 1031 | phba->fcf.current_rec.switch_name[0], |
| 1032 | phba->fcf.current_rec.switch_name[1], |
| 1033 | phba->fcf.current_rec.switch_name[2], |
| 1034 | phba->fcf.current_rec.switch_name[3], |
| 1035 | phba->fcf.current_rec.switch_name[4], |
| 1036 | phba->fcf.current_rec.switch_name[5], |
| 1037 | phba->fcf.current_rec.switch_name[6], |
| 1038 | phba->fcf.current_rec.switch_name[7], |
| 1039 | phba->fcf.current_rec.fabric_name[0], |
| 1040 | phba->fcf.current_rec.fabric_name[1], |
| 1041 | phba->fcf.current_rec.fabric_name[2], |
| 1042 | phba->fcf.current_rec.fabric_name[3], |
| 1043 | phba->fcf.current_rec.fabric_name[4], |
| 1044 | phba->fcf.current_rec.fabric_name[5], |
| 1045 | phba->fcf.current_rec.fabric_name[6], |
| 1046 | phba->fcf.current_rec.fabric_name[7]); |
| 1047 | lpfc_nlp_put(ndlp); |
| 1048 | spin_lock_irq(&phba->hbalock); |
| 1049 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1050 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 1051 | spin_unlock_irq(&phba->hbalock); |
| 1052 | goto out; |
| 1053 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1054 | if (!rc) { |
| 1055 | /* Mark the FCF discovery process done */ |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1056 | if (phba->hba_flag & HBA_FIP_SUPPORT) |
| 1057 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | |
| 1058 | LOG_ELS, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1059 | "2769 FLOGI to FCF (x%x) " |
| 1060 | "completed successfully\n", |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 1061 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1062 | spin_lock_irq(&phba->hbalock); |
| 1063 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 1064 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1065 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1066 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1067 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | flogifail: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1071 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1072 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1073 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1074 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1075 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1076 | |
| 1077 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1078 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1079 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 1080 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && |
| 1081 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) && |
| 1082 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 1083 | /* If FLOGI failed enable link interrupt. */ |
| 1084 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1085 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1086 | out: |
| 1087 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1088 | } |
| 1089 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1090 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1091 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1092 | * @vport: pointer to a host virtual N_Port data structure. |
| 1093 | * @ndlp: pointer to a node-list data structure. |
| 1094 | * @retry: number of retries to the command IOCB. |
| 1095 | * |
| 1096 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 1097 | * for a @vport. The initiator service parameters are put into the payload |
| 1098 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 1099 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 1100 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 1101 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 1102 | * |
| 1103 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1104 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1105 | * will be stored into the context1 field of the IOCB for the completion |
| 1106 | * callback function to the FLOGI ELS command. |
| 1107 | * |
| 1108 | * Return code |
| 1109 | * 0 - successfully issued flogi iocb for @vport |
| 1110 | * 1 - failed to issue flogi iocb for @vport |
| 1111 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1112 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1113 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1114 | uint8_t retry) |
| 1115 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1116 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1117 | struct serv_parm *sp; |
| 1118 | IOCB_t *icmd; |
| 1119 | struct lpfc_iocbq *elsiocb; |
| 1120 | struct lpfc_sli_ring *pring; |
| 1121 | uint8_t *pcmd; |
| 1122 | uint16_t cmdsize; |
| 1123 | uint32_t tmo; |
| 1124 | int rc; |
| 1125 | |
| 1126 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 1127 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1128 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1129 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1130 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1131 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1132 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1133 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1134 | |
| 1135 | icmd = &elsiocb->iocb; |
| 1136 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1137 | |
| 1138 | /* For FLOGI request, remainder of payload is service parameters */ |
| 1139 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1140 | pcmd += sizeof(uint32_t); |
| 1141 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1142 | sp = (struct serv_parm *) pcmd; |
| 1143 | |
| 1144 | /* Setup CSPs accordingly for Fabric */ |
| 1145 | sp->cmn.e_d_tov = 0; |
| 1146 | sp->cmn.w2.r_a_tov = 0; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 1147 | sp->cmn.virtual_fabric_support = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1148 | sp->cls1.classValid = 0; |
| 1149 | sp->cls2.seqDelivery = 1; |
| 1150 | sp->cls3.seqDelivery = 1; |
| 1151 | if (sp->cmn.fcphLow < FC_PH3) |
| 1152 | sp->cmn.fcphLow = FC_PH3; |
| 1153 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1154 | sp->cmn.fcphHigh = FC_PH3; |
| 1155 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 1156 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1157 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 1158 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 1159 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 1160 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 1161 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 1162 | /* Set the fcfi to the fcfi we registered with */ |
| 1163 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 1164 | } |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 1165 | } else { |
| 1166 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 1167 | sp->cmn.request_multiple_Nport = 1; |
| 1168 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 1169 | icmd->ulpCt_h = 1; |
| 1170 | icmd->ulpCt_l = 0; |
| 1171 | } else |
| 1172 | sp->cmn.request_multiple_Nport = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1173 | } |
| 1174 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1175 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1176 | icmd->un.elsreq64.myID = 0; |
| 1177 | icmd->un.elsreq64.fl = 1; |
| 1178 | } |
| 1179 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1180 | tmo = phba->fc_ratov; |
| 1181 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1182 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1183 | phba->fc_ratov = tmo; |
| 1184 | |
| 1185 | phba->fc_stat.elsXmitFLOGI++; |
| 1186 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1187 | |
| 1188 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1189 | "Issue FLOGI: opt:x%x", |
| 1190 | phba->sli3_options, 0, 0); |
| 1191 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1192 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1193 | if (rc == IOCB_ERROR) { |
| 1194 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1195 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1196 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1197 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1198 | } |
| 1199 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1200 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1201 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1202 | * @phba: pointer to lpfc hba data structure. |
| 1203 | * |
| 1204 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 1205 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 1206 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 1207 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 1208 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 1209 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 1210 | * |
| 1211 | * Return code |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 1212 | * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1213 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1214 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1215 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1216 | { |
| 1217 | struct lpfc_sli_ring *pring; |
| 1218 | struct lpfc_iocbq *iocb, *next_iocb; |
| 1219 | struct lpfc_nodelist *ndlp; |
| 1220 | IOCB_t *icmd; |
| 1221 | |
| 1222 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 1223 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1224 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 1225 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1226 | |
| 1227 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 1228 | |
| 1229 | /* |
| 1230 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 1231 | * searching for. |
| 1232 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1233 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1234 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 1235 | icmd = &iocb->iocb; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1236 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1237 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1238 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 1239 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1240 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1241 | } |
| 1242 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1243 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1244 | |
| 1245 | return 0; |
| 1246 | } |
| 1247 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1248 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1249 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1250 | * @vport: pointer to a host virtual N_Port data structure. |
| 1251 | * |
| 1252 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 1253 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1254 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1255 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1256 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 1257 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 1258 | * @vport. |
| 1259 | * |
| 1260 | * Return code |
| 1261 | * 0 - failed to issue initial flogi for @vport |
| 1262 | * 1 - successfully issued initial flogi for @vport |
| 1263 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1264 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1265 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1266 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1267 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1268 | struct lpfc_nodelist *ndlp; |
| 1269 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1270 | vport->port_state = LPFC_FLOGI; |
| 1271 | lpfc_set_disctmo(vport); |
| 1272 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1273 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1274 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1275 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1276 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1277 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1278 | if (!ndlp) |
| 1279 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1280 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1281 | /* Set the node type */ |
| 1282 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1283 | /* Put ndlp onto node list */ |
| 1284 | lpfc_enqueue_node(vport, ndlp); |
| 1285 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1286 | /* re-setup ndlp without removing from node list */ |
| 1287 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1288 | if (!ndlp) |
| 1289 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1290 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1291 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1292 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1293 | /* This decrement of reference count to node shall kick off |
| 1294 | * the release of the node. |
| 1295 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1296 | lpfc_nlp_put(ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1297 | return 0; |
| 1298 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1299 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1300 | } |
| 1301 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1302 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1303 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1304 | * @vport: pointer to a host virtual N_Port data structure. |
| 1305 | * |
| 1306 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 1307 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1308 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1309 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1310 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 1311 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 1312 | * @vport. |
| 1313 | * |
| 1314 | * Return code |
| 1315 | * 0 - failed to issue initial fdisc for @vport |
| 1316 | * 1 - successfully issued initial fdisc for @vport |
| 1317 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1318 | int |
| 1319 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 1320 | { |
| 1321 | struct lpfc_hba *phba = vport->phba; |
| 1322 | struct lpfc_nodelist *ndlp; |
| 1323 | |
| 1324 | /* First look for the Fabric ndlp */ |
| 1325 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1326 | if (!ndlp) { |
| 1327 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 1328 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1329 | if (!ndlp) |
| 1330 | return 0; |
| 1331 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1332 | /* Put ndlp onto node list */ |
| 1333 | lpfc_enqueue_node(vport, ndlp); |
| 1334 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1335 | /* re-setup ndlp without removing from node list */ |
| 1336 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1337 | if (!ndlp) |
| 1338 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1339 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1340 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1341 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1342 | /* decrement node reference count to trigger the release of |
| 1343 | * the node. |
| 1344 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1345 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1346 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1347 | } |
| 1348 | return 1; |
| 1349 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1350 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1351 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1352 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1353 | * @vport: pointer to a host virtual N_Port data structure. |
| 1354 | * |
| 1355 | * This routine checks whether there are more remaining Port Logins |
| 1356 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1357 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1358 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1359 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1360 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1361 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1362 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1363 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1364 | { |
| 1365 | int sentplogi; |
| 1366 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1367 | if (vport->num_disc_nodes) |
| 1368 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1369 | |
| 1370 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1371 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1372 | "0232 Continue discovery with %d PLOGIs to go " |
| 1373 | "Data: x%x x%x x%x\n", |
| 1374 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1375 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1376 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1377 | if (vport->fc_flag & FC_NLP_MORE) |
| 1378 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 1379 | sentplogi = lpfc_els_disc_plogi(vport); |
| 1380 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1381 | return; |
| 1382 | } |
| 1383 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1384 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1385 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1386 | * @phba: pointer to lpfc hba data structure. |
| 1387 | * @prsp: pointer to response IOCB payload. |
| 1388 | * @ndlp: pointer to a node-list data structure. |
| 1389 | * |
| 1390 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1391 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1392 | * The following cases are considered N_Port confirmed: |
| 1393 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1394 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1395 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1396 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1397 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1398 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1399 | * on that node to release the RPI associated with the node; 2) if there is |
| 1400 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1401 | * into, a new node shall be allocated (or activated). In either case, the |
| 1402 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1403 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1404 | * its pointer returned as the confirmed node. |
| 1405 | * |
| 1406 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1407 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1408 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1409 | * into an inactive state on the vport node list and the vport node list |
| 1410 | * management algorithm does not allow two node with a same DID. |
| 1411 | * |
| 1412 | * Return code |
| 1413 | * pointer to the PLOGI N_Port @ndlp |
| 1414 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1415 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1416 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1417 | struct lpfc_nodelist *ndlp) |
| 1418 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1419 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1420 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1421 | struct lpfc_rport_data *rdata; |
| 1422 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1423 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1424 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1425 | uint32_t rc, keepDID = 0; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1426 | int put_node; |
| 1427 | int put_rport; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1428 | struct lpfc_node_rrqs rrq; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1429 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1430 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1431 | * by WWPN. Just return the ndlp that was given to us. |
| 1432 | */ |
| 1433 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1434 | return ndlp; |
| 1435 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1436 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1437 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1438 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1439 | /* 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] | 1440 | * we have for that ndlp. If not, we have some work to do. |
| 1441 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1442 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1443 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1444 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1445 | return ndlp; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1446 | memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1447 | |
| 1448 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1449 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1450 | sizeof(struct lpfc_name)); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1451 | if (!rc) |
| 1452 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1453 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
| 1454 | if (!new_ndlp) |
| 1455 | return ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1456 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1457 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1458 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1459 | sizeof(struct lpfc_name)); |
| 1460 | if (!rc) |
| 1461 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1462 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1463 | NLP_STE_UNUSED_NODE); |
| 1464 | if (!new_ndlp) |
| 1465 | return ndlp; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1466 | keepDID = new_ndlp->nlp_DID; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1467 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1468 | memcpy(&rrq.xri_bitmap, |
| 1469 | &new_ndlp->active_rrqs.xri_bitmap, |
| 1470 | sizeof(new_ndlp->active_rrqs.xri_bitmap)); |
| 1471 | } else { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1472 | keepDID = new_ndlp->nlp_DID; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1473 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1474 | memcpy(&rrq.xri_bitmap, |
| 1475 | &new_ndlp->active_rrqs.xri_bitmap, |
| 1476 | sizeof(new_ndlp->active_rrqs.xri_bitmap)); |
| 1477 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1478 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1479 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1480 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1481 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1482 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1483 | memcpy(new_ndlp->active_rrqs.xri_bitmap, |
| 1484 | &ndlp->active_rrqs.xri_bitmap, |
| 1485 | sizeof(ndlp->active_rrqs.xri_bitmap)); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1486 | |
| 1487 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) |
| 1488 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 1489 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 1490 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1491 | /* 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] | 1492 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1493 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1494 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1495 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1496 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1497 | * to put ndlp on UNUSED list and try to free it. |
| 1498 | */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1499 | |
| 1500 | /* Fix up the rport accordingly */ |
| 1501 | rport = ndlp->rport; |
| 1502 | if (rport) { |
| 1503 | rdata = rport->dd_data; |
| 1504 | if (rdata->pnode == ndlp) { |
| 1505 | lpfc_nlp_put(ndlp); |
| 1506 | ndlp->rport = NULL; |
| 1507 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1508 | new_ndlp->rport = rport; |
| 1509 | } |
| 1510 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1511 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1512 | /* We shall actually free the ndlp with both nlp_DID and |
| 1513 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1514 | * nodelist never to be used. |
| 1515 | */ |
| 1516 | if (ndlp->nlp_DID == 0) { |
| 1517 | spin_lock_irq(&phba->ndlp_lock); |
| 1518 | NLP_SET_FREE_REQ(ndlp); |
| 1519 | spin_unlock_irq(&phba->ndlp_lock); |
| 1520 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1521 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1522 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1523 | ndlp->nlp_DID = keepDID; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1524 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1525 | memcpy(&ndlp->active_rrqs.xri_bitmap, |
| 1526 | &rrq.xri_bitmap, |
| 1527 | sizeof(ndlp->active_rrqs.xri_bitmap)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1528 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1529 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1530 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1531 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1532 | /* Two ndlps cannot have the same did */ |
| 1533 | ndlp->nlp_DID = keepDID; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1534 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1535 | memcpy(&ndlp->active_rrqs.xri_bitmap, |
| 1536 | &rrq.xri_bitmap, |
| 1537 | sizeof(ndlp->active_rrqs.xri_bitmap)); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1538 | /* Since we are swapping the ndlp passed in with the new one |
| 1539 | * and the did has already been swapped, copy over the |
| 1540 | * state and names. |
| 1541 | */ |
| 1542 | memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname, |
| 1543 | sizeof(struct lpfc_name)); |
| 1544 | memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename, |
| 1545 | sizeof(struct lpfc_name)); |
| 1546 | new_ndlp->nlp_state = ndlp->nlp_state; |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 1547 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1548 | /* Fix up the rport accordingly */ |
| 1549 | rport = ndlp->rport; |
| 1550 | if (rport) { |
| 1551 | rdata = rport->dd_data; |
| 1552 | put_node = rdata->pnode != NULL; |
| 1553 | put_rport = ndlp->rport != NULL; |
| 1554 | rdata->pnode = NULL; |
| 1555 | ndlp->rport = NULL; |
| 1556 | if (put_node) |
| 1557 | lpfc_nlp_put(ndlp); |
| 1558 | if (put_rport) |
| 1559 | put_device(&rport->dev); |
| 1560 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1561 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1562 | return new_ndlp; |
| 1563 | } |
| 1564 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1565 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1566 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1567 | * @vport: pointer to a host virtual N_Port data structure. |
| 1568 | * |
| 1569 | * This routine checks whether more Registration State Change |
| 1570 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1571 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1572 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1573 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1574 | * handling the RSCNs. |
| 1575 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1576 | void |
| 1577 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1578 | { |
| 1579 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1580 | |
| 1581 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1582 | /* |
| 1583 | * Check to see if more RSCNs came in while we were |
| 1584 | * processing this one. |
| 1585 | */ |
| 1586 | if (vport->fc_rscn_id_cnt || |
| 1587 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1588 | lpfc_els_handle_rscn(vport); |
| 1589 | else { |
| 1590 | spin_lock_irq(shost->host_lock); |
| 1591 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1592 | spin_unlock_irq(shost->host_lock); |
| 1593 | } |
| 1594 | } |
| 1595 | } |
| 1596 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1597 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1598 | * lpfc_cmpl_els_rrq - Completion handled for els RRQs. |
| 1599 | * @phba: pointer to lpfc hba data structure. |
| 1600 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1601 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1602 | * |
| 1603 | * This routine will call the clear rrq function to free the rrq and |
| 1604 | * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not |
| 1605 | * exist then the clear_rrq is still called because the rrq needs to |
| 1606 | * be freed. |
| 1607 | **/ |
| 1608 | |
| 1609 | static void |
| 1610 | lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1611 | struct lpfc_iocbq *rspiocb) |
| 1612 | { |
| 1613 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1614 | IOCB_t *irsp; |
| 1615 | struct lpfc_nodelist *ndlp; |
| 1616 | struct lpfc_node_rrq *rrq; |
| 1617 | |
| 1618 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1619 | rrq = cmdiocb->context_un.rrq; |
| 1620 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1621 | |
| 1622 | irsp = &rspiocb->iocb; |
| 1623 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1624 | "RRQ cmpl: status:x%x/x%x did:x%x", |
| 1625 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1626 | irsp->un.elsreq64.remoteID); |
| 1627 | |
| 1628 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
| 1629 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) { |
| 1630 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1631 | "2882 RRQ completes to NPort x%x " |
| 1632 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1633 | irsp->un.elsreq64.remoteID, |
| 1634 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1635 | irsp->ulpIoTag); |
| 1636 | goto out; |
| 1637 | } |
| 1638 | |
| 1639 | /* rrq completes to NPort <nlp_DID> */ |
| 1640 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1641 | "2880 RRQ completes to NPort x%x " |
| 1642 | "Data: x%x x%x x%x x%x x%x\n", |
| 1643 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1644 | irsp->ulpTimeout, rrq->xritag, rrq->rxid); |
| 1645 | |
| 1646 | if (irsp->ulpStatus) { |
| 1647 | /* Check for retry */ |
| 1648 | /* RRQ failed Don't print the vport to vport rjts */ |
| 1649 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1650 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1651 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1652 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1653 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1654 | "2881 RRQ failure DID:%06X Status:x%x/x%x\n", |
| 1655 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1656 | irsp->un.ulpWord[4]); |
| 1657 | } |
| 1658 | out: |
| 1659 | if (rrq) |
| 1660 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 1661 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1662 | return; |
| 1663 | } |
| 1664 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1665 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1666 | * @phba: pointer to lpfc hba data structure. |
| 1667 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1668 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1669 | * |
| 1670 | * This routine is the completion callback function for issuing the Port |
| 1671 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1672 | * ndlp on the vport node list that matches the remote node ID from the |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1673 | * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1674 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1675 | * checked for error conditons. If there is error status reported, PLOGI |
| 1676 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1677 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1678 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1679 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1680 | * there are additional N_Port nodes with the vport that need to perform |
| 1681 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1682 | * PLOGIs. |
| 1683 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1684 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1685 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1686 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1687 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1688 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1689 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1690 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1691 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1692 | struct lpfc_dmabuf *prsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1693 | int disc, rc, did, type; |
| 1694 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1695 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1696 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1697 | |
| 1698 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1699 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1700 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1701 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1702 | irsp->un.elsreq64.remoteID); |
| 1703 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1704 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1705 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1706 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1707 | "0136 PLOGI completes to NPort x%x " |
| 1708 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1709 | irsp->un.elsreq64.remoteID, |
| 1710 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1711 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1712 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1713 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1714 | |
| 1715 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1716 | * is being used during discovery. |
| 1717 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1718 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1719 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1720 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1721 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1722 | rc = 0; |
| 1723 | |
| 1724 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1725 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1726 | "0102 PLOGI completes to NPort x%x " |
| 1727 | "Data: x%x x%x x%x x%x x%x\n", |
| 1728 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1729 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1730 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1731 | if (lpfc_els_chk_latt(vport)) { |
| 1732 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1733 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1734 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1735 | goto out; |
| 1736 | } |
| 1737 | |
| 1738 | /* ndlp could be freed in DSM, save these values now */ |
| 1739 | type = ndlp->nlp_type; |
| 1740 | did = ndlp->nlp_DID; |
| 1741 | |
| 1742 | if (irsp->ulpStatus) { |
| 1743 | /* Check for retry */ |
| 1744 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1745 | /* ELS command is being retried */ |
| 1746 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1747 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1748 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1749 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1750 | } |
| 1751 | goto out; |
| 1752 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1753 | /* PLOGI failed Don't print the vport to vport rjts */ |
| 1754 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1755 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1756 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1757 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1758 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1759 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", |
| 1760 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1761 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1762 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1763 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1764 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1765 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1766 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1767 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1768 | } else { |
| 1769 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1770 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1771 | cmdiocb->context2)->list.next, |
| 1772 | struct lpfc_dmabuf, list); |
| 1773 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1774 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1775 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1776 | } |
| 1777 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1778 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1779 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1780 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1781 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1782 | if (vport->num_disc_nodes == 0) { |
| 1783 | spin_lock_irq(shost->host_lock); |
| 1784 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1785 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1786 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1787 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1788 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1789 | } |
| 1790 | } |
| 1791 | |
| 1792 | out: |
| 1793 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1794 | return; |
| 1795 | } |
| 1796 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1797 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1798 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1799 | * @vport: pointer to a host virtual N_Port data structure. |
| 1800 | * @did: destination port identifier. |
| 1801 | * @retry: number of retries to the command IOCB. |
| 1802 | * |
| 1803 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1804 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1805 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1806 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1807 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1808 | * |
| 1809 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1810 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1811 | * will be stored into the context1 field of the IOCB for the completion |
| 1812 | * callback function to the PLOGI ELS command. |
| 1813 | * |
| 1814 | * Return code |
| 1815 | * 0 - Successfully issued a plogi for @vport |
| 1816 | * 1 - failed to issue a plogi for @vport |
| 1817 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1818 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1819 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1820 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1821 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1822 | struct serv_parm *sp; |
| 1823 | IOCB_t *icmd; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1824 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1825 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1826 | struct lpfc_sli *psli; |
| 1827 | uint8_t *pcmd; |
| 1828 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1829 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1830 | |
| 1831 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1832 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1833 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1834 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1835 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1836 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1837 | /* 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] | 1838 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1839 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1840 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1841 | if (!elsiocb) |
| 1842 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1843 | |
| 1844 | icmd = &elsiocb->iocb; |
| 1845 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1846 | |
| 1847 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1848 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1849 | pcmd += sizeof(uint32_t); |
| 1850 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1851 | sp = (struct serv_parm *) pcmd; |
| 1852 | |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1853 | /* |
| 1854 | * If we are a N-port connected to a Fabric, fix-up paramm's so logins |
| 1855 | * to device on remote loops work. |
| 1856 | */ |
| 1857 | if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP)) |
| 1858 | sp->cmn.altBbCredit = 1; |
| 1859 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1860 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1861 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1862 | |
| 1863 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1864 | sp->cmn.fcphHigh = FC_PH3; |
| 1865 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1866 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1867 | "Issue PLOGI: did:x%x", |
| 1868 | did, 0, 0); |
| 1869 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1870 | phba->fc_stat.elsXmitPLOGI++; |
| 1871 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1872 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1873 | |
| 1874 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1875 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1876 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1877 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1878 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1879 | } |
| 1880 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1881 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1882 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1883 | * @phba: pointer to lpfc hba data structure. |
| 1884 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1885 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1886 | * |
| 1887 | * This routine is the completion callback function for a Process Login |
| 1888 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 1889 | * status. If there is error status reported, PRLI retry shall be attempted |
| 1890 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 1891 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 1892 | * ndlp to mark the PRLI completion. |
| 1893 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1894 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1895 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1896 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1897 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1898 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1899 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1900 | IOCB_t *irsp; |
| 1901 | struct lpfc_sli *psli; |
| 1902 | struct lpfc_nodelist *ndlp; |
| 1903 | |
| 1904 | psli = &phba->sli; |
| 1905 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1906 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1907 | |
| 1908 | irsp = &(rspiocb->iocb); |
| 1909 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1910 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1911 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1912 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1913 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1914 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1915 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 1916 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1917 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1918 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1919 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1920 | "0103 PRLI completes to NPort x%x " |
| 1921 | "Data: x%x x%x x%x x%x\n", |
| 1922 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1923 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1924 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1925 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1926 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1927 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1928 | goto out; |
| 1929 | |
| 1930 | if (irsp->ulpStatus) { |
| 1931 | /* Check for retry */ |
| 1932 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1933 | /* ELS command is being retried */ |
| 1934 | goto out; |
| 1935 | } |
| 1936 | /* PRLI failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1937 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1938 | "2754 PRLI failure DID:%06X Status:x%x/x%x\n", |
| 1939 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1940 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1941 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1942 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1943 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1944 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1945 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1946 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1947 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1948 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1949 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1950 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1951 | out: |
| 1952 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1953 | return; |
| 1954 | } |
| 1955 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1956 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1957 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1958 | * @vport: pointer to a host virtual N_Port data structure. |
| 1959 | * @ndlp: pointer to a node-list data structure. |
| 1960 | * @retry: number of retries to the command IOCB. |
| 1961 | * |
| 1962 | * This routine issues a Process Login (PRLI) ELS command for the |
| 1963 | * @vport. The PRLI service parameters are set up in the payload of the |
| 1964 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 1965 | * is put to the IOCB completion callback func field before invoking the |
| 1966 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 1967 | * |
| 1968 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1969 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1970 | * will be stored into the context1 field of the IOCB for the completion |
| 1971 | * callback function to the PRLI ELS command. |
| 1972 | * |
| 1973 | * Return code |
| 1974 | * 0 - successfully issued prli iocb command for @vport |
| 1975 | * 1 - failed to issue prli iocb command for @vport |
| 1976 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1977 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1978 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1979 | uint8_t retry) |
| 1980 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1981 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1982 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1983 | PRLI *npr; |
| 1984 | IOCB_t *icmd; |
| 1985 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1986 | uint8_t *pcmd; |
| 1987 | uint16_t cmdsize; |
| 1988 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1989 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1990 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1991 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1992 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1993 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1994 | |
| 1995 | icmd = &elsiocb->iocb; |
| 1996 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1997 | |
| 1998 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1999 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2000 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2001 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2002 | |
| 2003 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 2004 | npr = (PRLI *) pcmd; |
| 2005 | /* |
| 2006 | * If our firmware version is 3.20 or later, |
| 2007 | * set the following bits for FC-TAPE support. |
| 2008 | */ |
| 2009 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 2010 | npr->ConfmComplAllowed = 1; |
| 2011 | npr->Retry = 1; |
| 2012 | npr->TaskRetryIdReq = 1; |
| 2013 | } |
| 2014 | npr->estabImagePair = 1; |
| 2015 | npr->readXferRdyDis = 1; |
| 2016 | |
| 2017 | /* For FCP support */ |
| 2018 | npr->prliType = PRLI_FCP_TYPE; |
| 2019 | npr->initiatorFunc = 1; |
| 2020 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2021 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2022 | "Issue PRLI: did:x%x", |
| 2023 | ndlp->nlp_DID, 0, 0); |
| 2024 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2025 | phba->fc_stat.elsXmitPRLI++; |
| 2026 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2027 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2028 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2029 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2030 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2031 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2032 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2033 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2034 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2035 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2036 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2037 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2038 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2039 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2040 | } |
| 2041 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2042 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2043 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2044 | * @vport: pointer to a host virtual N_Port data structure. |
| 2045 | * |
| 2046 | * This routine performs Registration State Change Notification (RSCN) |
| 2047 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 2048 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 2049 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 2050 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 2051 | * invoked to check and handle possible more RSCN came in during the period |
| 2052 | * of processing the current ones. |
| 2053 | **/ |
| 2054 | static void |
| 2055 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 2056 | { |
| 2057 | lpfc_can_disctmo(vport); |
| 2058 | |
| 2059 | /* RSCN discovery */ |
| 2060 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 2061 | if (vport->fc_npr_cnt) |
| 2062 | if (lpfc_els_disc_plogi(vport)) |
| 2063 | return; |
| 2064 | |
| 2065 | lpfc_end_rscn(vport); |
| 2066 | } |
| 2067 | |
| 2068 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2069 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2070 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 2071 | * |
| 2072 | * This function is called when the final ADISC is completed during discovery. |
| 2073 | * This function handles clearing link attention or issuing reg_vpi depending |
| 2074 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 2075 | * discovery. |
| 2076 | * This function is called with no locks held. |
| 2077 | **/ |
| 2078 | static void |
| 2079 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 2080 | { |
| 2081 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2082 | struct lpfc_hba *phba = vport->phba; |
| 2083 | |
| 2084 | /* |
| 2085 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 2086 | * and continue discovery. |
| 2087 | */ |
| 2088 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2089 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 2090 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2091 | lpfc_issue_reg_vpi(phba, vport); |
| 2092 | return; |
| 2093 | } |
| 2094 | /* |
| 2095 | * For SLI2, we need to set port_state to READY |
| 2096 | * and continue discovery. |
| 2097 | */ |
| 2098 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2099 | /* If we get here, there is nothing to ADISC */ |
| 2100 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 2101 | lpfc_issue_clear_la(phba, vport); |
| 2102 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 2103 | vport->num_disc_nodes = 0; |
| 2104 | /* go thru NPR list, issue ELS PLOGIs */ |
| 2105 | if (vport->fc_npr_cnt) |
| 2106 | lpfc_els_disc_plogi(vport); |
| 2107 | if (!vport->num_disc_nodes) { |
| 2108 | spin_lock_irq(shost->host_lock); |
| 2109 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2110 | spin_unlock_irq(shost->host_lock); |
| 2111 | lpfc_can_disctmo(vport); |
| 2112 | lpfc_end_rscn(vport); |
| 2113 | } |
| 2114 | } |
| 2115 | vport->port_state = LPFC_VPORT_READY; |
| 2116 | } else |
| 2117 | lpfc_rscn_disc(vport); |
| 2118 | } |
| 2119 | |
| 2120 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2121 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2122 | * @vport: pointer to a host virtual N_Port data structure. |
| 2123 | * |
| 2124 | * This routine determines whether there are more ndlps on a @vport |
| 2125 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 2126 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 2127 | * remaining nodes which need to have ADISC sent. |
| 2128 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2129 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2130 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2131 | { |
| 2132 | int sentadisc; |
| 2133 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2134 | if (vport->num_disc_nodes) |
| 2135 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2136 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2137 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2138 | "0210 Continue discovery with %d ADISCs to go " |
| 2139 | "Data: x%x x%x x%x\n", |
| 2140 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 2141 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2142 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2143 | if (vport->fc_flag & FC_NLP_MORE) { |
| 2144 | lpfc_set_disctmo(vport); |
| 2145 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 2146 | sentadisc = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2147 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2148 | if (!vport->num_disc_nodes) |
| 2149 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2150 | return; |
| 2151 | } |
| 2152 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2153 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2154 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2155 | * @phba: pointer to lpfc hba data structure. |
| 2156 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2157 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2158 | * |
| 2159 | * This routine is the completion function for issuing the Address Discover |
| 2160 | * (ADISC) command. It first checks to see whether link went down during |
| 2161 | * the discovery process. If so, the node will be marked as node port |
| 2162 | * recovery for issuing discover IOCB by the link attention handler and |
| 2163 | * exit. Otherwise, the response status is checked. If error was reported |
| 2164 | * in the response status, the ADISC command shall be retried by invoking |
| 2165 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 2166 | * the response status, the state machine is invoked to set transition |
| 2167 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 2168 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2169 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2170 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2171 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2172 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2173 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2174 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2175 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2176 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2177 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2178 | |
| 2179 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2180 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2181 | |
| 2182 | irsp = &(rspiocb->iocb); |
| 2183 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2184 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2185 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2186 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 2187 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2188 | ndlp->nlp_DID); |
| 2189 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2190 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 2191 | * is being used during discovery. |
| 2192 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2193 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2194 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2195 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2196 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2197 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2198 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2199 | "0104 ADISC completes to NPort x%x " |
| 2200 | "Data: x%x x%x x%x x%x x%x\n", |
| 2201 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2202 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2203 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2204 | if (lpfc_els_chk_latt(vport)) { |
| 2205 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2206 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2207 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2208 | goto out; |
| 2209 | } |
| 2210 | |
| 2211 | if (irsp->ulpStatus) { |
| 2212 | /* Check for retry */ |
| 2213 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 2214 | /* ELS command is being retried */ |
| 2215 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2216 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2217 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2218 | spin_unlock_irq(shost->host_lock); |
| 2219 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2220 | } |
| 2221 | goto out; |
| 2222 | } |
| 2223 | /* ADISC failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2224 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2225 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", |
| 2226 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2227 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2228 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2229 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2230 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2231 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2232 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2233 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2234 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2235 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2236 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2237 | /* Check to see if there are more ADISCs to be sent */ |
| 2238 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2239 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2240 | out: |
| 2241 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2242 | return; |
| 2243 | } |
| 2244 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2245 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2246 | * 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] | 2247 | * @vport: pointer to a virtual N_Port data structure. |
| 2248 | * @ndlp: pointer to a node-list data structure. |
| 2249 | * @retry: number of retries to the command IOCB. |
| 2250 | * |
| 2251 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 2252 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 2253 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 2254 | * to issue the ADISC ELS command. |
| 2255 | * |
| 2256 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2257 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2258 | * will be stored into the context1 field of the IOCB for the completion |
| 2259 | * callback function to the ADISC ELS command. |
| 2260 | * |
| 2261 | * Return code |
| 2262 | * 0 - successfully issued adisc |
| 2263 | * 1 - failed to issue adisc |
| 2264 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2265 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2266 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2267 | uint8_t retry) |
| 2268 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2269 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2270 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2271 | ADISC *ap; |
| 2272 | IOCB_t *icmd; |
| 2273 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2274 | uint8_t *pcmd; |
| 2275 | uint16_t cmdsize; |
| 2276 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2277 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2278 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2279 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2280 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2281 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2282 | |
| 2283 | icmd = &elsiocb->iocb; |
| 2284 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2285 | |
| 2286 | /* For ADISC request, remainder of payload is service parameters */ |
| 2287 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2288 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2289 | |
| 2290 | /* Fill in ADISC payload */ |
| 2291 | ap = (ADISC *) pcmd; |
| 2292 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2293 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2294 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2295 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2296 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2297 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2298 | "Issue ADISC: did:x%x", |
| 2299 | ndlp->nlp_DID, 0, 0); |
| 2300 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2301 | phba->fc_stat.elsXmitADISC++; |
| 2302 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2303 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2304 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2305 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2306 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2307 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2308 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2309 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2310 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2311 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2312 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2313 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2314 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2315 | } |
| 2316 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2317 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2318 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2319 | * @phba: pointer to lpfc hba data structure. |
| 2320 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2321 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2322 | * |
| 2323 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 2324 | * command. If no error status was reported from the LOGO response, the |
| 2325 | * state machine of the associated ndlp shall be invoked for transition with |
| 2326 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 2327 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 2328 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2329 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2330 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2331 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2332 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2333 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2334 | struct lpfc_vport *vport = ndlp->vport; |
| 2335 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2336 | IOCB_t *irsp; |
| 2337 | struct lpfc_sli *psli; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2338 | struct lpfcMboxq *mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2339 | |
| 2340 | psli = &phba->sli; |
| 2341 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2342 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2343 | |
| 2344 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2345 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2346 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2347 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2348 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2349 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2350 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 2351 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2352 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2353 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2354 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2355 | "0105 LOGO completes to NPort x%x " |
| 2356 | "Data: x%x x%x x%x x%x\n", |
| 2357 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2358 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2359 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2360 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2361 | goto out; |
| 2362 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2363 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 2364 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 2365 | * which should abort all outstanding IOs. |
| 2366 | */ |
| 2367 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2368 | NLP_EVT_DEVICE_RM); |
| 2369 | goto out; |
| 2370 | } |
| 2371 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2372 | if (irsp->ulpStatus) { |
| 2373 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2374 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2375 | /* ELS command is being retried */ |
| 2376 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2377 | /* LOGO failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2378 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2379 | "2756 LOGO failure DID:%06X Status:x%x/x%x\n", |
| 2380 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2381 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2382 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2383 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2384 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2385 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2386 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2387 | NLP_EVT_CMPL_LOGO); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2388 | } else |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2389 | /* Good status, call state machine. |
| 2390 | * This will unregister the rpi if needed. |
| 2391 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2392 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2393 | NLP_EVT_CMPL_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2394 | out: |
| 2395 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2396 | /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */ |
| 2397 | if ((vport->fc_flag & FC_PT2PT) && |
| 2398 | !(vport->fc_flag & FC_PT2PT_PLOGI)) { |
| 2399 | phba->pport->fc_myDID = 0; |
| 2400 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2401 | if (mbox) { |
| 2402 | lpfc_config_link(phba, mbox); |
| 2403 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 2404 | mbox->vport = vport; |
| 2405 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == |
| 2406 | MBX_NOT_FINISHED) { |
| 2407 | mempool_free(mbox, phba->mbox_mem_pool); |
| 2408 | } |
| 2409 | } |
| 2410 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2411 | return; |
| 2412 | } |
| 2413 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2414 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2415 | * 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] | 2416 | * @vport: pointer to a virtual N_Port data structure. |
| 2417 | * @ndlp: pointer to a node-list data structure. |
| 2418 | * @retry: number of retries to the command IOCB. |
| 2419 | * |
| 2420 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2421 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2422 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2423 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2424 | * |
| 2425 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2426 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2427 | * will be stored into the context1 field of the IOCB for the completion |
| 2428 | * callback function to the LOGO ELS command. |
| 2429 | * |
| 2430 | * Return code |
| 2431 | * 0 - successfully issued logo |
| 2432 | * 1 - failed to issue logo |
| 2433 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2434 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2435 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2436 | uint8_t retry) |
| 2437 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2438 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2439 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2440 | IOCB_t *icmd; |
| 2441 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2442 | uint8_t *pcmd; |
| 2443 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2444 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2445 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2446 | spin_lock_irq(shost->host_lock); |
| 2447 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2448 | spin_unlock_irq(shost->host_lock); |
| 2449 | return 0; |
| 2450 | } |
| 2451 | spin_unlock_irq(shost->host_lock); |
| 2452 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2453 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2454 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2455 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2456 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2457 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2458 | |
| 2459 | icmd = &elsiocb->iocb; |
| 2460 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2461 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2462 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2463 | |
| 2464 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2465 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2466 | pcmd += sizeof(uint32_t); |
| 2467 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2468 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2469 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2470 | "Issue LOGO: did:x%x", |
| 2471 | ndlp->nlp_DID, 0, 0); |
| 2472 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2473 | phba->fc_stat.elsXmitLOGO++; |
| 2474 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2475 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2476 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2477 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2478 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2479 | |
| 2480 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2481 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2482 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2483 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2484 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2485 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2486 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2487 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2488 | } |
| 2489 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2490 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2491 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2492 | * @phba: pointer to lpfc hba data structure. |
| 2493 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2494 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2495 | * |
| 2496 | * This routine is a generic completion callback function for ELS commands. |
| 2497 | * Specifically, it is the callback function which does not need to perform |
| 2498 | * any command specific operations. It is currently used by the ELS command |
| 2499 | * issuing routines for the ELS State Change Request (SCR), |
| 2500 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 2501 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2502 | * certain debug loggings, this callback function simply invokes the |
| 2503 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2504 | * discovery process. |
| 2505 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2506 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2507 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2508 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2509 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2510 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2511 | IOCB_t *irsp; |
| 2512 | |
| 2513 | irsp = &rspiocb->iocb; |
| 2514 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2515 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2516 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2517 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2518 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2519 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2520 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2521 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2522 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2523 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2524 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2525 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2526 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2527 | return; |
| 2528 | } |
| 2529 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2530 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2531 | * 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] | 2532 | * @vport: pointer to a host virtual N_Port data structure. |
| 2533 | * @nportid: N_Port identifier to the remote node. |
| 2534 | * @retry: number of retries to the command IOCB. |
| 2535 | * |
| 2536 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2537 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2538 | * first search the @vport node list to find the matching ndlp. If no such |
| 2539 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2540 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2541 | * routine is invoked to send the SCR IOCB. |
| 2542 | * |
| 2543 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2544 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2545 | * will be stored into the context1 field of the IOCB for the completion |
| 2546 | * callback function to the SCR ELS command. |
| 2547 | * |
| 2548 | * Return code |
| 2549 | * 0 - Successfully issued scr command |
| 2550 | * 1 - Failed to issue scr command |
| 2551 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2552 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2553 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2554 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2555 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2556 | IOCB_t *icmd; |
| 2557 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2558 | struct lpfc_sli *psli; |
| 2559 | uint8_t *pcmd; |
| 2560 | uint16_t cmdsize; |
| 2561 | struct lpfc_nodelist *ndlp; |
| 2562 | |
| 2563 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2564 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2565 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2566 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2567 | if (!ndlp) { |
| 2568 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2569 | if (!ndlp) |
| 2570 | return 1; |
| 2571 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2572 | lpfc_enqueue_node(vport, ndlp); |
| 2573 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2574 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2575 | if (!ndlp) |
| 2576 | return 1; |
| 2577 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2578 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2579 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2580 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2581 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2582 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2583 | /* This will trigger the release of the node just |
| 2584 | * allocated |
| 2585 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2586 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2587 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2588 | } |
| 2589 | |
| 2590 | icmd = &elsiocb->iocb; |
| 2591 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2592 | |
| 2593 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2594 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2595 | |
| 2596 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2597 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2598 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2599 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2600 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2601 | "Issue SCR: did:x%x", |
| 2602 | ndlp->nlp_DID, 0, 0); |
| 2603 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2604 | phba->fc_stat.elsXmitSCR++; |
| 2605 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2606 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2607 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2608 | /* The additional lpfc_nlp_put will cause the following |
| 2609 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2610 | * the node. |
| 2611 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2612 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2613 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2614 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2615 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2616 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2617 | * trigger the release of node. |
| 2618 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2619 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2620 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2621 | } |
| 2622 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2623 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2624 | * 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] | 2625 | * @vport: pointer to a host virtual N_Port data structure. |
| 2626 | * @nportid: N_Port identifier to the remote node. |
| 2627 | * @retry: number of retries to the command IOCB. |
| 2628 | * |
| 2629 | * This routine issues a Fibre Channel Address Resolution Response |
| 2630 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2631 | * is passed into the function. It first search the @vport node list to find |
| 2632 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2633 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2634 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2635 | * |
| 2636 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2637 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2638 | * will be stored into the context1 field of the IOCB for the completion |
| 2639 | * callback function to the PARPR ELS command. |
| 2640 | * |
| 2641 | * Return code |
| 2642 | * 0 - Successfully issued farpr command |
| 2643 | * 1 - Failed to issue farpr command |
| 2644 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2645 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2646 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2647 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2648 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2649 | IOCB_t *icmd; |
| 2650 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2651 | struct lpfc_sli *psli; |
| 2652 | FARP *fp; |
| 2653 | uint8_t *pcmd; |
| 2654 | uint32_t *lp; |
| 2655 | uint16_t cmdsize; |
| 2656 | struct lpfc_nodelist *ondlp; |
| 2657 | struct lpfc_nodelist *ndlp; |
| 2658 | |
| 2659 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2660 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2661 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2662 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2663 | if (!ndlp) { |
| 2664 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2665 | if (!ndlp) |
| 2666 | return 1; |
| 2667 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2668 | lpfc_enqueue_node(vport, ndlp); |
| 2669 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2670 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2671 | if (!ndlp) |
| 2672 | return 1; |
| 2673 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2674 | |
| 2675 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2676 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2677 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2678 | /* This will trigger the release of the node just |
| 2679 | * allocated |
| 2680 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2681 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2682 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2683 | } |
| 2684 | |
| 2685 | icmd = &elsiocb->iocb; |
| 2686 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2687 | |
| 2688 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2689 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2690 | |
| 2691 | /* Fill in FARPR payload */ |
| 2692 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2693 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2694 | lp = (uint32_t *) pcmd; |
| 2695 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2696 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2697 | fp->Rflags = 0; |
| 2698 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2699 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2700 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2701 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2702 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2703 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2704 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2705 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2706 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2707 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 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 | "Issue FARPR: did:x%x", |
| 2712 | ndlp->nlp_DID, 0, 0); |
| 2713 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2714 | phba->fc_stat.elsXmitFARPR++; |
| 2715 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2716 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2717 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2718 | /* The additional lpfc_nlp_put will cause the following |
| 2719 | * lpfc_els_free_iocb routine to trigger the release of |
| 2720 | * the node. |
| 2721 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2722 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2723 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2724 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2725 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2726 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2727 | * trigger the release of the node. |
| 2728 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2729 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2730 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2731 | } |
| 2732 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2733 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2734 | * 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] | 2735 | * @vport: pointer to a host virtual N_Port data structure. |
| 2736 | * @nlp: pointer to a node-list data structure. |
| 2737 | * |
| 2738 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2739 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2740 | * removes the ELS retry event if it presents. In addition, if the |
| 2741 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2742 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2743 | * ADISC. |
| 2744 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2745 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2746 | 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] | 2747 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2748 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2749 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2750 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2751 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2752 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2753 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2754 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2755 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2756 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2757 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2758 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2759 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2760 | /* Decrement nlp reference count held for the delayed retry */ |
| 2761 | evtp = &nlp->els_retry_evt; |
| 2762 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2763 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2764 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2765 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2766 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2767 | spin_unlock_irq(shost->host_lock); |
| 2768 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2769 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2770 | /* Check if there are more ADISCs to be sent */ |
| 2771 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2772 | } else { |
| 2773 | /* Check if there are more PLOGIs to be sent */ |
| 2774 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2775 | if (vport->num_disc_nodes == 0) { |
| 2776 | spin_lock_irq(shost->host_lock); |
| 2777 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2778 | spin_unlock_irq(shost->host_lock); |
| 2779 | lpfc_can_disctmo(vport); |
| 2780 | lpfc_end_rscn(vport); |
| 2781 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2782 | } |
| 2783 | } |
| 2784 | } |
| 2785 | return; |
| 2786 | } |
| 2787 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2788 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2789 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2790 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2791 | * |
| 2792 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2793 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2794 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2795 | * adds the delayed events to the HBA work list and invokes the |
| 2796 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2797 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2798 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2799 | * reference to ndlp will still be available when the worker thread gets |
| 2800 | * to the event associated with the ndlp. |
| 2801 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2802 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2803 | lpfc_els_retry_delay(unsigned long ptr) |
| 2804 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2805 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2806 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2807 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2808 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2809 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2810 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2811 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2812 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2813 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2814 | return; |
| 2815 | } |
| 2816 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2817 | /* We need to hold the node by incrementing the reference |
| 2818 | * count until the queued work is done |
| 2819 | */ |
| 2820 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2821 | if (evtp->evt_arg1) { |
| 2822 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2823 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2824 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2825 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2826 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2827 | return; |
| 2828 | } |
| 2829 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2830 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2831 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2832 | * @ndlp: pointer to a node-list data structure. |
| 2833 | * |
| 2834 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 2835 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 2836 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 2837 | * function according to the delayed ELS command to retry the command. |
| 2838 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2839 | void |
| 2840 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 2841 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2842 | struct lpfc_vport *vport = ndlp->vport; |
| 2843 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2844 | uint32_t cmd, did, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2845 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2846 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2847 | did = ndlp->nlp_DID; |
| 2848 | cmd = ndlp->nlp_last_elscmd; |
| 2849 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2850 | |
| 2851 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2852 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2853 | return; |
| 2854 | } |
| 2855 | |
| 2856 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2857 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 2858 | /* |
| 2859 | * If a discovery event readded nlp_delayfunc after timer |
| 2860 | * firing and before processing the timer, cancel the |
| 2861 | * nlp_delayfunc. |
| 2862 | */ |
| 2863 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2864 | retry = ndlp->nlp_retry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 2865 | ndlp->nlp_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2866 | |
| 2867 | switch (cmd) { |
| 2868 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2869 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2870 | break; |
| 2871 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2872 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2873 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2874 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2875 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2876 | break; |
| 2877 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2878 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2879 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2880 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2881 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2882 | break; |
| 2883 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2884 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2885 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2886 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2887 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2888 | break; |
| 2889 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2890 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2891 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2892 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2893 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2894 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2895 | case ELS_CMD_FDISC: |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 2896 | if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)) |
| 2897 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2898 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2899 | } |
| 2900 | return; |
| 2901 | } |
| 2902 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2903 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2904 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2905 | * @phba: pointer to lpfc hba data structure. |
| 2906 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2907 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2908 | * |
| 2909 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 2910 | * failed. The following ELS IOCBs use this function for retrying the command |
| 2911 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 2912 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 2913 | * returned error status, it makes the decision whether a retry shall be |
| 2914 | * issued for the command, and whether a retry shall be made immediately or |
| 2915 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 2916 | * is called to retry the command. In the later case, the ELS command shall |
| 2917 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 2918 | * ndlp for the delayed command issusing. |
| 2919 | * |
| 2920 | * Return code |
| 2921 | * 0 - No retry of els command is made |
| 2922 | * 1 - Immediate or delayed retry of els command is made |
| 2923 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2924 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2925 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2926 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2927 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2928 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2929 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2930 | IOCB_t *irsp = &rspiocb->iocb; |
| 2931 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2932 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2933 | uint32_t *elscmd; |
| 2934 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2935 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2936 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2937 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2938 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2939 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2940 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2941 | /* Note: context2 may be 0 for internal driver abort |
| 2942 | * of delays ELS command. |
| 2943 | */ |
| 2944 | |
| 2945 | if (pcmd && pcmd->virt) { |
| 2946 | elscmd = (uint32_t *) (pcmd->virt); |
| 2947 | cmd = *elscmd++; |
| 2948 | } |
| 2949 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2950 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2951 | did = ndlp->nlp_DID; |
| 2952 | else { |
| 2953 | /* We should only hit this case for retrying PLOGI */ |
| 2954 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2955 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2956 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 2957 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2958 | return 1; |
| 2959 | } |
| 2960 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2961 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2962 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 2963 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 2964 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2965 | switch (irsp->ulpStatus) { |
| 2966 | case IOSTAT_FCP_RSP_ERROR: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2967 | break; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2968 | case IOSTAT_REMOTE_STOP: |
| 2969 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2970 | /* This IO was aborted by the target, we don't |
| 2971 | * know the rxid and because we did not send the |
| 2972 | * ABTS we cannot generate and RRQ. |
| 2973 | */ |
| 2974 | lpfc_set_rrq_active(phba, ndlp, |
| 2975 | cmdiocb->sli4_xritag, 0, 0); |
| 2976 | } |
| 2977 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2978 | case IOSTAT_LOCAL_REJECT: |
| 2979 | switch ((irsp->un.ulpWord[4] & 0xff)) { |
| 2980 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2981 | if (cmd == ELS_CMD_FLOGI) { |
| 2982 | if (PCI_DEVICE_ID_HORNET == |
| 2983 | phba->pcidev->device) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2984 | phba->fc_topology = LPFC_TOPOLOGY_LOOP; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2985 | phba->pport->fc_myDID = 0; |
| 2986 | phba->alpa_map[0] = 0; |
| 2987 | phba->alpa_map[1] = 0; |
| 2988 | } |
| 2989 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2990 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2991 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2992 | retry = 1; |
| 2993 | break; |
| 2994 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2995 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2996 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2997 | "0124 Retry illegal cmd x%x " |
| 2998 | "retry:x%x delay:x%x\n", |
| 2999 | cmd, cmdiocb->retry, delay); |
| 3000 | retry = 1; |
| 3001 | /* All command's retry policy */ |
| 3002 | maxretry = 8; |
| 3003 | if (cmdiocb->retry > 2) |
| 3004 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3005 | break; |
| 3006 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3007 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3008 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3009 | retry = 1; |
| 3010 | if (cmdiocb->retry > 100) |
| 3011 | delay = 100; |
| 3012 | maxretry = 250; |
| 3013 | break; |
| 3014 | |
| 3015 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3016 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3017 | retry = 1; |
| 3018 | break; |
| 3019 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3020 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3021 | case IOERR_INVALID_RPI: |
| 3022 | retry = 1; |
| 3023 | break; |
| 3024 | } |
| 3025 | break; |
| 3026 | |
| 3027 | case IOSTAT_NPORT_RJT: |
| 3028 | case IOSTAT_FABRIC_RJT: |
| 3029 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 3030 | retry = 1; |
| 3031 | break; |
| 3032 | } |
| 3033 | break; |
| 3034 | |
| 3035 | case IOSTAT_NPORT_BSY: |
| 3036 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3037 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3038 | retry = 1; |
| 3039 | break; |
| 3040 | |
| 3041 | case IOSTAT_LS_RJT: |
| 3042 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 3043 | /* Added for Vendor specifc support |
| 3044 | * Just keep retrying for these Rsn / Exp codes |
| 3045 | */ |
| 3046 | switch (stat.un.b.lsRjtRsnCode) { |
| 3047 | case LSRJT_UNABLE_TPC: |
| 3048 | if (stat.un.b.lsRjtRsnCodeExp == |
| 3049 | LSEXP_CMD_IN_PROGRESS) { |
| 3050 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3051 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3052 | maxretry = 48; |
| 3053 | } |
| 3054 | retry = 1; |
| 3055 | break; |
| 3056 | } |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 3057 | if (stat.un.b.lsRjtRsnCodeExp == |
| 3058 | LSEXP_CANT_GIVE_DATA) { |
| 3059 | if (cmd == ELS_CMD_PLOGI) { |
| 3060 | delay = 1000; |
| 3061 | maxretry = 48; |
| 3062 | } |
| 3063 | retry = 1; |
| 3064 | break; |
| 3065 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3066 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3067 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3068 | maxretry = lpfc_max_els_tries + 1; |
| 3069 | retry = 1; |
| 3070 | break; |
| 3071 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3072 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 3073 | (cmd == ELS_CMD_FDISC) && |
| 3074 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3075 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3076 | "0125 FDISC Failed (x%x). " |
| 3077 | "Fabric out of resources\n", |
| 3078 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3079 | lpfc_vport_set_state(vport, |
| 3080 | FC_VPORT_NO_FABRIC_RSCS); |
| 3081 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3082 | break; |
| 3083 | |
| 3084 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3085 | if ((cmd == ELS_CMD_PLOGI) || |
| 3086 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3087 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3088 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3089 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3090 | /* FDISC retry policy */ |
| 3091 | maxretry = 48; |
| 3092 | if (cmdiocb->retry >= 32) |
| 3093 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3094 | } |
| 3095 | retry = 1; |
| 3096 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3097 | |
| 3098 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3099 | /* There are some cases where switches return this |
| 3100 | * error when they are not ready and should be returning |
| 3101 | * Logical Busy. We should delay every time. |
| 3102 | */ |
| 3103 | if (cmd == ELS_CMD_FDISC && |
| 3104 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 3105 | maxretry = 3; |
| 3106 | delay = 1000; |
| 3107 | retry = 1; |
| 3108 | break; |
| 3109 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3110 | case LSRJT_PROTOCOL_ERR: |
| 3111 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 3112 | (cmd == ELS_CMD_FDISC) && |
| 3113 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 3114 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 3115 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3116 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3117 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3118 | "Fabric Detected Bad WWN\n", |
| 3119 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3120 | lpfc_vport_set_state(vport, |
| 3121 | FC_VPORT_FABRIC_REJ_WWN); |
| 3122 | } |
| 3123 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3124 | } |
| 3125 | break; |
| 3126 | |
| 3127 | case IOSTAT_INTERMED_RSP: |
| 3128 | case IOSTAT_BA_RJT: |
| 3129 | break; |
| 3130 | |
| 3131 | default: |
| 3132 | break; |
| 3133 | } |
| 3134 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3135 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3136 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3137 | |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3138 | if ((cmd == ELS_CMD_FLOGI) && |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3139 | (phba->fc_topology != LPFC_TOPOLOGY_LOOP) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 3140 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3141 | /* FLOGI retry policy */ |
| 3142 | retry = 1; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3143 | /* retry FLOGI forever */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3144 | maxretry = 0; |
| 3145 | if (cmdiocb->retry >= 100) |
| 3146 | delay = 5000; |
| 3147 | else if (cmdiocb->retry >= 32) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3148 | delay = 1000; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3149 | } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) { |
| 3150 | /* retry FDISCs every second up to devloss */ |
| 3151 | retry = 1; |
| 3152 | maxretry = vport->cfg_devloss_tmo; |
| 3153 | delay = 1000; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3154 | } |
| 3155 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3156 | cmdiocb->retry++; |
| 3157 | if (maxretry && (cmdiocb->retry >= maxretry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3158 | phba->fc_stat.elsRetryExceeded++; |
| 3159 | retry = 0; |
| 3160 | } |
| 3161 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3162 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 3163 | retry = 0; |
| 3164 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3165 | if (retry) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3166 | if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) { |
| 3167 | /* Stop retrying PLOGI and FDISC if in FCF discovery */ |
| 3168 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
| 3169 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3170 | "2849 Stop retry ELS command " |
| 3171 | "x%x to remote NPORT x%x, " |
| 3172 | "Data: x%x x%x\n", cmd, did, |
| 3173 | cmdiocb->retry, delay); |
| 3174 | return 0; |
| 3175 | } |
| 3176 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3177 | |
| 3178 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3179 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3180 | "0107 Retry ELS command x%x to remote " |
| 3181 | "NPORT x%x Data: x%x x%x\n", |
| 3182 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3183 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3184 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 3185 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 3186 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { |
| 3187 | /* Don't reset timer for no resources */ |
| 3188 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3189 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3190 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3191 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3192 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3193 | } |
| 3194 | |
| 3195 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3196 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3197 | phba->fc_stat.elsDelayRetry++; |
| 3198 | ndlp->nlp_retry = cmdiocb->retry; |
| 3199 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3200 | /* delay is specified in milliseconds */ |
| 3201 | mod_timer(&ndlp->nlp_delayfunc, |
| 3202 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3203 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3204 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3205 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3206 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3207 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3208 | if (cmd == ELS_CMD_PRLI) |
| 3209 | lpfc_nlp_set_state(vport, ndlp, |
| 3210 | NLP_STE_REG_LOGIN_ISSUE); |
| 3211 | else |
| 3212 | lpfc_nlp_set_state(vport, ndlp, |
| 3213 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3214 | ndlp->nlp_last_elscmd = cmd; |
| 3215 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3216 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3217 | } |
| 3218 | switch (cmd) { |
| 3219 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3220 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3221 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3222 | case ELS_CMD_FDISC: |
| 3223 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 3224 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3225 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3226 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3227 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3228 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3229 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3230 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3231 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3232 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3233 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3234 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3235 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 3236 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3237 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3238 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3239 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3240 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 3241 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3242 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3243 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3244 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3245 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 3246 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3247 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3248 | } |
| 3249 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3250 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3251 | if (logerr) { |
| 3252 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3253 | "0137 No retry ELS command x%x to remote " |
| 3254 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 3255 | cmd, did, irsp->ulpStatus, |
| 3256 | irsp->un.ulpWord[4]); |
| 3257 | } |
| 3258 | else { |
| 3259 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3260 | "0108 No retry ELS command x%x to remote " |
| 3261 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 3262 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 3263 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3264 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3265 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3266 | } |
| 3267 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3268 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3269 | * 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] | 3270 | * @phba: pointer to lpfc hba data structure. |
| 3271 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 3272 | * |
| 3273 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 3274 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 3275 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 3276 | * response of the command IOCB. If so, it will be released before releasing |
| 3277 | * the lpfc DMA buffer associated with the IOCB itself. |
| 3278 | * |
| 3279 | * Return code |
| 3280 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3281 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3282 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3283 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 3284 | { |
| 3285 | struct lpfc_dmabuf *buf_ptr; |
| 3286 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3287 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3288 | if (!list_empty(&buf_ptr1->list)) { |
| 3289 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 3290 | struct lpfc_dmabuf, |
| 3291 | list); |
| 3292 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3293 | kfree(buf_ptr); |
| 3294 | } |
| 3295 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 3296 | kfree(buf_ptr1); |
| 3297 | return 0; |
| 3298 | } |
| 3299 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3300 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3301 | * 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] | 3302 | * @phba: pointer to lpfc hba data structure. |
| 3303 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 3304 | * |
| 3305 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 3306 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 3307 | * pool. |
| 3308 | * |
| 3309 | * Return code |
| 3310 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3311 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3312 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3313 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 3314 | { |
| 3315 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3316 | kfree(buf_ptr); |
| 3317 | return 0; |
| 3318 | } |
| 3319 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3320 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3321 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3322 | * @phba: pointer to lpfc hba data structure. |
| 3323 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 3324 | * |
| 3325 | * This routine frees a command IOCB and its associated resources. The |
| 3326 | * command IOCB data structure contains the reference to various associated |
| 3327 | * resources, these fields must be set to NULL if the associated reference |
| 3328 | * not present: |
| 3329 | * context1 - reference to ndlp |
| 3330 | * context2 - reference to cmd |
| 3331 | * context2->next - reference to rsp |
| 3332 | * context3 - reference to bpl |
| 3333 | * |
| 3334 | * It first properly decrements the reference count held on ndlp for the |
| 3335 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 3336 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 3337 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 3338 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 3339 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 3340 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 3341 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 3342 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 3343 | * |
| 3344 | * Return code |
| 3345 | * 0 - Success (currently, always return 0) |
| 3346 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3347 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3348 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3349 | { |
| 3350 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3351 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3352 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3353 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 3354 | if (ndlp) { |
| 3355 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 3356 | lpfc_nlp_put(ndlp); |
| 3357 | |
| 3358 | /* If the ndlp is not being used by another discovery |
| 3359 | * thread, free it. |
| 3360 | */ |
| 3361 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3362 | /* If ndlp is being used by another discovery |
| 3363 | * thread, just clear NLP_DEFER_RM |
| 3364 | */ |
| 3365 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 3366 | } |
| 3367 | } |
| 3368 | else |
| 3369 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3370 | elsiocb->context1 = NULL; |
| 3371 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3372 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 3373 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3374 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 3375 | /* Firmware could still be in progress of DMAing |
| 3376 | * payload, so don't free data buffer till after |
| 3377 | * a hbeat. |
| 3378 | */ |
| 3379 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 3380 | buf_ptr = elsiocb->context2; |
| 3381 | elsiocb->context2 = NULL; |
| 3382 | if (buf_ptr) { |
| 3383 | buf_ptr1 = NULL; |
| 3384 | spin_lock_irq(&phba->hbalock); |
| 3385 | if (!list_empty(&buf_ptr->list)) { |
| 3386 | list_remove_head(&buf_ptr->list, |
| 3387 | buf_ptr1, struct lpfc_dmabuf, |
| 3388 | list); |
| 3389 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 3390 | list_add_tail(&buf_ptr1->list, |
| 3391 | &phba->elsbuf); |
| 3392 | phba->elsbuf_cnt++; |
| 3393 | } |
| 3394 | INIT_LIST_HEAD(&buf_ptr->list); |
| 3395 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 3396 | phba->elsbuf_cnt++; |
| 3397 | spin_unlock_irq(&phba->hbalock); |
| 3398 | } |
| 3399 | } else { |
| 3400 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 3401 | lpfc_els_free_data(phba, buf_ptr1); |
| 3402 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3403 | } |
| 3404 | |
| 3405 | if (elsiocb->context3) { |
| 3406 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3407 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3408 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3409 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3410 | return 0; |
| 3411 | } |
| 3412 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3413 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3414 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3415 | * @phba: pointer to lpfc hba data structure. |
| 3416 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3417 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3418 | * |
| 3419 | * This routine is the completion callback function to the Logout (LOGO) |
| 3420 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 3421 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 3422 | * release the ndlp if it has the last reference remaining (reference count |
| 3423 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 3424 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 3425 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 3426 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 3427 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 3428 | * IOCB data structure. |
| 3429 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3430 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3431 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3432 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3433 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3434 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3435 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3436 | IOCB_t *irsp; |
| 3437 | |
| 3438 | irsp = &rspiocb->iocb; |
| 3439 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3440 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 3441 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3442 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3443 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3444 | "0109 ACC to LOGO completes to NPort x%x " |
| 3445 | "Data: x%x x%x x%x\n", |
| 3446 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3447 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3448 | |
| 3449 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 3450 | /* NPort Recovery mode or node is just allocated */ |
| 3451 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3452 | /* If the ndlp is being used by another discovery |
| 3453 | * thread, just unregister the RPI. |
| 3454 | */ |
| 3455 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3456 | } else { |
| 3457 | /* Indicate the node has already released, should |
| 3458 | * not reference to it from within lpfc_els_free_iocb. |
| 3459 | */ |
| 3460 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3461 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3462 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3463 | |
| 3464 | /* |
| 3465 | * The driver received a LOGO from the rport and has ACK'd it. |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3466 | * At this point, the driver is done so release the IOCB |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3467 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3468 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 3469 | |
| 3470 | /* |
| 3471 | * Remove the ndlp reference if it's a fabric node that has |
| 3472 | * sent us an unsolicted LOGO. |
| 3473 | */ |
| 3474 | if (ndlp->nlp_type & NLP_FABRIC) |
| 3475 | lpfc_nlp_put(ndlp); |
| 3476 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3477 | return; |
| 3478 | } |
| 3479 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3480 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3481 | * 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] | 3482 | * @phba: pointer to lpfc hba data structure. |
| 3483 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 3484 | * |
| 3485 | * This routine is the completion callback function for unregister default |
| 3486 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 3487 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 3488 | * decrements the ndlp reference count held for this completion callback |
| 3489 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 3490 | * whether there is only one reference left on the ndlp. If so, it will |
| 3491 | * perform one more decrement and trigger the release of the ndlp. |
| 3492 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3493 | void |
| 3494 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3495 | { |
| 3496 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3497 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3498 | |
| 3499 | pmb->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3500 | pmb->context2 = NULL; |
| 3501 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3502 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3503 | kfree(mp); |
| 3504 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3505 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3506 | lpfc_nlp_put(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3507 | /* This is the end of the default RPI cleanup logic for this |
| 3508 | * ndlp. If no other discovery threads are using this ndlp. |
| 3509 | * we should free all resources associated with it. |
| 3510 | */ |
| 3511 | lpfc_nlp_not_used(ndlp); |
| 3512 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3513 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3514 | return; |
| 3515 | } |
| 3516 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3517 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3518 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3519 | * @phba: pointer to lpfc hba data structure. |
| 3520 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3521 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3522 | * |
| 3523 | * This routine is the completion callback function for ELS Response IOCB |
| 3524 | * command. In normal case, this callback function just properly sets the |
| 3525 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 3526 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 3527 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 3528 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 3529 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 3530 | * routine shall be invoked trying to release the ndlp if no other threads |
| 3531 | * are currently referring it. |
| 3532 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3533 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3534 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3535 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3536 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3537 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3538 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 3539 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3540 | IOCB_t *irsp; |
| 3541 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3542 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3543 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3544 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3545 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3546 | irsp = &rspiocb->iocb; |
| 3547 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3548 | if (cmdiocb->context_un.mbox) |
| 3549 | mbox = cmdiocb->context_un.mbox; |
| 3550 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3551 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 3552 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 3553 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3554 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3555 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3556 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3557 | /* A LS_RJT associated with Default RPI cleanup has its own |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 3558 | * separate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3559 | */ |
| 3560 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 3561 | ls_rjt = 1; |
| 3562 | } |
| 3563 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3564 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3565 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3566 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3567 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3568 | if (mp) { |
| 3569 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3570 | kfree(mp); |
| 3571 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3572 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3573 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3574 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3575 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3576 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3577 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3578 | /* Indicate the node has already released, |
| 3579 | * should not reference to it from within |
| 3580 | * the routine lpfc_els_free_iocb. |
| 3581 | */ |
| 3582 | cmdiocb->context1 = NULL; |
| 3583 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3584 | goto out; |
| 3585 | } |
| 3586 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3587 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3588 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3589 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3590 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3591 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3592 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3593 | "0110 ELS response tag x%x completes " |
| 3594 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3595 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3596 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3597 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3598 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3599 | if (mbox) { |
| 3600 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3601 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3602 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3603 | /* Increment reference count to ndlp to hold the |
| 3604 | * reference to ndlp for the callback function. |
| 3605 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3606 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3607 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3608 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3609 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3610 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3611 | } |
| 3612 | else { |
| 3613 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3614 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3615 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3616 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3617 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3618 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3619 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3620 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3621 | else |
| 3622 | /* Decrement the ndlp reference count we |
| 3623 | * set for this failed mailbox command. |
| 3624 | */ |
| 3625 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3626 | |
| 3627 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3628 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3629 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3630 | "Data: x%x x%x x%x\n", |
| 3631 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3632 | ndlp->nlp_rpi); |
| 3633 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3634 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3635 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3636 | /* Indicate node has already been released, |
| 3637 | * should not reference to it from within |
| 3638 | * the routine lpfc_els_free_iocb. |
| 3639 | */ |
| 3640 | cmdiocb->context1 = NULL; |
| 3641 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3642 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3643 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3644 | if (!lpfc_error_lost_link(irsp) && |
| 3645 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3646 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3647 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3648 | /* Indicate node has already been |
| 3649 | * released, should not reference |
| 3650 | * to it from within the routine |
| 3651 | * lpfc_els_free_iocb. |
| 3652 | */ |
| 3653 | cmdiocb->context1 = NULL; |
| 3654 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3655 | } |
| 3656 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3657 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3658 | if (mp) { |
| 3659 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3660 | kfree(mp); |
| 3661 | } |
| 3662 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3663 | } |
| 3664 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3665 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3666 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3667 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3668 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3669 | |
| 3670 | /* If the node is not being used by another discovery thread, |
| 3671 | * and we are sending a reject, we are done with it. |
| 3672 | * Release driver reference count here and free associated |
| 3673 | * resources. |
| 3674 | */ |
| 3675 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3676 | if (lpfc_nlp_not_used(ndlp)) |
| 3677 | /* Indicate node has already been released, |
| 3678 | * should not reference to it from within |
| 3679 | * the routine lpfc_els_free_iocb. |
| 3680 | */ |
| 3681 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3682 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3683 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3684 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3685 | return; |
| 3686 | } |
| 3687 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3688 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3689 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3690 | * @vport: pointer to a host virtual N_Port data structure. |
| 3691 | * @flag: the els command code to be accepted. |
| 3692 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3693 | * @ndlp: pointer to a node-list data structure. |
| 3694 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3695 | * |
| 3696 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3697 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3698 | * specific ACC response command to be issued and invokes the |
| 3699 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3700 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3701 | * field of the IOCB for the completion callback function to issue the |
| 3702 | * mailbox command to the HBA later when callback is invoked. |
| 3703 | * |
| 3704 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3705 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3706 | * will be stored into the context1 field of the IOCB for the completion |
| 3707 | * callback function to the corresponding response ELS IOCB command. |
| 3708 | * |
| 3709 | * Return code |
| 3710 | * 0 - Successfully issued acc response |
| 3711 | * 1 - Failed to issue acc response |
| 3712 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3713 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3714 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3715 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3716 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3717 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3718 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3719 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3720 | IOCB_t *icmd; |
| 3721 | IOCB_t *oldcmd; |
| 3722 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3723 | struct lpfc_sli *psli; |
| 3724 | uint8_t *pcmd; |
| 3725 | uint16_t cmdsize; |
| 3726 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3727 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3728 | |
| 3729 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3730 | oldcmd = &oldiocb->iocb; |
| 3731 | |
| 3732 | switch (flag) { |
| 3733 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3734 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3735 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3736 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3737 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3738 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3739 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3740 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3741 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3742 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3743 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3744 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3745 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 3746 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3747 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3748 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3749 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3750 | |
| 3751 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3752 | "Issue ACC: did:x%x flg:x%x", |
| 3753 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3754 | break; |
| 3755 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3756 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3757 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3758 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3759 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3760 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3761 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3762 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3763 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 3764 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3765 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3766 | |
| 3767 | if (mbox) |
| 3768 | elsiocb->context_un.mbox = mbox; |
| 3769 | |
| 3770 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3771 | pcmd += sizeof(uint32_t); |
| 3772 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3773 | |
| 3774 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3775 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 3776 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3777 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3778 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3779 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3780 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3781 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3782 | if (!elsiocb) |
| 3783 | return 1; |
| 3784 | |
| 3785 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3786 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 3787 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3788 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3789 | |
| 3790 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3791 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3792 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 3793 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 3794 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3795 | |
| 3796 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3797 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 3798 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3799 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3800 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3801 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3802 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3803 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3804 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3805 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
| 3806 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", |
| 3807 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3808 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3809 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3810 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3811 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3812 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3813 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3814 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 3815 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3816 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3817 | } |
| 3818 | |
| 3819 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3820 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3821 | if (rc == IOCB_ERROR) { |
| 3822 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3823 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3824 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3825 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3826 | } |
| 3827 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3828 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3829 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3830 | * @vport: pointer to a virtual N_Port data structure. |
| 3831 | * @rejectError: |
| 3832 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3833 | * @ndlp: pointer to a node-list data structure. |
| 3834 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3835 | * |
| 3836 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 3837 | * command. If a @mbox pointer is passed in, it will be put into the |
| 3838 | * context_un.mbox field of the IOCB for the completion callback function |
| 3839 | * to issue to the HBA later. |
| 3840 | * |
| 3841 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3842 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3843 | * will be stored into the context1 field of the IOCB for the completion |
| 3844 | * callback function to the reject response ELS IOCB command. |
| 3845 | * |
| 3846 | * Return code |
| 3847 | * 0 - Successfully issued reject response |
| 3848 | * 1 - Failed to issue reject response |
| 3849 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3850 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3851 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3852 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 3853 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3854 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3855 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3856 | IOCB_t *icmd; |
| 3857 | IOCB_t *oldcmd; |
| 3858 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3859 | struct lpfc_sli *psli; |
| 3860 | uint8_t *pcmd; |
| 3861 | uint16_t cmdsize; |
| 3862 | int rc; |
| 3863 | |
| 3864 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3865 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3866 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3867 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3868 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3869 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3870 | |
| 3871 | icmd = &elsiocb->iocb; |
| 3872 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3873 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 3874 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3875 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3876 | |
| 3877 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3878 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3879 | *((uint32_t *) (pcmd)) = rejectError; |
| 3880 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3881 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3882 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3883 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3884 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3885 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3886 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 3887 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 3888 | "rpi x%x\n", |
| 3889 | rejectError, elsiocb->iotag, |
| 3890 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 3891 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3892 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3893 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 3894 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 3895 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3896 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3897 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3898 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3899 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3900 | if (rc == IOCB_ERROR) { |
| 3901 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3902 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3903 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3904 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3905 | } |
| 3906 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3907 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3908 | * 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] | 3909 | * @vport: pointer to a virtual N_Port data structure. |
| 3910 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3911 | * @ndlp: pointer to a node-list data structure. |
| 3912 | * |
| 3913 | * This routine prepares and issues an Accept (ACC) response to Address |
| 3914 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 3915 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3916 | * |
| 3917 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3918 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3919 | * will be stored into the context1 field of the IOCB for the completion |
| 3920 | * callback function to the ADISC Accept response ELS IOCB command. |
| 3921 | * |
| 3922 | * Return code |
| 3923 | * 0 - Successfully issued acc adisc response |
| 3924 | * 1 - Failed to issue adisc acc response |
| 3925 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3926 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3927 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 3928 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3929 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3930 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3931 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3932 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3933 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3934 | uint8_t *pcmd; |
| 3935 | uint16_t cmdsize; |
| 3936 | int rc; |
| 3937 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3938 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3939 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3940 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3941 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3942 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3943 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3944 | icmd = &elsiocb->iocb; |
| 3945 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3946 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 3947 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3948 | |
| 3949 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3950 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3951 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 3952 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 3953 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3954 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3955 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3956 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3957 | |
| 3958 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3959 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3960 | |
| 3961 | ap = (ADISC *) (pcmd); |
| 3962 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3963 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3964 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3965 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3966 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3967 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3968 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 3969 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3970 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3971 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3972 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3973 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3974 | if (rc == IOCB_ERROR) { |
| 3975 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3976 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3977 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3978 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3979 | } |
| 3980 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3981 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3982 | * 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] | 3983 | * @vport: pointer to a virtual N_Port data structure. |
| 3984 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3985 | * @ndlp: pointer to a node-list data structure. |
| 3986 | * |
| 3987 | * This routine prepares and issues an Accept (ACC) response to Process |
| 3988 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 3989 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3990 | * |
| 3991 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3992 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3993 | * will be stored into the context1 field of the IOCB for the completion |
| 3994 | * callback function to the PRLI Accept response ELS IOCB command. |
| 3995 | * |
| 3996 | * Return code |
| 3997 | * 0 - Successfully issued acc prli response |
| 3998 | * 1 - Failed to issue acc prli response |
| 3999 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4000 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4001 | 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] | 4002 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4003 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4004 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4005 | PRLI *npr; |
| 4006 | lpfc_vpd_t *vpd; |
| 4007 | IOCB_t *icmd; |
| 4008 | IOCB_t *oldcmd; |
| 4009 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4010 | struct lpfc_sli *psli; |
| 4011 | uint8_t *pcmd; |
| 4012 | uint16_t cmdsize; |
| 4013 | int rc; |
| 4014 | |
| 4015 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4016 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4017 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4018 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4019 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4020 | if (!elsiocb) |
| 4021 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4022 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4023 | icmd = &elsiocb->iocb; |
| 4024 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4025 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4026 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| 4027 | |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4028 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4029 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4030 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 4031 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4032 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4033 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4034 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4035 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4036 | |
| 4037 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4038 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4039 | |
| 4040 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4041 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4042 | |
| 4043 | npr = (PRLI *) pcmd; |
| 4044 | vpd = &phba->vpd; |
| 4045 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4046 | * If the remote port is a target and our firmware version is 3.20 or |
| 4047 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4048 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4049 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 4050 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4051 | npr->ConfmComplAllowed = 1; |
| 4052 | npr->Retry = 1; |
| 4053 | npr->TaskRetryIdReq = 1; |
| 4054 | } |
| 4055 | |
| 4056 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 4057 | npr->estabImagePair = 1; |
| 4058 | npr->readXferRdyDis = 1; |
| 4059 | npr->ConfmComplAllowed = 1; |
| 4060 | |
| 4061 | npr->prliType = PRLI_FCP_TYPE; |
| 4062 | npr->initiatorFunc = 1; |
| 4063 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4064 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4065 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 4066 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4067 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4068 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4069 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4070 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4071 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4072 | if (rc == IOCB_ERROR) { |
| 4073 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4074 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4075 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4076 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4077 | } |
| 4078 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4079 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4080 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4081 | * @vport: pointer to a virtual N_Port data structure. |
| 4082 | * @format: rnid command format. |
| 4083 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4084 | * @ndlp: pointer to a node-list data structure. |
| 4085 | * |
| 4086 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 4087 | * (ACC) response. It constructs the RNID ACC response command according to |
| 4088 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 4089 | * issue the response. Note that this command does not need to hold the ndlp |
| 4090 | * reference count for the callback. So, the ndlp reference count taken by |
| 4091 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 4092 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 4093 | * there is no ndlp reference available. |
| 4094 | * |
| 4095 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4096 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4097 | * will be stored into the context1 field of the IOCB for the completion |
| 4098 | * callback function. However, for the RNID Accept Response ELS command, |
| 4099 | * this is undone later by this routine after the IOCB is allocated. |
| 4100 | * |
| 4101 | * Return code |
| 4102 | * 0 - Successfully issued acc rnid response |
| 4103 | * 1 - Failed to issue acc rnid response |
| 4104 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4105 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4106 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4107 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4108 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4109 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4110 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4111 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4112 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4113 | struct lpfc_sli *psli; |
| 4114 | uint8_t *pcmd; |
| 4115 | uint16_t cmdsize; |
| 4116 | int rc; |
| 4117 | |
| 4118 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4119 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 4120 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4121 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4122 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4123 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4124 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4125 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4126 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4127 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4128 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4129 | icmd = &elsiocb->iocb; |
| 4130 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4131 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 4132 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
| 4133 | |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4134 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4135 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4136 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 4137 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4138 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4139 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4140 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4141 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4142 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4143 | rn = (RNID *) (pcmd); |
| 4144 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4145 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 4146 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 4147 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4148 | switch (format) { |
| 4149 | case 0: |
| 4150 | rn->SpecificLen = 0; |
| 4151 | break; |
| 4152 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4153 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4154 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4155 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4156 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 4157 | rn->un.topologyDisc.physPort = 0; |
| 4158 | rn->un.topologyDisc.attachedNodes = 0; |
| 4159 | break; |
| 4160 | default: |
| 4161 | rn->CommonLen = 0; |
| 4162 | rn->SpecificLen = 0; |
| 4163 | break; |
| 4164 | } |
| 4165 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4166 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4167 | "Issue ACC RNID: did:x%x flg:x%x", |
| 4168 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4169 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4170 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4171 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4172 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4173 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4174 | if (rc == IOCB_ERROR) { |
| 4175 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4176 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4177 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4178 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4179 | } |
| 4180 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4181 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4182 | * lpfc_els_clear_rrq - Clear the rq that this rrq describes. |
| 4183 | * @vport: pointer to a virtual N_Port data structure. |
| 4184 | * @iocb: pointer to the lpfc command iocb data structure. |
| 4185 | * @ndlp: pointer to a node-list data structure. |
| 4186 | * |
| 4187 | * Return |
| 4188 | **/ |
| 4189 | static void |
| 4190 | lpfc_els_clear_rrq(struct lpfc_vport *vport, |
| 4191 | struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp) |
| 4192 | { |
| 4193 | struct lpfc_hba *phba = vport->phba; |
| 4194 | uint8_t *pcmd; |
| 4195 | struct RRQ *rrq; |
| 4196 | uint16_t rxid; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4197 | uint16_t xri; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4198 | struct lpfc_node_rrq *prrq; |
| 4199 | |
| 4200 | |
| 4201 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt); |
| 4202 | pcmd += sizeof(uint32_t); |
| 4203 | rrq = (struct RRQ *)pcmd; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4204 | rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg); |
James Smart | 9589b06 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4205 | rxid = bf_get(rrq_rxid, rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4206 | |
| 4207 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4208 | "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x" |
| 4209 | " x%x x%x\n", |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4210 | be32_to_cpu(bf_get(rrq_did, rrq)), |
James Smart | 9589b06 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4211 | bf_get(rrq_oxid, rrq), |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4212 | rxid, |
| 4213 | iocb->iotag, iocb->iocb.ulpContext); |
| 4214 | |
| 4215 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4216 | "Clear RRQ: did:x%x flg:x%x exchg:x%.08x", |
| 4217 | ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4218 | if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq))) |
James Smart | 9589b06 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4219 | xri = bf_get(rrq_oxid, rrq); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4220 | else |
| 4221 | xri = rxid; |
| 4222 | prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4223 | if (prrq) |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4224 | lpfc_clr_rrq_active(phba, xri, prrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4225 | return; |
| 4226 | } |
| 4227 | |
| 4228 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4229 | * lpfc_els_rsp_echo_acc - Issue echo acc response |
| 4230 | * @vport: pointer to a virtual N_Port data structure. |
| 4231 | * @data: pointer to echo data to return in the accept. |
| 4232 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4233 | * @ndlp: pointer to a node-list data structure. |
| 4234 | * |
| 4235 | * Return code |
| 4236 | * 0 - Successfully issued acc echo response |
| 4237 | * 1 - Failed to issue acc echo response |
| 4238 | **/ |
| 4239 | static int |
| 4240 | lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data, |
| 4241 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| 4242 | { |
| 4243 | struct lpfc_hba *phba = vport->phba; |
| 4244 | struct lpfc_iocbq *elsiocb; |
| 4245 | struct lpfc_sli *psli; |
| 4246 | uint8_t *pcmd; |
| 4247 | uint16_t cmdsize; |
| 4248 | int rc; |
| 4249 | |
| 4250 | psli = &phba->sli; |
| 4251 | cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len; |
| 4252 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 4253 | /* The accumulated length can exceed the BPL_SIZE. For |
| 4254 | * now, use this as the limit |
| 4255 | */ |
| 4256 | if (cmdsize > LPFC_BPL_SIZE) |
| 4257 | cmdsize = LPFC_BPL_SIZE; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4258 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4259 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 4260 | if (!elsiocb) |
| 4261 | return 1; |
| 4262 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4263 | elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */ |
| 4264 | elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id; |
| 4265 | |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4266 | /* Xmit ECHO ACC response tag <ulpIoTag> */ |
| 4267 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4268 | "2876 Xmit ECHO ACC response tag x%x xri x%x\n", |
| 4269 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| 4270 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4271 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 4272 | pcmd += sizeof(uint32_t); |
| 4273 | memcpy(pcmd, data, cmdsize - sizeof(uint32_t)); |
| 4274 | |
| 4275 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 4276 | "Issue ACC ECHO: did:x%x flg:x%x", |
| 4277 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4278 | |
| 4279 | phba->fc_stat.elsXmitACC++; |
| 4280 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4281 | |
| 4282 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 4283 | if (rc == IOCB_ERROR) { |
| 4284 | lpfc_els_free_iocb(phba, elsiocb); |
| 4285 | return 1; |
| 4286 | } |
| 4287 | return 0; |
| 4288 | } |
| 4289 | |
| 4290 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4291 | * 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] | 4292 | * @vport: pointer to a host virtual N_Port data structure. |
| 4293 | * |
| 4294 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 4295 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 4296 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 4297 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 4298 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 4299 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 4300 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 4301 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 4302 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 4303 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 4304 | * no more ADISC need to be sent. |
| 4305 | * |
| 4306 | * Return code |
| 4307 | * The number of N_Ports with adisc issued. |
| 4308 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4309 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4310 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4311 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4312 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4313 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4314 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4315 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4316 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4317 | 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] | 4318 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4319 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4320 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 4321 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4322 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4323 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4324 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4325 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4326 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4327 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 4328 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4329 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4330 | vport->num_disc_nodes++; |
| 4331 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4332 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4333 | spin_lock_irq(shost->host_lock); |
| 4334 | vport->fc_flag |= FC_NLP_MORE; |
| 4335 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4336 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4337 | } |
| 4338 | } |
| 4339 | } |
| 4340 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4341 | spin_lock_irq(shost->host_lock); |
| 4342 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4343 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4344 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4345 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4346 | } |
| 4347 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4348 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4349 | * 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] | 4350 | * @vport: pointer to a host virtual N_Port data structure. |
| 4351 | * |
| 4352 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 4353 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 4354 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 4355 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 4356 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 4357 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 4358 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 4359 | * later pick up. On the other hand, after walking through all the ndlps with |
| 4360 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 4361 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 4362 | * PLOGI need to be sent. |
| 4363 | * |
| 4364 | * Return code |
| 4365 | * The number of N_Ports with plogi issued. |
| 4366 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4367 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4368 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4369 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4370 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4371 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4372 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4373 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4374 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 4375 | 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] | 4376 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 4377 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4378 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 4379 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 4380 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 4381 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 4382 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4383 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 4384 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4385 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4386 | vport->num_disc_nodes++; |
| 4387 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4388 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4389 | spin_lock_irq(shost->host_lock); |
| 4390 | vport->fc_flag |= FC_NLP_MORE; |
| 4391 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4392 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4393 | } |
| 4394 | } |
| 4395 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4396 | if (sentplogi) { |
| 4397 | lpfc_set_disctmo(vport); |
| 4398 | } |
| 4399 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4400 | spin_lock_irq(shost->host_lock); |
| 4401 | vport->fc_flag &= ~FC_NLP_MORE; |
| 4402 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4403 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4404 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4405 | } |
| 4406 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4407 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4408 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4409 | * @vport: pointer to a host virtual N_Port data structure. |
| 4410 | * |
| 4411 | * This routine cleans up any Registration State Change Notification |
| 4412 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 4413 | * @vport together with the host_lock is used to prevent multiple thread |
| 4414 | * trying to access the RSCN array on a same @vport at the same time. |
| 4415 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4416 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4417 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4418 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4419 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4420 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4421 | int i; |
| 4422 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4423 | spin_lock_irq(shost->host_lock); |
| 4424 | if (vport->fc_rscn_flush) { |
| 4425 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4426 | spin_unlock_irq(shost->host_lock); |
| 4427 | return; |
| 4428 | } |
| 4429 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 4430 | vport->fc_rscn_flush = 1; |
| 4431 | spin_unlock_irq(shost->host_lock); |
| 4432 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4433 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4434 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4435 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4436 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4437 | spin_lock_irq(shost->host_lock); |
| 4438 | vport->fc_rscn_id_cnt = 0; |
| 4439 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 4440 | spin_unlock_irq(shost->host_lock); |
| 4441 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4442 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 4443 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4444 | } |
| 4445 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4446 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4447 | * 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] | 4448 | * @vport: pointer to a host virtual N_Port data structure. |
| 4449 | * @did: remote destination port identifier. |
| 4450 | * |
| 4451 | * This routine checks whether there is any pending Registration State |
| 4452 | * Configuration Notification (RSCN) to a @did on @vport. |
| 4453 | * |
| 4454 | * Return code |
| 4455 | * None zero - The @did matched with a pending rscn |
| 4456 | * 0 - not able to match @did with a pending rscn |
| 4457 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4458 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4459 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4460 | { |
| 4461 | D_ID ns_did; |
| 4462 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4463 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4464 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4465 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4466 | |
| 4467 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4468 | |
| 4469 | /* Never match fabric nodes for RSCNs */ |
| 4470 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4471 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4472 | |
| 4473 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4474 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4475 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4476 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4477 | spin_lock_irq(shost->host_lock); |
| 4478 | if (vport->fc_rscn_flush) { |
| 4479 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4480 | spin_unlock_irq(shost->host_lock); |
| 4481 | return 0; |
| 4482 | } |
| 4483 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4484 | vport->fc_rscn_flush = 1; |
| 4485 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4486 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4487 | lp = vport->fc_rscn_id_list[i]->virt; |
| 4488 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4489 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4490 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4491 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 4492 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4493 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 4494 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4495 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4496 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 4497 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4498 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4499 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4500 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4501 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4502 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4503 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4504 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4505 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4506 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4507 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4508 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4509 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4510 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4511 | } |
| 4512 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4513 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4514 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4515 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4516 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4517 | return_did_out: |
| 4518 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4519 | vport->fc_rscn_flush = 0; |
| 4520 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4521 | } |
| 4522 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4523 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4524 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4525 | * @vport: pointer to a host virtual N_Port data structure. |
| 4526 | * |
| 4527 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 4528 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 4529 | * State Change Notification). |
| 4530 | * |
| 4531 | * Return code |
| 4532 | * 0 - Successful (currently alway return 0) |
| 4533 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4534 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4535 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4536 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4537 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4538 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4539 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4540 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4541 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4542 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 4543 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4544 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4545 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4546 | NLP_EVT_DEVICE_RECOVERY); |
| 4547 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4548 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4549 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4550 | } |
| 4551 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4552 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4553 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4554 | * @vport: pointer to a host virtual N_Port data structure. |
| 4555 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4556 | * |
| 4557 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 4558 | * applications. |
| 4559 | */ |
| 4560 | static void |
| 4561 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 4562 | struct lpfc_iocbq *cmdiocb) |
| 4563 | { |
| 4564 | struct lpfc_dmabuf *pcmd; |
| 4565 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4566 | uint32_t *payload_ptr; |
| 4567 | uint32_t payload_len; |
| 4568 | struct lpfc_rscn_event_header *rscn_event_data; |
| 4569 | |
| 4570 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4571 | payload_ptr = (uint32_t *) pcmd->virt; |
| 4572 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 4573 | |
| 4574 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 4575 | payload_len, GFP_KERNEL); |
| 4576 | if (!rscn_event_data) { |
| 4577 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4578 | "0147 Failed to allocate memory for RSCN event\n"); |
| 4579 | return; |
| 4580 | } |
| 4581 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 4582 | rscn_event_data->payload_length = payload_len; |
| 4583 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 4584 | payload_len); |
| 4585 | |
| 4586 | fc_host_post_vendor_event(shost, |
| 4587 | fc_get_event_number(), |
| 4588 | sizeof(struct lpfc_els_event_header) + payload_len, |
| 4589 | (char *)rscn_event_data, |
| 4590 | LPFC_NL_VENDOR_ID); |
| 4591 | |
| 4592 | kfree(rscn_event_data); |
| 4593 | } |
| 4594 | |
| 4595 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4596 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4597 | * @vport: pointer to a host virtual N_Port data structure. |
| 4598 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4599 | * @ndlp: pointer to a node-list data structure. |
| 4600 | * |
| 4601 | * This routine processes an unsolicited RSCN (Registration State Change |
| 4602 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 4603 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 4604 | * discover state machine is about to begin discovery, it just accepts the |
| 4605 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 4606 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 4607 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 4608 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 4609 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 4610 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 4611 | * routine is invoked to handle the RSCN event. |
| 4612 | * |
| 4613 | * Return code |
| 4614 | * 0 - Just sent the acc response |
| 4615 | * 1 - Sent the acc response and waited for name server completion |
| 4616 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4617 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4618 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4619 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4620 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4621 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4622 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4623 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4624 | uint32_t *lp, *datap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4625 | IOCB_t *icmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4626 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4627 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4628 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4629 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4630 | |
| 4631 | icmd = &cmdiocb->iocb; |
| 4632 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4633 | lp = (uint32_t *) pcmd->virt; |
| 4634 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4635 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4636 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4637 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4638 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4639 | "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] | 4640 | vport->fc_flag, payload_len, *lp, |
| 4641 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4642 | |
| 4643 | /* Send an RSCN event to the management application */ |
| 4644 | lpfc_send_rscn_event(vport, cmdiocb); |
| 4645 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4646 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4647 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4648 | FCH_EVT_RSCN, lp[i]); |
| 4649 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4650 | /* If we are about to begin discovery, just ACC the RSCN. |
| 4651 | * Discovery processing will satisfy it. |
| 4652 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4653 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4654 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4655 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 4656 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4657 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4658 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4659 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4660 | } |
| 4661 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4662 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 4663 | * just ACC and ignore it. |
| 4664 | */ |
| 4665 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4666 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4667 | i = payload_len; |
| 4668 | datap = lp; |
| 4669 | while (i > 0) { |
| 4670 | nportid = *datap++; |
| 4671 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 4672 | i -= sizeof(uint32_t); |
| 4673 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4674 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 4675 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4676 | } |
| 4677 | if (rscn_id == hba_id) { |
| 4678 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4679 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4680 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4681 | "Data: x%x x%x x%x x%x\n", |
| 4682 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4683 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4684 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4685 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 4686 | ndlp->nlp_DID, vport->port_state, |
| 4687 | ndlp->nlp_flag); |
| 4688 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4689 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4690 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4691 | return 0; |
| 4692 | } |
| 4693 | } |
| 4694 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4695 | spin_lock_irq(shost->host_lock); |
| 4696 | if (vport->fc_rscn_flush) { |
| 4697 | /* Another thread is walking fc_rscn_id_list on this vport */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4698 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 4699 | spin_unlock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4700 | /* Send back ACC */ |
| 4701 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4702 | return 0; |
| 4703 | } |
| 4704 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4705 | vport->fc_rscn_flush = 1; |
| 4706 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4707 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4708 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4709 | /* If we are already processing an RSCN, save the received |
| 4710 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 4711 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4712 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4713 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4714 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 4715 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4716 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4717 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4718 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 4719 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4720 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4721 | vport->fc_flag |= FC_RSCN_MODE; |
| 4722 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4723 | if (rscn_cnt) { |
| 4724 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 4725 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 4726 | } |
| 4727 | if ((rscn_cnt) && |
| 4728 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 4729 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4730 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4731 | memcpy(((uint8_t *)cmd) + length, lp, |
| 4732 | payload_len); |
| 4733 | } else { |
| 4734 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 4735 | vport->fc_rscn_id_cnt++; |
| 4736 | /* If we zero, cmdiocb->context2, the calling |
| 4737 | * routine will not try to free it. |
| 4738 | */ |
| 4739 | cmdiocb->context2 = NULL; |
| 4740 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4741 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4742 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4743 | "0235 Deferred RSCN " |
| 4744 | "Data: x%x x%x x%x\n", |
| 4745 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4746 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4747 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4748 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 4749 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4750 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4751 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4752 | "0234 ReDiscovery RSCN " |
| 4753 | "Data: x%x x%x x%x\n", |
| 4754 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4755 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4756 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4757 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4758 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4759 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4760 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4761 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4762 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4763 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4764 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4765 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4766 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4767 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4768 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4769 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 4770 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4771 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4772 | spin_lock_irq(shost->host_lock); |
| 4773 | vport->fc_flag |= FC_RSCN_MODE; |
| 4774 | spin_unlock_irq(shost->host_lock); |
| 4775 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4776 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4777 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4778 | /* |
| 4779 | * If we zero, cmdiocb->context2, the calling routine will |
| 4780 | * not try to free it. |
| 4781 | */ |
| 4782 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4783 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4784 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4785 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4786 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4787 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4788 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4789 | } |
| 4790 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4791 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4792 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4793 | * @vport: pointer to a host virtual N_Port data structure. |
| 4794 | * |
| 4795 | * This routine handles the Registration State Configuration Notification |
| 4796 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 4797 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 4798 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 4799 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 4800 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 4801 | * RSCN activities with the @vport. |
| 4802 | * |
| 4803 | * Return code |
| 4804 | * 0 - Cleaned up rscn on the @vport |
| 4805 | * 1 - Wait for plogi to name server before proceed |
| 4806 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4807 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4808 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4809 | { |
| 4810 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4811 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4812 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4813 | /* Ignore RSCN if the port is being torn down. */ |
| 4814 | if (vport->load_flag & FC_UNLOADING) { |
| 4815 | lpfc_els_flush_rscn(vport); |
| 4816 | return 0; |
| 4817 | } |
| 4818 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4819 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4820 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4821 | |
| 4822 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4823 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4824 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 4825 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 4826 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4827 | |
| 4828 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4829 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4830 | vport->num_disc_nodes = 0; |
| 4831 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4832 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4833 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 4834 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4835 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4836 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4837 | /* Wait for NameServer query cmpl before we can |
| 4838 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4839 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4840 | } else { |
| 4841 | /* If login to NameServer does not exist, issue one */ |
| 4842 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4843 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4844 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4845 | /* Wait for NameServer login cmpl before we can |
| 4846 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4847 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4848 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4849 | if (ndlp) { |
| 4850 | ndlp = lpfc_enable_node(vport, ndlp, |
| 4851 | NLP_STE_PLOGI_ISSUE); |
| 4852 | if (!ndlp) { |
| 4853 | lpfc_els_flush_rscn(vport); |
| 4854 | return 0; |
| 4855 | } |
| 4856 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4857 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4858 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4859 | if (!ndlp) { |
| 4860 | lpfc_els_flush_rscn(vport); |
| 4861 | return 0; |
| 4862 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4863 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4864 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4865 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4866 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4867 | ndlp->nlp_type |= NLP_FABRIC; |
| 4868 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 4869 | /* Wait for NameServer login cmpl before we can |
| 4870 | * continue |
| 4871 | */ |
| 4872 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4873 | } |
| 4874 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4875 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4876 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4877 | } |
| 4878 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4879 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4880 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4881 | * @vport: pointer to a host virtual N_Port data structure. |
| 4882 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4883 | * @ndlp: pointer to a node-list data structure. |
| 4884 | * |
| 4885 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 4886 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 4887 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 4888 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 4889 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 4890 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 4891 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 4892 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 4893 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 4894 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 4895 | * higher priority (as the winning port) and will initiate PLOGI and |
| 4896 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 4897 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 4898 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 4899 | * |
| 4900 | * Return code |
| 4901 | * 0 - Successfully processed the unsolicited flogi |
| 4902 | * 1 - Failed to process the unsolicited flogi |
| 4903 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4904 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4905 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4906 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4907 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4908 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4909 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4910 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4911 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 4912 | IOCB_t *icmd = &cmdiocb->iocb; |
| 4913 | struct serv_parm *sp; |
| 4914 | LPFC_MBOXQ_t *mbox; |
| 4915 | struct ls_rjt stat; |
| 4916 | uint32_t cmd, did; |
| 4917 | int rc; |
| 4918 | |
| 4919 | cmd = *lp++; |
| 4920 | sp = (struct serv_parm *) lp; |
| 4921 | |
| 4922 | /* FLOGI received */ |
| 4923 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4924 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4925 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4926 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4927 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 4928 | did = icmd->un.elsreq64.remoteID; |
| 4929 | |
| 4930 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 4931 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4932 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4933 | "0113 An FLOGI ELS command x%x was " |
| 4934 | "received from DID x%x in Loop Mode\n", |
| 4935 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4936 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4937 | } |
| 4938 | |
| 4939 | did = Fabric_DID; |
| 4940 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 4941 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4942 | /* For a FLOGI we accept, then if our portname is greater |
| 4943 | * then the remote portname we initiate Nport login. |
| 4944 | */ |
| 4945 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4946 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4947 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4948 | |
| 4949 | if (!rc) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 4950 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 4951 | mbox = mempool_alloc(phba->mbox_mem_pool, |
| 4952 | GFP_KERNEL); |
| 4953 | if (!mbox) |
| 4954 | return 1; |
| 4955 | lpfc_linkdown(phba); |
| 4956 | lpfc_init_link(phba, mbox, |
| 4957 | phba->cfg_topology, |
| 4958 | phba->cfg_link_speed); |
| 4959 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| 4960 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4961 | mbox->vport = vport; |
| 4962 | rc = lpfc_sli_issue_mbox(phba, mbox, |
| 4963 | MBX_NOWAIT); |
| 4964 | lpfc_set_loopback_flag(phba); |
| 4965 | if (rc == MBX_NOT_FINISHED) |
| 4966 | mempool_free(mbox, phba->mbox_mem_pool); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4967 | return 1; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 4968 | } else { |
| 4969 | /* abort the flogi coming back to ourselves |
| 4970 | * due to external loopback on the port. |
| 4971 | */ |
| 4972 | lpfc_els_abort_flogi(phba); |
| 4973 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4974 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4975 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4976 | spin_lock_irq(shost->host_lock); |
| 4977 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 4978 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4979 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4980 | spin_lock_irq(shost->host_lock); |
| 4981 | vport->fc_flag |= FC_PT2PT; |
| 4982 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 4983 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4984 | } else { |
| 4985 | /* Reject this request because invalid parameters */ |
| 4986 | stat.un.b.lsRjtRsvd0 = 0; |
| 4987 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4988 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 4989 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4990 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4991 | NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4992 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4993 | } |
| 4994 | |
| 4995 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4996 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4997 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4998 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4999 | } |
| 5000 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5001 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5002 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5003 | * @vport: pointer to a host virtual N_Port data structure. |
| 5004 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5005 | * @ndlp: pointer to a node-list data structure. |
| 5006 | * |
| 5007 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 5008 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 5009 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 5010 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 5011 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 5012 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 5013 | * |
| 5014 | * Return code |
| 5015 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 5016 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5017 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5018 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5019 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5020 | { |
| 5021 | struct lpfc_dmabuf *pcmd; |
| 5022 | uint32_t *lp; |
| 5023 | IOCB_t *icmd; |
| 5024 | RNID *rn; |
| 5025 | struct ls_rjt stat; |
| 5026 | uint32_t cmd, did; |
| 5027 | |
| 5028 | icmd = &cmdiocb->iocb; |
| 5029 | did = icmd->un.elsreq64.remoteID; |
| 5030 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5031 | lp = (uint32_t *) pcmd->virt; |
| 5032 | |
| 5033 | cmd = *lp++; |
| 5034 | rn = (RNID *) lp; |
| 5035 | |
| 5036 | /* RNID received */ |
| 5037 | |
| 5038 | switch (rn->Format) { |
| 5039 | case 0: |
| 5040 | case RNID_TOPOLOGY_DISC: |
| 5041 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5042 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5043 | break; |
| 5044 | default: |
| 5045 | /* Reject this request because format not supported */ |
| 5046 | stat.un.b.lsRjtRsvd0 = 0; |
| 5047 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5048 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5049 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5050 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 5051 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5052 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5053 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5054 | } |
| 5055 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5056 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5057 | * lpfc_els_rcv_echo - Process an unsolicited echo iocb |
| 5058 | * @vport: pointer to a host virtual N_Port data structure. |
| 5059 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5060 | * @ndlp: pointer to a node-list data structure. |
| 5061 | * |
| 5062 | * Return code |
| 5063 | * 0 - Successfully processed echo iocb (currently always return 0) |
| 5064 | **/ |
| 5065 | static int |
| 5066 | lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5067 | struct lpfc_nodelist *ndlp) |
| 5068 | { |
| 5069 | uint8_t *pcmd; |
| 5070 | |
| 5071 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
| 5072 | |
| 5073 | /* skip over first word of echo command to find echo data */ |
| 5074 | pcmd += sizeof(uint32_t); |
| 5075 | |
| 5076 | lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp); |
| 5077 | return 0; |
| 5078 | } |
| 5079 | |
| 5080 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5081 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5082 | * @vport: pointer to a host virtual N_Port data structure. |
| 5083 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5084 | * @ndlp: pointer to a node-list data structure. |
| 5085 | * |
| 5086 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 5087 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 5088 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 5089 | * |
| 5090 | * Return code |
| 5091 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 5092 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5093 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5094 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5095 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5096 | { |
| 5097 | struct ls_rjt stat; |
| 5098 | |
| 5099 | /* For now, unconditionally reject this command */ |
| 5100 | stat.un.b.lsRjtRsvd0 = 0; |
| 5101 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5102 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5103 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5104 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5105 | return 0; |
| 5106 | } |
| 5107 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5108 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 5109 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb |
| 5110 | * @vport: pointer to a host virtual N_Port data structure. |
| 5111 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5112 | * @ndlp: pointer to a node-list data structure. |
| 5113 | * |
| 5114 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB |
| 5115 | * received as an ELS unsolicited event. A request to RRQ shall only |
| 5116 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder |
| 5117 | * Nx_Port N_Port_ID of the target Exchange is the same as the |
| 5118 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is |
| 5119 | * not accepted, an LS_RJT with reason code "Unable to perform |
| 5120 | * command request" and reason code explanation "Invalid Originator |
| 5121 | * S_ID" shall be returned. For now, we just unconditionally accept |
| 5122 | * RRQ from the target. |
| 5123 | **/ |
| 5124 | static void |
| 5125 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5126 | struct lpfc_nodelist *ndlp) |
| 5127 | { |
| 5128 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5129 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
| 5130 | lpfc_els_clear_rrq(vport, cmdiocb, ndlp); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 5131 | } |
| 5132 | |
| 5133 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5134 | * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd |
| 5135 | * @phba: pointer to lpfc hba data structure. |
| 5136 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 5137 | * |
| 5138 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 5139 | * mailbox command. This callback function is to actually send the Accept |
| 5140 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 5141 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 5142 | * mailbox command, constructs the RPS response with the link statistics |
| 5143 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 5144 | * response to the RPS. |
| 5145 | * |
| 5146 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5147 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5148 | * will be stored into the context1 field of the IOCB for the completion |
| 5149 | * callback function to the RPS Accept Response ELS IOCB command. |
| 5150 | * |
| 5151 | **/ |
| 5152 | static void |
| 5153 | lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 5154 | { |
| 5155 | MAILBOX_t *mb; |
| 5156 | IOCB_t *icmd; |
| 5157 | struct RLS_RSP *rls_rsp; |
| 5158 | uint8_t *pcmd; |
| 5159 | struct lpfc_iocbq *elsiocb; |
| 5160 | struct lpfc_nodelist *ndlp; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5161 | uint16_t oxid; |
| 5162 | uint16_t rxid; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5163 | uint32_t cmdsize; |
| 5164 | |
| 5165 | mb = &pmb->u.mb; |
| 5166 | |
| 5167 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5168 | rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff); |
| 5169 | oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff); |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5170 | pmb->context1 = NULL; |
| 5171 | pmb->context2 = NULL; |
| 5172 | |
| 5173 | if (mb->mbxStatus) { |
| 5174 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5175 | return; |
| 5176 | } |
| 5177 | |
| 5178 | cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t); |
| 5179 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5180 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5181 | lpfc_max_els_tries, ndlp, |
| 5182 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 5183 | |
| 5184 | /* Decrement the ndlp reference count from previous mbox command */ |
| 5185 | lpfc_nlp_put(ndlp); |
| 5186 | |
| 5187 | if (!elsiocb) |
| 5188 | return; |
| 5189 | |
| 5190 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5191 | icmd->ulpContext = rxid; |
| 5192 | icmd->unsli3.rcvsli3.ox_id = oxid; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5193 | |
| 5194 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5195 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 5196 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 5197 | rls_rsp = (struct RLS_RSP *)pcmd; |
| 5198 | |
| 5199 | rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 5200 | rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 5201 | rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 5202 | rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 5203 | rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 5204 | rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
| 5205 | |
| 5206 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 5207 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 5208 | "2874 Xmit ELS RLS ACC response tag x%x xri x%x, " |
| 5209 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 5210 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5211 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5212 | ndlp->nlp_rpi); |
| 5213 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5214 | phba->fc_stat.elsXmitACC++; |
| 5215 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 5216 | lpfc_els_free_iocb(phba, elsiocb); |
| 5217 | } |
| 5218 | |
| 5219 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5220 | * 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] | 5221 | * @phba: pointer to lpfc hba data structure. |
| 5222 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 5223 | * |
| 5224 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 5225 | * mailbox command. This callback function is to actually send the Accept |
| 5226 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 5227 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 5228 | * mailbox command, constructs the RPS response with the link statistics |
| 5229 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 5230 | * response to the RPS. |
| 5231 | * |
| 5232 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5233 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5234 | * will be stored into the context1 field of the IOCB for the completion |
| 5235 | * callback function to the RPS Accept Response ELS IOCB command. |
| 5236 | * |
| 5237 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 5238 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5239 | 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] | 5240 | { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5241 | MAILBOX_t *mb; |
| 5242 | IOCB_t *icmd; |
| 5243 | RPS_RSP *rps_rsp; |
| 5244 | uint8_t *pcmd; |
| 5245 | struct lpfc_iocbq *elsiocb; |
| 5246 | struct lpfc_nodelist *ndlp; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5247 | uint16_t status; |
| 5248 | uint16_t oxid; |
| 5249 | uint16_t rxid; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5250 | uint32_t cmdsize; |
| 5251 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5252 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5253 | |
| 5254 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5255 | rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff); |
| 5256 | oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 5257 | pmb->context1 = NULL; |
| 5258 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5259 | |
| 5260 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5261 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5262 | return; |
| 5263 | } |
| 5264 | |
| 5265 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5266 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5267 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5268 | lpfc_max_els_tries, ndlp, |
| 5269 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5270 | |
| 5271 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5272 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5273 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5274 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5275 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5276 | |
| 5277 | icmd = &elsiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5278 | icmd->ulpContext = rxid; |
| 5279 | icmd->unsli3.rcvsli3.ox_id = oxid; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5280 | |
| 5281 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5282 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5283 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5284 | rps_rsp = (RPS_RSP *)pcmd; |
| 5285 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5286 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5287 | status = 0x10; |
| 5288 | else |
| 5289 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5290 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5291 | status |= 0x4; |
| 5292 | |
| 5293 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5294 | rps_rsp->portStatus = cpu_to_be16(status); |
| 5295 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 5296 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 5297 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 5298 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 5299 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 5300 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5301 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5302 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 5303 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 5304 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 5305 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5306 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5307 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5308 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5309 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5310 | 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] | 5311 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5312 | return; |
| 5313 | } |
| 5314 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5315 | /** |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5316 | * lpfc_els_rcv_rls - Process an unsolicited rls iocb |
| 5317 | * @vport: pointer to a host virtual N_Port data structure. |
| 5318 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5319 | * @ndlp: pointer to a node-list data structure. |
| 5320 | * |
| 5321 | * This routine processes Read Port Status (RPL) IOCB received as an |
| 5322 | * ELS unsolicited event. It first checks the remote port state. If the |
| 5323 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 5324 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 5325 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 5326 | * for reading the HBA link statistics. It is for the callback function, |
| 5327 | * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 5328 | * to actually sending out RPL Accept (ACC) response. |
| 5329 | * |
| 5330 | * Return codes |
| 5331 | * 0 - Successfully processed rls iocb (currently always return 0) |
| 5332 | **/ |
| 5333 | static int |
| 5334 | lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5335 | struct lpfc_nodelist *ndlp) |
| 5336 | { |
| 5337 | struct lpfc_hba *phba = vport->phba; |
| 5338 | LPFC_MBOXQ_t *mbox; |
| 5339 | struct lpfc_dmabuf *pcmd; |
| 5340 | struct ls_rjt stat; |
| 5341 | |
| 5342 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 5343 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5344 | /* reject the unsolicited RPS request and done with it */ |
| 5345 | goto reject_out; |
| 5346 | |
| 5347 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5348 | |
| 5349 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 5350 | if (mbox) { |
| 5351 | lpfc_read_lnk_stat(phba, mbox); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5352 | mbox->context1 = (void *)((unsigned long) |
| 5353 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | |
| 5354 | cmdiocb->iocb.ulpContext)); /* rx_id */ |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5355 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 5356 | mbox->vport = vport; |
| 5357 | mbox->mbox_cmpl = lpfc_els_rsp_rls_acc; |
| 5358 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
| 5359 | != MBX_NOT_FINISHED) |
| 5360 | /* Mbox completion will send ELS Response */ |
| 5361 | return 0; |
| 5362 | /* Decrement reference count used for the failed mbox |
| 5363 | * command. |
| 5364 | */ |
| 5365 | lpfc_nlp_put(ndlp); |
| 5366 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5367 | } |
| 5368 | reject_out: |
| 5369 | /* issue rejection response */ |
| 5370 | stat.un.b.lsRjtRsvd0 = 0; |
| 5371 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5372 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5373 | stat.un.b.vendorUnique = 0; |
| 5374 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5375 | return 0; |
| 5376 | } |
| 5377 | |
| 5378 | /** |
| 5379 | * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb |
| 5380 | * @vport: pointer to a host virtual N_Port data structure. |
| 5381 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5382 | * @ndlp: pointer to a node-list data structure. |
| 5383 | * |
| 5384 | * This routine processes Read Timout Value (RTV) IOCB received as an |
| 5385 | * ELS unsolicited event. It first checks the remote port state. If the |
| 5386 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 5387 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject |
| 5388 | * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout |
| 5389 | * Value (RTV) unsolicited IOCB event. |
| 5390 | * |
| 5391 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5392 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5393 | * will be stored into the context1 field of the IOCB for the completion |
| 5394 | * callback function to the RPS Accept Response ELS IOCB command. |
| 5395 | * |
| 5396 | * Return codes |
| 5397 | * 0 - Successfully processed rtv iocb (currently always return 0) |
| 5398 | **/ |
| 5399 | static int |
| 5400 | lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5401 | struct lpfc_nodelist *ndlp) |
| 5402 | { |
| 5403 | struct lpfc_hba *phba = vport->phba; |
| 5404 | struct ls_rjt stat; |
| 5405 | struct RTV_RSP *rtv_rsp; |
| 5406 | uint8_t *pcmd; |
| 5407 | struct lpfc_iocbq *elsiocb; |
| 5408 | uint32_t cmdsize; |
| 5409 | |
| 5410 | |
| 5411 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 5412 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5413 | /* reject the unsolicited RPS request and done with it */ |
| 5414 | goto reject_out; |
| 5415 | |
| 5416 | cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t); |
| 5417 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 5418 | lpfc_max_els_tries, ndlp, |
| 5419 | ndlp->nlp_DID, ELS_CMD_ACC); |
| 5420 | |
| 5421 | if (!elsiocb) |
| 5422 | return 1; |
| 5423 | |
| 5424 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5425 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 5426 | pcmd += sizeof(uint32_t); /* Skip past command */ |
| 5427 | |
| 5428 | /* use the command's xri in the response */ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5429 | elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */ |
| 5430 | elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5431 | |
| 5432 | rtv_rsp = (struct RTV_RSP *)pcmd; |
| 5433 | |
| 5434 | /* populate RTV payload */ |
| 5435 | rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */ |
| 5436 | rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov); |
| 5437 | bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0); |
| 5438 | bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */ |
| 5439 | rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov); |
| 5440 | |
| 5441 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
| 5442 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 5443 | "2875 Xmit ELS RTV ACC response tag x%x xri x%x, " |
| 5444 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, " |
| 5445 | "Data: x%x x%x x%x\n", |
| 5446 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5447 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5448 | ndlp->nlp_rpi, |
| 5449 | rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov); |
| 5450 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| 5451 | phba->fc_stat.elsXmitACC++; |
| 5452 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
| 5453 | lpfc_els_free_iocb(phba, elsiocb); |
| 5454 | return 0; |
| 5455 | |
| 5456 | reject_out: |
| 5457 | /* issue rejection response */ |
| 5458 | stat.un.b.lsRjtRsvd0 = 0; |
| 5459 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5460 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5461 | stat.un.b.vendorUnique = 0; |
| 5462 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
| 5463 | return 0; |
| 5464 | } |
| 5465 | |
| 5466 | /* lpfc_els_rcv_rps - Process an unsolicited rps iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5467 | * @vport: pointer to a host virtual N_Port data structure. |
| 5468 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5469 | * @ndlp: pointer to a node-list data structure. |
| 5470 | * |
| 5471 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 5472 | * ELS unsolicited event. It first checks the remote port state. If the |
| 5473 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 5474 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 5475 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 5476 | * for reading the HBA link statistics. It is for the callback function, |
| 5477 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 5478 | * to actually sending out RPS Accept (ACC) response. |
| 5479 | * |
| 5480 | * Return codes |
| 5481 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 5482 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5483 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5484 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5485 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5486 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5487 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5488 | uint32_t *lp; |
| 5489 | uint8_t flag; |
| 5490 | LPFC_MBOXQ_t *mbox; |
| 5491 | struct lpfc_dmabuf *pcmd; |
| 5492 | RPS *rps; |
| 5493 | struct ls_rjt stat; |
| 5494 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5495 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5496 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 5497 | /* reject the unsolicited RPS request and done with it */ |
| 5498 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5499 | |
| 5500 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5501 | lp = (uint32_t *) pcmd->virt; |
| 5502 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 5503 | rps = (RPS *) lp; |
| 5504 | |
| 5505 | if ((flag == 0) || |
| 5506 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5507 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5508 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5509 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5510 | printk("Fix me....\n"); |
| 5511 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5512 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 5513 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5514 | lpfc_read_lnk_stat(phba, mbox); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5515 | mbox->context1 = (void *)((unsigned long) |
| 5516 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | |
| 5517 | cmdiocb->iocb.ulpContext)); /* rx_id */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5518 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5519 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5520 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5521 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5522 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5523 | /* Mbox completion will send ELS Response */ |
| 5524 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5525 | /* Decrement reference count used for the failed mbox |
| 5526 | * command. |
| 5527 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5528 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5529 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5530 | } |
| 5531 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5532 | |
| 5533 | reject_out: |
| 5534 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5535 | stat.un.b.lsRjtRsvd0 = 0; |
| 5536 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5537 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5538 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5539 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5540 | return 0; |
| 5541 | } |
| 5542 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5543 | /* lpfc_issue_els_rrq - Process an unsolicited rps iocb |
| 5544 | * @vport: pointer to a host virtual N_Port data structure. |
| 5545 | * @ndlp: pointer to a node-list data structure. |
| 5546 | * @did: DID of the target. |
| 5547 | * @rrq: Pointer to the rrq struct. |
| 5548 | * |
| 5549 | * Build a ELS RRQ command and send it to the target. If the issue_iocb is |
| 5550 | * Successful the the completion handler will clear the RRQ. |
| 5551 | * |
| 5552 | * Return codes |
| 5553 | * 0 - Successfully sent rrq els iocb. |
| 5554 | * 1 - Failed to send rrq els iocb. |
| 5555 | **/ |
| 5556 | static int |
| 5557 | lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 5558 | uint32_t did, struct lpfc_node_rrq *rrq) |
| 5559 | { |
| 5560 | struct lpfc_hba *phba = vport->phba; |
| 5561 | struct RRQ *els_rrq; |
| 5562 | IOCB_t *icmd; |
| 5563 | struct lpfc_iocbq *elsiocb; |
| 5564 | uint8_t *pcmd; |
| 5565 | uint16_t cmdsize; |
| 5566 | int ret; |
| 5567 | |
| 5568 | |
| 5569 | if (ndlp != rrq->ndlp) |
| 5570 | ndlp = rrq->ndlp; |
| 5571 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 5572 | return 1; |
| 5573 | |
| 5574 | /* If ndlp is not NULL, we will bump the reference count on it */ |
| 5575 | cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ)); |
| 5576 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did, |
| 5577 | ELS_CMD_RRQ); |
| 5578 | if (!elsiocb) |
| 5579 | return 1; |
| 5580 | |
| 5581 | icmd = &elsiocb->iocb; |
| 5582 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5583 | |
| 5584 | /* For RRQ request, remainder of payload is Exchange IDs */ |
| 5585 | *((uint32_t *) (pcmd)) = ELS_CMD_RRQ; |
| 5586 | pcmd += sizeof(uint32_t); |
| 5587 | els_rrq = (struct RRQ *) pcmd; |
| 5588 | |
| 5589 | bf_set(rrq_oxid, els_rrq, rrq->xritag); |
| 5590 | bf_set(rrq_rxid, els_rrq, rrq->rxid); |
| 5591 | bf_set(rrq_did, els_rrq, vport->fc_myDID); |
| 5592 | els_rrq->rrq = cpu_to_be32(els_rrq->rrq); |
| 5593 | els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg); |
| 5594 | |
| 5595 | |
| 5596 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 5597 | "Issue RRQ: did:x%x", |
| 5598 | did, rrq->xritag, rrq->rxid); |
| 5599 | elsiocb->context_un.rrq = rrq; |
| 5600 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq; |
| 5601 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| 5602 | |
| 5603 | if (ret == IOCB_ERROR) { |
| 5604 | lpfc_els_free_iocb(phba, elsiocb); |
| 5605 | return 1; |
| 5606 | } |
| 5607 | return 0; |
| 5608 | } |
| 5609 | |
| 5610 | /** |
| 5611 | * lpfc_send_rrq - Sends ELS RRQ if needed. |
| 5612 | * @phba: pointer to lpfc hba data structure. |
| 5613 | * @rrq: pointer to the active rrq. |
| 5614 | * |
| 5615 | * This routine will call the lpfc_issue_els_rrq if the rrq is |
| 5616 | * still active for the xri. If this function returns a failure then |
| 5617 | * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq. |
| 5618 | * |
| 5619 | * Returns 0 Success. |
| 5620 | * 1 Failure. |
| 5621 | **/ |
| 5622 | int |
| 5623 | lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq) |
| 5624 | { |
| 5625 | struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport, |
| 5626 | rrq->nlp_DID); |
| 5627 | if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag)) |
| 5628 | return lpfc_issue_els_rrq(rrq->vport, ndlp, |
| 5629 | rrq->nlp_DID, rrq); |
| 5630 | else |
| 5631 | return 1; |
| 5632 | } |
| 5633 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5634 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5635 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5636 | * @vport: pointer to a host virtual N_Port data structure. |
| 5637 | * @cmdsize: size of the ELS command. |
| 5638 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 5639 | * @ndlp: pointer to a node-list data structure. |
| 5640 | * |
| 5641 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 5642 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 5643 | * |
| 5644 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5645 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5646 | * will be stored into the context1 field of the IOCB for the completion |
| 5647 | * callback function to the RPL Accept Response ELS command. |
| 5648 | * |
| 5649 | * Return code |
| 5650 | * 0 - Successfully issued ACC RPL ELS command |
| 5651 | * 1 - Failed to issue ACC RPL ELS command |
| 5652 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 5653 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5654 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 5655 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5656 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5657 | struct lpfc_hba *phba = vport->phba; |
| 5658 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5659 | RPL_RSP rpl_rsp; |
| 5660 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5661 | uint8_t *pcmd; |
| 5662 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5663 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 5664 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5665 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5666 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5667 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5668 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5669 | icmd = &elsiocb->iocb; |
| 5670 | oldcmd = &oldiocb->iocb; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5671 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
| 5672 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5673 | |
| 5674 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5675 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5676 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5677 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 5678 | pcmd += sizeof(uint16_t); |
| 5679 | |
| 5680 | /* Setup the RPL ACC payload */ |
| 5681 | rpl_rsp.listLen = be32_to_cpu(1); |
| 5682 | rpl_rsp.index = 0; |
| 5683 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5684 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 5685 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5686 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5687 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5688 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5689 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5690 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 5691 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 5692 | "rpi x%x\n", |
| 5693 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 5694 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 5695 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5696 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5697 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5698 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 5699 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5700 | lpfc_els_free_iocb(phba, elsiocb); |
| 5701 | return 1; |
| 5702 | } |
| 5703 | return 0; |
| 5704 | } |
| 5705 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5706 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5707 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5708 | * @vport: pointer to a host virtual N_Port data structure. |
| 5709 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5710 | * @ndlp: pointer to a node-list data structure. |
| 5711 | * |
| 5712 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 5713 | * unsolicited event. It first checks the remote port state. If the remote |
| 5714 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 5715 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 5716 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 5717 | * to accept the RPL. |
| 5718 | * |
| 5719 | * Return code |
| 5720 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 5721 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5722 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5723 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5724 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5725 | { |
| 5726 | struct lpfc_dmabuf *pcmd; |
| 5727 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5728 | uint32_t maxsize; |
| 5729 | uint16_t cmdsize; |
| 5730 | RPL *rpl; |
| 5731 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5732 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5733 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 5734 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5735 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5736 | stat.un.b.lsRjtRsvd0 = 0; |
| 5737 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 5738 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 5739 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5740 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 5741 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5742 | /* rejected the unsolicited RPL request and done with it */ |
| 5743 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5744 | } |
| 5745 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5746 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5747 | lp = (uint32_t *) pcmd->virt; |
| 5748 | rpl = (RPL *) (lp + 1); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5749 | maxsize = be32_to_cpu(rpl->maxsize); |
| 5750 | |
| 5751 | /* We support only one port */ |
| 5752 | if ((rpl->index == 0) && |
| 5753 | ((maxsize == 0) || |
| 5754 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 5755 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5756 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5757 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 5758 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5759 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5760 | |
| 5761 | return 0; |
| 5762 | } |
| 5763 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5764 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5765 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5766 | * @vport: pointer to a virtual N_Port data structure. |
| 5767 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5768 | * @ndlp: pointer to a node-list data structure. |
| 5769 | * |
| 5770 | * This routine processes Fibre Channel Address Resolution Protocol |
| 5771 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 5772 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 5773 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 5774 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 5775 | * remote PortName is compared against the FC PortName stored in the @vport |
| 5776 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 5777 | * compared against the FC NodeName stored in the @vport data structure. |
| 5778 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 5779 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 5780 | * invoked to send out FARP Response to the remote node. Before sending the |
| 5781 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 5782 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 5783 | * routine is invoked to log into the remote port first. |
| 5784 | * |
| 5785 | * Return code |
| 5786 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 5787 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5788 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5789 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5790 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5791 | { |
| 5792 | struct lpfc_dmabuf *pcmd; |
| 5793 | uint32_t *lp; |
| 5794 | IOCB_t *icmd; |
| 5795 | FARP *fp; |
| 5796 | uint32_t cmd, cnt, did; |
| 5797 | |
| 5798 | icmd = &cmdiocb->iocb; |
| 5799 | did = icmd->un.elsreq64.remoteID; |
| 5800 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5801 | lp = (uint32_t *) pcmd->virt; |
| 5802 | |
| 5803 | cmd = *lp++; |
| 5804 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5805 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5806 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5807 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5808 | /* We will only support match on WWPN or WWNN */ |
| 5809 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5810 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5811 | } |
| 5812 | |
| 5813 | cnt = 0; |
| 5814 | /* If this FARP command is searching for my portname */ |
| 5815 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5816 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5817 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5818 | cnt = 1; |
| 5819 | } |
| 5820 | |
| 5821 | /* If this FARP command is searching for my nodename */ |
| 5822 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5823 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5824 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5825 | cnt = 1; |
| 5826 | } |
| 5827 | |
| 5828 | if (cnt) { |
| 5829 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 5830 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 5831 | /* Log back into the node before sending the FARP. */ |
| 5832 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5833 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5834 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 5835 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5836 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5837 | } |
| 5838 | |
| 5839 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5840 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 5841 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5842 | } |
| 5843 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5844 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5845 | } |
| 5846 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5847 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5848 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5849 | * @vport: pointer to a host virtual N_Port data structure. |
| 5850 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5851 | * @ndlp: pointer to a node-list data structure. |
| 5852 | * |
| 5853 | * This routine processes Fibre Channel Address Resolution Protocol |
| 5854 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 5855 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 5856 | * the FARP response request. |
| 5857 | * |
| 5858 | * Return code |
| 5859 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 5860 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5861 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5862 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5863 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5864 | { |
| 5865 | struct lpfc_dmabuf *pcmd; |
| 5866 | uint32_t *lp; |
| 5867 | IOCB_t *icmd; |
| 5868 | uint32_t cmd, did; |
| 5869 | |
| 5870 | icmd = &cmdiocb->iocb; |
| 5871 | did = icmd->un.elsreq64.remoteID; |
| 5872 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5873 | lp = (uint32_t *) pcmd->virt; |
| 5874 | |
| 5875 | cmd = *lp++; |
| 5876 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5877 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5878 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5879 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5880 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5881 | |
| 5882 | return 0; |
| 5883 | } |
| 5884 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5885 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5886 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5887 | * @vport: pointer to a host virtual N_Port data structure. |
| 5888 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5889 | * @fan_ndlp: pointer to a node-list data structure. |
| 5890 | * |
| 5891 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 5892 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 5893 | * only be processed on a physical port (i.e., the @vport represents the |
| 5894 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 5895 | * compared against those in the phba data structure. If any of those is |
| 5896 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 5897 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 5898 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 5899 | * is invoked to register login to the fabric. |
| 5900 | * |
| 5901 | * Return code |
| 5902 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 5903 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5904 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5905 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5906 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5907 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5908 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5909 | uint32_t *lp; |
| 5910 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5911 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5912 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 5913 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 5914 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5915 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5916 | if ((vport == phba->pport) && |
| 5917 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5918 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5919 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5920 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5921 | sizeof(struct lpfc_name)))) { |
| 5922 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5923 | lpfc_issue_init_vfi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5924 | } else { |
| 5925 | /* FAN verified - skip FLOGI */ |
| 5926 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5927 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5928 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 5929 | else { |
| 5930 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5931 | "3138 Need register VFI: (x%x/%x)\n", |
| 5932 | vport->fc_prevDID, vport->fc_myDID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5933 | lpfc_issue_reg_vfi(vport); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 5934 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5935 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5936 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5937 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5938 | } |
| 5939 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5940 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5941 | * lpfc_els_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5942 | * @ptr: holder for the timer function associated data. |
| 5943 | * |
| 5944 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 5945 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 5946 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 5947 | * up the worker thread. It is for the worker thread to invoke the routine |
| 5948 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 5949 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5950 | void |
| 5951 | lpfc_els_timeout(unsigned long ptr) |
| 5952 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5953 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 5954 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5955 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5956 | unsigned long iflag; |
| 5957 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5958 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5959 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
| 5960 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5961 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5962 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5963 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5964 | if (!tmo_posted) |
| 5965 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5966 | return; |
| 5967 | } |
| 5968 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5969 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5970 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5971 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5972 | * @vport: pointer to a virtual N_Port data structure. |
| 5973 | * |
| 5974 | * This routine is the actual handler function that processes an ELS timeout |
| 5975 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 5976 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 5977 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5978 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5979 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5980 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5981 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5982 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5983 | struct lpfc_sli_ring *pring; |
| 5984 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5985 | IOCB_t *cmd = NULL; |
| 5986 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5987 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5988 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5989 | uint32_t remote_ID = 0xffffffff; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5990 | LIST_HEAD(txcmplq_completions); |
| 5991 | LIST_HEAD(abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5992 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5993 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5994 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 5995 | |
| 5996 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5997 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5998 | spin_lock_irq(&phba->hbalock); |
| 5999 | list_splice_init(&pring->txcmplq, &txcmplq_completions); |
| 6000 | spin_unlock_irq(&phba->hbalock); |
| 6001 | |
| 6002 | list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6003 | cmd = &piocb->iocb; |
| 6004 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6005 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 6006 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 6007 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6008 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6009 | |
| 6010 | if (piocb->vport != vport) |
| 6011 | continue; |
| 6012 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6013 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6014 | if (pcmd) |
| 6015 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6016 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6017 | if (els_command == ELS_CMD_FARP || |
| 6018 | els_command == ELS_CMD_FARPR || |
| 6019 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6020 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6021 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6022 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6023 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6024 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6025 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6026 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6027 | continue; |
| 6028 | } |
| 6029 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6030 | remote_ID = 0xffffffff; |
| 6031 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6032 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6033 | else { |
| 6034 | struct lpfc_nodelist *ndlp; |
| 6035 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6036 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6037 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6038 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6039 | list_add_tail(&piocb->dlist, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6040 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6041 | spin_lock_irq(&phba->hbalock); |
| 6042 | list_splice(&txcmplq_completions, &pring->txcmplq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6043 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 6044 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 6045 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
| 6046 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6047 | "0127 ELS timeout Data: x%x x%x x%x " |
| 6048 | "x%x\n", els_command, |
| 6049 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
| 6050 | spin_lock_irq(&phba->hbalock); |
| 6051 | list_del_init(&piocb->dlist); |
| 6052 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 6053 | spin_unlock_irq(&phba->hbalock); |
| 6054 | } |
| 6055 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6056 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
| 6057 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6058 | } |
| 6059 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6060 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6061 | * 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] | 6062 | * @vport: pointer to a host virtual N_Port data structure. |
| 6063 | * |
| 6064 | * This routine is used to clean up all the outstanding ELS commands on a |
| 6065 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 6066 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 6067 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 6068 | * the IOCBs with a non-NULL completion callback function, the callback |
| 6069 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 6070 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 6071 | * callback function, the IOCB will simply be released. Finally, it walks |
| 6072 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 6073 | * completion queue IOCB that is associated with the @vport and is not |
| 6074 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 6075 | * part of the discovery state machine) out to HBA by invoking the |
| 6076 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 6077 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 6078 | * the IOCBs are aborted when this function returns. |
| 6079 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6080 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6081 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6082 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 6083 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6084 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6085 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6086 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6087 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6088 | |
| 6089 | lpfc_fabric_abort_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6090 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6091 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6092 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 6093 | cmd = &piocb->iocb; |
| 6094 | |
| 6095 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 6096 | continue; |
| 6097 | } |
| 6098 | |
| 6099 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6100 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 6101 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 6102 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 6103 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6104 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6105 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6106 | if (piocb->vport != vport) |
| 6107 | continue; |
| 6108 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 6109 | list_move_tail(&piocb->list, &completions); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6110 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6111 | } |
| 6112 | |
| 6113 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6114 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 6115 | continue; |
| 6116 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6117 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6118 | if (piocb->vport != vport) |
| 6119 | continue; |
| 6120 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 6121 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6122 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6123 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 6124 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6125 | /* Cancell all the IOCBs from the completions list */ |
| 6126 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6127 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 6128 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6129 | return; |
| 6130 | } |
| 6131 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6132 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6133 | * 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] | 6134 | * @phba: pointer to lpfc hba data structure. |
| 6135 | * |
| 6136 | * This routine is used to clean up all the outstanding ELS commands on a |
| 6137 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 6138 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 6139 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 6140 | * the IOCBs with the completion callback function associated, the callback |
| 6141 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 6142 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 6143 | * callback function associated, the IOCB will simply be released. Finally, |
| 6144 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 6145 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 6146 | * management plane IOCBs that are not part of the discovery state machine) |
| 6147 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 6148 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6149 | void |
| 6150 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 6151 | { |
| 6152 | LIST_HEAD(completions); |
| 6153 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 6154 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6155 | IOCB_t *cmd = NULL; |
| 6156 | |
| 6157 | lpfc_fabric_abort_hba(phba); |
| 6158 | spin_lock_irq(&phba->hbalock); |
| 6159 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 6160 | cmd = &piocb->iocb; |
| 6161 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 6162 | continue; |
| 6163 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
| 6164 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 6165 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 6166 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 6167 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| 6168 | continue; |
| 6169 | list_move_tail(&piocb->list, &completions); |
| 6170 | pring->txq_cnt--; |
| 6171 | } |
| 6172 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 6173 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 6174 | continue; |
| 6175 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 6176 | } |
| 6177 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6178 | |
| 6179 | /* Cancel all the IOCBs from the completions list */ |
| 6180 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6181 | IOERR_SLI_ABORTED); |
| 6182 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6183 | return; |
| 6184 | } |
| 6185 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6186 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6187 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6188 | * @phba: Pointer to hba context object. |
| 6189 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 6190 | * @rspiocbp: Pointer to response iocb which reported error. |
| 6191 | * |
| 6192 | * This function sends an event when there is an ELS command |
| 6193 | * failure. |
| 6194 | **/ |
| 6195 | void |
| 6196 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 6197 | struct lpfc_iocbq *cmdiocbp, |
| 6198 | struct lpfc_iocbq *rspiocbp) |
| 6199 | { |
| 6200 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 6201 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6202 | struct lpfc_lsrjt_event lsrjt_event; |
| 6203 | struct lpfc_fabric_event_header fabric_event; |
| 6204 | struct ls_rjt stat; |
| 6205 | struct lpfc_nodelist *ndlp; |
| 6206 | uint32_t *pcmd; |
| 6207 | |
| 6208 | ndlp = cmdiocbp->context1; |
| 6209 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 6210 | return; |
| 6211 | |
| 6212 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 6213 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 6214 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 6215 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 6216 | sizeof(struct lpfc_name)); |
| 6217 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 6218 | sizeof(struct lpfc_name)); |
| 6219 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 6220 | cmdiocbp->context2)->virt); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6221 | lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6222 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 6223 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 6224 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 6225 | fc_host_post_vendor_event(shost, |
| 6226 | fc_get_event_number(), |
| 6227 | sizeof(lsrjt_event), |
| 6228 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6229 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6230 | return; |
| 6231 | } |
| 6232 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 6233 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 6234 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 6235 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 6236 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 6237 | else |
| 6238 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 6239 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 6240 | sizeof(struct lpfc_name)); |
| 6241 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 6242 | sizeof(struct lpfc_name)); |
| 6243 | fc_host_post_vendor_event(shost, |
| 6244 | fc_get_event_number(), |
| 6245 | sizeof(fabric_event), |
| 6246 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6247 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6248 | return; |
| 6249 | } |
| 6250 | |
| 6251 | } |
| 6252 | |
| 6253 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6254 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6255 | * @vport: Pointer to vport object. |
| 6256 | * @ndlp: Pointer FC node object. |
| 6257 | * @cmd: ELS command code. |
| 6258 | * |
| 6259 | * This function posts an event when there is an incoming |
| 6260 | * unsolicited ELS command. |
| 6261 | **/ |
| 6262 | static void |
| 6263 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 6264 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6265 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6266 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6267 | struct lpfc_els_event_header *els_data = NULL; |
| 6268 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6269 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6270 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6271 | if (*payload == ELS_CMD_LOGO) { |
| 6272 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 6273 | if (!logo_data) { |
| 6274 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6275 | "0148 Failed to allocate memory " |
| 6276 | "for LOGO event\n"); |
| 6277 | return; |
| 6278 | } |
| 6279 | els_data = &logo_data->header; |
| 6280 | } else { |
| 6281 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 6282 | GFP_KERNEL); |
| 6283 | if (!els_data) { |
| 6284 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6285 | "0149 Failed to allocate memory " |
| 6286 | "for ELS event\n"); |
| 6287 | return; |
| 6288 | } |
| 6289 | } |
| 6290 | els_data->event_type = FC_REG_ELS_EVENT; |
| 6291 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6292 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6293 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6294 | break; |
| 6295 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6296 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6297 | break; |
| 6298 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6299 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 6300 | break; |
| 6301 | case ELS_CMD_LOGO: |
| 6302 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 6303 | /* Copy the WWPN in the LOGO payload */ |
| 6304 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 6305 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6306 | break; |
| 6307 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 6308 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6309 | return; |
| 6310 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6311 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 6312 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 6313 | if (*payload == ELS_CMD_LOGO) { |
| 6314 | fc_host_post_vendor_event(shost, |
| 6315 | fc_get_event_number(), |
| 6316 | sizeof(struct lpfc_logo_event), |
| 6317 | (char *)logo_data, |
| 6318 | LPFC_NL_VENDOR_ID); |
| 6319 | kfree(logo_data); |
| 6320 | } else { |
| 6321 | fc_host_post_vendor_event(shost, |
| 6322 | fc_get_event_number(), |
| 6323 | sizeof(struct lpfc_els_event_header), |
| 6324 | (char *)els_data, |
| 6325 | LPFC_NL_VENDOR_ID); |
| 6326 | kfree(els_data); |
| 6327 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6328 | |
| 6329 | return; |
| 6330 | } |
| 6331 | |
| 6332 | |
| 6333 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6334 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6335 | * @phba: pointer to lpfc hba data structure. |
| 6336 | * @pring: pointer to a SLI ring. |
| 6337 | * @vport: pointer to a host virtual N_Port data structure. |
| 6338 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 6339 | * |
| 6340 | * This routine is used for processing the IOCB associated with a unsolicited |
| 6341 | * event. It first determines whether there is an existing ndlp that matches |
| 6342 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 6343 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 6344 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 6345 | * of the discovery state machine. |
| 6346 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6347 | static void |
| 6348 | 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] | 6349 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6350 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6351 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6352 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6353 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6354 | uint32_t *payload; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6355 | uint32_t cmd, did, newnode, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6356 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6357 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6358 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6359 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6360 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6361 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6362 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 6363 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6364 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 6365 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6366 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6367 | did = icmd->un.rcvels.remoteID; |
| 6368 | if (icmd->ulpStatus) { |
| 6369 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6370 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 6371 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6372 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6373 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6374 | |
| 6375 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6376 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6377 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6378 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 6379 | /* Ignore traffic received during vport shutdown. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6380 | if (vport->load_flag & FC_UNLOADING) |
| 6381 | goto dropit; |
| 6382 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 6383 | /* If NPort discovery is delayed drop incoming ELS */ |
| 6384 | if ((vport->fc_flag & FC_DISC_DELAYED) && |
| 6385 | (cmd != ELS_CMD_PLOGI)) |
| 6386 | goto dropit; |
| 6387 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6388 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6389 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6390 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6391 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6392 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6393 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6394 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6395 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6396 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6397 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6398 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6399 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6400 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 6401 | ndlp = lpfc_enable_node(vport, ndlp, |
| 6402 | NLP_STE_UNUSED_NODE); |
| 6403 | if (!ndlp) |
| 6404 | goto dropit; |
| 6405 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 6406 | newnode = 1; |
| 6407 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 6408 | ndlp->nlp_type |= NLP_FABRIC; |
| 6409 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 6410 | /* This is similar to the new node path */ |
| 6411 | ndlp = lpfc_nlp_get(ndlp); |
| 6412 | if (!ndlp) |
| 6413 | goto dropit; |
| 6414 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 6415 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6416 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6417 | |
| 6418 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6419 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6420 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6421 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6422 | |
| 6423 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 6424 | cmd &= ELS_CMD_MASK; |
| 6425 | } |
| 6426 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6427 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6428 | "0112 ELS command x%x received from NPORT x%x " |
| 6429 | "Data: x%x\n", cmd, did, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6430 | switch (cmd) { |
| 6431 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6432 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6433 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 6434 | did, vport->port_state, ndlp->nlp_flag); |
| 6435 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6436 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6437 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
| 6438 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6439 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 6440 | |
| 6441 | /* If Nport discovery is delayed, reject PLOGIs */ |
| 6442 | if (vport->fc_flag & FC_DISC_DELAYED) { |
| 6443 | rjt_err = LSRJT_UNABLE_TPC; |
| 6444 | break; |
| 6445 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6446 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 6447 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 6448 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 6449 | rjt_err = LSRJT_UNABLE_TPC; |
| 6450 | break; |
| 6451 | } |
| 6452 | /* We get here, and drop thru, if we are PT2PT with |
| 6453 | * another NPort and the other side has initiated |
| 6454 | * the PLOGI before responding to our FLOGI. |
| 6455 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6456 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6457 | |
| 6458 | shost = lpfc_shost_from_vport(vport); |
| 6459 | spin_lock_irq(shost->host_lock); |
| 6460 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 6461 | spin_unlock_irq(shost->host_lock); |
| 6462 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6463 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 6464 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6465 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6466 | break; |
| 6467 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6468 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6469 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 6470 | did, vport->port_state, ndlp->nlp_flag); |
| 6471 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6472 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6473 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6474 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6475 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6476 | break; |
| 6477 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6478 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6479 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 6480 | did, vport->port_state, ndlp->nlp_flag); |
| 6481 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6482 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6483 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6484 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6485 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6486 | break; |
| 6487 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6488 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6489 | break; |
| 6490 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6491 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6492 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 6493 | did, vport->port_state, ndlp->nlp_flag); |
| 6494 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6495 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6496 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6497 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6498 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6499 | break; |
| 6500 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6501 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6502 | break; |
| 6503 | case ELS_CMD_RSCN: |
| 6504 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6505 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6506 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6507 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6508 | break; |
| 6509 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6510 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6511 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 6512 | did, vport->port_state, ndlp->nlp_flag); |
| 6513 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6514 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6515 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6516 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6517 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6518 | break; |
| 6519 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6520 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 6521 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6522 | break; |
| 6523 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6524 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6525 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 6526 | did, vport->port_state, ndlp->nlp_flag); |
| 6527 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6528 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6529 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6530 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6531 | break; |
| 6532 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6533 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 6534 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6535 | break; |
| 6536 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6537 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6538 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 6539 | did, vport->port_state, ndlp->nlp_flag); |
| 6540 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6541 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6542 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6543 | break; |
| 6544 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6545 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6546 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 6547 | did, vport->port_state, ndlp->nlp_flag); |
| 6548 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6549 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6550 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6551 | break; |
| 6552 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6553 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6554 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 6555 | did, vport->port_state, ndlp->nlp_flag); |
| 6556 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6557 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6558 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6559 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6560 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6561 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6562 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 6563 | did, vport->port_state, ndlp->nlp_flag); |
| 6564 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6565 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6566 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6567 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6568 | break; |
| 6569 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6570 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6571 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6572 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6573 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6574 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 6575 | did, vport->port_state, ndlp->nlp_flag); |
| 6576 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6577 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6578 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6579 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6580 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6581 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6582 | case ELS_CMD_RLS: |
| 6583 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6584 | "RCV RLS: did:x%x/ste:x%x flg:x%x", |
| 6585 | did, vport->port_state, ndlp->nlp_flag); |
| 6586 | |
| 6587 | phba->fc_stat.elsRcvRLS++; |
| 6588 | lpfc_els_rcv_rls(vport, elsiocb, ndlp); |
| 6589 | if (newnode) |
| 6590 | lpfc_nlp_put(ndlp); |
| 6591 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6592 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6593 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6594 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 6595 | did, vport->port_state, ndlp->nlp_flag); |
| 6596 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6597 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6598 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6599 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6600 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6601 | break; |
| 6602 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6603 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6604 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 6605 | did, vport->port_state, ndlp->nlp_flag); |
| 6606 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6607 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6608 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6609 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6610 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6611 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6612 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6613 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6614 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 6615 | did, vport->port_state, ndlp->nlp_flag); |
| 6616 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6617 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6618 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6619 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6620 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6621 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6622 | case ELS_CMD_RTV: |
| 6623 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6624 | "RCV RTV: did:x%x/ste:x%x flg:x%x", |
| 6625 | did, vport->port_state, ndlp->nlp_flag); |
| 6626 | phba->fc_stat.elsRcvRTV++; |
| 6627 | lpfc_els_rcv_rtv(vport, elsiocb, ndlp); |
| 6628 | if (newnode) |
| 6629 | lpfc_nlp_put(ndlp); |
| 6630 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6631 | case ELS_CMD_RRQ: |
| 6632 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6633 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", |
| 6634 | did, vport->port_state, ndlp->nlp_flag); |
| 6635 | |
| 6636 | phba->fc_stat.elsRcvRRQ++; |
| 6637 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); |
| 6638 | if (newnode) |
| 6639 | lpfc_nlp_put(ndlp); |
| 6640 | break; |
James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6641 | case ELS_CMD_ECHO: |
| 6642 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6643 | "RCV ECHO: did:x%x/ste:x%x flg:x%x", |
| 6644 | did, vport->port_state, ndlp->nlp_flag); |
| 6645 | |
| 6646 | phba->fc_stat.elsRcvECHO++; |
| 6647 | lpfc_els_rcv_echo(vport, elsiocb, ndlp); |
| 6648 | if (newnode) |
| 6649 | lpfc_nlp_put(ndlp); |
| 6650 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6651 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6652 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 6653 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 6654 | cmd, did, vport->port_state); |
| 6655 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6656 | /* Unsupported ELS command, reject */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6657 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6658 | |
| 6659 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6660 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6661 | "0115 Unknown ELS command x%x " |
| 6662 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6663 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6664 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6665 | break; |
| 6666 | } |
| 6667 | |
| 6668 | /* check if need to LS_RJT received ELS cmd */ |
| 6669 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6670 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6671 | stat.un.b.lsRjtRsnCode = rjt_err; |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 6672 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6673 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 6674 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6675 | } |
| 6676 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6677 | lpfc_nlp_put(elsiocb->context1); |
| 6678 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6679 | return; |
| 6680 | |
| 6681 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6682 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6683 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6684 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6685 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6686 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6687 | phba->fc_stat.elsRcvDrop++; |
| 6688 | } |
| 6689 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6690 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6691 | * 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] | 6692 | * @phba: pointer to lpfc hba data structure. |
| 6693 | * @pring: pointer to a SLI ring. |
| 6694 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 6695 | * |
| 6696 | * This routine is used to process an unsolicited event received from a SLI |
| 6697 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 6698 | * associated with the unsolicited event is done by invoking the routine |
| 6699 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 6700 | * SLI ring on which the unsolicited event was received. |
| 6701 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6702 | void |
| 6703 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 6704 | struct lpfc_iocbq *elsiocb) |
| 6705 | { |
| 6706 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6707 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6708 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6709 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 6710 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6711 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6712 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6713 | elsiocb->context2 = NULL; |
| 6714 | elsiocb->context3 = NULL; |
| 6715 | |
| 6716 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 6717 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 6718 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 6719 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6720 | phba->fc_stat.NoRcvBuf++; |
| 6721 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6722 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 6723 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6724 | return; |
| 6725 | } |
| 6726 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6727 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 6728 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 6729 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 6730 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 6731 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6732 | else |
| 6733 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6734 | icmd->unsli3.rcvsli3.vpi); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6735 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6736 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6737 | /* If there are no BDEs associated |
| 6738 | * with this IOCB, there is nothing to do. |
| 6739 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6740 | if (icmd->ulpBdeCount == 0) |
| 6741 | return; |
| 6742 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6743 | /* type of ELS cmd is first 32bit word |
| 6744 | * in packet |
| 6745 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6746 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6747 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6748 | } else { |
| 6749 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 6750 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6751 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 6752 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6753 | } |
| 6754 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6755 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 6756 | /* |
| 6757 | * The different unsolicited event handlers would tell us |
| 6758 | * if they are done with "mp" by setting context2 to NULL. |
| 6759 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6760 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6761 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 6762 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6763 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6764 | |
| 6765 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6766 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6767 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6768 | elsiocb->context2 = bdeBuf2; |
| 6769 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6770 | /* free mp if we are done with it */ |
| 6771 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6772 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 6773 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6774 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6775 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6776 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6777 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6778 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6779 | * 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] | 6780 | * @phba: pointer to lpfc hba data structure. |
| 6781 | * @vport: pointer to a virtual N_Port data structure. |
| 6782 | * |
| 6783 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 6784 | * State Change Request (SCR) for a @vport. This routine will create an |
| 6785 | * ndlp for the Name Server associated to the @vport if such node does |
| 6786 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 6787 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 6788 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 6789 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 6790 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6791 | void |
| 6792 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 6793 | { |
| 6794 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 6795 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6796 | |
| 6797 | /* |
| 6798 | * If lpfc_delay_discovery parameter is set and the clean address |
| 6799 | * bit is cleared and fc fabric parameters chenged, delay FC NPort |
| 6800 | * discovery. |
| 6801 | */ |
| 6802 | spin_lock_irq(shost->host_lock); |
| 6803 | if (vport->fc_flag & FC_DISC_DELAYED) { |
| 6804 | spin_unlock_irq(shost->host_lock); |
| 6805 | mod_timer(&vport->delayed_disc_tmo, |
| 6806 | jiffies + HZ * phba->fc_ratov); |
| 6807 | return; |
| 6808 | } |
| 6809 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6810 | |
| 6811 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 6812 | if (!ndlp) { |
| 6813 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 6814 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6815 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6816 | lpfc_disc_start(vport); |
| 6817 | return; |
| 6818 | } |
| 6819 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6820 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6821 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6822 | return; |
| 6823 | } |
| 6824 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6825 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 6826 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 6827 | if (!ndlp) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6828 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6829 | lpfc_disc_start(vport); |
| 6830 | return; |
| 6831 | } |
| 6832 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6833 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6834 | "0348 NameServer login: node freed\n"); |
| 6835 | return; |
| 6836 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6837 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6838 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6839 | |
| 6840 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 6841 | |
| 6842 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 6843 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6844 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6845 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6846 | return; |
| 6847 | } |
| 6848 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6849 | if (vport->cfg_fdmi_on) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6850 | /* If this is the first time, allocate an ndlp and initialize |
| 6851 | * it. Otherwise, make sure the node is enabled and then do the |
| 6852 | * login. |
| 6853 | */ |
| 6854 | ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID); |
| 6855 | if (!ndlp_fdmi) { |
| 6856 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 6857 | GFP_KERNEL); |
| 6858 | if (ndlp_fdmi) { |
| 6859 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 6860 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
| 6861 | } else |
| 6862 | return; |
| 6863 | } |
| 6864 | if (!NLP_CHK_NODE_ACT(ndlp_fdmi)) |
| 6865 | ndlp_fdmi = lpfc_enable_node(vport, |
| 6866 | ndlp_fdmi, |
| 6867 | NLP_STE_NPR_NODE); |
| 6868 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6869 | if (ndlp_fdmi) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6870 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6871 | NLP_STE_PLOGI_ISSUE); |
| 6872 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6873 | } |
| 6874 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6875 | } |
| 6876 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6877 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6878 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6879 | * @phba: pointer to lpfc hba data structure. |
| 6880 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 6881 | * |
| 6882 | * This routine is the completion callback function to register new vport |
| 6883 | * mailbox command. If the new vport mailbox command completes successfully, |
| 6884 | * the fabric registration login shall be performed on physical port (the |
| 6885 | * new vport created is actually a physical port, with VPI 0) or the port |
| 6886 | * login to Name Server for State Change Request (SCR) will be performed |
| 6887 | * on virtual port (real virtual port, with VPI greater than 0). |
| 6888 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6889 | static void |
| 6890 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6891 | { |
| 6892 | struct lpfc_vport *vport = pmb->vport; |
| 6893 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6894 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6895 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6896 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6897 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6898 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6899 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6900 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6901 | |
| 6902 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6903 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6904 | "0915 Register VPI failed : Status: x%x" |
| 6905 | " upd bit: x%x \n", mb->mbxStatus, |
| 6906 | mb->un.varRegVpi.upd); |
| 6907 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 6908 | mb->un.varRegVpi.upd) |
| 6909 | goto mbox_err_exit ; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6910 | |
| 6911 | switch (mb->mbxStatus) { |
| 6912 | case 0x11: /* unsupported feature */ |
| 6913 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6914 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6915 | /* giving up on vport registration */ |
| 6916 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6917 | spin_lock_irq(shost->host_lock); |
| 6918 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 6919 | spin_unlock_irq(shost->host_lock); |
| 6920 | lpfc_can_disctmo(vport); |
| 6921 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6922 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
| 6923 | case 0x20: |
| 6924 | spin_lock_irq(shost->host_lock); |
| 6925 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 6926 | spin_unlock_irq(shost->host_lock); |
| 6927 | lpfc_init_vpi(phba, pmb, vport->vpi); |
| 6928 | pmb->vport = vport; |
| 6929 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 6930 | rc = lpfc_sli_issue_mbox(phba, pmb, |
| 6931 | MBX_NOWAIT); |
| 6932 | if (rc == MBX_NOT_FINISHED) { |
| 6933 | lpfc_printf_vlog(vport, |
| 6934 | KERN_ERR, LOG_MBOX, |
| 6935 | "2732 Failed to issue INIT_VPI" |
| 6936 | " mailbox command\n"); |
| 6937 | } else { |
| 6938 | lpfc_nlp_put(ndlp); |
| 6939 | return; |
| 6940 | } |
| 6941 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6942 | default: |
| 6943 | /* Try to recover from this error */ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 6944 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6945 | lpfc_sli4_unreg_all_rpis(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6946 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6947 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6948 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6949 | spin_unlock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6950 | if (vport->port_type == LPFC_PHYSICAL_PORT |
| 6951 | && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6952 | lpfc_issue_init_vfi(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6953 | else |
| 6954 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6955 | break; |
| 6956 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6957 | } else { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6958 | spin_lock_irq(shost->host_lock); |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 6959 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6960 | spin_unlock_irq(shost->host_lock); |
| 6961 | if (vport == phba->pport) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6962 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 6963 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6964 | else { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6965 | /* |
| 6966 | * If the physical port is instantiated using |
| 6967 | * FDISC, do not start vport discovery. |
| 6968 | */ |
| 6969 | if (vport->port_state != LPFC_FDISC) |
| 6970 | lpfc_start_fdiscs(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6971 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6972 | } |
| 6973 | } else |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6974 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6975 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6976 | mbox_err_exit: |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6977 | /* Now, we decrement the ndlp reference count held for this |
| 6978 | * callback function |
| 6979 | */ |
| 6980 | lpfc_nlp_put(ndlp); |
| 6981 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6982 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6983 | return; |
| 6984 | } |
| 6985 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6986 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6987 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6988 | * @phba: pointer to lpfc hba data structure. |
| 6989 | * @vport: pointer to a host virtual N_Port data structure. |
| 6990 | * @ndlp: pointer to a node-list data structure. |
| 6991 | * |
| 6992 | * This routine registers the @vport as a new virtual port with a HBA. |
| 6993 | * It is done through a registering vpi mailbox command. |
| 6994 | **/ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6995 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6996 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 6997 | struct lpfc_nodelist *ndlp) |
| 6998 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6999 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7000 | LPFC_MBOXQ_t *mbox; |
| 7001 | |
| 7002 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7003 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7004 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7005 | mbox->vport = vport; |
| 7006 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 7007 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 7008 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7009 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 7010 | /* mailbox command not success, decrement ndlp |
| 7011 | * reference count for this command |
| 7012 | */ |
| 7013 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7014 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7015 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7016 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 7017 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 7018 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7019 | } |
| 7020 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7021 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 7022 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 7023 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7024 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 7025 | return; |
| 7026 | |
| 7027 | mbox_err_exit: |
| 7028 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 7029 | spin_lock_irq(shost->host_lock); |
| 7030 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 7031 | spin_unlock_irq(shost->host_lock); |
| 7032 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7033 | } |
| 7034 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7035 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7036 | * 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] | 7037 | * @phba: pointer to lpfc hba data structure. |
| 7038 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7039 | * This routine cancels the retry delay timers to all the vports. |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7040 | **/ |
| 7041 | void |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7042 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7043 | { |
| 7044 | struct lpfc_vport **vports; |
| 7045 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7046 | uint32_t link_state; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7047 | int i; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7048 | |
| 7049 | /* Treat this failure as linkdown for all vports */ |
| 7050 | link_state = phba->link_state; |
| 7051 | lpfc_linkdown(phba); |
| 7052 | phba->link_state = link_state; |
| 7053 | |
| 7054 | vports = lpfc_create_vport_work_array(phba); |
| 7055 | |
| 7056 | if (vports) { |
| 7057 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 7058 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 7059 | if (ndlp) |
| 7060 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
| 7061 | lpfc_els_flush_cmd(vports[i]); |
| 7062 | } |
| 7063 | lpfc_destroy_vport_work_array(phba, vports); |
| 7064 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7065 | } |
| 7066 | |
| 7067 | /** |
| 7068 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. |
| 7069 | * @phba: pointer to lpfc hba data structure. |
| 7070 | * |
| 7071 | * This routine abort all pending discovery commands and |
| 7072 | * start a timer to retry FLOGI for the physical port |
| 7073 | * discovery. |
| 7074 | **/ |
| 7075 | void |
| 7076 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) |
| 7077 | { |
| 7078 | struct lpfc_nodelist *ndlp; |
| 7079 | struct Scsi_Host *shost; |
| 7080 | |
| 7081 | /* Cancel the all vports retry delay retry timers */ |
| 7082 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7083 | |
| 7084 | /* If fabric require FLOGI, then re-instantiate physical login */ |
| 7085 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 7086 | if (!ndlp) |
| 7087 | return; |
| 7088 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7089 | shost = lpfc_shost_from_vport(phba->pport); |
| 7090 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); |
| 7091 | spin_lock_irq(shost->host_lock); |
| 7092 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 7093 | spin_unlock_irq(shost->host_lock); |
| 7094 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; |
| 7095 | phba->pport->port_state = LPFC_FLOGI; |
| 7096 | return; |
| 7097 | } |
| 7098 | |
| 7099 | /** |
| 7100 | * lpfc_fabric_login_reqd - Check if FLOGI required. |
| 7101 | * @phba: pointer to lpfc hba data structure. |
| 7102 | * @cmdiocb: pointer to FDISC command iocb. |
| 7103 | * @rspiocb: pointer to FDISC response iocb. |
| 7104 | * |
| 7105 | * This routine checks if a FLOGI is reguired for FDISC |
| 7106 | * to succeed. |
| 7107 | **/ |
| 7108 | static int |
| 7109 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, |
| 7110 | struct lpfc_iocbq *cmdiocb, |
| 7111 | struct lpfc_iocbq *rspiocb) |
| 7112 | { |
| 7113 | |
| 7114 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || |
| 7115 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) |
| 7116 | return 0; |
| 7117 | else |
| 7118 | return 1; |
| 7119 | } |
| 7120 | |
| 7121 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7122 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7123 | * @phba: pointer to lpfc hba data structure. |
| 7124 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7125 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 7126 | * |
| 7127 | * This routine is the completion callback function to a Fabric Discover |
| 7128 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 7129 | * single threaded, each FDISC completion callback function will reset |
| 7130 | * the discovery timer for all vports such that the timers will not get |
| 7131 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 7132 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 7133 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 7134 | * assigned to the vport has been changed with the completion of the FDISC |
| 7135 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 7136 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 7137 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 7138 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 7139 | * Server for State Change Request (SCR). |
| 7140 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7141 | static void |
| 7142 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 7143 | struct lpfc_iocbq *rspiocb) |
| 7144 | { |
| 7145 | struct lpfc_vport *vport = cmdiocb->vport; |
| 7146 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7147 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 7148 | struct lpfc_nodelist *np; |
| 7149 | struct lpfc_nodelist *next_np; |
| 7150 | IOCB_t *irsp = &rspiocb->iocb; |
| 7151 | struct lpfc_iocbq *piocb; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7152 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 7153 | struct serv_parm *sp; |
| 7154 | uint8_t fabric_param_changed; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7155 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7156 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7157 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 7158 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 7159 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7160 | /* Since all FDISCs are being single threaded, we |
| 7161 | * must reset the discovery timer for ALL vports |
| 7162 | * waiting to send FDISC when one completes. |
| 7163 | */ |
| 7164 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 7165 | lpfc_set_disctmo(piocb->vport); |
| 7166 | } |
| 7167 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7168 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 7169 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 7170 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 7171 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7172 | if (irsp->ulpStatus) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7173 | |
| 7174 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { |
| 7175 | lpfc_retry_pport_discovery(phba); |
| 7176 | goto out; |
| 7177 | } |
| 7178 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7179 | /* Check for retry */ |
| 7180 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 7181 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7182 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7183 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7184 | "0126 FDISC failed. (x%x/x%x)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7185 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7186 | goto fdisc_failed; |
| 7187 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7188 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7189 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 7190 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7191 | vport->fc_flag |= FC_FABRIC; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7192 | if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7193 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 7194 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7195 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7196 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 7197 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7198 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 7199 | sp = prsp->virt + sizeof(uint32_t); |
| 7200 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); |
| 7201 | memcpy(&vport->fabric_portname, &sp->portName, |
| 7202 | sizeof(struct lpfc_name)); |
| 7203 | memcpy(&vport->fabric_nodename, &sp->nodeName, |
| 7204 | sizeof(struct lpfc_name)); |
| 7205 | if (fabric_param_changed && |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7206 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 7207 | /* If our NportID changed, we need to ensure all |
| 7208 | * remaining NPORTs get unreg_login'ed so we can |
| 7209 | * issue unreg_vpi. |
| 7210 | */ |
| 7211 | list_for_each_entry_safe(np, next_np, |
| 7212 | &vport->fc_nodes, nlp_listp) { |
| 7213 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 7214 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 7215 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 7216 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7217 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7218 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7219 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7220 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7221 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 7222 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 7223 | |
| 7224 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7225 | lpfc_sli4_unreg_all_rpis(vport); |
| 7226 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7227 | lpfc_mbx_unreg_vpi(vport); |
| 7228 | spin_lock_irq(shost->host_lock); |
| 7229 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7230 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7231 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 7232 | else |
| 7233 | vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7234 | spin_unlock_irq(shost->host_lock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 7235 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 7236 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 7237 | /* |
| 7238 | * Driver needs to re-reg VPI in order for f/w |
| 7239 | * to update the MAC address. |
| 7240 | */ |
| 7241 | lpfc_register_new_vport(phba, vport, ndlp); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 7242 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7243 | } |
| 7244 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 7245 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
| 7246 | lpfc_issue_init_vpi(vport); |
| 7247 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7248 | lpfc_register_new_vport(phba, vport, ndlp); |
| 7249 | else |
| 7250 | lpfc_do_scr_ns_plogi(phba, vport); |
| 7251 | goto out; |
| 7252 | fdisc_failed: |
| 7253 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 7254 | /* Cancel discovery timer */ |
| 7255 | lpfc_can_disctmo(vport); |
| 7256 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7257 | out: |
| 7258 | lpfc_els_free_iocb(phba, cmdiocb); |
| 7259 | } |
| 7260 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7261 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7262 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7263 | * @vport: pointer to a virtual N_Port data structure. |
| 7264 | * @ndlp: pointer to a node-list data structure. |
| 7265 | * @retry: number of retries to the command IOCB. |
| 7266 | * |
| 7267 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 7268 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 7269 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 7270 | * IOCB will be sent off HBA at any given time. |
| 7271 | * |
| 7272 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 7273 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 7274 | * will be stored into the context1 field of the IOCB for the completion |
| 7275 | * callback function to the FDISC ELS command. |
| 7276 | * |
| 7277 | * Return code |
| 7278 | * 0 - Successfully issued fdisc iocb command |
| 7279 | * 1 - Failed to issue fdisc iocb command |
| 7280 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 7281 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7282 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 7283 | uint8_t retry) |
| 7284 | { |
| 7285 | struct lpfc_hba *phba = vport->phba; |
| 7286 | IOCB_t *icmd; |
| 7287 | struct lpfc_iocbq *elsiocb; |
| 7288 | struct serv_parm *sp; |
| 7289 | uint8_t *pcmd; |
| 7290 | uint16_t cmdsize; |
| 7291 | int did = ndlp->nlp_DID; |
| 7292 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7293 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7294 | vport->port_state = LPFC_FDISC; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7295 | vport->fc_myDID = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7296 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 7297 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 7298 | ELS_CMD_FDISC); |
| 7299 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7300 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7301 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7302 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7303 | return 1; |
| 7304 | } |
| 7305 | |
| 7306 | icmd = &elsiocb->iocb; |
| 7307 | icmd->un.elsreq64.myID = 0; |
| 7308 | icmd->un.elsreq64.fl = 1; |
| 7309 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7310 | /* |
| 7311 | * SLI3 ports require a different context type value than SLI4. |
| 7312 | * Catch SLI3 ports here and override the prep. |
| 7313 | */ |
| 7314 | if (phba->sli_rev == LPFC_SLI_REV3) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7315 | icmd->ulpCt_h = 1; |
| 7316 | icmd->ulpCt_l = 0; |
| 7317 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7318 | |
| 7319 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 7320 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 7321 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 7322 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 7323 | sp = (struct serv_parm *) pcmd; |
| 7324 | /* Setup CSPs accordingly for Fabric */ |
| 7325 | sp->cmn.e_d_tov = 0; |
| 7326 | sp->cmn.w2.r_a_tov = 0; |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 7327 | sp->cmn.virtual_fabric_support = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7328 | sp->cls1.classValid = 0; |
| 7329 | sp->cls2.seqDelivery = 1; |
| 7330 | sp->cls3.seqDelivery = 1; |
| 7331 | |
| 7332 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 7333 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 7334 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 7335 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 7336 | memcpy(pcmd, &vport->fc_portname, 8); |
| 7337 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 7338 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 7339 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 7340 | |
| 7341 | lpfc_set_disctmo(vport); |
| 7342 | |
| 7343 | phba->fc_stat.elsXmitFDISC++; |
| 7344 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 7345 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7346 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 7347 | "Issue FDISC: did:x%x", |
| 7348 | did, 0, 0); |
| 7349 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7350 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 7351 | if (rc == IOCB_ERROR) { |
| 7352 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7353 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7354 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 7355 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7356 | return 1; |
| 7357 | } |
| 7358 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7359 | return 0; |
| 7360 | } |
| 7361 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7362 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7363 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7364 | * @phba: pointer to lpfc hba data structure. |
| 7365 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7366 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 7367 | * |
| 7368 | * This routine is the completion callback function to the issuing of a LOGO |
| 7369 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 7370 | * reference count held on ndlp for this completion function, indicating that |
| 7371 | * the reference to the ndlp is no long needed. Note that the |
| 7372 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 7373 | * callback function and an additional explicit ndlp reference decrementation |
| 7374 | * will trigger the actual release of the ndlp. |
| 7375 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7376 | static void |
| 7377 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 7378 | struct lpfc_iocbq *rspiocb) |
| 7379 | { |
| 7380 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7381 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7382 | struct lpfc_nodelist *ndlp; |
James Smart | 9589b06 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 7383 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7384 | |
James Smart | 9589b06 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 7385 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7386 | irsp = &rspiocb->iocb; |
| 7387 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 7388 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 7389 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7390 | |
| 7391 | lpfc_els_free_iocb(phba, cmdiocb); |
| 7392 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7393 | |
| 7394 | /* Trigger the release of the ndlp after logo */ |
| 7395 | lpfc_nlp_put(ndlp); |
James Smart | 9589b06 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 7396 | |
| 7397 | /* NPIV LOGO completes to NPort <nlp_DID> */ |
| 7398 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 7399 | "2928 NPIV LOGO completes to NPort x%x " |
| 7400 | "Data: x%x x%x x%x x%x\n", |
| 7401 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 7402 | irsp->ulpTimeout, vport->num_disc_nodes); |
| 7403 | |
| 7404 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
| 7405 | spin_lock_irq(shost->host_lock); |
| 7406 | vport->fc_flag &= ~FC_FABRIC; |
| 7407 | spin_unlock_irq(shost->host_lock); |
| 7408 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7409 | } |
| 7410 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7411 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7412 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7413 | * @vport: pointer to a virtual N_Port data structure. |
| 7414 | * @ndlp: pointer to a node-list data structure. |
| 7415 | * |
| 7416 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 7417 | * |
| 7418 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 7419 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 7420 | * will be stored into the context1 field of the IOCB for the completion |
| 7421 | * callback function to the LOGO ELS command. |
| 7422 | * |
| 7423 | * Return codes |
| 7424 | * 0 - Successfully issued logo off the @vport |
| 7425 | * 1 - Failed to issue logo off the @vport |
| 7426 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7427 | int |
| 7428 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 7429 | { |
| 7430 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 7431 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7432 | IOCB_t *icmd; |
| 7433 | struct lpfc_iocbq *elsiocb; |
| 7434 | uint8_t *pcmd; |
| 7435 | uint16_t cmdsize; |
| 7436 | |
| 7437 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 7438 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 7439 | ELS_CMD_LOGO); |
| 7440 | if (!elsiocb) |
| 7441 | return 1; |
| 7442 | |
| 7443 | icmd = &elsiocb->iocb; |
| 7444 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 7445 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 7446 | pcmd += sizeof(uint32_t); |
| 7447 | |
| 7448 | /* Fill in LOGO payload */ |
| 7449 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 7450 | pcmd += sizeof(uint32_t); |
| 7451 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 7452 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7453 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 7454 | "Issue LOGO npiv did:x%x flg:x%x", |
| 7455 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 7456 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7457 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 7458 | spin_lock_irq(shost->host_lock); |
| 7459 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 7460 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7461 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 7462 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7463 | spin_lock_irq(shost->host_lock); |
| 7464 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 7465 | spin_unlock_irq(shost->host_lock); |
| 7466 | lpfc_els_free_iocb(phba, elsiocb); |
| 7467 | return 1; |
| 7468 | } |
| 7469 | return 0; |
| 7470 | } |
| 7471 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7472 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7473 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7474 | * @ptr: holder for the timer function associated data. |
| 7475 | * |
| 7476 | * This routine is invoked by the fabric iocb block timer after |
| 7477 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 7478 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 7479 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 7480 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 7481 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 7482 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7483 | void |
| 7484 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 7485 | { |
| 7486 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 7487 | unsigned long iflags; |
| 7488 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7489 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7490 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 7491 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 7492 | if (!tmo_posted) |
| 7493 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 7494 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 7495 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7496 | if (!tmo_posted) |
| 7497 | lpfc_worker_wake_up(phba); |
| 7498 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7499 | } |
| 7500 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7501 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7502 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7503 | * @phba: pointer to lpfc hba data structure. |
| 7504 | * |
| 7505 | * This routine issues one fabric iocb from the driver internal list to |
| 7506 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 7507 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 7508 | * remove one pending fabric iocb from the driver internal list and invokes |
| 7509 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 7510 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7511 | static void |
| 7512 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 7513 | { |
| 7514 | struct lpfc_iocbq *iocb; |
| 7515 | unsigned long iflags; |
| 7516 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7517 | IOCB_t *cmd; |
| 7518 | |
| 7519 | repeat: |
| 7520 | iocb = NULL; |
| 7521 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7522 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7523 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 7524 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 7525 | list); |
| 7526 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7527 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7528 | atomic_inc(&phba->fabric_iocb_count); |
| 7529 | } |
| 7530 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7531 | if (iocb) { |
| 7532 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 7533 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 7534 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 7535 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7536 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 7537 | "Fabric sched1: ste:x%x", |
| 7538 | iocb->vport->port_state, 0, 0); |
| 7539 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7540 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7541 | |
| 7542 | if (ret == IOCB_ERROR) { |
| 7543 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 7544 | iocb->fabric_iocb_cmpl = NULL; |
| 7545 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 7546 | cmd = &iocb->iocb; |
| 7547 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 7548 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 7549 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 7550 | |
| 7551 | atomic_dec(&phba->fabric_iocb_count); |
| 7552 | goto repeat; |
| 7553 | } |
| 7554 | } |
| 7555 | |
| 7556 | return; |
| 7557 | } |
| 7558 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7559 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7560 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7561 | * @phba: pointer to lpfc hba data structure. |
| 7562 | * |
| 7563 | * This routine unblocks the issuing fabric iocb command. The function |
| 7564 | * will clear the fabric iocb block bit and then invoke the routine |
| 7565 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 7566 | * from the driver internal fabric iocb list. |
| 7567 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7568 | void |
| 7569 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 7570 | { |
| 7571 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 7572 | |
| 7573 | lpfc_resume_fabric_iocbs(phba); |
| 7574 | return; |
| 7575 | } |
| 7576 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7577 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7578 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7579 | * @phba: pointer to lpfc hba data structure. |
| 7580 | * |
| 7581 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 7582 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 7583 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 7584 | * fabric iocb will be issued out of the HBA. |
| 7585 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7586 | static void |
| 7587 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 7588 | { |
| 7589 | int blocked; |
| 7590 | |
| 7591 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7592 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7593 | if (!blocked) |
| 7594 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); |
| 7595 | |
| 7596 | return; |
| 7597 | } |
| 7598 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7599 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7600 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7601 | * @phba: pointer to lpfc hba data structure. |
| 7602 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 7603 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 7604 | * |
| 7605 | * This routine is the callback function that is put to the fabric iocb's |
| 7606 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 7607 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 7608 | * function first restores and invokes the original iocb's callback function |
| 7609 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 7610 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 7611 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7612 | static void |
| 7613 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 7614 | struct lpfc_iocbq *rspiocb) |
| 7615 | { |
| 7616 | struct ls_rjt stat; |
| 7617 | |
| 7618 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 7619 | BUG(); |
| 7620 | |
| 7621 | switch (rspiocb->iocb.ulpStatus) { |
| 7622 | case IOSTAT_NPORT_RJT: |
| 7623 | case IOSTAT_FABRIC_RJT: |
| 7624 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 7625 | lpfc_block_fabric_iocbs(phba); |
| 7626 | } |
| 7627 | break; |
| 7628 | |
| 7629 | case IOSTAT_NPORT_BSY: |
| 7630 | case IOSTAT_FABRIC_BSY: |
| 7631 | lpfc_block_fabric_iocbs(phba); |
| 7632 | break; |
| 7633 | |
| 7634 | case IOSTAT_LS_RJT: |
| 7635 | stat.un.lsRjtError = |
| 7636 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 7637 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 7638 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 7639 | lpfc_block_fabric_iocbs(phba); |
| 7640 | break; |
| 7641 | } |
| 7642 | |
| 7643 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 7644 | BUG(); |
| 7645 | |
| 7646 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 7647 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 7648 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 7649 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 7650 | |
| 7651 | atomic_dec(&phba->fabric_iocb_count); |
| 7652 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7653 | /* Post any pending iocbs to HBA */ |
| 7654 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7655 | } |
| 7656 | } |
| 7657 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7658 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7659 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7660 | * @phba: pointer to lpfc hba data structure. |
| 7661 | * @iocb: pointer to lpfc command iocb data structure. |
| 7662 | * |
| 7663 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 7664 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 7665 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 7666 | * any given time. As such, this function will first check to see whether there |
| 7667 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 7668 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 7669 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 7670 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 7671 | * |
| 7672 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 7673 | * order. The problem is caused by the construction of the "ready" boolen does |
| 7674 | * not include the condition that the internal fabric IOCB list is empty. As |
| 7675 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 7676 | * ahead of the fabric IOCBs in the internal list. |
| 7677 | * |
| 7678 | * Return code |
| 7679 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 7680 | * IOCB_ERROR - failed to issue fabric iocb |
| 7681 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 7682 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7683 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 7684 | { |
| 7685 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7686 | int ready; |
| 7687 | int ret; |
| 7688 | |
| 7689 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 7690 | BUG(); |
| 7691 | |
| 7692 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7693 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 7694 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 7695 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7696 | if (ready) |
| 7697 | /* Increment fabric iocb count to hold the position */ |
| 7698 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7699 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7700 | if (ready) { |
| 7701 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 7702 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 7703 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 7704 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7705 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 7706 | "Fabric sched2: ste:x%x", |
| 7707 | iocb->vport->port_state, 0, 0); |
| 7708 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7709 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7710 | |
| 7711 | if (ret == IOCB_ERROR) { |
| 7712 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 7713 | iocb->fabric_iocb_cmpl = NULL; |
| 7714 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 7715 | atomic_dec(&phba->fabric_iocb_count); |
| 7716 | } |
| 7717 | } else { |
| 7718 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7719 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 7720 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7721 | ret = IOCB_SUCCESS; |
| 7722 | } |
| 7723 | return ret; |
| 7724 | } |
| 7725 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7726 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7727 | * 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] | 7728 | * @vport: pointer to a virtual N_Port data structure. |
| 7729 | * |
| 7730 | * This routine aborts all the IOCBs associated with a @vport from the |
| 7731 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 7732 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 7733 | * list, removes each IOCB associated with the @vport off the list, set the |
| 7734 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 7735 | * associated with the IOCB. |
| 7736 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 7737 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7738 | { |
| 7739 | LIST_HEAD(completions); |
| 7740 | struct lpfc_hba *phba = vport->phba; |
| 7741 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7742 | |
| 7743 | spin_lock_irq(&phba->hbalock); |
| 7744 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 7745 | list) { |
| 7746 | |
| 7747 | if (piocb->vport != vport) |
| 7748 | continue; |
| 7749 | |
| 7750 | list_move_tail(&piocb->list, &completions); |
| 7751 | } |
| 7752 | spin_unlock_irq(&phba->hbalock); |
| 7753 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7754 | /* Cancel all the IOCBs from the completions list */ |
| 7755 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 7756 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7757 | } |
| 7758 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7759 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7760 | * 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] | 7761 | * @ndlp: pointer to a node-list data structure. |
| 7762 | * |
| 7763 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 7764 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 7765 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 7766 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 7767 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 7768 | * associated with the IOCB. |
| 7769 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7770 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 7771 | { |
| 7772 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7773 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7774 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 7775 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7776 | |
| 7777 | spin_lock_irq(&phba->hbalock); |
| 7778 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 7779 | list) { |
| 7780 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 7781 | |
| 7782 | list_move_tail(&piocb->list, &completions); |
| 7783 | } |
| 7784 | } |
| 7785 | spin_unlock_irq(&phba->hbalock); |
| 7786 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7787 | /* Cancel all the IOCBs from the completions list */ |
| 7788 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 7789 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7790 | } |
| 7791 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7792 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7793 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7794 | * @phba: pointer to lpfc hba data structure. |
| 7795 | * |
| 7796 | * This routine aborts all the IOCBs currently on the driver internal |
| 7797 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 7798 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 7799 | * list, removes IOCBs off the list, set the status feild to |
| 7800 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 7801 | * the IOCB. |
| 7802 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7803 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 7804 | { |
| 7805 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7806 | |
| 7807 | spin_lock_irq(&phba->hbalock); |
| 7808 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 7809 | spin_unlock_irq(&phba->hbalock); |
| 7810 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7811 | /* Cancel all the IOCBs from the completions list */ |
| 7812 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 7813 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7814 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7815 | |
| 7816 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 7817 | * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport |
| 7818 | * @vport: pointer to lpfc vport data structure. |
| 7819 | * |
| 7820 | * This routine is invoked by the vport cleanup for deletions and the cleanup |
| 7821 | * for an ndlp on removal. |
| 7822 | **/ |
| 7823 | void |
| 7824 | lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport) |
| 7825 | { |
| 7826 | struct lpfc_hba *phba = vport->phba; |
| 7827 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 7828 | unsigned long iflag = 0; |
| 7829 | |
| 7830 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7831 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
| 7832 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 7833 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 7834 | if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) |
| 7835 | sglq_entry->ndlp = NULL; |
| 7836 | } |
| 7837 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 7838 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7839 | return; |
| 7840 | } |
| 7841 | |
| 7842 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7843 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 7844 | * @phba: pointer to lpfc hba data structure. |
| 7845 | * @axri: pointer to the els xri abort wcqe structure. |
| 7846 | * |
| 7847 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 7848 | * ELS aborted xri. |
| 7849 | **/ |
| 7850 | void |
| 7851 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 7852 | struct sli4_wcqe_xri_aborted *axri) |
| 7853 | { |
| 7854 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7855 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7856 | uint16_t lxri = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7857 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7858 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 7859 | unsigned long iflag = 0; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7860 | struct lpfc_nodelist *ndlp; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 7861 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7862 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7863 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7864 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7865 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 7866 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 7867 | if (sglq_entry->sli4_xritag == xri) { |
| 7868 | list_del(&sglq_entry->list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7869 | ndlp = sglq_entry->ndlp; |
| 7870 | sglq_entry->ndlp = NULL; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7871 | list_add_tail(&sglq_entry->list, |
| 7872 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7873 | sglq_entry->state = SGL_FREED; |
| 7874 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7875 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7876 | lpfc_set_rrq_active(phba, ndlp, xri, rxid, 1); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 7877 | |
| 7878 | /* Check if TXQ queue needs to be serviced */ |
| 7879 | if (pring->txq_cnt) |
| 7880 | lpfc_worker_wake_up(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7881 | return; |
| 7882 | } |
| 7883 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7884 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7885 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 7886 | if (lxri == NO_XRI) { |
| 7887 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7888 | return; |
| 7889 | } |
| 7890 | sglq_entry = __lpfc_get_active_sglq(phba, lxri); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7891 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { |
| 7892 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7893 | return; |
| 7894 | } |
| 7895 | sglq_entry->state = SGL_XRI_ABORTED; |
| 7896 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7897 | return; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7898 | } |