| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | d8e93df | 2009-05-22 14:53:05 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2009 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 5 | * EMULEX and SLI are trademarks of Emulex. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6 | * www.emulex.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8 | * * |
| 9 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 10 | * modify it under the terms of version 2 of the GNU General * |
| 11 | * Public License as published by the Free Software Foundation. * |
| 12 | * This program is distributed in the hope that it will be useful. * |
| 13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 18 | * more details, a copy of which can be found in the file COPYING * |
| 19 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 20 | *******************************************************************/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 21 | /* See Fibre Channel protocol T11 FC-LS for details */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | #include <linux/blkdev.h> |
| 23 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/slab.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 25 | #include <linux/interrupt.h> |
| 26 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 27 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 28 | #include <scsi/scsi_device.h> |
| 29 | #include <scsi/scsi_host.h> |
| 30 | #include <scsi/scsi_transport_fc.h> |
| 31 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 32 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 33 | #include "lpfc_hw.h" |
| 34 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 35 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 36 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 37 | #include "lpfc_disc.h" |
| 38 | #include "lpfc_scsi.h" |
| 39 | #include "lpfc.h" |
| 40 | #include "lpfc_logmsg.h" |
| 41 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 42 | #include "lpfc_vport.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 43 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 44 | |
| 45 | static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *, |
| 46 | struct lpfc_iocbq *); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 47 | static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *, |
| 48 | struct lpfc_iocbq *); |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 49 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport); |
| 50 | static int lpfc_issue_els_fdisc(struct lpfc_vport *vport, |
| 51 | struct lpfc_nodelist *ndlp, uint8_t retry); |
| 52 | static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba, |
| 53 | struct lpfc_iocbq *iocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 54 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 55 | static int lpfc_max_els_tries = 3; |
| 56 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 57 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 58 | * lpfc_els_chk_latt - Check host link attention event for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 59 | * @vport: pointer to a host virtual N_Port data structure. |
| 60 | * |
| 61 | * This routine checks whether there is an outstanding host link |
| 62 | * attention event during the discovery process with the @vport. It is done |
| 63 | * by reading the HBA's Host Attention (HA) register. If there is any host |
| 64 | * link attention events during this @vport's discovery process, the @vport |
| 65 | * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall |
| 66 | * be issued if the link state is not already in host link cleared state, |
| 67 | * and a return code shall indicate whether the host link attention event |
| 68 | * had happened. |
| 69 | * |
| 70 | * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport |
| 71 | * state in LPFC_VPORT_READY, the request for checking host link attention |
| 72 | * event will be ignored and a return code shall indicate no host link |
| 73 | * attention event had happened. |
| 74 | * |
| 75 | * Return codes |
| 76 | * 0 - no host link attention event happened |
| 77 | * 1 - host link attention event happened |
| 78 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 79 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 80 | lpfc_els_chk_latt(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 81 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 82 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 83 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 84 | uint32_t ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 85 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 86 | if (vport->port_state >= LPFC_VPORT_READY || |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 87 | phba->link_state == LPFC_LINK_DOWN || |
| 88 | phba->sli_rev > LPFC_SLI_REV3) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 89 | return 0; |
| 90 | |
| 91 | /* Read the HBA Host Attention Register */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 92 | ha_copy = readl(phba->HAregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 93 | |
| 94 | if (!(ha_copy & HA_LATT)) |
| 95 | return 0; |
| 96 | |
| 97 | /* Pending Link Event during Discovery */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 98 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 99 | "0237 Pending Link Event during " |
| 100 | "Discovery: State x%x\n", |
| 101 | phba->pport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 102 | |
| 103 | /* CLEAR_LA should re-enable link attention events and |
| 104 | * we should then imediately take a LATT event. The |
| 105 | * LATT processing should call lpfc_linkdown() which |
| 106 | * will cleanup any left over in-progress discovery |
| 107 | * events. |
| 108 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 109 | spin_lock_irq(shost->host_lock); |
| 110 | vport->fc_flag |= FC_ABORT_DISCOVERY; |
| 111 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 112 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 113 | if (phba->link_state != LPFC_CLEAR_LA) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 114 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 115 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 116 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 117 | } |
| 118 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 119 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 120 | * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 121 | * @vport: pointer to a host virtual N_Port data structure. |
| 122 | * @expectRsp: flag indicating whether response is expected. |
| 123 | * @cmdSize: size of the ELS command. |
| 124 | * @retry: number of retries to the command IOCB when it fails. |
| 125 | * @ndlp: pointer to a node-list data structure. |
| 126 | * @did: destination identifier. |
| 127 | * @elscmd: the ELS command code. |
| 128 | * |
| 129 | * This routine is used for allocating a lpfc-IOCB data structure from |
| 130 | * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters |
| 131 | * passed into the routine for discovery state machine to issue an Extended |
| 132 | * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation |
| 133 | * and preparation routine that is used by all the discovery state machine |
| 134 | * routines and the ELS command-specific fields will be later set up by |
| 135 | * the individual discovery machine routines after calling this routine |
| 136 | * allocating and preparing a generic IOCB data structure. It fills in the |
| 137 | * Buffer Descriptor Entries (BDEs), allocates buffers for both command |
| 138 | * payload and response payload (if expected). The reference count on the |
| 139 | * ndlp is incremented by 1 and the reference to the ndlp is put into |
| 140 | * context1 of the IOCB data structure for this IOCB to hold the ndlp |
| 141 | * reference for the command's callback function to access later. |
| 142 | * |
| 143 | * Return code |
| 144 | * Pointer to the newly allocated/prepared els iocb data structure |
| 145 | * NULL - when els iocb data structure allocation/preparation failed |
| 146 | **/ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 147 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 148 | lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, |
| 149 | uint16_t cmdSize, uint8_t retry, |
| 150 | struct lpfc_nodelist *ndlp, uint32_t did, |
| 151 | uint32_t elscmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 152 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 153 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 154 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 155 | struct lpfc_dmabuf *pcmd, *prsp, *pbuflist; |
| 156 | struct ulp_bde64 *bpl; |
| 157 | IOCB_t *icmd; |
| 158 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 159 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 160 | if (!lpfc_is_link_up(phba)) |
| 161 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 162 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 163 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 164 | elsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 165 | |
| 166 | if (elsiocb == NULL) |
| 167 | return NULL; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 168 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 169 | /* |
| 170 | * If this command is for fabric controller and HBA running |
| 171 | * in FIP mode send FLOGI, FDISC and LOGO as FIP frames. |
| 172 | */ |
| 173 | if ((did == Fabric_DID) && |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 174 | (phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 175 | ((elscmd == ELS_CMD_FLOGI) || |
| 176 | (elscmd == ELS_CMD_FDISC) || |
| 177 | (elscmd == ELS_CMD_LOGO))) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 178 | switch (elscmd) { |
| 179 | case ELS_CMD_FLOGI: |
| 180 | elsiocb->iocb_flag |= ((ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT) |
| 181 | & LPFC_FIP_ELS_ID_MASK); |
| 182 | break; |
| 183 | case ELS_CMD_FDISC: |
| 184 | elsiocb->iocb_flag |= ((ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT) |
| 185 | & LPFC_FIP_ELS_ID_MASK); |
| 186 | break; |
| 187 | case ELS_CMD_LOGO: |
| 188 | elsiocb->iocb_flag |= ((ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT) |
| 189 | & LPFC_FIP_ELS_ID_MASK); |
| 190 | break; |
| 191 | } |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 192 | else |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 193 | elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 194 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 195 | icmd = &elsiocb->iocb; |
| 196 | |
| 197 | /* fill in BDEs for command */ |
| 198 | /* Allocate buffer for command payload */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 199 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 200 | if (pcmd) |
| 201 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 202 | if (!pcmd || !pcmd->virt) |
| 203 | goto els_iocb_free_pcmb_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 204 | |
| 205 | INIT_LIST_HEAD(&pcmd->list); |
| 206 | |
| 207 | /* Allocate buffer for response payload */ |
| 208 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 209 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 210 | if (prsp) |
| 211 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 212 | &prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 213 | if (!prsp || !prsp->virt) |
| 214 | goto els_iocb_free_prsp_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 215 | INIT_LIST_HEAD(&prsp->list); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 216 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 217 | prsp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 218 | |
| 219 | /* Allocate buffer for Buffer ptr list */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 220 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 221 | if (pbuflist) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 222 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 223 | &pbuflist->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 224 | if (!pbuflist || !pbuflist->virt) |
| 225 | goto els_iocb_free_pbuf_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 226 | |
| 227 | INIT_LIST_HEAD(&pbuflist->list); |
| 228 | |
| 229 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 230 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 231 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 232 | icmd->un.elsreq64.remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 233 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 234 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 235 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 236 | icmd->ulpTimeout = phba->fc_ratov * 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 237 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 238 | icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 239 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; |
| 240 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 241 | icmd->ulpBdeCount = 1; |
| 242 | icmd->ulpLe = 1; |
| 243 | icmd->ulpClass = CLASS3; |
| 244 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 245 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 246 | icmd->un.elsreq64.myID = vport->fc_myDID; |
| 247 | |
| 248 | /* For ELS_REQUEST64_CR, use the VPI by default */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 249 | icmd->ulpContext = vport->vpi + phba->vpi_base; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 250 | icmd->ulpCt_h = 0; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 251 | /* The CT field must be 0=INVALID_RPI for the ECHO cmd */ |
| 252 | if (elscmd == ELS_CMD_ECHO) |
| 253 | icmd->ulpCt_l = 0; /* context = invalid RPI */ |
| 254 | else |
| 255 | icmd->ulpCt_l = 1; /* context = VPI */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 256 | } |
| 257 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 258 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
| 259 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); |
| 260 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); |
| 261 | bpl->tus.f.bdeSize = cmdSize; |
| 262 | bpl->tus.f.bdeFlags = 0; |
| 263 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 264 | |
| 265 | if (expectRsp) { |
| 266 | bpl++; |
| 267 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); |
| 268 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); |
| 269 | bpl->tus.f.bdeSize = FCELSSIZE; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 270 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 271 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 272 | } |
| 273 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 274 | /* prevent preparing iocb with NULL ndlp reference */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 275 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 276 | if (!elsiocb->context1) |
| 277 | goto els_iocb_free_pbuf_exit; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 278 | elsiocb->context2 = pcmd; |
| 279 | elsiocb->context3 = pbuflist; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 280 | elsiocb->retry = retry; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 281 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 282 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
| 283 | |
| 284 | if (prsp) { |
| 285 | list_add(&prsp->list, &pcmd->list); |
| 286 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 287 | if (expectRsp) { |
| 288 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 289 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 290 | "0116 Xmit ELS command x%x to remote " |
| 291 | "NPORT x%x I/O tag: x%x, port state: x%x\n", |
| 292 | elscmd, did, elsiocb->iotag, |
| 293 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 294 | } else { |
| 295 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 296 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 297 | "0117 Xmit ELS response x%x to remote " |
| 298 | "NPORT x%x I/O tag: x%x, size: x%x\n", |
| 299 | elscmd, ndlp->nlp_DID, elsiocb->iotag, |
| 300 | cmdSize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 301 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 302 | return elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 303 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 304 | els_iocb_free_pbuf_exit: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 305 | if (expectRsp) |
| 306 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 307 | kfree(pbuflist); |
| 308 | |
| 309 | els_iocb_free_prsp_exit: |
| 310 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 311 | kfree(prsp); |
| 312 | |
| 313 | els_iocb_free_pcmb_exit: |
| 314 | kfree(pcmd); |
| 315 | lpfc_sli_release_iocbq(phba, elsiocb); |
| 316 | return NULL; |
| 317 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 318 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 319 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 320 | * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 321 | * @vport: pointer to a host virtual N_Port data structure. |
| 322 | * |
| 323 | * This routine issues a fabric registration login for a @vport. An |
| 324 | * active ndlp node with Fabric_DID must already exist for this @vport. |
| 325 | * The routine invokes two mailbox commands to carry out fabric registration |
| 326 | * login through the HBA firmware: the first mailbox command requests the |
| 327 | * HBA to perform link configuration for the @vport; and the second mailbox |
| 328 | * command requests the HBA to perform the actual fabric registration login |
| 329 | * with the @vport. |
| 330 | * |
| 331 | * Return code |
| 332 | * 0 - successfully issued fabric registration login for @vport |
| 333 | * -ENXIO -- failed to issue fabric registration login for @vport |
| 334 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 335 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 336 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
| 337 | { |
| 338 | struct lpfc_hba *phba = vport->phba; |
| 339 | LPFC_MBOXQ_t *mbox; |
| 340 | struct lpfc_dmabuf *mp; |
| 341 | struct lpfc_nodelist *ndlp; |
| 342 | struct serv_parm *sp; |
| 343 | int rc; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 344 | int err = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 345 | |
| 346 | sp = &phba->fc_fabparam; |
| 347 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 348 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 349 | err = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 350 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 351 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 352 | |
| 353 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 354 | if (!mbox) { |
| 355 | err = 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 356 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 357 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 358 | |
| 359 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 360 | lpfc_config_link(phba, mbox); |
| 361 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 362 | mbox->vport = vport; |
| 363 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 364 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 365 | if (rc == MBX_NOT_FINISHED) { |
| 366 | err = 3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 367 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 368 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 369 | |
| 370 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 371 | if (!mbox) { |
| 372 | err = 4; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 373 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 374 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 375 | rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, 0); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 376 | if (rc) { |
| 377 | err = 5; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 378 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 379 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 380 | |
| 381 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; |
| 382 | mbox->vport = vport; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 383 | /* increment the reference count on ndlp to hold reference |
| 384 | * for the callback routine. |
| 385 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 386 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 387 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 388 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 389 | if (rc == MBX_NOT_FINISHED) { |
| 390 | err = 6; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 391 | goto fail_issue_reg_login; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 392 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 393 | |
| 394 | return 0; |
| 395 | |
| 396 | fail_issue_reg_login: |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 397 | /* decrement the reference count on ndlp just incremented |
| 398 | * for the failed mbox command. |
| 399 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 400 | lpfc_nlp_put(ndlp); |
| 401 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 402 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 403 | kfree(mp); |
| 404 | fail_free_mbox: |
| 405 | mempool_free(mbox, phba->mbox_mem_pool); |
| 406 | |
| 407 | fail: |
| 408 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 409 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 410 | "0249 Cannot issue Register Fabric login: Err %d\n", err); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 411 | return -ENXIO; |
| 412 | } |
| 413 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 414 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 415 | * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login |
| 416 | * @vport: pointer to a host virtual N_Port data structure. |
| 417 | * |
| 418 | * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for |
| 419 | * the @vport. This mailbox command is necessary for FCoE only. |
| 420 | * |
| 421 | * Return code |
| 422 | * 0 - successfully issued REG_VFI for @vport |
| 423 | * A failure code otherwise. |
| 424 | **/ |
| 425 | static int |
| 426 | lpfc_issue_reg_vfi(struct lpfc_vport *vport) |
| 427 | { |
| 428 | struct lpfc_hba *phba = vport->phba; |
| 429 | LPFC_MBOXQ_t *mboxq; |
| 430 | struct lpfc_nodelist *ndlp; |
| 431 | struct serv_parm *sp; |
| 432 | struct lpfc_dmabuf *dmabuf; |
| 433 | int rc = 0; |
| 434 | |
| 435 | sp = &phba->fc_fabparam; |
| 436 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 437 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
| 438 | rc = -ENODEV; |
| 439 | goto fail; |
| 440 | } |
| 441 | |
| 442 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 443 | if (!dmabuf) { |
| 444 | rc = -ENOMEM; |
| 445 | goto fail; |
| 446 | } |
| 447 | dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys); |
| 448 | if (!dmabuf->virt) { |
| 449 | rc = -ENOMEM; |
| 450 | goto fail_free_dmabuf; |
| 451 | } |
| 452 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 453 | if (!mboxq) { |
| 454 | rc = -ENOMEM; |
| 455 | goto fail_free_coherent; |
| 456 | } |
| 457 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 458 | memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam)); |
| 459 | lpfc_reg_vfi(mboxq, vport, dmabuf->phys); |
| 460 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi; |
| 461 | mboxq->vport = vport; |
| 462 | mboxq->context1 = dmabuf; |
| 463 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 464 | if (rc == MBX_NOT_FINISHED) { |
| 465 | rc = -ENXIO; |
| 466 | goto fail_free_mbox; |
| 467 | } |
| 468 | return 0; |
| 469 | |
| 470 | fail_free_mbox: |
| 471 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 472 | fail_free_coherent: |
| 473 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 474 | fail_free_dmabuf: |
| 475 | kfree(dmabuf); |
| 476 | fail: |
| 477 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 478 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 479 | "0289 Issue Register VFI failed: Err %d\n", rc); |
| 480 | return rc; |
| 481 | } |
| 482 | |
| 483 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 484 | * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 485 | * @vport: pointer to a host virtual N_Port data structure. |
| 486 | * @ndlp: pointer to a node-list data structure. |
| 487 | * @sp: pointer to service parameter data structure. |
| 488 | * @irsp: pointer to the IOCB within the lpfc response IOCB. |
| 489 | * |
| 490 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 491 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric |
| 492 | * port in a fabric topology. It properly sets up the parameters to the @ndlp |
| 493 | * from the IOCB response. It also check the newly assigned N_Port ID to the |
| 494 | * @vport against the previously assigned N_Port ID. If it is different from |
| 495 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine |
| 496 | * is invoked on all the remaining nodes with the @vport to unregister the |
| 497 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() |
| 498 | * is invoked to register login to the fabric. |
| 499 | * |
| 500 | * Return code |
| 501 | * 0 - Success (currently, always return 0) |
| 502 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 503 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 504 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 505 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 506 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 507 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 508 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 509 | struct lpfc_nodelist *np; |
| 510 | struct lpfc_nodelist *next_np; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 511 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 512 | spin_lock_irq(shost->host_lock); |
| 513 | vport->fc_flag |= FC_FABRIC; |
| 514 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 515 | |
| 516 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 517 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 518 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 519 | |
| 520 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 521 | |
| 522 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 523 | spin_lock_irq(shost->host_lock); |
| 524 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 525 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 526 | } else { |
| 527 | /* |
| 528 | * If we are a N-port connected to a Fabric, fixup sparam's so |
| 529 | * logins to devices on remote loops work. |
| 530 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 531 | vport->fc_sparam.cmn.altBbCredit = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 532 | } |
| 533 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 534 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 535 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 536 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 537 | ndlp->nlp_class_sup = 0; |
| 538 | if (sp->cls1.classValid) |
| 539 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 540 | if (sp->cls2.classValid) |
| 541 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 542 | if (sp->cls3.classValid) |
| 543 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 544 | if (sp->cls4.classValid) |
| 545 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 546 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 547 | sp->cmn.bbRcvSizeLsb; |
| 548 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 549 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 550 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 551 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 552 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 553 | LOG_ELS | LOG_VPORT, |
| 554 | "1816 FLOGI NPIV supported, " |
| 555 | "response data 0x%x\n", |
| 556 | sp->cmn.response_multiple_NPort); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 557 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 558 | } else { |
| 559 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 560 | to call reg_vnpid atleast for the physcial host */ |
| 561 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 562 | LOG_ELS | LOG_VPORT, |
| 563 | "1817 Fabric does not support NPIV " |
| 564 | "- configuring single port mode.\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 565 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 570 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 571 | |
| 572 | /* If our NportID changed, we need to ensure all |
| 573 | * remaining NPORTs get unreg_login'ed. |
| 574 | */ |
| 575 | list_for_each_entry_safe(np, next_np, |
| 576 | &vport->fc_nodes, nlp_listp) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 577 | if (!NLP_CHK_NODE_ACT(np)) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 578 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 579 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 580 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 581 | continue; |
| 582 | spin_lock_irq(shost->host_lock); |
| 583 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 584 | spin_unlock_irq(shost->host_lock); |
| 585 | lpfc_unreg_rpi(vport, np); |
| 586 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 587 | lpfc_cleanup_pending_mbox(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 588 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 589 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 590 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 591 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 592 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 593 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 594 | /* |
| 595 | * If VPI is unreged, driver need to do INIT_VPI |
| 596 | * before re-registering |
| 597 | */ |
| 598 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 599 | spin_lock_irq(shost->host_lock); |
| 600 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 601 | spin_unlock_irq(shost->host_lock); |
| 602 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 603 | } |
| 604 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 605 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 606 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
| 607 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 608 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 609 | lpfc_register_new_vport(phba, vport, ndlp); |
| 610 | else |
| 611 | lpfc_issue_fabric_reglogin(vport); |
| 612 | } else { |
| 613 | ndlp->nlp_type |= NLP_FABRIC; |
| 614 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 615 | if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) && |
| 616 | (vport->vpi_state & LPFC_VPI_REGISTERED)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 617 | lpfc_start_fdiscs(phba); |
| 618 | lpfc_do_scr_ns_plogi(phba, vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 619 | } else if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 620 | lpfc_issue_init_vpi(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 621 | else |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 622 | lpfc_issue_reg_vfi(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 623 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 624 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 625 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 626 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 627 | * 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] | 628 | * @vport: pointer to a host virtual N_Port data structure. |
| 629 | * @ndlp: pointer to a node-list data structure. |
| 630 | * @sp: pointer to service parameter data structure. |
| 631 | * |
| 632 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 633 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 634 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 635 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 636 | * the received N_Port Name lexicographically, this node shall assign local |
| 637 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 638 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 639 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 640 | * N_Port IDs. |
| 641 | * |
| 642 | * Return code |
| 643 | * 0 - Success |
| 644 | * -ENXIO - Fail |
| 645 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 646 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 647 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 648 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 649 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 650 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 651 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 652 | LPFC_MBOXQ_t *mbox; |
| 653 | int rc; |
| 654 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 655 | spin_lock_irq(shost->host_lock); |
| 656 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 657 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 658 | |
| 659 | phba->fc_edtov = FF_DEF_EDTOV; |
| 660 | phba->fc_ratov = FF_DEF_RATOV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 661 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 662 | sizeof(vport->fc_portname)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 663 | if (rc >= 0) { |
| 664 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 665 | spin_lock_irq(shost->host_lock); |
| 666 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 667 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 668 | |
| 669 | /* |
| 670 | * N_Port ID cannot be 0, set our to LocalID the other |
| 671 | * side will be RemoteID. |
| 672 | */ |
| 673 | |
| 674 | /* not equal */ |
| 675 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 676 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 677 | |
| 678 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 679 | if (!mbox) |
| 680 | goto fail; |
| 681 | |
| 682 | lpfc_config_link(phba, mbox); |
| 683 | |
| 684 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 685 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 686 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 687 | if (rc == MBX_NOT_FINISHED) { |
| 688 | mempool_free(mbox, phba->mbox_mem_pool); |
| 689 | goto fail; |
| 690 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 691 | /* Decrement ndlp reference count indicating that ndlp can be |
| 692 | * safely released when other references to it are done. |
| 693 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 694 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 695 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 696 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 697 | if (!ndlp) { |
| 698 | /* |
| 699 | * Cannot find existing Fabric ndlp, so allocate a |
| 700 | * new one |
| 701 | */ |
| 702 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 703 | if (!ndlp) |
| 704 | goto fail; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 705 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 706 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 707 | ndlp = lpfc_enable_node(vport, ndlp, |
| 708 | NLP_STE_UNUSED_NODE); |
| 709 | if(!ndlp) |
| 710 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 714 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 715 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 716 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 717 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 718 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 719 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 720 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 721 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 722 | } else |
| 723 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 724 | * count indicating that ndlp can be released when other |
| 725 | * references to it are done. |
| 726 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 727 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 728 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 729 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 730 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 731 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 732 | spin_lock_irq(shost->host_lock); |
| 733 | vport->fc_flag |= FC_PT2PT; |
| 734 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 735 | |
| 736 | /* Start discovery - this should just do CLEAR_LA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 737 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 738 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 739 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 740 | return -ENXIO; |
| 741 | } |
| 742 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 743 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 744 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 745 | * @phba: pointer to lpfc hba data structure. |
| 746 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 747 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 748 | * |
| 749 | * This routine is the top-level completion callback function for issuing |
| 750 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 751 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 752 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 753 | * returning 1), the command IOCB will be released and function returned. |
| 754 | * If the retry attempt has been given up (possibly reach the maximum |
| 755 | * number of retries), one additional decrement of ndlp reference shall be |
| 756 | * invoked before going out after releasing the command IOCB. This will |
| 757 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 758 | * invoke one decrement of ndlp reference count). If no error reported in |
| 759 | * the IOCB status, the command Port ID field is used to determine whether |
| 760 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 761 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 762 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 763 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 764 | * specific topology completion conditions. |
| 765 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 766 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 767 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 768 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 769 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 770 | struct lpfc_vport *vport = cmdiocb->vport; |
| 771 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 772 | IOCB_t *irsp = &rspiocb->iocb; |
| 773 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 774 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 775 | struct serv_parm *sp; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 776 | uint16_t fcf_index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 777 | int rc; |
| 778 | |
| 779 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 780 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 781 | /* One additional decrement on node reference count to |
| 782 | * trigger the release of the node |
| 783 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 784 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 785 | goto out; |
| 786 | } |
| 787 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 788 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 789 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 790 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 791 | vport->port_state); |
| 792 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 793 | if (irsp->ulpStatus) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 794 | /* |
| 795 | * In case of FIP mode, perform round robin FCF failover |
| 796 | * due to new FCF discovery |
| 797 | */ |
| 798 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 799 | (phba->fcf.fcf_flag & FCF_DISCOVERY) && |
| 800 | (irsp->ulpStatus != IOSTAT_LOCAL_REJECT) && |
| 801 | (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED)) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 802 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
| 803 | "2611 FLOGI failed on registered " |
| 804 | "FCF record fcf_index:%d, trying " |
| 805 | "to perform round robin failover\n", |
| 806 | phba->fcf.current_rec.fcf_indx); |
| 807 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
| 808 | if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) { |
| 809 | /* |
| 810 | * Exhausted the eligible FCF record list, |
| 811 | * fail through to retry FLOGI on current |
| 812 | * FCF record. |
| 813 | */ |
| 814 | lpfc_printf_log(phba, KERN_WARNING, |
| 815 | LOG_FIP | LOG_ELS, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 816 | "2760 Completed one round " |
| 817 | "of FLOGI FCF round robin " |
| 818 | "failover list, retry FLOGI " |
| 819 | "on currently registered " |
| 820 | "FCF index:%d\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 821 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 822 | } else { |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 823 | lpfc_printf_log(phba, KERN_INFO, |
| 824 | LOG_FIP | LOG_ELS, |
| 825 | "2794 FLOGI FCF round robin " |
| 826 | "failover to FCF index x%x\n", |
| 827 | fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 828 | rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, |
| 829 | fcf_index); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 830 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 831 | lpfc_printf_log(phba, KERN_WARNING, |
| 832 | LOG_FIP | LOG_ELS, |
| 833 | "2761 FLOGI round " |
| 834 | "robin FCF failover " |
| 835 | "read FCF failed " |
| 836 | "rc:x%x, fcf_index:" |
| 837 | "%d\n", rc, |
| 838 | phba->fcf.current_rec.fcf_indx); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 839 | else |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 840 | goto out; |
| 841 | } |
| 842 | } |
| 843 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 844 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 845 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 846 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 847 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 848 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 849 | spin_lock_irq(shost->host_lock); |
| 850 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 851 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 852 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 853 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 854 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 855 | * alpa map would take too long otherwise. |
| 856 | */ |
| 857 | if (phba->alpa_map[0] == 0) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 858 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | /* FLOGI failure */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 862 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 863 | "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 864 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 865 | irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 866 | goto flogifail; |
| 867 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 868 | spin_lock_irq(shost->host_lock); |
| 869 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 870 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 871 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 872 | |
| 873 | /* |
| 874 | * The FLogI succeeded. Sync the data for the CPU before |
| 875 | * accessing it. |
| 876 | */ |
| 877 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 878 | |
| 879 | sp = prsp->virt + sizeof(uint32_t); |
| 880 | |
| 881 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 882 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 883 | "0101 FLOGI completes successfully " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 884 | "Data: x%x x%x x%x x%x\n", |
| 885 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
| 886 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 887 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 888 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 889 | /* |
| 890 | * If Common Service Parameters indicate Nport |
| 891 | * we are point to point, if Fport we are Fabric. |
| 892 | */ |
| 893 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 894 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 895 | else if (!(phba->hba_flag & HBA_FCOE_SUPPORT)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 896 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 897 | else { |
| 898 | lpfc_printf_vlog(vport, KERN_ERR, |
| 899 | LOG_FIP | LOG_ELS, |
| 900 | "2831 FLOGI response with cleared Fabric " |
| 901 | "bit fcf_index 0x%x " |
| 902 | "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x " |
| 903 | "Fabric Name " |
| 904 | "%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 905 | phba->fcf.current_rec.fcf_indx, |
| 906 | phba->fcf.current_rec.switch_name[0], |
| 907 | phba->fcf.current_rec.switch_name[1], |
| 908 | phba->fcf.current_rec.switch_name[2], |
| 909 | phba->fcf.current_rec.switch_name[3], |
| 910 | phba->fcf.current_rec.switch_name[4], |
| 911 | phba->fcf.current_rec.switch_name[5], |
| 912 | phba->fcf.current_rec.switch_name[6], |
| 913 | phba->fcf.current_rec.switch_name[7], |
| 914 | phba->fcf.current_rec.fabric_name[0], |
| 915 | phba->fcf.current_rec.fabric_name[1], |
| 916 | phba->fcf.current_rec.fabric_name[2], |
| 917 | phba->fcf.current_rec.fabric_name[3], |
| 918 | phba->fcf.current_rec.fabric_name[4], |
| 919 | phba->fcf.current_rec.fabric_name[5], |
| 920 | phba->fcf.current_rec.fabric_name[6], |
| 921 | phba->fcf.current_rec.fabric_name[7]); |
| 922 | lpfc_nlp_put(ndlp); |
| 923 | spin_lock_irq(&phba->hbalock); |
| 924 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
| 925 | spin_unlock_irq(&phba->hbalock); |
| 926 | goto out; |
| 927 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 928 | if (!rc) { |
| 929 | /* Mark the FCF discovery process done */ |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 930 | if (phba->hba_flag & HBA_FIP_SUPPORT) |
| 931 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | |
| 932 | LOG_ELS, |
| 933 | "2769 FLOGI successful on FCF " |
| 934 | "record: current_fcf_index:" |
| 935 | "x%x, terminate FCF round " |
| 936 | "robin failover process\n", |
| 937 | phba->fcf.current_rec.fcf_indx); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 938 | spin_lock_irq(&phba->hbalock); |
| 939 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
| 940 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 941 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 942 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | flogifail: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 946 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 947 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 948 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 949 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 950 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 951 | |
| 952 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 953 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 954 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 955 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && |
| 956 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) && |
| 957 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 958 | /* If FLOGI failed enable link interrupt. */ |
| 959 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 960 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 961 | out: |
| 962 | lpfc_els_free_iocb(phba, cmdiocb); |
| 963 | } |
| 964 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 965 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 966 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 967 | * @vport: pointer to a host virtual N_Port data structure. |
| 968 | * @ndlp: pointer to a node-list data structure. |
| 969 | * @retry: number of retries to the command IOCB. |
| 970 | * |
| 971 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 972 | * for a @vport. The initiator service parameters are put into the payload |
| 973 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 974 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 975 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 976 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 977 | * |
| 978 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 979 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 980 | * will be stored into the context1 field of the IOCB for the completion |
| 981 | * callback function to the FLOGI ELS command. |
| 982 | * |
| 983 | * Return code |
| 984 | * 0 - successfully issued flogi iocb for @vport |
| 985 | * 1 - failed to issue flogi iocb for @vport |
| 986 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 987 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 988 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 989 | uint8_t retry) |
| 990 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 991 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 992 | struct serv_parm *sp; |
| 993 | IOCB_t *icmd; |
| 994 | struct lpfc_iocbq *elsiocb; |
| 995 | struct lpfc_sli_ring *pring; |
| 996 | uint8_t *pcmd; |
| 997 | uint16_t cmdsize; |
| 998 | uint32_t tmo; |
| 999 | int rc; |
| 1000 | |
| 1001 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 1002 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1003 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1004 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1005 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1006 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1007 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1008 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1009 | |
| 1010 | icmd = &elsiocb->iocb; |
| 1011 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1012 | |
| 1013 | /* For FLOGI request, remainder of payload is service parameters */ |
| 1014 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1015 | pcmd += sizeof(uint32_t); |
| 1016 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1017 | sp = (struct serv_parm *) pcmd; |
| 1018 | |
| 1019 | /* Setup CSPs accordingly for Fabric */ |
| 1020 | sp->cmn.e_d_tov = 0; |
| 1021 | sp->cmn.w2.r_a_tov = 0; |
| 1022 | sp->cls1.classValid = 0; |
| 1023 | sp->cls2.seqDelivery = 1; |
| 1024 | sp->cls3.seqDelivery = 1; |
| 1025 | if (sp->cmn.fcphLow < FC_PH3) |
| 1026 | sp->cmn.fcphLow = FC_PH3; |
| 1027 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1028 | sp->cmn.fcphHigh = FC_PH3; |
| 1029 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1030 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1031 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 1032 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 1033 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 1034 | /* Set the fcfi to the fcfi we registered with */ |
| 1035 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 1036 | } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1037 | sp->cmn.request_multiple_Nport = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1038 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 1039 | icmd->ulpCt_h = 1; |
| 1040 | icmd->ulpCt_l = 0; |
| 1041 | } |
| 1042 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1043 | if (phba->fc_topology != TOPOLOGY_LOOP) { |
| 1044 | icmd->un.elsreq64.myID = 0; |
| 1045 | icmd->un.elsreq64.fl = 1; |
| 1046 | } |
| 1047 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1048 | tmo = phba->fc_ratov; |
| 1049 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1050 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1051 | phba->fc_ratov = tmo; |
| 1052 | |
| 1053 | phba->fc_stat.elsXmitFLOGI++; |
| 1054 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1055 | |
| 1056 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1057 | "Issue FLOGI: opt:x%x", |
| 1058 | phba->sli3_options, 0, 0); |
| 1059 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1060 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1061 | if (rc == IOCB_ERROR) { |
| 1062 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1063 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1064 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1065 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1066 | } |
| 1067 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1068 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1069 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1070 | * @phba: pointer to lpfc hba data structure. |
| 1071 | * |
| 1072 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 1073 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 1074 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 1075 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 1076 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 1077 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 1078 | * |
| 1079 | * Return code |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 1080 | * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1081 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1082 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1083 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1084 | { |
| 1085 | struct lpfc_sli_ring *pring; |
| 1086 | struct lpfc_iocbq *iocb, *next_iocb; |
| 1087 | struct lpfc_nodelist *ndlp; |
| 1088 | IOCB_t *icmd; |
| 1089 | |
| 1090 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 1091 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1092 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 1093 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1094 | |
| 1095 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 1096 | |
| 1097 | /* |
| 1098 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 1099 | * searching for. |
| 1100 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1101 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1102 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 1103 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1104 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR && |
| 1105 | icmd->un.elsreq64.bdl.ulpIoTag32) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1106 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1107 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 1108 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1109 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1110 | } |
| 1111 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1112 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1113 | |
| 1114 | return 0; |
| 1115 | } |
| 1116 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1117 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1118 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1119 | * @vport: pointer to a host virtual N_Port data structure. |
| 1120 | * |
| 1121 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 1122 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1123 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1124 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1125 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 1126 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 1127 | * @vport. |
| 1128 | * |
| 1129 | * Return code |
| 1130 | * 0 - failed to issue initial flogi for @vport |
| 1131 | * 1 - successfully issued initial flogi for @vport |
| 1132 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1133 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1134 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1135 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1136 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1137 | struct lpfc_nodelist *ndlp; |
| 1138 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1139 | vport->port_state = LPFC_FLOGI; |
| 1140 | lpfc_set_disctmo(vport); |
| 1141 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1142 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1143 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1144 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1145 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1146 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1147 | if (!ndlp) |
| 1148 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1149 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1150 | /* Set the node type */ |
| 1151 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1152 | /* Put ndlp onto node list */ |
| 1153 | lpfc_enqueue_node(vport, ndlp); |
| 1154 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1155 | /* re-setup ndlp without removing from node list */ |
| 1156 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1157 | if (!ndlp) |
| 1158 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1159 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1160 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1161 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1162 | /* This decrement of reference count to node shall kick off |
| 1163 | * the release of the node. |
| 1164 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1165 | lpfc_nlp_put(ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1166 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1167 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1168 | } |
| 1169 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1170 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1171 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1172 | * @vport: pointer to a host virtual N_Port data structure. |
| 1173 | * |
| 1174 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 1175 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1176 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1177 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1178 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 1179 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 1180 | * @vport. |
| 1181 | * |
| 1182 | * Return code |
| 1183 | * 0 - failed to issue initial fdisc for @vport |
| 1184 | * 1 - successfully issued initial fdisc for @vport |
| 1185 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1186 | int |
| 1187 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 1188 | { |
| 1189 | struct lpfc_hba *phba = vport->phba; |
| 1190 | struct lpfc_nodelist *ndlp; |
| 1191 | |
| 1192 | /* First look for the Fabric ndlp */ |
| 1193 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1194 | if (!ndlp) { |
| 1195 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 1196 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1197 | if (!ndlp) |
| 1198 | return 0; |
| 1199 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1200 | /* Put ndlp onto node list */ |
| 1201 | lpfc_enqueue_node(vport, ndlp); |
| 1202 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1203 | /* re-setup ndlp without removing from node list */ |
| 1204 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1205 | if (!ndlp) |
| 1206 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1207 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1208 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1209 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1210 | /* decrement node reference count to trigger the release of |
| 1211 | * the node. |
| 1212 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1213 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1214 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1215 | } |
| 1216 | return 1; |
| 1217 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1218 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1219 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1220 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1221 | * @vport: pointer to a host virtual N_Port data structure. |
| 1222 | * |
| 1223 | * This routine checks whether there are more remaining Port Logins |
| 1224 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1225 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1226 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1227 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1228 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1229 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1230 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1231 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1232 | { |
| 1233 | int sentplogi; |
| 1234 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1235 | if (vport->num_disc_nodes) |
| 1236 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1237 | |
| 1238 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1239 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1240 | "0232 Continue discovery with %d PLOGIs to go " |
| 1241 | "Data: x%x x%x x%x\n", |
| 1242 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1243 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1244 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1245 | if (vport->fc_flag & FC_NLP_MORE) |
| 1246 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 1247 | sentplogi = lpfc_els_disc_plogi(vport); |
| 1248 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1249 | return; |
| 1250 | } |
| 1251 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1252 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1253 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1254 | * @phba: pointer to lpfc hba data structure. |
| 1255 | * @prsp: pointer to response IOCB payload. |
| 1256 | * @ndlp: pointer to a node-list data structure. |
| 1257 | * |
| 1258 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1259 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1260 | * The following cases are considered N_Port confirmed: |
| 1261 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1262 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1263 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1264 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1265 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1266 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1267 | * on that node to release the RPI associated with the node; 2) if there is |
| 1268 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1269 | * into, a new node shall be allocated (or activated). In either case, the |
| 1270 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1271 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1272 | * its pointer returned as the confirmed node. |
| 1273 | * |
| 1274 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1275 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1276 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1277 | * into an inactive state on the vport node list and the vport node list |
| 1278 | * management algorithm does not allow two node with a same DID. |
| 1279 | * |
| 1280 | * Return code |
| 1281 | * pointer to the PLOGI N_Port @ndlp |
| 1282 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1283 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1284 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1285 | struct lpfc_nodelist *ndlp) |
| 1286 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1287 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1288 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1289 | struct lpfc_rport_data *rdata; |
| 1290 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1291 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1292 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1293 | uint32_t rc, keepDID = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1294 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1295 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1296 | * by WWPN. Just return the ndlp that was given to us. |
| 1297 | */ |
| 1298 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1299 | return ndlp; |
| 1300 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1301 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1302 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1303 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1304 | /* 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] | 1305 | * we have for that ndlp. If not, we have some work to do. |
| 1306 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1307 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1308 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1309 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1310 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1311 | |
| 1312 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1313 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1314 | sizeof(struct lpfc_name)); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1315 | if (!rc) |
| 1316 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1317 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
| 1318 | if (!new_ndlp) |
| 1319 | return ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1320 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1321 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1322 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1323 | sizeof(struct lpfc_name)); |
| 1324 | if (!rc) |
| 1325 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1326 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1327 | NLP_STE_UNUSED_NODE); |
| 1328 | if (!new_ndlp) |
| 1329 | return ndlp; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1330 | keepDID = new_ndlp->nlp_DID; |
| 1331 | } else |
| 1332 | keepDID = new_ndlp->nlp_DID; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1333 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1334 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1335 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1336 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1337 | |
| 1338 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) |
| 1339 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 1340 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 1341 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1342 | /* 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] | 1343 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1344 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1345 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1346 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1347 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1348 | * to put ndlp on UNUSED list and try to free it. |
| 1349 | */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1350 | |
| 1351 | /* Fix up the rport accordingly */ |
| 1352 | rport = ndlp->rport; |
| 1353 | if (rport) { |
| 1354 | rdata = rport->dd_data; |
| 1355 | if (rdata->pnode == ndlp) { |
| 1356 | lpfc_nlp_put(ndlp); |
| 1357 | ndlp->rport = NULL; |
| 1358 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1359 | new_ndlp->rport = rport; |
| 1360 | } |
| 1361 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1362 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1363 | /* We shall actually free the ndlp with both nlp_DID and |
| 1364 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1365 | * nodelist never to be used. |
| 1366 | */ |
| 1367 | if (ndlp->nlp_DID == 0) { |
| 1368 | spin_lock_irq(&phba->ndlp_lock); |
| 1369 | NLP_SET_FREE_REQ(ndlp); |
| 1370 | spin_unlock_irq(&phba->ndlp_lock); |
| 1371 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1372 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1373 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1374 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1375 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1376 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1377 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1378 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1379 | /* Two ndlps cannot have the same did */ |
| 1380 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1381 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1382 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1383 | return new_ndlp; |
| 1384 | } |
| 1385 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1386 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1387 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1388 | * @vport: pointer to a host virtual N_Port data structure. |
| 1389 | * |
| 1390 | * This routine checks whether more Registration State Change |
| 1391 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1392 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1393 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1394 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1395 | * handling the RSCNs. |
| 1396 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1397 | void |
| 1398 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1399 | { |
| 1400 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1401 | |
| 1402 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1403 | /* |
| 1404 | * Check to see if more RSCNs came in while we were |
| 1405 | * processing this one. |
| 1406 | */ |
| 1407 | if (vport->fc_rscn_id_cnt || |
| 1408 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1409 | lpfc_els_handle_rscn(vport); |
| 1410 | else { |
| 1411 | spin_lock_irq(shost->host_lock); |
| 1412 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1413 | spin_unlock_irq(shost->host_lock); |
| 1414 | } |
| 1415 | } |
| 1416 | } |
| 1417 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1418 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1419 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1420 | * @phba: pointer to lpfc hba data structure. |
| 1421 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1422 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1423 | * |
| 1424 | * This routine is the completion callback function for issuing the Port |
| 1425 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1426 | * ndlp on the vport node list that matches the remote node ID from the |
| 1427 | * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply |
| 1428 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1429 | * checked for error conditons. If there is error status reported, PLOGI |
| 1430 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1431 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1432 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1433 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1434 | * there are additional N_Port nodes with the vport that need to perform |
| 1435 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1436 | * PLOGIs. |
| 1437 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1438 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1439 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1440 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1441 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1442 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1443 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1444 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1445 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1446 | struct lpfc_dmabuf *prsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1447 | int disc, rc, did, type; |
| 1448 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1449 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1450 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1451 | |
| 1452 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1453 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1454 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1455 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1456 | irsp->un.elsreq64.remoteID); |
| 1457 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1458 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1459 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1460 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1461 | "0136 PLOGI completes to NPort x%x " |
| 1462 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1463 | irsp->un.elsreq64.remoteID, |
| 1464 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1465 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1466 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1467 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1468 | |
| 1469 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1470 | * is being used during discovery. |
| 1471 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1472 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1473 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1474 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1475 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1476 | rc = 0; |
| 1477 | |
| 1478 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1479 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1480 | "0102 PLOGI completes to NPort x%x " |
| 1481 | "Data: x%x x%x x%x x%x x%x\n", |
| 1482 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1483 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1484 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1485 | if (lpfc_els_chk_latt(vport)) { |
| 1486 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1487 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1488 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1489 | goto out; |
| 1490 | } |
| 1491 | |
| 1492 | /* ndlp could be freed in DSM, save these values now */ |
| 1493 | type = ndlp->nlp_type; |
| 1494 | did = ndlp->nlp_DID; |
| 1495 | |
| 1496 | if (irsp->ulpStatus) { |
| 1497 | /* Check for retry */ |
| 1498 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1499 | /* ELS command is being retried */ |
| 1500 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1501 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1502 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1503 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1504 | } |
| 1505 | goto out; |
| 1506 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1507 | /* PLOGI failed Don't print the vport to vport rjts */ |
| 1508 | if (irsp->ulpStatus != IOSTAT_LS_RJT || |
| 1509 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && |
| 1510 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || |
| 1511 | (phba)->pport->cfg_log_verbose & LOG_ELS) |
| 1512 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1513 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", |
| 1514 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1515 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1516 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1517 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1518 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1519 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1520 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1521 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1522 | } else { |
| 1523 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1524 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1525 | cmdiocb->context2)->list.next, |
| 1526 | struct lpfc_dmabuf, list); |
| 1527 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1528 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1529 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1530 | } |
| 1531 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1532 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1533 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1534 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1535 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1536 | if (vport->num_disc_nodes == 0) { |
| 1537 | spin_lock_irq(shost->host_lock); |
| 1538 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1539 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1540 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1541 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1542 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1543 | } |
| 1544 | } |
| 1545 | |
| 1546 | out: |
| 1547 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1548 | return; |
| 1549 | } |
| 1550 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1551 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1552 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1553 | * @vport: pointer to a host virtual N_Port data structure. |
| 1554 | * @did: destination port identifier. |
| 1555 | * @retry: number of retries to the command IOCB. |
| 1556 | * |
| 1557 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1558 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1559 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1560 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1561 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1562 | * |
| 1563 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1564 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1565 | * will be stored into the context1 field of the IOCB for the completion |
| 1566 | * callback function to the PLOGI ELS command. |
| 1567 | * |
| 1568 | * Return code |
| 1569 | * 0 - Successfully issued a plogi for @vport |
| 1570 | * 1 - failed to issue a plogi for @vport |
| 1571 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1572 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1573 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1574 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1575 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1576 | struct serv_parm *sp; |
| 1577 | IOCB_t *icmd; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1578 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1579 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1580 | struct lpfc_sli *psli; |
| 1581 | uint8_t *pcmd; |
| 1582 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1583 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1584 | |
| 1585 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1586 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1587 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1588 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1589 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1590 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1591 | /* 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] | 1592 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1593 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1594 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1595 | if (!elsiocb) |
| 1596 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1597 | |
| 1598 | icmd = &elsiocb->iocb; |
| 1599 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1600 | |
| 1601 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1602 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1603 | pcmd += sizeof(uint32_t); |
| 1604 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1605 | sp = (struct serv_parm *) pcmd; |
| 1606 | |
| 1607 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1608 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1609 | |
| 1610 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1611 | sp->cmn.fcphHigh = FC_PH3; |
| 1612 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1613 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1614 | "Issue PLOGI: did:x%x", |
| 1615 | did, 0, 0); |
| 1616 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1617 | phba->fc_stat.elsXmitPLOGI++; |
| 1618 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1619 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1620 | |
| 1621 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1622 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1623 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1624 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1625 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1626 | } |
| 1627 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1628 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1629 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1630 | * @phba: pointer to lpfc hba data structure. |
| 1631 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1632 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1633 | * |
| 1634 | * This routine is the completion callback function for a Process Login |
| 1635 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 1636 | * status. If there is error status reported, PRLI retry shall be attempted |
| 1637 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 1638 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 1639 | * ndlp to mark the PRLI completion. |
| 1640 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1641 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1642 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1643 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1644 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1645 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1646 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1647 | IOCB_t *irsp; |
| 1648 | struct lpfc_sli *psli; |
| 1649 | struct lpfc_nodelist *ndlp; |
| 1650 | |
| 1651 | psli = &phba->sli; |
| 1652 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1653 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1654 | |
| 1655 | irsp = &(rspiocb->iocb); |
| 1656 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1657 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1658 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1659 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1660 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1661 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1662 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 1663 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1664 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1665 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1666 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1667 | "0103 PRLI completes to NPort x%x " |
| 1668 | "Data: x%x x%x x%x x%x\n", |
| 1669 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1670 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1671 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1672 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1673 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1674 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1675 | goto out; |
| 1676 | |
| 1677 | if (irsp->ulpStatus) { |
| 1678 | /* Check for retry */ |
| 1679 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1680 | /* ELS command is being retried */ |
| 1681 | goto out; |
| 1682 | } |
| 1683 | /* PRLI failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1684 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1685 | "2754 PRLI failure DID:%06X Status:x%x/x%x\n", |
| 1686 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1687 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1688 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1689 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1690 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1691 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1692 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1693 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1694 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1695 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1696 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1697 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1698 | out: |
| 1699 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1700 | return; |
| 1701 | } |
| 1702 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1703 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1704 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1705 | * @vport: pointer to a host virtual N_Port data structure. |
| 1706 | * @ndlp: pointer to a node-list data structure. |
| 1707 | * @retry: number of retries to the command IOCB. |
| 1708 | * |
| 1709 | * This routine issues a Process Login (PRLI) ELS command for the |
| 1710 | * @vport. The PRLI service parameters are set up in the payload of the |
| 1711 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 1712 | * is put to the IOCB completion callback func field before invoking the |
| 1713 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 1714 | * |
| 1715 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1716 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1717 | * will be stored into the context1 field of the IOCB for the completion |
| 1718 | * callback function to the PRLI ELS command. |
| 1719 | * |
| 1720 | * Return code |
| 1721 | * 0 - successfully issued prli iocb command for @vport |
| 1722 | * 1 - failed to issue prli iocb command for @vport |
| 1723 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1724 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1725 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1726 | uint8_t retry) |
| 1727 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1728 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1729 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1730 | PRLI *npr; |
| 1731 | IOCB_t *icmd; |
| 1732 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1733 | uint8_t *pcmd; |
| 1734 | uint16_t cmdsize; |
| 1735 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1736 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1737 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1738 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1739 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1740 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1741 | |
| 1742 | icmd = &elsiocb->iocb; |
| 1743 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1744 | |
| 1745 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1746 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1747 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1748 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1749 | |
| 1750 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 1751 | npr = (PRLI *) pcmd; |
| 1752 | /* |
| 1753 | * If our firmware version is 3.20 or later, |
| 1754 | * set the following bits for FC-TAPE support. |
| 1755 | */ |
| 1756 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 1757 | npr->ConfmComplAllowed = 1; |
| 1758 | npr->Retry = 1; |
| 1759 | npr->TaskRetryIdReq = 1; |
| 1760 | } |
| 1761 | npr->estabImagePair = 1; |
| 1762 | npr->readXferRdyDis = 1; |
| 1763 | |
| 1764 | /* For FCP support */ |
| 1765 | npr->prliType = PRLI_FCP_TYPE; |
| 1766 | npr->initiatorFunc = 1; |
| 1767 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1768 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1769 | "Issue PRLI: did:x%x", |
| 1770 | ndlp->nlp_DID, 0, 0); |
| 1771 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1772 | phba->fc_stat.elsXmitPRLI++; |
| 1773 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1774 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1775 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1776 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1777 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 1778 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1779 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1780 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1781 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1782 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1783 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1784 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1785 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1786 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1787 | } |
| 1788 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1789 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1790 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1791 | * @vport: pointer to a host virtual N_Port data structure. |
| 1792 | * |
| 1793 | * This routine performs Registration State Change Notification (RSCN) |
| 1794 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 1795 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 1796 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 1797 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 1798 | * invoked to check and handle possible more RSCN came in during the period |
| 1799 | * of processing the current ones. |
| 1800 | **/ |
| 1801 | static void |
| 1802 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 1803 | { |
| 1804 | lpfc_can_disctmo(vport); |
| 1805 | |
| 1806 | /* RSCN discovery */ |
| 1807 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 1808 | if (vport->fc_npr_cnt) |
| 1809 | if (lpfc_els_disc_plogi(vport)) |
| 1810 | return; |
| 1811 | |
| 1812 | lpfc_end_rscn(vport); |
| 1813 | } |
| 1814 | |
| 1815 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1816 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1817 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 1818 | * |
| 1819 | * This function is called when the final ADISC is completed during discovery. |
| 1820 | * This function handles clearing link attention or issuing reg_vpi depending |
| 1821 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 1822 | * discovery. |
| 1823 | * This function is called with no locks held. |
| 1824 | **/ |
| 1825 | static void |
| 1826 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 1827 | { |
| 1828 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1829 | struct lpfc_hba *phba = vport->phba; |
| 1830 | |
| 1831 | /* |
| 1832 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 1833 | * and continue discovery. |
| 1834 | */ |
| 1835 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1836 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 1837 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1838 | lpfc_issue_reg_vpi(phba, vport); |
| 1839 | return; |
| 1840 | } |
| 1841 | /* |
| 1842 | * For SLI2, we need to set port_state to READY |
| 1843 | * and continue discovery. |
| 1844 | */ |
| 1845 | if (vport->port_state < LPFC_VPORT_READY) { |
| 1846 | /* If we get here, there is nothing to ADISC */ |
| 1847 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1848 | lpfc_issue_clear_la(phba, vport); |
| 1849 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 1850 | vport->num_disc_nodes = 0; |
| 1851 | /* go thru NPR list, issue ELS PLOGIs */ |
| 1852 | if (vport->fc_npr_cnt) |
| 1853 | lpfc_els_disc_plogi(vport); |
| 1854 | if (!vport->num_disc_nodes) { |
| 1855 | spin_lock_irq(shost->host_lock); |
| 1856 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1857 | spin_unlock_irq(shost->host_lock); |
| 1858 | lpfc_can_disctmo(vport); |
| 1859 | lpfc_end_rscn(vport); |
| 1860 | } |
| 1861 | } |
| 1862 | vport->port_state = LPFC_VPORT_READY; |
| 1863 | } else |
| 1864 | lpfc_rscn_disc(vport); |
| 1865 | } |
| 1866 | |
| 1867 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1868 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1869 | * @vport: pointer to a host virtual N_Port data structure. |
| 1870 | * |
| 1871 | * This routine determines whether there are more ndlps on a @vport |
| 1872 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 1873 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 1874 | * remaining nodes which need to have ADISC sent. |
| 1875 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1876 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1877 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1878 | { |
| 1879 | int sentadisc; |
| 1880 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1881 | if (vport->num_disc_nodes) |
| 1882 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1883 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1884 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1885 | "0210 Continue discovery with %d ADISCs to go " |
| 1886 | "Data: x%x x%x x%x\n", |
| 1887 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 1888 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1889 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1890 | if (vport->fc_flag & FC_NLP_MORE) { |
| 1891 | lpfc_set_disctmo(vport); |
| 1892 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 1893 | sentadisc = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1894 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1895 | if (!vport->num_disc_nodes) |
| 1896 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1897 | return; |
| 1898 | } |
| 1899 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1900 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1901 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1902 | * @phba: pointer to lpfc hba data structure. |
| 1903 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1904 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1905 | * |
| 1906 | * This routine is the completion function for issuing the Address Discover |
| 1907 | * (ADISC) command. It first checks to see whether link went down during |
| 1908 | * the discovery process. If so, the node will be marked as node port |
| 1909 | * recovery for issuing discover IOCB by the link attention handler and |
| 1910 | * exit. Otherwise, the response status is checked. If error was reported |
| 1911 | * in the response status, the ADISC command shall be retried by invoking |
| 1912 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 1913 | * the response status, the state machine is invoked to set transition |
| 1914 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 1915 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1916 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1917 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1918 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1919 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1920 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1921 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1922 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1923 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1924 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1925 | |
| 1926 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1927 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1928 | |
| 1929 | irsp = &(rspiocb->iocb); |
| 1930 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1931 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1932 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1933 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 1934 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1935 | ndlp->nlp_DID); |
| 1936 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1937 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1938 | * is being used during discovery. |
| 1939 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1940 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1941 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1942 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1943 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1944 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1945 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1946 | "0104 ADISC completes to NPort x%x " |
| 1947 | "Data: x%x x%x x%x x%x x%x\n", |
| 1948 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1949 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1950 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1951 | if (lpfc_els_chk_latt(vport)) { |
| 1952 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1953 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1954 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1955 | goto out; |
| 1956 | } |
| 1957 | |
| 1958 | if (irsp->ulpStatus) { |
| 1959 | /* Check for retry */ |
| 1960 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1961 | /* ELS command is being retried */ |
| 1962 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1963 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1964 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1965 | spin_unlock_irq(shost->host_lock); |
| 1966 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1967 | } |
| 1968 | goto out; |
| 1969 | } |
| 1970 | /* ADISC failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1971 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1972 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", |
| 1973 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1974 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1975 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1976 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1977 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1978 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1979 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1980 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1981 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1982 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1983 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1984 | /* Check to see if there are more ADISCs to be sent */ |
| 1985 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1986 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1987 | out: |
| 1988 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1989 | return; |
| 1990 | } |
| 1991 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1992 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1993 | * 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] | 1994 | * @vport: pointer to a virtual N_Port data structure. |
| 1995 | * @ndlp: pointer to a node-list data structure. |
| 1996 | * @retry: number of retries to the command IOCB. |
| 1997 | * |
| 1998 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 1999 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 2000 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 2001 | * to issue the ADISC ELS command. |
| 2002 | * |
| 2003 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2004 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2005 | * will be stored into the context1 field of the IOCB for the completion |
| 2006 | * callback function to the ADISC ELS command. |
| 2007 | * |
| 2008 | * Return code |
| 2009 | * 0 - successfully issued adisc |
| 2010 | * 1 - failed to issue adisc |
| 2011 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2012 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2013 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2014 | uint8_t retry) |
| 2015 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2016 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2017 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2018 | ADISC *ap; |
| 2019 | IOCB_t *icmd; |
| 2020 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2021 | uint8_t *pcmd; |
| 2022 | uint16_t cmdsize; |
| 2023 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2024 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2025 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2026 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2027 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2028 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2029 | |
| 2030 | icmd = &elsiocb->iocb; |
| 2031 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2032 | |
| 2033 | /* For ADISC request, remainder of payload is service parameters */ |
| 2034 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2035 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2036 | |
| 2037 | /* Fill in ADISC payload */ |
| 2038 | ap = (ADISC *) pcmd; |
| 2039 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2040 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2041 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2042 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2043 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2044 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2045 | "Issue ADISC: did:x%x", |
| 2046 | ndlp->nlp_DID, 0, 0); |
| 2047 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2048 | phba->fc_stat.elsXmitADISC++; |
| 2049 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2050 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2051 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2052 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2053 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2054 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2055 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2056 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2057 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2058 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2059 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2060 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2061 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2062 | } |
| 2063 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2064 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2065 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2066 | * @phba: pointer to lpfc hba data structure. |
| 2067 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2068 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2069 | * |
| 2070 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 2071 | * command. If no error status was reported from the LOGO response, the |
| 2072 | * state machine of the associated ndlp shall be invoked for transition with |
| 2073 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 2074 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 2075 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2076 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2077 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2078 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2079 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2080 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2081 | struct lpfc_vport *vport = ndlp->vport; |
| 2082 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2083 | IOCB_t *irsp; |
| 2084 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2085 | |
| 2086 | psli = &phba->sli; |
| 2087 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2088 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2089 | |
| 2090 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2091 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2092 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2093 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2094 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2095 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2096 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 2097 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2098 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2099 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2100 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2101 | "0105 LOGO completes to NPort x%x " |
| 2102 | "Data: x%x x%x x%x x%x\n", |
| 2103 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2104 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2105 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2106 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2107 | goto out; |
| 2108 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2109 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 2110 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 2111 | * which should abort all outstanding IOs. |
| 2112 | */ |
| 2113 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2114 | NLP_EVT_DEVICE_RM); |
| 2115 | goto out; |
| 2116 | } |
| 2117 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2118 | if (irsp->ulpStatus) { |
| 2119 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2120 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2121 | /* ELS command is being retried */ |
| 2122 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2123 | /* LOGO failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2124 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2125 | "2756 LOGO failure DID:%06X Status:x%x/x%x\n", |
| 2126 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2127 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2128 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2129 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2130 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2131 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2132 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2133 | NLP_EVT_CMPL_LOGO); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2134 | } else |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2135 | /* Good status, call state machine. |
| 2136 | * This will unregister the rpi if needed. |
| 2137 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2138 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2139 | NLP_EVT_CMPL_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2140 | out: |
| 2141 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2142 | return; |
| 2143 | } |
| 2144 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2145 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2146 | * 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] | 2147 | * @vport: pointer to a virtual N_Port data structure. |
| 2148 | * @ndlp: pointer to a node-list data structure. |
| 2149 | * @retry: number of retries to the command IOCB. |
| 2150 | * |
| 2151 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2152 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2153 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2154 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2155 | * |
| 2156 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2157 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2158 | * will be stored into the context1 field of the IOCB for the completion |
| 2159 | * callback function to the LOGO ELS command. |
| 2160 | * |
| 2161 | * Return code |
| 2162 | * 0 - successfully issued logo |
| 2163 | * 1 - failed to issue logo |
| 2164 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2165 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2166 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2167 | uint8_t retry) |
| 2168 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2169 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2170 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2171 | IOCB_t *icmd; |
| 2172 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2173 | uint8_t *pcmd; |
| 2174 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2175 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2176 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2177 | spin_lock_irq(shost->host_lock); |
| 2178 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2179 | spin_unlock_irq(shost->host_lock); |
| 2180 | return 0; |
| 2181 | } |
| 2182 | spin_unlock_irq(shost->host_lock); |
| 2183 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2184 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2185 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2186 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2187 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2188 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2189 | |
| 2190 | icmd = &elsiocb->iocb; |
| 2191 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2192 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2193 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2194 | |
| 2195 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2196 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2197 | pcmd += sizeof(uint32_t); |
| 2198 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2199 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2200 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2201 | "Issue LOGO: did:x%x", |
| 2202 | ndlp->nlp_DID, 0, 0); |
| 2203 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2204 | phba->fc_stat.elsXmitLOGO++; |
| 2205 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2206 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2207 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2208 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2209 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2210 | |
| 2211 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2212 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2213 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2214 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2215 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2216 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2217 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2218 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2219 | } |
| 2220 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2221 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2222 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2223 | * @phba: pointer to lpfc hba data structure. |
| 2224 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2225 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2226 | * |
| 2227 | * This routine is a generic completion callback function for ELS commands. |
| 2228 | * Specifically, it is the callback function which does not need to perform |
| 2229 | * any command specific operations. It is currently used by the ELS command |
| 2230 | * issuing routines for the ELS State Change Request (SCR), |
| 2231 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 2232 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2233 | * certain debug loggings, this callback function simply invokes the |
| 2234 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2235 | * discovery process. |
| 2236 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2237 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2238 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2239 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2240 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2241 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2242 | IOCB_t *irsp; |
| 2243 | |
| 2244 | irsp = &rspiocb->iocb; |
| 2245 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2246 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2247 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2248 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2249 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2250 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2251 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2252 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2253 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2254 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2255 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2256 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2257 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2258 | return; |
| 2259 | } |
| 2260 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2261 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2262 | * 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] | 2263 | * @vport: pointer to a host virtual N_Port data structure. |
| 2264 | * @nportid: N_Port identifier to the remote node. |
| 2265 | * @retry: number of retries to the command IOCB. |
| 2266 | * |
| 2267 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2268 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2269 | * first search the @vport node list to find the matching ndlp. If no such |
| 2270 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2271 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2272 | * routine is invoked to send the SCR IOCB. |
| 2273 | * |
| 2274 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2275 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2276 | * will be stored into the context1 field of the IOCB for the completion |
| 2277 | * callback function to the SCR ELS command. |
| 2278 | * |
| 2279 | * Return code |
| 2280 | * 0 - Successfully issued scr command |
| 2281 | * 1 - Failed to issue scr command |
| 2282 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2283 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2284 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2285 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2286 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2287 | IOCB_t *icmd; |
| 2288 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2289 | struct lpfc_sli *psli; |
| 2290 | uint8_t *pcmd; |
| 2291 | uint16_t cmdsize; |
| 2292 | struct lpfc_nodelist *ndlp; |
| 2293 | |
| 2294 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2295 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2296 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2297 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2298 | if (!ndlp) { |
| 2299 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2300 | if (!ndlp) |
| 2301 | return 1; |
| 2302 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2303 | lpfc_enqueue_node(vport, ndlp); |
| 2304 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2305 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2306 | if (!ndlp) |
| 2307 | return 1; |
| 2308 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2309 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2310 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2311 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2312 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2313 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2314 | /* This will trigger the release of the node just |
| 2315 | * allocated |
| 2316 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2317 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2318 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2319 | } |
| 2320 | |
| 2321 | icmd = &elsiocb->iocb; |
| 2322 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2323 | |
| 2324 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2325 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2326 | |
| 2327 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2328 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2329 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2330 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2331 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2332 | "Issue SCR: did:x%x", |
| 2333 | ndlp->nlp_DID, 0, 0); |
| 2334 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2335 | phba->fc_stat.elsXmitSCR++; |
| 2336 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2337 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2338 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2339 | /* The additional lpfc_nlp_put will cause the following |
| 2340 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2341 | * the node. |
| 2342 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2343 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2344 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2345 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2346 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2347 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2348 | * trigger the release of node. |
| 2349 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2350 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2351 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2352 | } |
| 2353 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2354 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2355 | * 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] | 2356 | * @vport: pointer to a host virtual N_Port data structure. |
| 2357 | * @nportid: N_Port identifier to the remote node. |
| 2358 | * @retry: number of retries to the command IOCB. |
| 2359 | * |
| 2360 | * This routine issues a Fibre Channel Address Resolution Response |
| 2361 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2362 | * is passed into the function. It first search the @vport node list to find |
| 2363 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2364 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2365 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2366 | * |
| 2367 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2368 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2369 | * will be stored into the context1 field of the IOCB for the completion |
| 2370 | * callback function to the PARPR ELS command. |
| 2371 | * |
| 2372 | * Return code |
| 2373 | * 0 - Successfully issued farpr command |
| 2374 | * 1 - Failed to issue farpr command |
| 2375 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2376 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2377 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2378 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2379 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2380 | IOCB_t *icmd; |
| 2381 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2382 | struct lpfc_sli *psli; |
| 2383 | FARP *fp; |
| 2384 | uint8_t *pcmd; |
| 2385 | uint32_t *lp; |
| 2386 | uint16_t cmdsize; |
| 2387 | struct lpfc_nodelist *ondlp; |
| 2388 | struct lpfc_nodelist *ndlp; |
| 2389 | |
| 2390 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2391 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2392 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2393 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2394 | if (!ndlp) { |
| 2395 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2396 | if (!ndlp) |
| 2397 | return 1; |
| 2398 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2399 | lpfc_enqueue_node(vport, ndlp); |
| 2400 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2401 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2402 | if (!ndlp) |
| 2403 | return 1; |
| 2404 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2405 | |
| 2406 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2407 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2408 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2409 | /* This will trigger the release of the node just |
| 2410 | * allocated |
| 2411 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2412 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2413 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2414 | } |
| 2415 | |
| 2416 | icmd = &elsiocb->iocb; |
| 2417 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2418 | |
| 2419 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2420 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2421 | |
| 2422 | /* Fill in FARPR payload */ |
| 2423 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2424 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2425 | lp = (uint32_t *) pcmd; |
| 2426 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2427 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2428 | fp->Rflags = 0; |
| 2429 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2430 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2431 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2432 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2433 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2434 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2435 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2436 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2437 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2438 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2439 | } |
| 2440 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2441 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2442 | "Issue FARPR: did:x%x", |
| 2443 | ndlp->nlp_DID, 0, 0); |
| 2444 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2445 | phba->fc_stat.elsXmitFARPR++; |
| 2446 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2447 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2448 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2449 | /* The additional lpfc_nlp_put will cause the following |
| 2450 | * lpfc_els_free_iocb routine to trigger the release of |
| 2451 | * the node. |
| 2452 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2453 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2454 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2455 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2456 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2457 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2458 | * trigger the release of the node. |
| 2459 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2460 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2461 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2462 | } |
| 2463 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2464 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2465 | * 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] | 2466 | * @vport: pointer to a host virtual N_Port data structure. |
| 2467 | * @nlp: pointer to a node-list data structure. |
| 2468 | * |
| 2469 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2470 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2471 | * removes the ELS retry event if it presents. In addition, if the |
| 2472 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2473 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2474 | * ADISC. |
| 2475 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2476 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2477 | 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] | 2478 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2479 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2480 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2481 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2482 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2483 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2484 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2485 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2486 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2487 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2488 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2489 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2490 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2491 | /* Decrement nlp reference count held for the delayed retry */ |
| 2492 | evtp = &nlp->els_retry_evt; |
| 2493 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2494 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2495 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2496 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2497 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2498 | spin_unlock_irq(shost->host_lock); |
| 2499 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2500 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2501 | /* Check if there are more ADISCs to be sent */ |
| 2502 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2503 | } else { |
| 2504 | /* Check if there are more PLOGIs to be sent */ |
| 2505 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2506 | if (vport->num_disc_nodes == 0) { |
| 2507 | spin_lock_irq(shost->host_lock); |
| 2508 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2509 | spin_unlock_irq(shost->host_lock); |
| 2510 | lpfc_can_disctmo(vport); |
| 2511 | lpfc_end_rscn(vport); |
| 2512 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2513 | } |
| 2514 | } |
| 2515 | } |
| 2516 | return; |
| 2517 | } |
| 2518 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2519 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2520 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2521 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2522 | * |
| 2523 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2524 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2525 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2526 | * adds the delayed events to the HBA work list and invokes the |
| 2527 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2528 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2529 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2530 | * reference to ndlp will still be available when the worker thread gets |
| 2531 | * to the event associated with the ndlp. |
| 2532 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2533 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2534 | lpfc_els_retry_delay(unsigned long ptr) |
| 2535 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2536 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2537 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2538 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2539 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2540 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2541 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2542 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2543 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2544 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2545 | return; |
| 2546 | } |
| 2547 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2548 | /* We need to hold the node by incrementing the reference |
| 2549 | * count until the queued work is done |
| 2550 | */ |
| 2551 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2552 | if (evtp->evt_arg1) { |
| 2553 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2554 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2555 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2556 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2557 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2558 | return; |
| 2559 | } |
| 2560 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2561 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2562 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2563 | * @ndlp: pointer to a node-list data structure. |
| 2564 | * |
| 2565 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 2566 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 2567 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 2568 | * function according to the delayed ELS command to retry the command. |
| 2569 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2570 | void |
| 2571 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 2572 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2573 | struct lpfc_vport *vport = ndlp->vport; |
| 2574 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2575 | uint32_t cmd, did, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2576 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2577 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2578 | did = ndlp->nlp_DID; |
| 2579 | cmd = ndlp->nlp_last_elscmd; |
| 2580 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2581 | |
| 2582 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2583 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2584 | return; |
| 2585 | } |
| 2586 | |
| 2587 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2588 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 2589 | /* |
| 2590 | * If a discovery event readded nlp_delayfunc after timer |
| 2591 | * firing and before processing the timer, cancel the |
| 2592 | * nlp_delayfunc. |
| 2593 | */ |
| 2594 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2595 | retry = ndlp->nlp_retry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 2596 | ndlp->nlp_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2597 | |
| 2598 | switch (cmd) { |
| 2599 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2600 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2601 | break; |
| 2602 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2603 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2604 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2605 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2606 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2607 | break; |
| 2608 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2609 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2610 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2611 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2612 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2613 | break; |
| 2614 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2615 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2616 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2617 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2618 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2619 | break; |
| 2620 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2621 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2622 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2623 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2624 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2625 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2626 | case ELS_CMD_FDISC: |
| 2627 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
| 2628 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2629 | } |
| 2630 | return; |
| 2631 | } |
| 2632 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2633 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2634 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2635 | * @phba: pointer to lpfc hba data structure. |
| 2636 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2637 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2638 | * |
| 2639 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 2640 | * failed. The following ELS IOCBs use this function for retrying the command |
| 2641 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 2642 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 2643 | * returned error status, it makes the decision whether a retry shall be |
| 2644 | * issued for the command, and whether a retry shall be made immediately or |
| 2645 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 2646 | * is called to retry the command. In the later case, the ELS command shall |
| 2647 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 2648 | * ndlp for the delayed command issusing. |
| 2649 | * |
| 2650 | * Return code |
| 2651 | * 0 - No retry of els command is made |
| 2652 | * 1 - Immediate or delayed retry of els command is made |
| 2653 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2654 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2655 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2656 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2657 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2658 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2659 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2660 | IOCB_t *irsp = &rspiocb->iocb; |
| 2661 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2662 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2663 | uint32_t *elscmd; |
| 2664 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2665 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2666 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2667 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2668 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2669 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2670 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2671 | /* Note: context2 may be 0 for internal driver abort |
| 2672 | * of delays ELS command. |
| 2673 | */ |
| 2674 | |
| 2675 | if (pcmd && pcmd->virt) { |
| 2676 | elscmd = (uint32_t *) (pcmd->virt); |
| 2677 | cmd = *elscmd++; |
| 2678 | } |
| 2679 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2680 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2681 | did = ndlp->nlp_DID; |
| 2682 | else { |
| 2683 | /* We should only hit this case for retrying PLOGI */ |
| 2684 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2685 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2686 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 2687 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2688 | return 1; |
| 2689 | } |
| 2690 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2691 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2692 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 2693 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 2694 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2695 | switch (irsp->ulpStatus) { |
| 2696 | case IOSTAT_FCP_RSP_ERROR: |
| 2697 | case IOSTAT_REMOTE_STOP: |
| 2698 | break; |
| 2699 | |
| 2700 | case IOSTAT_LOCAL_REJECT: |
| 2701 | switch ((irsp->un.ulpWord[4] & 0xff)) { |
| 2702 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2703 | if (cmd == ELS_CMD_FLOGI) { |
| 2704 | if (PCI_DEVICE_ID_HORNET == |
| 2705 | phba->pcidev->device) { |
| 2706 | phba->fc_topology = TOPOLOGY_LOOP; |
| 2707 | phba->pport->fc_myDID = 0; |
| 2708 | phba->alpa_map[0] = 0; |
| 2709 | phba->alpa_map[1] = 0; |
| 2710 | } |
| 2711 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2712 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2713 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2714 | retry = 1; |
| 2715 | break; |
| 2716 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2717 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2718 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2719 | "0124 Retry illegal cmd x%x " |
| 2720 | "retry:x%x delay:x%x\n", |
| 2721 | cmd, cmdiocb->retry, delay); |
| 2722 | retry = 1; |
| 2723 | /* All command's retry policy */ |
| 2724 | maxretry = 8; |
| 2725 | if (cmdiocb->retry > 2) |
| 2726 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2727 | break; |
| 2728 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2729 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2730 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2731 | retry = 1; |
| 2732 | if (cmdiocb->retry > 100) |
| 2733 | delay = 100; |
| 2734 | maxretry = 250; |
| 2735 | break; |
| 2736 | |
| 2737 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2738 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2739 | retry = 1; |
| 2740 | break; |
| 2741 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2742 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2743 | case IOERR_INVALID_RPI: |
| 2744 | retry = 1; |
| 2745 | break; |
| 2746 | } |
| 2747 | break; |
| 2748 | |
| 2749 | case IOSTAT_NPORT_RJT: |
| 2750 | case IOSTAT_FABRIC_RJT: |
| 2751 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 2752 | retry = 1; |
| 2753 | break; |
| 2754 | } |
| 2755 | break; |
| 2756 | |
| 2757 | case IOSTAT_NPORT_BSY: |
| 2758 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2759 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2760 | retry = 1; |
| 2761 | break; |
| 2762 | |
| 2763 | case IOSTAT_LS_RJT: |
| 2764 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 2765 | /* Added for Vendor specifc support |
| 2766 | * Just keep retrying for these Rsn / Exp codes |
| 2767 | */ |
| 2768 | switch (stat.un.b.lsRjtRsnCode) { |
| 2769 | case LSRJT_UNABLE_TPC: |
| 2770 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2771 | LSEXP_CMD_IN_PROGRESS) { |
| 2772 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2773 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2774 | maxretry = 48; |
| 2775 | } |
| 2776 | retry = 1; |
| 2777 | break; |
| 2778 | } |
James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 2779 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2780 | LSEXP_CANT_GIVE_DATA) { |
| 2781 | if (cmd == ELS_CMD_PLOGI) { |
| 2782 | delay = 1000; |
| 2783 | maxretry = 48; |
| 2784 | } |
| 2785 | retry = 1; |
| 2786 | break; |
| 2787 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2788 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2789 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2790 | maxretry = lpfc_max_els_tries + 1; |
| 2791 | retry = 1; |
| 2792 | break; |
| 2793 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2794 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2795 | (cmd == ELS_CMD_FDISC) && |
| 2796 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2797 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2798 | "0125 FDISC Failed (x%x). " |
| 2799 | "Fabric out of resources\n", |
| 2800 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2801 | lpfc_vport_set_state(vport, |
| 2802 | FC_VPORT_NO_FABRIC_RSCS); |
| 2803 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2804 | break; |
| 2805 | |
| 2806 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2807 | if ((cmd == ELS_CMD_PLOGI) || |
| 2808 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2809 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2810 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2811 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2812 | /* FDISC retry policy */ |
| 2813 | maxretry = 48; |
| 2814 | if (cmdiocb->retry >= 32) |
| 2815 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2816 | } |
| 2817 | retry = 1; |
| 2818 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2819 | |
| 2820 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2821 | /* There are some cases where switches return this |
| 2822 | * error when they are not ready and should be returning |
| 2823 | * Logical Busy. We should delay every time. |
| 2824 | */ |
| 2825 | if (cmd == ELS_CMD_FDISC && |
| 2826 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 2827 | maxretry = 3; |
| 2828 | delay = 1000; |
| 2829 | retry = 1; |
| 2830 | break; |
| 2831 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2832 | case LSRJT_PROTOCOL_ERR: |
| 2833 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2834 | (cmd == ELS_CMD_FDISC) && |
| 2835 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 2836 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 2837 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2838 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2839 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2840 | "Fabric Detected Bad WWN\n", |
| 2841 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2842 | lpfc_vport_set_state(vport, |
| 2843 | FC_VPORT_FABRIC_REJ_WWN); |
| 2844 | } |
| 2845 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2846 | } |
| 2847 | break; |
| 2848 | |
| 2849 | case IOSTAT_INTERMED_RSP: |
| 2850 | case IOSTAT_BA_RJT: |
| 2851 | break; |
| 2852 | |
| 2853 | default: |
| 2854 | break; |
| 2855 | } |
| 2856 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2857 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2858 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2859 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2860 | if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 2861 | (phba->fc_topology != TOPOLOGY_LOOP) && |
| 2862 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2863 | /* FLOGI retry policy */ |
| 2864 | retry = 1; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2865 | /* retry forever */ |
| 2866 | maxretry = 0; |
| 2867 | if (cmdiocb->retry >= 100) |
| 2868 | delay = 5000; |
| 2869 | else if (cmdiocb->retry >= 32) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2870 | delay = 1000; |
| 2871 | } |
| 2872 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2873 | cmdiocb->retry++; |
| 2874 | if (maxretry && (cmdiocb->retry >= maxretry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2875 | phba->fc_stat.elsRetryExceeded++; |
| 2876 | retry = 0; |
| 2877 | } |
| 2878 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2879 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 2880 | retry = 0; |
| 2881 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2882 | if (retry) { |
| 2883 | |
| 2884 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2885 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2886 | "0107 Retry ELS command x%x to remote " |
| 2887 | "NPORT x%x Data: x%x x%x\n", |
| 2888 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2889 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2890 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 2891 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 2892 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { |
| 2893 | /* Don't reset timer for no resources */ |
| 2894 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2895 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2896 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2897 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2898 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2899 | } |
| 2900 | |
| 2901 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2902 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2903 | phba->fc_stat.elsDelayRetry++; |
| 2904 | ndlp->nlp_retry = cmdiocb->retry; |
| 2905 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2906 | /* delay is specified in milliseconds */ |
| 2907 | mod_timer(&ndlp->nlp_delayfunc, |
| 2908 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2909 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2910 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2911 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2912 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2913 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2914 | if (cmd == ELS_CMD_PRLI) |
| 2915 | lpfc_nlp_set_state(vport, ndlp, |
| 2916 | NLP_STE_REG_LOGIN_ISSUE); |
| 2917 | else |
| 2918 | lpfc_nlp_set_state(vport, ndlp, |
| 2919 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2920 | ndlp->nlp_last_elscmd = cmd; |
| 2921 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2922 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2923 | } |
| 2924 | switch (cmd) { |
| 2925 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2926 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2927 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2928 | case ELS_CMD_FDISC: |
| 2929 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 2930 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2931 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2932 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2933 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2934 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2935 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2936 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2937 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2938 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2939 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2940 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2941 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 2942 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2943 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2944 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2945 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2946 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 2947 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2948 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2949 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2950 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2951 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 2952 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2953 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2954 | } |
| 2955 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2956 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2957 | if (logerr) { |
| 2958 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2959 | "0137 No retry ELS command x%x to remote " |
| 2960 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 2961 | cmd, did, irsp->ulpStatus, |
| 2962 | irsp->un.ulpWord[4]); |
| 2963 | } |
| 2964 | else { |
| 2965 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2966 | "0108 No retry ELS command x%x to remote " |
| 2967 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 2968 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 2969 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2970 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2971 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2972 | } |
| 2973 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2974 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2975 | * 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] | 2976 | * @phba: pointer to lpfc hba data structure. |
| 2977 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 2978 | * |
| 2979 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 2980 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 2981 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 2982 | * response of the command IOCB. If so, it will be released before releasing |
| 2983 | * the lpfc DMA buffer associated with the IOCB itself. |
| 2984 | * |
| 2985 | * Return code |
| 2986 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2987 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2988 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2989 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 2990 | { |
| 2991 | struct lpfc_dmabuf *buf_ptr; |
| 2992 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2993 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2994 | if (!list_empty(&buf_ptr1->list)) { |
| 2995 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 2996 | struct lpfc_dmabuf, |
| 2997 | list); |
| 2998 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2999 | kfree(buf_ptr); |
| 3000 | } |
| 3001 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 3002 | kfree(buf_ptr1); |
| 3003 | return 0; |
| 3004 | } |
| 3005 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3006 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3007 | * 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] | 3008 | * @phba: pointer to lpfc hba data structure. |
| 3009 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 3010 | * |
| 3011 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 3012 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 3013 | * pool. |
| 3014 | * |
| 3015 | * Return code |
| 3016 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 3017 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3018 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3019 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 3020 | { |
| 3021 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 3022 | kfree(buf_ptr); |
| 3023 | return 0; |
| 3024 | } |
| 3025 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3026 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3027 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3028 | * @phba: pointer to lpfc hba data structure. |
| 3029 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 3030 | * |
| 3031 | * This routine frees a command IOCB and its associated resources. The |
| 3032 | * command IOCB data structure contains the reference to various associated |
| 3033 | * resources, these fields must be set to NULL if the associated reference |
| 3034 | * not present: |
| 3035 | * context1 - reference to ndlp |
| 3036 | * context2 - reference to cmd |
| 3037 | * context2->next - reference to rsp |
| 3038 | * context3 - reference to bpl |
| 3039 | * |
| 3040 | * It first properly decrements the reference count held on ndlp for the |
| 3041 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 3042 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 3043 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 3044 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 3045 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 3046 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 3047 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 3048 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 3049 | * |
| 3050 | * Return code |
| 3051 | * 0 - Success (currently, always return 0) |
| 3052 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3053 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3054 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3055 | { |
| 3056 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3057 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3058 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3059 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 3060 | if (ndlp) { |
| 3061 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 3062 | lpfc_nlp_put(ndlp); |
| 3063 | |
| 3064 | /* If the ndlp is not being used by another discovery |
| 3065 | * thread, free it. |
| 3066 | */ |
| 3067 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3068 | /* If ndlp is being used by another discovery |
| 3069 | * thread, just clear NLP_DEFER_RM |
| 3070 | */ |
| 3071 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 3072 | } |
| 3073 | } |
| 3074 | else |
| 3075 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3076 | elsiocb->context1 = NULL; |
| 3077 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3078 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 3079 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3080 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 3081 | /* Firmware could still be in progress of DMAing |
| 3082 | * payload, so don't free data buffer till after |
| 3083 | * a hbeat. |
| 3084 | */ |
| 3085 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 3086 | buf_ptr = elsiocb->context2; |
| 3087 | elsiocb->context2 = NULL; |
| 3088 | if (buf_ptr) { |
| 3089 | buf_ptr1 = NULL; |
| 3090 | spin_lock_irq(&phba->hbalock); |
| 3091 | if (!list_empty(&buf_ptr->list)) { |
| 3092 | list_remove_head(&buf_ptr->list, |
| 3093 | buf_ptr1, struct lpfc_dmabuf, |
| 3094 | list); |
| 3095 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 3096 | list_add_tail(&buf_ptr1->list, |
| 3097 | &phba->elsbuf); |
| 3098 | phba->elsbuf_cnt++; |
| 3099 | } |
| 3100 | INIT_LIST_HEAD(&buf_ptr->list); |
| 3101 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 3102 | phba->elsbuf_cnt++; |
| 3103 | spin_unlock_irq(&phba->hbalock); |
| 3104 | } |
| 3105 | } else { |
| 3106 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 3107 | lpfc_els_free_data(phba, buf_ptr1); |
| 3108 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3109 | } |
| 3110 | |
| 3111 | if (elsiocb->context3) { |
| 3112 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3113 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3114 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3115 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3116 | return 0; |
| 3117 | } |
| 3118 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3119 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3120 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3121 | * @phba: pointer to lpfc hba data structure. |
| 3122 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3123 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3124 | * |
| 3125 | * This routine is the completion callback function to the Logout (LOGO) |
| 3126 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 3127 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 3128 | * release the ndlp if it has the last reference remaining (reference count |
| 3129 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 3130 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 3131 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 3132 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 3133 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 3134 | * IOCB data structure. |
| 3135 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3136 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3137 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3138 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3139 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3140 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3141 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3142 | IOCB_t *irsp; |
| 3143 | |
| 3144 | irsp = &rspiocb->iocb; |
| 3145 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3146 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 3147 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3148 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3149 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3150 | "0109 ACC to LOGO completes to NPort x%x " |
| 3151 | "Data: x%x x%x x%x\n", |
| 3152 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3153 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3154 | |
| 3155 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 3156 | /* NPort Recovery mode or node is just allocated */ |
| 3157 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3158 | /* If the ndlp is being used by another discovery |
| 3159 | * thread, just unregister the RPI. |
| 3160 | */ |
| 3161 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3162 | } else { |
| 3163 | /* Indicate the node has already released, should |
| 3164 | * not reference to it from within lpfc_els_free_iocb. |
| 3165 | */ |
| 3166 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3167 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3168 | } |
| 3169 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3170 | return; |
| 3171 | } |
| 3172 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3173 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3174 | * 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] | 3175 | * @phba: pointer to lpfc hba data structure. |
| 3176 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 3177 | * |
| 3178 | * This routine is the completion callback function for unregister default |
| 3179 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 3180 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 3181 | * decrements the ndlp reference count held for this completion callback |
| 3182 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 3183 | * whether there is only one reference left on the ndlp. If so, it will |
| 3184 | * perform one more decrement and trigger the release of the ndlp. |
| 3185 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3186 | void |
| 3187 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3188 | { |
| 3189 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3190 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3191 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3192 | /* |
| 3193 | * This routine is used to register and unregister in previous SLI |
| 3194 | * modes. |
| 3195 | */ |
| 3196 | if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) && |
| 3197 | (phba->sli_rev == LPFC_SLI_REV4)) |
| 3198 | lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi); |
| 3199 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3200 | pmb->context1 = NULL; |
| 3201 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3202 | kfree(mp); |
| 3203 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3204 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3205 | lpfc_nlp_put(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3206 | /* This is the end of the default RPI cleanup logic for this |
| 3207 | * ndlp. If no other discovery threads are using this ndlp. |
| 3208 | * we should free all resources associated with it. |
| 3209 | */ |
| 3210 | lpfc_nlp_not_used(ndlp); |
| 3211 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3212 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3213 | return; |
| 3214 | } |
| 3215 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3216 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3217 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3218 | * @phba: pointer to lpfc hba data structure. |
| 3219 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3220 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3221 | * |
| 3222 | * This routine is the completion callback function for ELS Response IOCB |
| 3223 | * command. In normal case, this callback function just properly sets the |
| 3224 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 3225 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 3226 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 3227 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 3228 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 3229 | * routine shall be invoked trying to release the ndlp if no other threads |
| 3230 | * are currently referring it. |
| 3231 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3232 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3233 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3234 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3235 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3236 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3237 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 3238 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3239 | IOCB_t *irsp; |
| 3240 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3241 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3242 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3243 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3244 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3245 | irsp = &rspiocb->iocb; |
| 3246 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3247 | if (cmdiocb->context_un.mbox) |
| 3248 | mbox = cmdiocb->context_un.mbox; |
| 3249 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3250 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 3251 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 3252 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3253 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3254 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3255 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3256 | /* A LS_RJT associated with Default RPI cleanup has its own |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 3257 | * separate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3258 | */ |
| 3259 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 3260 | ls_rjt = 1; |
| 3261 | } |
| 3262 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3263 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3264 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3265 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3266 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3267 | if (mp) { |
| 3268 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3269 | kfree(mp); |
| 3270 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3271 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3272 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3273 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3274 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3275 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3276 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3277 | /* Indicate the node has already released, |
| 3278 | * should not reference to it from within |
| 3279 | * the routine lpfc_els_free_iocb. |
| 3280 | */ |
| 3281 | cmdiocb->context1 = NULL; |
| 3282 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3283 | goto out; |
| 3284 | } |
| 3285 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3286 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3287 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3288 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3289 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3290 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3291 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3292 | "0110 ELS response tag x%x completes " |
| 3293 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3294 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3295 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3296 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3297 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3298 | if (mbox) { |
| 3299 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3300 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3301 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3302 | /* Increment reference count to ndlp to hold the |
| 3303 | * reference to ndlp for the callback function. |
| 3304 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3305 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3306 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3307 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3308 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3309 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3310 | } |
| 3311 | else { |
| 3312 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3313 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3314 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3315 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3316 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3317 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3318 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3319 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3320 | else |
| 3321 | /* Decrement the ndlp reference count we |
| 3322 | * set for this failed mailbox command. |
| 3323 | */ |
| 3324 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3325 | |
| 3326 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3327 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3328 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3329 | "Data: x%x x%x x%x\n", |
| 3330 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3331 | ndlp->nlp_rpi); |
| 3332 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3333 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3334 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3335 | /* Indicate node has already been released, |
| 3336 | * should not reference to it from within |
| 3337 | * the routine lpfc_els_free_iocb. |
| 3338 | */ |
| 3339 | cmdiocb->context1 = NULL; |
| 3340 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3341 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3342 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3343 | if (!lpfc_error_lost_link(irsp) && |
| 3344 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3345 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3346 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3347 | /* Indicate node has already been |
| 3348 | * released, should not reference |
| 3349 | * to it from within the routine |
| 3350 | * lpfc_els_free_iocb. |
| 3351 | */ |
| 3352 | cmdiocb->context1 = NULL; |
| 3353 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3354 | } |
| 3355 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3356 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3357 | if (mp) { |
| 3358 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3359 | kfree(mp); |
| 3360 | } |
| 3361 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3362 | } |
| 3363 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3364 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3365 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3366 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3367 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3368 | |
| 3369 | /* If the node is not being used by another discovery thread, |
| 3370 | * and we are sending a reject, we are done with it. |
| 3371 | * Release driver reference count here and free associated |
| 3372 | * resources. |
| 3373 | */ |
| 3374 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3375 | if (lpfc_nlp_not_used(ndlp)) |
| 3376 | /* Indicate node has already been released, |
| 3377 | * should not reference to it from within |
| 3378 | * the routine lpfc_els_free_iocb. |
| 3379 | */ |
| 3380 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3381 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3382 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3383 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3384 | return; |
| 3385 | } |
| 3386 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3387 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3388 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3389 | * @vport: pointer to a host virtual N_Port data structure. |
| 3390 | * @flag: the els command code to be accepted. |
| 3391 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3392 | * @ndlp: pointer to a node-list data structure. |
| 3393 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3394 | * |
| 3395 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3396 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3397 | * specific ACC response command to be issued and invokes the |
| 3398 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3399 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3400 | * field of the IOCB for the completion callback function to issue the |
| 3401 | * mailbox command to the HBA later when callback is invoked. |
| 3402 | * |
| 3403 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3404 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3405 | * will be stored into the context1 field of the IOCB for the completion |
| 3406 | * callback function to the corresponding response ELS IOCB command. |
| 3407 | * |
| 3408 | * Return code |
| 3409 | * 0 - Successfully issued acc response |
| 3410 | * 1 - Failed to issue acc response |
| 3411 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3412 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3413 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3414 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3415 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3416 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3417 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3418 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3419 | IOCB_t *icmd; |
| 3420 | IOCB_t *oldcmd; |
| 3421 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3422 | struct lpfc_sli *psli; |
| 3423 | uint8_t *pcmd; |
| 3424 | uint16_t cmdsize; |
| 3425 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3426 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3427 | |
| 3428 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3429 | oldcmd = &oldiocb->iocb; |
| 3430 | |
| 3431 | switch (flag) { |
| 3432 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3433 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3434 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3435 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3436 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3437 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3438 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3439 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3440 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3441 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3442 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3443 | icmd = &elsiocb->iocb; |
| 3444 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3445 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3446 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3447 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3448 | |
| 3449 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3450 | "Issue ACC: did:x%x flg:x%x", |
| 3451 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3452 | break; |
| 3453 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3454 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3455 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3456 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3457 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3458 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3459 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3460 | icmd = &elsiocb->iocb; |
| 3461 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3462 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3463 | |
| 3464 | if (mbox) |
| 3465 | elsiocb->context_un.mbox = mbox; |
| 3466 | |
| 3467 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3468 | pcmd += sizeof(uint32_t); |
| 3469 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3470 | |
| 3471 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3472 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 3473 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3474 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3475 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3476 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3477 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3478 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3479 | if (!elsiocb) |
| 3480 | return 1; |
| 3481 | |
| 3482 | icmd = &elsiocb->iocb; |
| 3483 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3484 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3485 | |
| 3486 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3487 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3488 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 3489 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 3490 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3491 | |
| 3492 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3493 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 3494 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3495 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3496 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3497 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3498 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3499 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3500 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3501 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
| 3502 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", |
| 3503 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3504 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3505 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3506 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3507 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3508 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3509 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3510 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 3511 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3512 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3513 | } |
| 3514 | |
| 3515 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3516 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3517 | if (rc == IOCB_ERROR) { |
| 3518 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3519 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3520 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3521 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3522 | } |
| 3523 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3524 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3525 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3526 | * @vport: pointer to a virtual N_Port data structure. |
| 3527 | * @rejectError: |
| 3528 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3529 | * @ndlp: pointer to a node-list data structure. |
| 3530 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3531 | * |
| 3532 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 3533 | * command. If a @mbox pointer is passed in, it will be put into the |
| 3534 | * context_un.mbox field of the IOCB for the completion callback function |
| 3535 | * to issue to the HBA later. |
| 3536 | * |
| 3537 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3538 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3539 | * will be stored into the context1 field of the IOCB for the completion |
| 3540 | * callback function to the reject response ELS IOCB command. |
| 3541 | * |
| 3542 | * Return code |
| 3543 | * 0 - Successfully issued reject response |
| 3544 | * 1 - Failed to issue reject response |
| 3545 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3546 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3547 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3548 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 3549 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3550 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3551 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3552 | IOCB_t *icmd; |
| 3553 | IOCB_t *oldcmd; |
| 3554 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3555 | struct lpfc_sli *psli; |
| 3556 | uint8_t *pcmd; |
| 3557 | uint16_t cmdsize; |
| 3558 | int rc; |
| 3559 | |
| 3560 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3561 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3562 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3563 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3564 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3565 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3566 | |
| 3567 | icmd = &elsiocb->iocb; |
| 3568 | oldcmd = &oldiocb->iocb; |
| 3569 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3570 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3571 | |
| 3572 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3573 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3574 | *((uint32_t *) (pcmd)) = rejectError; |
| 3575 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3576 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3577 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3578 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3579 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3580 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3581 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 3582 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 3583 | "rpi x%x\n", |
| 3584 | rejectError, elsiocb->iotag, |
| 3585 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 3586 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3587 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3588 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 3589 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 3590 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3591 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3592 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3593 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3594 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3595 | if (rc == IOCB_ERROR) { |
| 3596 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3597 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3598 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3599 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3600 | } |
| 3601 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3602 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3603 | * 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] | 3604 | * @vport: pointer to a virtual N_Port data structure. |
| 3605 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3606 | * @ndlp: pointer to a node-list data structure. |
| 3607 | * |
| 3608 | * This routine prepares and issues an Accept (ACC) response to Address |
| 3609 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 3610 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3611 | * |
| 3612 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3613 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3614 | * will be stored into the context1 field of the IOCB for the completion |
| 3615 | * callback function to the ADISC Accept response ELS IOCB command. |
| 3616 | * |
| 3617 | * Return code |
| 3618 | * 0 - Successfully issued acc adisc response |
| 3619 | * 1 - Failed to issue adisc acc response |
| 3620 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3621 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3622 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 3623 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3624 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3625 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3626 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3627 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3628 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3629 | uint8_t *pcmd; |
| 3630 | uint16_t cmdsize; |
| 3631 | int rc; |
| 3632 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3633 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3634 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3635 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3636 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3637 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3638 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3639 | icmd = &elsiocb->iocb; |
| 3640 | oldcmd = &oldiocb->iocb; |
| 3641 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3642 | |
| 3643 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3644 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3645 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 3646 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 3647 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3648 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3649 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3650 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3651 | |
| 3652 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3653 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3654 | |
| 3655 | ap = (ADISC *) (pcmd); |
| 3656 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3657 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3658 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3659 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3660 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3661 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3662 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 3663 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3664 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3665 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3666 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3667 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3668 | if (rc == IOCB_ERROR) { |
| 3669 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3670 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3671 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3672 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3673 | } |
| 3674 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3675 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3676 | * 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] | 3677 | * @vport: pointer to a virtual N_Port data structure. |
| 3678 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3679 | * @ndlp: pointer to a node-list data structure. |
| 3680 | * |
| 3681 | * This routine prepares and issues an Accept (ACC) response to Process |
| 3682 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 3683 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3684 | * |
| 3685 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3686 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3687 | * will be stored into the context1 field of the IOCB for the completion |
| 3688 | * callback function to the PRLI Accept response ELS IOCB command. |
| 3689 | * |
| 3690 | * Return code |
| 3691 | * 0 - Successfully issued acc prli response |
| 3692 | * 1 - Failed to issue acc prli response |
| 3693 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3694 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3695 | 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] | 3696 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3697 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3698 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3699 | PRLI *npr; |
| 3700 | lpfc_vpd_t *vpd; |
| 3701 | IOCB_t *icmd; |
| 3702 | IOCB_t *oldcmd; |
| 3703 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3704 | struct lpfc_sli *psli; |
| 3705 | uint8_t *pcmd; |
| 3706 | uint16_t cmdsize; |
| 3707 | int rc; |
| 3708 | |
| 3709 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3710 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3711 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3712 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3713 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3714 | if (!elsiocb) |
| 3715 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3716 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3717 | icmd = &elsiocb->iocb; |
| 3718 | oldcmd = &oldiocb->iocb; |
| 3719 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3720 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3721 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3722 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 3723 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 3724 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3725 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3726 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3727 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3728 | |
| 3729 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3730 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3731 | |
| 3732 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3733 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3734 | |
| 3735 | npr = (PRLI *) pcmd; |
| 3736 | vpd = &phba->vpd; |
| 3737 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3738 | * If the remote port is a target and our firmware version is 3.20 or |
| 3739 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3740 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3741 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 3742 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3743 | npr->ConfmComplAllowed = 1; |
| 3744 | npr->Retry = 1; |
| 3745 | npr->TaskRetryIdReq = 1; |
| 3746 | } |
| 3747 | |
| 3748 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 3749 | npr->estabImagePair = 1; |
| 3750 | npr->readXferRdyDis = 1; |
| 3751 | npr->ConfmComplAllowed = 1; |
| 3752 | |
| 3753 | npr->prliType = PRLI_FCP_TYPE; |
| 3754 | npr->initiatorFunc = 1; |
| 3755 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3756 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3757 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 3758 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3759 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3760 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3761 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3762 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3763 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3764 | if (rc == IOCB_ERROR) { |
| 3765 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3766 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3767 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3768 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3769 | } |
| 3770 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3771 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3772 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3773 | * @vport: pointer to a virtual N_Port data structure. |
| 3774 | * @format: rnid command format. |
| 3775 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3776 | * @ndlp: pointer to a node-list data structure. |
| 3777 | * |
| 3778 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 3779 | * (ACC) response. It constructs the RNID ACC response command according to |
| 3780 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 3781 | * issue the response. Note that this command does not need to hold the ndlp |
| 3782 | * reference count for the callback. So, the ndlp reference count taken by |
| 3783 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 3784 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 3785 | * there is no ndlp reference available. |
| 3786 | * |
| 3787 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3788 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3789 | * will be stored into the context1 field of the IOCB for the completion |
| 3790 | * callback function. However, for the RNID Accept Response ELS command, |
| 3791 | * this is undone later by this routine after the IOCB is allocated. |
| 3792 | * |
| 3793 | * Return code |
| 3794 | * 0 - Successfully issued acc rnid response |
| 3795 | * 1 - Failed to issue acc rnid response |
| 3796 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3797 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3798 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3799 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3800 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3801 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3802 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3803 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3804 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3805 | struct lpfc_sli *psli; |
| 3806 | uint8_t *pcmd; |
| 3807 | uint16_t cmdsize; |
| 3808 | int rc; |
| 3809 | |
| 3810 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3811 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 3812 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3813 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3814 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3815 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3816 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3817 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3818 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3819 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3820 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3821 | icmd = &elsiocb->iocb; |
| 3822 | oldcmd = &oldiocb->iocb; |
| 3823 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3824 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3825 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3826 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 3827 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3828 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3829 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3830 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3831 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3832 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3833 | rn = (RNID *) (pcmd); |
| 3834 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3835 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 3836 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3837 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3838 | switch (format) { |
| 3839 | case 0: |
| 3840 | rn->SpecificLen = 0; |
| 3841 | break; |
| 3842 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3843 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3844 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3845 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3846 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 3847 | rn->un.topologyDisc.physPort = 0; |
| 3848 | rn->un.topologyDisc.attachedNodes = 0; |
| 3849 | break; |
| 3850 | default: |
| 3851 | rn->CommonLen = 0; |
| 3852 | rn->SpecificLen = 0; |
| 3853 | break; |
| 3854 | } |
| 3855 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3856 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3857 | "Issue ACC RNID: did:x%x flg:x%x", |
| 3858 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3859 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3860 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3861 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3862 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3863 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 3864 | * it could be freed */ |
| 3865 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3866 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3867 | if (rc == IOCB_ERROR) { |
| 3868 | lpfc_els_free_iocb(phba, 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 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3871 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3872 | } |
| 3873 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3874 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3875 | * 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] | 3876 | * @vport: pointer to a host virtual N_Port data structure. |
| 3877 | * |
| 3878 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 3879 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 3880 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 3881 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 3882 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 3883 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 3884 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 3885 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 3886 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 3887 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 3888 | * no more ADISC need to be sent. |
| 3889 | * |
| 3890 | * Return code |
| 3891 | * The number of N_Ports with adisc issued. |
| 3892 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3893 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3894 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3895 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3896 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3897 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3898 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3899 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3900 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3901 | 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] | 3902 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3903 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3904 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3905 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3906 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3907 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3908 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3909 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3910 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3911 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 3912 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3913 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3914 | vport->num_disc_nodes++; |
| 3915 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3916 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3917 | spin_lock_irq(shost->host_lock); |
| 3918 | vport->fc_flag |= FC_NLP_MORE; |
| 3919 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3920 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3921 | } |
| 3922 | } |
| 3923 | } |
| 3924 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3925 | spin_lock_irq(shost->host_lock); |
| 3926 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3927 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3928 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3929 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3930 | } |
| 3931 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3932 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3933 | * 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] | 3934 | * @vport: pointer to a host virtual N_Port data structure. |
| 3935 | * |
| 3936 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 3937 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 3938 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 3939 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 3940 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 3941 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 3942 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 3943 | * later pick up. On the other hand, after walking through all the ndlps with |
| 3944 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 3945 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 3946 | * PLOGI need to be sent. |
| 3947 | * |
| 3948 | * Return code |
| 3949 | * The number of N_Ports with plogi issued. |
| 3950 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3951 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3952 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3953 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3954 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3955 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3956 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3957 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3958 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 3959 | 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] | 3960 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3961 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3962 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3963 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3964 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 3965 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 3966 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3967 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 3968 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3969 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3970 | vport->num_disc_nodes++; |
| 3971 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3972 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3973 | spin_lock_irq(shost->host_lock); |
| 3974 | vport->fc_flag |= FC_NLP_MORE; |
| 3975 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3976 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3977 | } |
| 3978 | } |
| 3979 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3980 | if (sentplogi) { |
| 3981 | lpfc_set_disctmo(vport); |
| 3982 | } |
| 3983 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3984 | spin_lock_irq(shost->host_lock); |
| 3985 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3986 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3987 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3988 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3989 | } |
| 3990 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3991 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3992 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3993 | * @vport: pointer to a host virtual N_Port data structure. |
| 3994 | * |
| 3995 | * This routine cleans up any Registration State Change Notification |
| 3996 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 3997 | * @vport together with the host_lock is used to prevent multiple thread |
| 3998 | * trying to access the RSCN array on a same @vport at the same time. |
| 3999 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4000 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4001 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4002 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4003 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4004 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4005 | int i; |
| 4006 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4007 | spin_lock_irq(shost->host_lock); |
| 4008 | if (vport->fc_rscn_flush) { |
| 4009 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4010 | spin_unlock_irq(shost->host_lock); |
| 4011 | return; |
| 4012 | } |
| 4013 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 4014 | vport->fc_rscn_flush = 1; |
| 4015 | spin_unlock_irq(shost->host_lock); |
| 4016 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4017 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4018 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4019 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4020 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4021 | spin_lock_irq(shost->host_lock); |
| 4022 | vport->fc_rscn_id_cnt = 0; |
| 4023 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 4024 | spin_unlock_irq(shost->host_lock); |
| 4025 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4026 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 4027 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4028 | } |
| 4029 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4030 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4031 | * 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] | 4032 | * @vport: pointer to a host virtual N_Port data structure. |
| 4033 | * @did: remote destination port identifier. |
| 4034 | * |
| 4035 | * This routine checks whether there is any pending Registration State |
| 4036 | * Configuration Notification (RSCN) to a @did on @vport. |
| 4037 | * |
| 4038 | * Return code |
| 4039 | * None zero - The @did matched with a pending rscn |
| 4040 | * 0 - not able to match @did with a pending rscn |
| 4041 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4042 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4043 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4044 | { |
| 4045 | D_ID ns_did; |
| 4046 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4047 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4048 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4049 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4050 | |
| 4051 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4052 | |
| 4053 | /* Never match fabric nodes for RSCNs */ |
| 4054 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4055 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4056 | |
| 4057 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4058 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4059 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4060 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4061 | spin_lock_irq(shost->host_lock); |
| 4062 | if (vport->fc_rscn_flush) { |
| 4063 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4064 | spin_unlock_irq(shost->host_lock); |
| 4065 | return 0; |
| 4066 | } |
| 4067 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4068 | vport->fc_rscn_flush = 1; |
| 4069 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4070 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4071 | lp = vport->fc_rscn_id_list[i]->virt; |
| 4072 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4073 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4074 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4075 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 4076 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4077 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 4078 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4079 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4080 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 4081 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4082 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4083 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4084 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4085 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4086 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4087 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4088 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4089 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4090 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4091 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4092 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4093 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4094 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4095 | } |
| 4096 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4097 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4098 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4099 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4100 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4101 | return_did_out: |
| 4102 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4103 | vport->fc_rscn_flush = 0; |
| 4104 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4105 | } |
| 4106 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4107 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4108 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4109 | * @vport: pointer to a host virtual N_Port data structure. |
| 4110 | * |
| 4111 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 4112 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 4113 | * State Change Notification). |
| 4114 | * |
| 4115 | * Return code |
| 4116 | * 0 - Successful (currently alway return 0) |
| 4117 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4118 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4119 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4120 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4121 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4122 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4123 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4124 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4125 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4126 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 4127 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4128 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4129 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4130 | NLP_EVT_DEVICE_RECOVERY); |
| 4131 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4132 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4133 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4134 | } |
| 4135 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4136 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4137 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4138 | * @vport: pointer to a host virtual N_Port data structure. |
| 4139 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4140 | * |
| 4141 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 4142 | * applications. |
| 4143 | */ |
| 4144 | static void |
| 4145 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 4146 | struct lpfc_iocbq *cmdiocb) |
| 4147 | { |
| 4148 | struct lpfc_dmabuf *pcmd; |
| 4149 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4150 | uint32_t *payload_ptr; |
| 4151 | uint32_t payload_len; |
| 4152 | struct lpfc_rscn_event_header *rscn_event_data; |
| 4153 | |
| 4154 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4155 | payload_ptr = (uint32_t *) pcmd->virt; |
| 4156 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 4157 | |
| 4158 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 4159 | payload_len, GFP_KERNEL); |
| 4160 | if (!rscn_event_data) { |
| 4161 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4162 | "0147 Failed to allocate memory for RSCN event\n"); |
| 4163 | return; |
| 4164 | } |
| 4165 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 4166 | rscn_event_data->payload_length = payload_len; |
| 4167 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 4168 | payload_len); |
| 4169 | |
| 4170 | fc_host_post_vendor_event(shost, |
| 4171 | fc_get_event_number(), |
| 4172 | sizeof(struct lpfc_els_event_header) + payload_len, |
| 4173 | (char *)rscn_event_data, |
| 4174 | LPFC_NL_VENDOR_ID); |
| 4175 | |
| 4176 | kfree(rscn_event_data); |
| 4177 | } |
| 4178 | |
| 4179 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4180 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4181 | * @vport: pointer to a host virtual N_Port data structure. |
| 4182 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4183 | * @ndlp: pointer to a node-list data structure. |
| 4184 | * |
| 4185 | * This routine processes an unsolicited RSCN (Registration State Change |
| 4186 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 4187 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 4188 | * discover state machine is about to begin discovery, it just accepts the |
| 4189 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 4190 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 4191 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 4192 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 4193 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 4194 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 4195 | * routine is invoked to handle the RSCN event. |
| 4196 | * |
| 4197 | * Return code |
| 4198 | * 0 - Just sent the acc response |
| 4199 | * 1 - Sent the acc response and waited for name server completion |
| 4200 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4201 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4202 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4203 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4204 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4205 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4206 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4207 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4208 | uint32_t *lp, *datap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4209 | IOCB_t *icmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4210 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4211 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4212 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4213 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4214 | |
| 4215 | icmd = &cmdiocb->iocb; |
| 4216 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4217 | lp = (uint32_t *) pcmd->virt; |
| 4218 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4219 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4220 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4221 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4222 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4223 | "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] | 4224 | vport->fc_flag, payload_len, *lp, |
| 4225 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4226 | |
| 4227 | /* Send an RSCN event to the management application */ |
| 4228 | lpfc_send_rscn_event(vport, cmdiocb); |
| 4229 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4230 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4231 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4232 | FCH_EVT_RSCN, lp[i]); |
| 4233 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4234 | /* If we are about to begin discovery, just ACC the RSCN. |
| 4235 | * Discovery processing will satisfy it. |
| 4236 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4237 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4238 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4239 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 4240 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4241 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4242 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4243 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4244 | } |
| 4245 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4246 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 4247 | * just ACC and ignore it. |
| 4248 | */ |
| 4249 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4250 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4251 | i = payload_len; |
| 4252 | datap = lp; |
| 4253 | while (i > 0) { |
| 4254 | nportid = *datap++; |
| 4255 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 4256 | i -= sizeof(uint32_t); |
| 4257 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4258 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 4259 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4260 | } |
| 4261 | if (rscn_id == hba_id) { |
| 4262 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4263 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4264 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4265 | "Data: x%x x%x x%x x%x\n", |
| 4266 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4267 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4268 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4269 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 4270 | ndlp->nlp_DID, vport->port_state, |
| 4271 | ndlp->nlp_flag); |
| 4272 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4273 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4274 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4275 | return 0; |
| 4276 | } |
| 4277 | } |
| 4278 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4279 | spin_lock_irq(shost->host_lock); |
| 4280 | if (vport->fc_rscn_flush) { |
| 4281 | /* Another thread is walking fc_rscn_id_list on this vport */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4282 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 4283 | spin_unlock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4284 | /* Send back ACC */ |
| 4285 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4286 | return 0; |
| 4287 | } |
| 4288 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4289 | vport->fc_rscn_flush = 1; |
| 4290 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4291 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4292 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4293 | /* If we are already processing an RSCN, save the received |
| 4294 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 4295 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4296 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4297 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4298 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 4299 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4300 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4301 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4302 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 4303 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4304 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4305 | vport->fc_flag |= FC_RSCN_MODE; |
| 4306 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4307 | if (rscn_cnt) { |
| 4308 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 4309 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 4310 | } |
| 4311 | if ((rscn_cnt) && |
| 4312 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 4313 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4314 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4315 | memcpy(((uint8_t *)cmd) + length, lp, |
| 4316 | payload_len); |
| 4317 | } else { |
| 4318 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 4319 | vport->fc_rscn_id_cnt++; |
| 4320 | /* If we zero, cmdiocb->context2, the calling |
| 4321 | * routine will not try to free it. |
| 4322 | */ |
| 4323 | cmdiocb->context2 = NULL; |
| 4324 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4325 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4326 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4327 | "0235 Deferred RSCN " |
| 4328 | "Data: x%x x%x x%x\n", |
| 4329 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4330 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4331 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4332 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 4333 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4334 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4335 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4336 | "0234 ReDiscovery RSCN " |
| 4337 | "Data: x%x x%x x%x\n", |
| 4338 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4339 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4340 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4341 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4342 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4343 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4344 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4345 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4346 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4347 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4348 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4349 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4350 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4351 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4352 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4353 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 4354 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4355 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4356 | spin_lock_irq(shost->host_lock); |
| 4357 | vport->fc_flag |= FC_RSCN_MODE; |
| 4358 | spin_unlock_irq(shost->host_lock); |
| 4359 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4360 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4361 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4362 | /* |
| 4363 | * If we zero, cmdiocb->context2, the calling routine will |
| 4364 | * not try to free it. |
| 4365 | */ |
| 4366 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4367 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4368 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4369 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4370 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4371 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4372 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4373 | } |
| 4374 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4375 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4376 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4377 | * @vport: pointer to a host virtual N_Port data structure. |
| 4378 | * |
| 4379 | * This routine handles the Registration State Configuration Notification |
| 4380 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 4381 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 4382 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 4383 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 4384 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 4385 | * RSCN activities with the @vport. |
| 4386 | * |
| 4387 | * Return code |
| 4388 | * 0 - Cleaned up rscn on the @vport |
| 4389 | * 1 - Wait for plogi to name server before proceed |
| 4390 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4391 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4392 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4393 | { |
| 4394 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4395 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4396 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4397 | /* Ignore RSCN if the port is being torn down. */ |
| 4398 | if (vport->load_flag & FC_UNLOADING) { |
| 4399 | lpfc_els_flush_rscn(vport); |
| 4400 | return 0; |
| 4401 | } |
| 4402 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4403 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4404 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4405 | |
| 4406 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4407 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4408 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 4409 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 4410 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4411 | |
| 4412 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4413 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4414 | vport->num_disc_nodes = 0; |
| 4415 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4416 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4417 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 4418 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4419 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4420 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4421 | /* Wait for NameServer query cmpl before we can |
| 4422 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4423 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4424 | } else { |
| 4425 | /* If login to NameServer does not exist, issue one */ |
| 4426 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4427 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4428 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4429 | /* Wait for NameServer login cmpl before we can |
| 4430 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4431 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4432 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4433 | if (ndlp) { |
| 4434 | ndlp = lpfc_enable_node(vport, ndlp, |
| 4435 | NLP_STE_PLOGI_ISSUE); |
| 4436 | if (!ndlp) { |
| 4437 | lpfc_els_flush_rscn(vport); |
| 4438 | return 0; |
| 4439 | } |
| 4440 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4441 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4442 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4443 | if (!ndlp) { |
| 4444 | lpfc_els_flush_rscn(vport); |
| 4445 | return 0; |
| 4446 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4447 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4448 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4449 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4450 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4451 | ndlp->nlp_type |= NLP_FABRIC; |
| 4452 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 4453 | /* Wait for NameServer login cmpl before we can |
| 4454 | * continue |
| 4455 | */ |
| 4456 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4457 | } |
| 4458 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4459 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4460 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4461 | } |
| 4462 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4463 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4464 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4465 | * @vport: pointer to a host virtual N_Port data structure. |
| 4466 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4467 | * @ndlp: pointer to a node-list data structure. |
| 4468 | * |
| 4469 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 4470 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 4471 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 4472 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 4473 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 4474 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 4475 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 4476 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 4477 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 4478 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 4479 | * higher priority (as the winning port) and will initiate PLOGI and |
| 4480 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 4481 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 4482 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 4483 | * |
| 4484 | * Return code |
| 4485 | * 0 - Successfully processed the unsolicited flogi |
| 4486 | * 1 - Failed to process the unsolicited flogi |
| 4487 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4488 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4489 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4490 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4491 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4492 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4493 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4494 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4495 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 4496 | IOCB_t *icmd = &cmdiocb->iocb; |
| 4497 | struct serv_parm *sp; |
| 4498 | LPFC_MBOXQ_t *mbox; |
| 4499 | struct ls_rjt stat; |
| 4500 | uint32_t cmd, did; |
| 4501 | int rc; |
| 4502 | |
| 4503 | cmd = *lp++; |
| 4504 | sp = (struct serv_parm *) lp; |
| 4505 | |
| 4506 | /* FLOGI received */ |
| 4507 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4508 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4509 | |
| 4510 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 4511 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 4512 | did = icmd->un.elsreq64.remoteID; |
| 4513 | |
| 4514 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 4515 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4516 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4517 | "0113 An FLOGI ELS command x%x was " |
| 4518 | "received from DID x%x in Loop Mode\n", |
| 4519 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4520 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4521 | } |
| 4522 | |
| 4523 | did = Fabric_DID; |
| 4524 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 4525 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4526 | /* For a FLOGI we accept, then if our portname is greater |
| 4527 | * then the remote portname we initiate Nport login. |
| 4528 | */ |
| 4529 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4530 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4531 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4532 | |
| 4533 | if (!rc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4534 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4535 | if (!mbox) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4536 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4537 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4538 | lpfc_linkdown(phba); |
| 4539 | lpfc_init_link(phba, mbox, |
| 4540 | phba->cfg_topology, |
| 4541 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4542 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4543 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4544 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4545 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4546 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4547 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4548 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4549 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4550 | return 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4551 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4552 | spin_lock_irq(shost->host_lock); |
| 4553 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 4554 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4555 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4556 | spin_lock_irq(shost->host_lock); |
| 4557 | vport->fc_flag |= FC_PT2PT; |
| 4558 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 4559 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4560 | } else { |
| 4561 | /* Reject this request because invalid parameters */ |
| 4562 | stat.un.b.lsRjtRsvd0 = 0; |
| 4563 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4564 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 4565 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4566 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4567 | NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4568 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4569 | } |
| 4570 | |
| 4571 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4572 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4573 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4574 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4575 | } |
| 4576 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4577 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4578 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4579 | * @vport: pointer to a host virtual N_Port data structure. |
| 4580 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4581 | * @ndlp: pointer to a node-list data structure. |
| 4582 | * |
| 4583 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 4584 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 4585 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 4586 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 4587 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 4588 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 4589 | * |
| 4590 | * Return code |
| 4591 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 4592 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4593 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4594 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4595 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4596 | { |
| 4597 | struct lpfc_dmabuf *pcmd; |
| 4598 | uint32_t *lp; |
| 4599 | IOCB_t *icmd; |
| 4600 | RNID *rn; |
| 4601 | struct ls_rjt stat; |
| 4602 | uint32_t cmd, did; |
| 4603 | |
| 4604 | icmd = &cmdiocb->iocb; |
| 4605 | did = icmd->un.elsreq64.remoteID; |
| 4606 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4607 | lp = (uint32_t *) pcmd->virt; |
| 4608 | |
| 4609 | cmd = *lp++; |
| 4610 | rn = (RNID *) lp; |
| 4611 | |
| 4612 | /* RNID received */ |
| 4613 | |
| 4614 | switch (rn->Format) { |
| 4615 | case 0: |
| 4616 | case RNID_TOPOLOGY_DISC: |
| 4617 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4618 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4619 | break; |
| 4620 | default: |
| 4621 | /* Reject this request because format not supported */ |
| 4622 | stat.un.b.lsRjtRsvd0 = 0; |
| 4623 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4624 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4625 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4626 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4627 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4628 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4629 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4630 | } |
| 4631 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4632 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4633 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4634 | * @vport: pointer to a host virtual N_Port data structure. |
| 4635 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4636 | * @ndlp: pointer to a node-list data structure. |
| 4637 | * |
| 4638 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 4639 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 4640 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 4641 | * |
| 4642 | * Return code |
| 4643 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 4644 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4645 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4646 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4647 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4648 | { |
| 4649 | struct ls_rjt stat; |
| 4650 | |
| 4651 | /* For now, unconditionally reject this command */ |
| 4652 | stat.un.b.lsRjtRsvd0 = 0; |
| 4653 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4654 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4655 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4656 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4657 | return 0; |
| 4658 | } |
| 4659 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4660 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4661 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb |
| 4662 | * @vport: pointer to a host virtual N_Port data structure. |
| 4663 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4664 | * @ndlp: pointer to a node-list data structure. |
| 4665 | * |
| 4666 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB |
| 4667 | * received as an ELS unsolicited event. A request to RRQ shall only |
| 4668 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder |
| 4669 | * Nx_Port N_Port_ID of the target Exchange is the same as the |
| 4670 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is |
| 4671 | * not accepted, an LS_RJT with reason code "Unable to perform |
| 4672 | * command request" and reason code explanation "Invalid Originator |
| 4673 | * S_ID" shall be returned. For now, we just unconditionally accept |
| 4674 | * RRQ from the target. |
| 4675 | **/ |
| 4676 | static void |
| 4677 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4678 | struct lpfc_nodelist *ndlp) |
| 4679 | { |
| 4680 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| 4681 | } |
| 4682 | |
| 4683 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4684 | * 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] | 4685 | * @phba: pointer to lpfc hba data structure. |
| 4686 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4687 | * |
| 4688 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 4689 | * mailbox command. This callback function is to actually send the Accept |
| 4690 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 4691 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 4692 | * mailbox command, constructs the RPS response with the link statistics |
| 4693 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 4694 | * response to the RPS. |
| 4695 | * |
| 4696 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4697 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4698 | * will be stored into the context1 field of the IOCB for the completion |
| 4699 | * callback function to the RPS Accept Response ELS IOCB command. |
| 4700 | * |
| 4701 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4702 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4703 | 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] | 4704 | { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4705 | MAILBOX_t *mb; |
| 4706 | IOCB_t *icmd; |
| 4707 | RPS_RSP *rps_rsp; |
| 4708 | uint8_t *pcmd; |
| 4709 | struct lpfc_iocbq *elsiocb; |
| 4710 | struct lpfc_nodelist *ndlp; |
| 4711 | uint16_t xri, status; |
| 4712 | uint32_t cmdsize; |
| 4713 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4714 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4715 | |
| 4716 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4717 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 4718 | pmb->context1 = NULL; |
| 4719 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4720 | |
| 4721 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4722 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4723 | return; |
| 4724 | } |
| 4725 | |
| 4726 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4727 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4728 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 4729 | lpfc_max_els_tries, ndlp, |
| 4730 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4731 | |
| 4732 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4733 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4734 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4735 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4736 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4737 | |
| 4738 | icmd = &elsiocb->iocb; |
| 4739 | icmd->ulpContext = xri; |
| 4740 | |
| 4741 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4742 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4743 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4744 | rps_rsp = (RPS_RSP *)pcmd; |
| 4745 | |
| 4746 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| 4747 | status = 0x10; |
| 4748 | else |
| 4749 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4750 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4751 | status |= 0x4; |
| 4752 | |
| 4753 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4754 | rps_rsp->portStatus = cpu_to_be16(status); |
| 4755 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 4756 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 4757 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 4758 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 4759 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 4760 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4761 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4762 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 4763 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 4764 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4765 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4766 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4767 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4768 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4769 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4770 | 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] | 4771 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4772 | return; |
| 4773 | } |
| 4774 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4775 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4776 | * lpfc_els_rcv_rps - Process an unsolicited rps iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4777 | * @vport: pointer to a host virtual N_Port data structure. |
| 4778 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4779 | * @ndlp: pointer to a node-list data structure. |
| 4780 | * |
| 4781 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 4782 | * ELS unsolicited event. It first checks the remote port state. If the |
| 4783 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 4784 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 4785 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 4786 | * for reading the HBA link statistics. It is for the callback function, |
| 4787 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 4788 | * to actually sending out RPS Accept (ACC) response. |
| 4789 | * |
| 4790 | * Return codes |
| 4791 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 4792 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4793 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4794 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4795 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4796 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4797 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4798 | uint32_t *lp; |
| 4799 | uint8_t flag; |
| 4800 | LPFC_MBOXQ_t *mbox; |
| 4801 | struct lpfc_dmabuf *pcmd; |
| 4802 | RPS *rps; |
| 4803 | struct ls_rjt stat; |
| 4804 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4805 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4806 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 4807 | /* reject the unsolicited RPS request and done with it */ |
| 4808 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4809 | |
| 4810 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4811 | lp = (uint32_t *) pcmd->virt; |
| 4812 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 4813 | rps = (RPS *) lp; |
| 4814 | |
| 4815 | if ((flag == 0) || |
| 4816 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4817 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4818 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4819 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4820 | printk("Fix me....\n"); |
| 4821 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4822 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 4823 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4824 | lpfc_read_lnk_stat(phba, mbox); |
| 4825 | mbox->context1 = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4826 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4827 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4828 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4829 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4830 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4831 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4832 | /* Mbox completion will send ELS Response */ |
| 4833 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4834 | /* Decrement reference count used for the failed mbox |
| 4835 | * command. |
| 4836 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4837 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4838 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4839 | } |
| 4840 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4841 | |
| 4842 | reject_out: |
| 4843 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4844 | stat.un.b.lsRjtRsvd0 = 0; |
| 4845 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4846 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4847 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4848 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4849 | return 0; |
| 4850 | } |
| 4851 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4852 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4853 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4854 | * @vport: pointer to a host virtual N_Port data structure. |
| 4855 | * @cmdsize: size of the ELS command. |
| 4856 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4857 | * @ndlp: pointer to a node-list data structure. |
| 4858 | * |
| 4859 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 4860 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 4861 | * |
| 4862 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4863 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4864 | * will be stored into the context1 field of the IOCB for the completion |
| 4865 | * callback function to the RPL Accept Response ELS command. |
| 4866 | * |
| 4867 | * Return code |
| 4868 | * 0 - Successfully issued ACC RPL ELS command |
| 4869 | * 1 - Failed to issue ACC RPL ELS command |
| 4870 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4871 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4872 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 4873 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4874 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4875 | struct lpfc_hba *phba = vport->phba; |
| 4876 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4877 | RPL_RSP rpl_rsp; |
| 4878 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4879 | uint8_t *pcmd; |
| 4880 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4881 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4882 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4883 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4884 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4885 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4886 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4887 | icmd = &elsiocb->iocb; |
| 4888 | oldcmd = &oldiocb->iocb; |
| 4889 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 4890 | |
| 4891 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4892 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4893 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4894 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 4895 | pcmd += sizeof(uint16_t); |
| 4896 | |
| 4897 | /* Setup the RPL ACC payload */ |
| 4898 | rpl_rsp.listLen = be32_to_cpu(1); |
| 4899 | rpl_rsp.index = 0; |
| 4900 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4901 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 4902 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4903 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4904 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4905 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4906 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4907 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 4908 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 4909 | "rpi x%x\n", |
| 4910 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4911 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4912 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4913 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4914 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4915 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 4916 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4917 | lpfc_els_free_iocb(phba, elsiocb); |
| 4918 | return 1; |
| 4919 | } |
| 4920 | return 0; |
| 4921 | } |
| 4922 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4923 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4924 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4925 | * @vport: pointer to a host virtual N_Port data structure. |
| 4926 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4927 | * @ndlp: pointer to a node-list data structure. |
| 4928 | * |
| 4929 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 4930 | * unsolicited event. It first checks the remote port state. If the remote |
| 4931 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 4932 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 4933 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 4934 | * to accept the RPL. |
| 4935 | * |
| 4936 | * Return code |
| 4937 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 4938 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4939 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4940 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4941 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4942 | { |
| 4943 | struct lpfc_dmabuf *pcmd; |
| 4944 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4945 | uint32_t maxsize; |
| 4946 | uint16_t cmdsize; |
| 4947 | RPL *rpl; |
| 4948 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4949 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4950 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 4951 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4952 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4953 | stat.un.b.lsRjtRsvd0 = 0; |
| 4954 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4955 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4956 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4957 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4958 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4959 | /* rejected the unsolicited RPL request and done with it */ |
| 4960 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4961 | } |
| 4962 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4963 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4964 | lp = (uint32_t *) pcmd->virt; |
| 4965 | rpl = (RPL *) (lp + 1); |
| 4966 | |
| 4967 | maxsize = be32_to_cpu(rpl->maxsize); |
| 4968 | |
| 4969 | /* We support only one port */ |
| 4970 | if ((rpl->index == 0) && |
| 4971 | ((maxsize == 0) || |
| 4972 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 4973 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4974 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4975 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 4976 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4977 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4978 | |
| 4979 | return 0; |
| 4980 | } |
| 4981 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4982 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4983 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4984 | * @vport: pointer to a virtual N_Port data structure. |
| 4985 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4986 | * @ndlp: pointer to a node-list data structure. |
| 4987 | * |
| 4988 | * This routine processes Fibre Channel Address Resolution Protocol |
| 4989 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 4990 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 4991 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 4992 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 4993 | * remote PortName is compared against the FC PortName stored in the @vport |
| 4994 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 4995 | * compared against the FC NodeName stored in the @vport data structure. |
| 4996 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 4997 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 4998 | * invoked to send out FARP Response to the remote node. Before sending the |
| 4999 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 5000 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 5001 | * routine is invoked to log into the remote port first. |
| 5002 | * |
| 5003 | * Return code |
| 5004 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 5005 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5006 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5007 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5008 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5009 | { |
| 5010 | struct lpfc_dmabuf *pcmd; |
| 5011 | uint32_t *lp; |
| 5012 | IOCB_t *icmd; |
| 5013 | FARP *fp; |
| 5014 | uint32_t cmd, cnt, did; |
| 5015 | |
| 5016 | icmd = &cmdiocb->iocb; |
| 5017 | did = icmd->un.elsreq64.remoteID; |
| 5018 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5019 | lp = (uint32_t *) pcmd->virt; |
| 5020 | |
| 5021 | cmd = *lp++; |
| 5022 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5023 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5024 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5025 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5026 | /* We will only support match on WWPN or WWNN */ |
| 5027 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5028 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5029 | } |
| 5030 | |
| 5031 | cnt = 0; |
| 5032 | /* If this FARP command is searching for my portname */ |
| 5033 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5034 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5035 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5036 | cnt = 1; |
| 5037 | } |
| 5038 | |
| 5039 | /* If this FARP command is searching for my nodename */ |
| 5040 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5041 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5042 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5043 | cnt = 1; |
| 5044 | } |
| 5045 | |
| 5046 | if (cnt) { |
| 5047 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 5048 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 5049 | /* Log back into the node before sending the FARP. */ |
| 5050 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5051 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5052 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 5053 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5054 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5055 | } |
| 5056 | |
| 5057 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5058 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 5059 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5060 | } |
| 5061 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5062 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5063 | } |
| 5064 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5065 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5066 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5067 | * @vport: pointer to a host virtual N_Port data structure. |
| 5068 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5069 | * @ndlp: pointer to a node-list data structure. |
| 5070 | * |
| 5071 | * This routine processes Fibre Channel Address Resolution Protocol |
| 5072 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 5073 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 5074 | * the FARP response request. |
| 5075 | * |
| 5076 | * Return code |
| 5077 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 5078 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5079 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5080 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5081 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5082 | { |
| 5083 | struct lpfc_dmabuf *pcmd; |
| 5084 | uint32_t *lp; |
| 5085 | IOCB_t *icmd; |
| 5086 | uint32_t cmd, did; |
| 5087 | |
| 5088 | icmd = &cmdiocb->iocb; |
| 5089 | did = icmd->un.elsreq64.remoteID; |
| 5090 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5091 | lp = (uint32_t *) pcmd->virt; |
| 5092 | |
| 5093 | cmd = *lp++; |
| 5094 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5095 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5096 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5097 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5098 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5099 | |
| 5100 | return 0; |
| 5101 | } |
| 5102 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5103 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5104 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5105 | * @vport: pointer to a host virtual N_Port data structure. |
| 5106 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5107 | * @fan_ndlp: pointer to a node-list data structure. |
| 5108 | * |
| 5109 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 5110 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 5111 | * only be processed on a physical port (i.e., the @vport represents the |
| 5112 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 5113 | * compared against those in the phba data structure. If any of those is |
| 5114 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 5115 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 5116 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 5117 | * is invoked to register login to the fabric. |
| 5118 | * |
| 5119 | * Return code |
| 5120 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 5121 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5122 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5123 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5124 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5125 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5126 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5127 | uint32_t *lp; |
| 5128 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5129 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5130 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 5131 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 5132 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5133 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5134 | if ((vport == phba->pport) && |
| 5135 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5136 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5137 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5138 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5139 | sizeof(struct lpfc_name)))) { |
| 5140 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5141 | lpfc_initial_flogi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5142 | } else { |
| 5143 | /* FAN verified - skip FLOGI */ |
| 5144 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5145 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5146 | lpfc_issue_fabric_reglogin(vport); |
| 5147 | else |
| 5148 | lpfc_issue_reg_vfi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5149 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5150 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5151 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5152 | } |
| 5153 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5154 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5155 | * lpfc_els_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5156 | * @ptr: holder for the timer function associated data. |
| 5157 | * |
| 5158 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 5159 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 5160 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 5161 | * up the worker thread. It is for the worker thread to invoke the routine |
| 5162 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 5163 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5164 | void |
| 5165 | lpfc_els_timeout(unsigned long ptr) |
| 5166 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5167 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 5168 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5169 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5170 | unsigned long iflag; |
| 5171 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5172 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5173 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
| 5174 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5175 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5176 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5177 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5178 | if (!tmo_posted) |
| 5179 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5180 | return; |
| 5181 | } |
| 5182 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5183 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5184 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5185 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5186 | * @vport: pointer to a virtual N_Port data structure. |
| 5187 | * |
| 5188 | * This routine is the actual handler function that processes an ELS timeout |
| 5189 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 5190 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 5191 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5192 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5193 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5194 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5195 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5196 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5197 | struct lpfc_sli_ring *pring; |
| 5198 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5199 | IOCB_t *cmd = NULL; |
| 5200 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5201 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5202 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5203 | uint32_t remote_ID = 0xffffffff; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5204 | LIST_HEAD(txcmplq_completions); |
| 5205 | LIST_HEAD(abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5206 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5207 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5208 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 5209 | |
| 5210 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5211 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5212 | spin_lock_irq(&phba->hbalock); |
| 5213 | list_splice_init(&pring->txcmplq, &txcmplq_completions); |
| 5214 | spin_unlock_irq(&phba->hbalock); |
| 5215 | |
| 5216 | list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5217 | cmd = &piocb->iocb; |
| 5218 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5219 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 5220 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 5221 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5222 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5223 | |
| 5224 | if (piocb->vport != vport) |
| 5225 | continue; |
| 5226 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5227 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5228 | if (pcmd) |
| 5229 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5230 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5231 | if (els_command == ELS_CMD_FARP || |
| 5232 | els_command == ELS_CMD_FARPR || |
| 5233 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5234 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5235 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5236 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5237 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5238 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5239 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5240 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5241 | continue; |
| 5242 | } |
| 5243 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5244 | remote_ID = 0xffffffff; |
| 5245 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5246 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5247 | else { |
| 5248 | struct lpfc_nodelist *ndlp; |
| 5249 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5250 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5251 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5252 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5253 | list_add_tail(&piocb->dlist, &abort_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5254 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5255 | spin_lock_irq(&phba->hbalock); |
| 5256 | list_splice(&txcmplq_completions, &pring->txcmplq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5257 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 5258 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5259 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { |
| 5260 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5261 | "0127 ELS timeout Data: x%x x%x x%x " |
| 5262 | "x%x\n", els_command, |
| 5263 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
| 5264 | spin_lock_irq(&phba->hbalock); |
| 5265 | list_del_init(&piocb->dlist); |
| 5266 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5267 | spin_unlock_irq(&phba->hbalock); |
| 5268 | } |
| 5269 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5270 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
| 5271 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5272 | } |
| 5273 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5274 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5275 | * 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] | 5276 | * @vport: pointer to a host virtual N_Port data structure. |
| 5277 | * |
| 5278 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5279 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 5280 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5281 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5282 | * the IOCBs with a non-NULL completion callback function, the callback |
| 5283 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5284 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 5285 | * callback function, the IOCB will simply be released. Finally, it walks |
| 5286 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 5287 | * completion queue IOCB that is associated with the @vport and is not |
| 5288 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 5289 | * part of the discovery state machine) out to HBA by invoking the |
| 5290 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 5291 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 5292 | * the IOCBs are aborted when this function returns. |
| 5293 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5294 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5295 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5296 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5297 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5298 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5299 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5300 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5301 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5302 | |
| 5303 | lpfc_fabric_abort_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5304 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5305 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5306 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5307 | cmd = &piocb->iocb; |
| 5308 | |
| 5309 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5310 | continue; |
| 5311 | } |
| 5312 | |
| 5313 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5314 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5315 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5316 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5317 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5318 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5319 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5320 | if (piocb->vport != vport) |
| 5321 | continue; |
| 5322 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5323 | list_move_tail(&piocb->list, &completions); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5324 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5325 | } |
| 5326 | |
| 5327 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5328 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5329 | continue; |
| 5330 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5331 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5332 | if (piocb->vport != vport) |
| 5333 | continue; |
| 5334 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5335 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5336 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5337 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5338 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5339 | /* Cancell all the IOCBs from the completions list */ |
| 5340 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5341 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5342 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5343 | return; |
| 5344 | } |
| 5345 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5346 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5347 | * 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] | 5348 | * @phba: pointer to lpfc hba data structure. |
| 5349 | * |
| 5350 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5351 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 5352 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5353 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5354 | * the IOCBs with the completion callback function associated, the callback |
| 5355 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5356 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 5357 | * callback function associated, the IOCB will simply be released. Finally, |
| 5358 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 5359 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 5360 | * management plane IOCBs that are not part of the discovery state machine) |
| 5361 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5362 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5363 | void |
| 5364 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 5365 | { |
| 5366 | LIST_HEAD(completions); |
| 5367 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 5368 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5369 | IOCB_t *cmd = NULL; |
| 5370 | |
| 5371 | lpfc_fabric_abort_hba(phba); |
| 5372 | spin_lock_irq(&phba->hbalock); |
| 5373 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5374 | cmd = &piocb->iocb; |
| 5375 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5376 | continue; |
| 5377 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
| 5378 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5379 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5380 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5381 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| 5382 | continue; |
| 5383 | list_move_tail(&piocb->list, &completions); |
| 5384 | pring->txq_cnt--; |
| 5385 | } |
| 5386 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5387 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5388 | continue; |
| 5389 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5390 | } |
| 5391 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5392 | |
| 5393 | /* Cancel all the IOCBs from the completions list */ |
| 5394 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5395 | IOERR_SLI_ABORTED); |
| 5396 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5397 | return; |
| 5398 | } |
| 5399 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5400 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5401 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5402 | * @phba: Pointer to hba context object. |
| 5403 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 5404 | * @rspiocbp: Pointer to response iocb which reported error. |
| 5405 | * |
| 5406 | * This function sends an event when there is an ELS command |
| 5407 | * failure. |
| 5408 | **/ |
| 5409 | void |
| 5410 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 5411 | struct lpfc_iocbq *cmdiocbp, |
| 5412 | struct lpfc_iocbq *rspiocbp) |
| 5413 | { |
| 5414 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 5415 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5416 | struct lpfc_lsrjt_event lsrjt_event; |
| 5417 | struct lpfc_fabric_event_header fabric_event; |
| 5418 | struct ls_rjt stat; |
| 5419 | struct lpfc_nodelist *ndlp; |
| 5420 | uint32_t *pcmd; |
| 5421 | |
| 5422 | ndlp = cmdiocbp->context1; |
| 5423 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 5424 | return; |
| 5425 | |
| 5426 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 5427 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 5428 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 5429 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 5430 | sizeof(struct lpfc_name)); |
| 5431 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 5432 | sizeof(struct lpfc_name)); |
| 5433 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 5434 | cmdiocbp->context2)->virt); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 5435 | lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5436 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 5437 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 5438 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 5439 | fc_host_post_vendor_event(shost, |
| 5440 | fc_get_event_number(), |
| 5441 | sizeof(lsrjt_event), |
| 5442 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5443 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5444 | return; |
| 5445 | } |
| 5446 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 5447 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 5448 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 5449 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 5450 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 5451 | else |
| 5452 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 5453 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 5454 | sizeof(struct lpfc_name)); |
| 5455 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 5456 | sizeof(struct lpfc_name)); |
| 5457 | fc_host_post_vendor_event(shost, |
| 5458 | fc_get_event_number(), |
| 5459 | sizeof(fabric_event), |
| 5460 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5461 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5462 | return; |
| 5463 | } |
| 5464 | |
| 5465 | } |
| 5466 | |
| 5467 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5468 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5469 | * @vport: Pointer to vport object. |
| 5470 | * @ndlp: Pointer FC node object. |
| 5471 | * @cmd: ELS command code. |
| 5472 | * |
| 5473 | * This function posts an event when there is an incoming |
| 5474 | * unsolicited ELS command. |
| 5475 | **/ |
| 5476 | static void |
| 5477 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 5478 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5479 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5480 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5481 | struct lpfc_els_event_header *els_data = NULL; |
| 5482 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5483 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5484 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5485 | if (*payload == ELS_CMD_LOGO) { |
| 5486 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 5487 | if (!logo_data) { |
| 5488 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5489 | "0148 Failed to allocate memory " |
| 5490 | "for LOGO event\n"); |
| 5491 | return; |
| 5492 | } |
| 5493 | els_data = &logo_data->header; |
| 5494 | } else { |
| 5495 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 5496 | GFP_KERNEL); |
| 5497 | if (!els_data) { |
| 5498 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5499 | "0149 Failed to allocate memory " |
| 5500 | "for ELS event\n"); |
| 5501 | return; |
| 5502 | } |
| 5503 | } |
| 5504 | els_data->event_type = FC_REG_ELS_EVENT; |
| 5505 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5506 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5507 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5508 | break; |
| 5509 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5510 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5511 | break; |
| 5512 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5513 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 5514 | break; |
| 5515 | case ELS_CMD_LOGO: |
| 5516 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 5517 | /* Copy the WWPN in the LOGO payload */ |
| 5518 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 5519 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5520 | break; |
| 5521 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 5522 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5523 | return; |
| 5524 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5525 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 5526 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 5527 | if (*payload == ELS_CMD_LOGO) { |
| 5528 | fc_host_post_vendor_event(shost, |
| 5529 | fc_get_event_number(), |
| 5530 | sizeof(struct lpfc_logo_event), |
| 5531 | (char *)logo_data, |
| 5532 | LPFC_NL_VENDOR_ID); |
| 5533 | kfree(logo_data); |
| 5534 | } else { |
| 5535 | fc_host_post_vendor_event(shost, |
| 5536 | fc_get_event_number(), |
| 5537 | sizeof(struct lpfc_els_event_header), |
| 5538 | (char *)els_data, |
| 5539 | LPFC_NL_VENDOR_ID); |
| 5540 | kfree(els_data); |
| 5541 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5542 | |
| 5543 | return; |
| 5544 | } |
| 5545 | |
| 5546 | |
| 5547 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5548 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5549 | * @phba: pointer to lpfc hba data structure. |
| 5550 | * @pring: pointer to a SLI ring. |
| 5551 | * @vport: pointer to a host virtual N_Port data structure. |
| 5552 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 5553 | * |
| 5554 | * This routine is used for processing the IOCB associated with a unsolicited |
| 5555 | * event. It first determines whether there is an existing ndlp that matches |
| 5556 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 5557 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 5558 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 5559 | * of the discovery state machine. |
| 5560 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5561 | static void |
| 5562 | 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] | 5563 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5564 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5565 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5566 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5567 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5568 | uint32_t *payload; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5569 | uint32_t cmd, did, newnode, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5570 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5571 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5572 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5573 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5574 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5575 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5576 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 5577 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5578 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5579 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5580 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5581 | did = icmd->un.rcvels.remoteID; |
| 5582 | if (icmd->ulpStatus) { |
| 5583 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5584 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 5585 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5586 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5587 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5588 | |
| 5589 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5590 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5591 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5592 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 5593 | /* Ignore traffic received during vport shutdown. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5594 | if (vport->load_flag & FC_UNLOADING) |
| 5595 | goto dropit; |
| 5596 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5597 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5598 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5599 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5600 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5601 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5602 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5603 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5604 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5605 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5606 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5607 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5608 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5609 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5610 | ndlp = lpfc_enable_node(vport, ndlp, |
| 5611 | NLP_STE_UNUSED_NODE); |
| 5612 | if (!ndlp) |
| 5613 | goto dropit; |
| 5614 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5615 | newnode = 1; |
| 5616 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 5617 | ndlp->nlp_type |= NLP_FABRIC; |
| 5618 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 5619 | /* This is similar to the new node path */ |
| 5620 | ndlp = lpfc_nlp_get(ndlp); |
| 5621 | if (!ndlp) |
| 5622 | goto dropit; |
| 5623 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5624 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5625 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5626 | |
| 5627 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5628 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5629 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5630 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5631 | |
| 5632 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 5633 | cmd &= ELS_CMD_MASK; |
| 5634 | } |
| 5635 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5636 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5637 | "0112 ELS command x%x received from NPORT x%x " |
| 5638 | "Data: x%x\n", cmd, did, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5639 | switch (cmd) { |
| 5640 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5641 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5642 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 5643 | did, vport->port_state, ndlp->nlp_flag); |
| 5644 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5645 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5646 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
| 5647 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5648 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5649 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5650 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 5651 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 5652 | rjt_err = LSRJT_UNABLE_TPC; |
| 5653 | break; |
| 5654 | } |
| 5655 | /* We get here, and drop thru, if we are PT2PT with |
| 5656 | * another NPort and the other side has initiated |
| 5657 | * the PLOGI before responding to our FLOGI. |
| 5658 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5659 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5660 | |
| 5661 | shost = lpfc_shost_from_vport(vport); |
| 5662 | spin_lock_irq(shost->host_lock); |
| 5663 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 5664 | spin_unlock_irq(shost->host_lock); |
| 5665 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5666 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5667 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5668 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5669 | break; |
| 5670 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5671 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5672 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 5673 | did, vport->port_state, ndlp->nlp_flag); |
| 5674 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5675 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5676 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5677 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5678 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5679 | break; |
| 5680 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5681 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5682 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 5683 | did, vport->port_state, ndlp->nlp_flag); |
| 5684 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5685 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5686 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5687 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5688 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5689 | break; |
| 5690 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5691 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5692 | break; |
| 5693 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5694 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5695 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 5696 | did, vport->port_state, ndlp->nlp_flag); |
| 5697 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5698 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5699 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5700 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5701 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5702 | break; |
| 5703 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5704 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5705 | break; |
| 5706 | case ELS_CMD_RSCN: |
| 5707 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5708 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5709 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5710 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5711 | break; |
| 5712 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5713 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5714 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 5715 | did, vport->port_state, ndlp->nlp_flag); |
| 5716 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5717 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5718 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5719 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5720 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5721 | break; |
| 5722 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5723 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5724 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5725 | break; |
| 5726 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5727 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5728 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 5729 | did, vport->port_state, ndlp->nlp_flag); |
| 5730 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5731 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5732 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5733 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5734 | break; |
| 5735 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5736 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5737 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5738 | break; |
| 5739 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5740 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5741 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 5742 | did, vport->port_state, ndlp->nlp_flag); |
| 5743 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5744 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5745 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5746 | break; |
| 5747 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5748 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5749 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 5750 | did, vport->port_state, ndlp->nlp_flag); |
| 5751 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5752 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5753 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5754 | break; |
| 5755 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5756 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5757 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 5758 | did, vport->port_state, ndlp->nlp_flag); |
| 5759 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5760 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5761 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5762 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5763 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5764 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5765 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 5766 | did, vport->port_state, ndlp->nlp_flag); |
| 5767 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5768 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5769 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5770 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5771 | break; |
| 5772 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5773 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5774 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5775 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5776 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5777 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 5778 | did, vport->port_state, ndlp->nlp_flag); |
| 5779 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5780 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5781 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5782 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5783 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5784 | break; |
| 5785 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5786 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5787 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 5788 | did, vport->port_state, ndlp->nlp_flag); |
| 5789 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5790 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5791 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5792 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5793 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5794 | break; |
| 5795 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5796 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5797 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 5798 | did, vport->port_state, ndlp->nlp_flag); |
| 5799 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5800 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5801 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5802 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5803 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5804 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5805 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5806 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5807 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 5808 | did, vport->port_state, ndlp->nlp_flag); |
| 5809 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5810 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5811 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5812 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5813 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5814 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 5815 | case ELS_CMD_RRQ: |
| 5816 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5817 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", |
| 5818 | did, vport->port_state, ndlp->nlp_flag); |
| 5819 | |
| 5820 | phba->fc_stat.elsRcvRRQ++; |
| 5821 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); |
| 5822 | if (newnode) |
| 5823 | lpfc_nlp_put(ndlp); |
| 5824 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5825 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5826 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5827 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 5828 | cmd, did, vport->port_state); |
| 5829 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5830 | /* Unsupported ELS command, reject */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5831 | rjt_err = LSRJT_INVALID_CMD; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5832 | |
| 5833 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5834 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5835 | "0115 Unknown ELS command x%x " |
| 5836 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5837 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5838 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5839 | break; |
| 5840 | } |
| 5841 | |
| 5842 | /* check if need to LS_RJT received ELS cmd */ |
| 5843 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5844 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5845 | stat.un.b.lsRjtRsnCode = rjt_err; |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 5846 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5847 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 5848 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5849 | } |
| 5850 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5851 | lpfc_nlp_put(elsiocb->context1); |
| 5852 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5853 | return; |
| 5854 | |
| 5855 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5856 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5857 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5858 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5859 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5860 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5861 | phba->fc_stat.elsRcvDrop++; |
| 5862 | } |
| 5863 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5864 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5865 | * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5866 | * @phba: pointer to lpfc hba data structure. |
| 5867 | * @vpi: host virtual N_Port identifier. |
| 5868 | * |
| 5869 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 5870 | * @vpi. The function walks the HBA's vport list and returns the address |
| 5871 | * of the vport with the matching @vpi. |
| 5872 | * |
| 5873 | * Return code |
| 5874 | * NULL - No vport with the matching @vpi found |
| 5875 | * Otherwise - Address to the vport with the matching @vpi. |
| 5876 | **/ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5877 | struct lpfc_vport * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5878 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 5879 | { |
| 5880 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5881 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5882 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5883 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5884 | list_for_each_entry(vport, &phba->port_list, listentry) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5885 | if (vport->vpi == vpi) { |
| 5886 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5887 | return vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5888 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5889 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5890 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5891 | return NULL; |
| 5892 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5893 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5894 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5895 | * 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] | 5896 | * @phba: pointer to lpfc hba data structure. |
| 5897 | * @pring: pointer to a SLI ring. |
| 5898 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 5899 | * |
| 5900 | * This routine is used to process an unsolicited event received from a SLI |
| 5901 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 5902 | * associated with the unsolicited event is done by invoking the routine |
| 5903 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 5904 | * SLI ring on which the unsolicited event was received. |
| 5905 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5906 | void |
| 5907 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 5908 | struct lpfc_iocbq *elsiocb) |
| 5909 | { |
| 5910 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5911 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5912 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5913 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 5914 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5915 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5916 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5917 | elsiocb->context2 = NULL; |
| 5918 | elsiocb->context3 = NULL; |
| 5919 | |
| 5920 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 5921 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 5922 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 5923 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5924 | phba->fc_stat.NoRcvBuf++; |
| 5925 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5926 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5927 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5928 | return; |
| 5929 | } |
| 5930 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5931 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 5932 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 5933 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 5934 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 5935 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5936 | else |
| 5937 | vport = lpfc_find_vport_by_vpid(phba, |
| 5938 | icmd->unsli3.rcvsli3.vpi - phba->vpi_base); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5939 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5940 | /* If there are no BDEs associated |
| 5941 | * with this IOCB, there is nothing to do. |
| 5942 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5943 | if (icmd->ulpBdeCount == 0) |
| 5944 | return; |
| 5945 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5946 | /* type of ELS cmd is first 32bit word |
| 5947 | * in packet |
| 5948 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5949 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5950 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5951 | } else { |
| 5952 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 5953 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5954 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 5955 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5956 | } |
| 5957 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5958 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 5959 | /* |
| 5960 | * The different unsolicited event handlers would tell us |
| 5961 | * if they are done with "mp" by setting context2 to NULL. |
| 5962 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5963 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5964 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 5965 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5966 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5967 | |
| 5968 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5969 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5970 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5971 | elsiocb->context2 = bdeBuf2; |
| 5972 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5973 | /* free mp if we are done with it */ |
| 5974 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5975 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 5976 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5977 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5978 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5979 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5980 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5981 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5982 | * 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] | 5983 | * @phba: pointer to lpfc hba data structure. |
| 5984 | * @vport: pointer to a virtual N_Port data structure. |
| 5985 | * |
| 5986 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 5987 | * State Change Request (SCR) for a @vport. This routine will create an |
| 5988 | * ndlp for the Name Server associated to the @vport if such node does |
| 5989 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 5990 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 5991 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 5992 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 5993 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5994 | void |
| 5995 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 5996 | { |
| 5997 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
| 5998 | |
| 5999 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 6000 | if (!ndlp) { |
| 6001 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 6002 | if (!ndlp) { |
| 6003 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 6004 | lpfc_disc_start(vport); |
| 6005 | return; |
| 6006 | } |
| 6007 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6008 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6009 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6010 | return; |
| 6011 | } |
| 6012 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6013 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 6014 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 6015 | if (!ndlp) { |
| 6016 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 6017 | lpfc_disc_start(vport); |
| 6018 | return; |
| 6019 | } |
| 6020 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6021 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6022 | "0348 NameServer login: node freed\n"); |
| 6023 | return; |
| 6024 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6025 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6026 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6027 | |
| 6028 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 6029 | |
| 6030 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 6031 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6032 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6033 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6034 | return; |
| 6035 | } |
| 6036 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6037 | if (vport->cfg_fdmi_on) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6038 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 6039 | GFP_KERNEL); |
| 6040 | if (ndlp_fdmi) { |
| 6041 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 6042 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6043 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
| 6044 | NLP_STE_PLOGI_ISSUE); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6045 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, |
| 6046 | 0); |
| 6047 | } |
| 6048 | } |
| 6049 | return; |
| 6050 | } |
| 6051 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6052 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6053 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6054 | * @phba: pointer to lpfc hba data structure. |
| 6055 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 6056 | * |
| 6057 | * This routine is the completion callback function to register new vport |
| 6058 | * mailbox command. If the new vport mailbox command completes successfully, |
| 6059 | * the fabric registration login shall be performed on physical port (the |
| 6060 | * new vport created is actually a physical port, with VPI 0) or the port |
| 6061 | * login to Name Server for State Change Request (SCR) will be performed |
| 6062 | * on virtual port (real virtual port, with VPI greater than 0). |
| 6063 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6064 | static void |
| 6065 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6066 | { |
| 6067 | struct lpfc_vport *vport = pmb->vport; |
| 6068 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6069 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6070 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6071 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6072 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6073 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6074 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6075 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6076 | |
| 6077 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6078 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6079 | "0915 Register VPI failed: 0x%x\n", |
| 6080 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6081 | |
| 6082 | switch (mb->mbxStatus) { |
| 6083 | case 0x11: /* unsupported feature */ |
| 6084 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6085 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6086 | /* giving up on vport registration */ |
| 6087 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6088 | spin_lock_irq(shost->host_lock); |
| 6089 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 6090 | spin_unlock_irq(shost->host_lock); |
| 6091 | lpfc_can_disctmo(vport); |
| 6092 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6093 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
| 6094 | case 0x20: |
| 6095 | spin_lock_irq(shost->host_lock); |
| 6096 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 6097 | spin_unlock_irq(shost->host_lock); |
| 6098 | lpfc_init_vpi(phba, pmb, vport->vpi); |
| 6099 | pmb->vport = vport; |
| 6100 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 6101 | rc = lpfc_sli_issue_mbox(phba, pmb, |
| 6102 | MBX_NOWAIT); |
| 6103 | if (rc == MBX_NOT_FINISHED) { |
| 6104 | lpfc_printf_vlog(vport, |
| 6105 | KERN_ERR, LOG_MBOX, |
| 6106 | "2732 Failed to issue INIT_VPI" |
| 6107 | " mailbox command\n"); |
| 6108 | } else { |
| 6109 | lpfc_nlp_put(ndlp); |
| 6110 | return; |
| 6111 | } |
| 6112 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6113 | default: |
| 6114 | /* Try to recover from this error */ |
| 6115 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6116 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6117 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6118 | spin_unlock_irq(shost->host_lock); |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6119 | if (vport->port_type == LPFC_PHYSICAL_PORT |
| 6120 | && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6121 | lpfc_initial_flogi(vport); |
| 6122 | else |
| 6123 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6124 | break; |
| 6125 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6126 | } else { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6127 | spin_lock_irq(shost->host_lock); |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 6128 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6129 | spin_unlock_irq(shost->host_lock); |
| 6130 | if (vport == phba->pport) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6131 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 6132 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6133 | else { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6134 | /* |
| 6135 | * If the physical port is instantiated using |
| 6136 | * FDISC, do not start vport discovery. |
| 6137 | */ |
| 6138 | if (vport->port_state != LPFC_FDISC) |
| 6139 | lpfc_start_fdiscs(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6140 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6141 | } |
| 6142 | } else |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6143 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6144 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6145 | |
| 6146 | /* Now, we decrement the ndlp reference count held for this |
| 6147 | * callback function |
| 6148 | */ |
| 6149 | lpfc_nlp_put(ndlp); |
| 6150 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6151 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6152 | return; |
| 6153 | } |
| 6154 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6155 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6156 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6157 | * @phba: pointer to lpfc hba data structure. |
| 6158 | * @vport: pointer to a host virtual N_Port data structure. |
| 6159 | * @ndlp: pointer to a node-list data structure. |
| 6160 | * |
| 6161 | * This routine registers the @vport as a new virtual port with a HBA. |
| 6162 | * It is done through a registering vpi mailbox command. |
| 6163 | **/ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6164 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6165 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 6166 | struct lpfc_nodelist *ndlp) |
| 6167 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6168 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6169 | LPFC_MBOXQ_t *mbox; |
| 6170 | |
| 6171 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6172 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6173 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6174 | mbox->vport = vport; |
| 6175 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 6176 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 6177 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6178 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6179 | /* mailbox command not success, decrement ndlp |
| 6180 | * reference count for this command |
| 6181 | */ |
| 6182 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6183 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6184 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6185 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6186 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6187 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6188 | } |
| 6189 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6190 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6191 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6192 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6193 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6194 | return; |
| 6195 | |
| 6196 | mbox_err_exit: |
| 6197 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6198 | spin_lock_irq(shost->host_lock); |
| 6199 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 6200 | spin_unlock_irq(shost->host_lock); |
| 6201 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6202 | } |
| 6203 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6204 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6205 | * 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] | 6206 | * @phba: pointer to lpfc hba data structure. |
| 6207 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6208 | * This routine cancels the retry delay timers to all the vports. |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6209 | **/ |
| 6210 | void |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6211 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6212 | { |
| 6213 | struct lpfc_vport **vports; |
| 6214 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6215 | uint32_t link_state; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6216 | int i; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6217 | |
| 6218 | /* Treat this failure as linkdown for all vports */ |
| 6219 | link_state = phba->link_state; |
| 6220 | lpfc_linkdown(phba); |
| 6221 | phba->link_state = link_state; |
| 6222 | |
| 6223 | vports = lpfc_create_vport_work_array(phba); |
| 6224 | |
| 6225 | if (vports) { |
| 6226 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 6227 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 6228 | if (ndlp) |
| 6229 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
| 6230 | lpfc_els_flush_cmd(vports[i]); |
| 6231 | } |
| 6232 | lpfc_destroy_vport_work_array(phba, vports); |
| 6233 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6234 | } |
| 6235 | |
| 6236 | /** |
| 6237 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. |
| 6238 | * @phba: pointer to lpfc hba data structure. |
| 6239 | * |
| 6240 | * This routine abort all pending discovery commands and |
| 6241 | * start a timer to retry FLOGI for the physical port |
| 6242 | * discovery. |
| 6243 | **/ |
| 6244 | void |
| 6245 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) |
| 6246 | { |
| 6247 | struct lpfc_nodelist *ndlp; |
| 6248 | struct Scsi_Host *shost; |
| 6249 | |
| 6250 | /* Cancel the all vports retry delay retry timers */ |
| 6251 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6252 | |
| 6253 | /* If fabric require FLOGI, then re-instantiate physical login */ |
| 6254 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 6255 | if (!ndlp) |
| 6256 | return; |
| 6257 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6258 | shost = lpfc_shost_from_vport(phba->pport); |
| 6259 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); |
| 6260 | spin_lock_irq(shost->host_lock); |
| 6261 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 6262 | spin_unlock_irq(shost->host_lock); |
| 6263 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; |
| 6264 | phba->pport->port_state = LPFC_FLOGI; |
| 6265 | return; |
| 6266 | } |
| 6267 | |
| 6268 | /** |
| 6269 | * lpfc_fabric_login_reqd - Check if FLOGI required. |
| 6270 | * @phba: pointer to lpfc hba data structure. |
| 6271 | * @cmdiocb: pointer to FDISC command iocb. |
| 6272 | * @rspiocb: pointer to FDISC response iocb. |
| 6273 | * |
| 6274 | * This routine checks if a FLOGI is reguired for FDISC |
| 6275 | * to succeed. |
| 6276 | **/ |
| 6277 | static int |
| 6278 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, |
| 6279 | struct lpfc_iocbq *cmdiocb, |
| 6280 | struct lpfc_iocbq *rspiocb) |
| 6281 | { |
| 6282 | |
| 6283 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || |
| 6284 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) |
| 6285 | return 0; |
| 6286 | else |
| 6287 | return 1; |
| 6288 | } |
| 6289 | |
| 6290 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6291 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6292 | * @phba: pointer to lpfc hba data structure. |
| 6293 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6294 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6295 | * |
| 6296 | * This routine is the completion callback function to a Fabric Discover |
| 6297 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 6298 | * single threaded, each FDISC completion callback function will reset |
| 6299 | * the discovery timer for all vports such that the timers will not get |
| 6300 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 6301 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 6302 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 6303 | * assigned to the vport has been changed with the completion of the FDISC |
| 6304 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 6305 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 6306 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 6307 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 6308 | * Server for State Change Request (SCR). |
| 6309 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6310 | static void |
| 6311 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6312 | struct lpfc_iocbq *rspiocb) |
| 6313 | { |
| 6314 | struct lpfc_vport *vport = cmdiocb->vport; |
| 6315 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6316 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 6317 | struct lpfc_nodelist *np; |
| 6318 | struct lpfc_nodelist *next_np; |
| 6319 | IOCB_t *irsp = &rspiocb->iocb; |
| 6320 | struct lpfc_iocbq *piocb; |
| 6321 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6322 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6323 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 6324 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 6325 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6326 | /* Since all FDISCs are being single threaded, we |
| 6327 | * must reset the discovery timer for ALL vports |
| 6328 | * waiting to send FDISC when one completes. |
| 6329 | */ |
| 6330 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 6331 | lpfc_set_disctmo(piocb->vport); |
| 6332 | } |
| 6333 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6334 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6335 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 6336 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 6337 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6338 | if (irsp->ulpStatus) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6339 | |
| 6340 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { |
| 6341 | lpfc_retry_pport_discovery(phba); |
| 6342 | goto out; |
| 6343 | } |
| 6344 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6345 | /* Check for retry */ |
| 6346 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 6347 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6348 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6349 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6350 | "0126 FDISC failed. (%d/%d)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6351 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6352 | goto fdisc_failed; |
| 6353 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6354 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6355 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6356 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6357 | vport->fc_flag |= FC_FABRIC; |
| 6358 | if (vport->phba->fc_topology == TOPOLOGY_LOOP) |
| 6359 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 6360 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6361 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6362 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 6363 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
| 6364 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 6365 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 6366 | /* If our NportID changed, we need to ensure all |
| 6367 | * remaining NPORTs get unreg_login'ed so we can |
| 6368 | * issue unreg_vpi. |
| 6369 | */ |
| 6370 | list_for_each_entry_safe(np, next_np, |
| 6371 | &vport->fc_nodes, nlp_listp) { |
| 6372 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 6373 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 6374 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 6375 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6376 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6377 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6378 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6379 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6380 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 6381 | lpfc_cleanup_pending_mbox(vport); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6382 | lpfc_mbx_unreg_vpi(vport); |
| 6383 | spin_lock_irq(shost->host_lock); |
| 6384 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 6385 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6386 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6387 | else |
| 6388 | vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6389 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6390 | } |
| 6391 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6392 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
| 6393 | lpfc_issue_init_vpi(vport); |
| 6394 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6395 | lpfc_register_new_vport(phba, vport, ndlp); |
| 6396 | else |
| 6397 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6398 | goto out; |
| 6399 | fdisc_failed: |
| 6400 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6401 | /* Cancel discovery timer */ |
| 6402 | lpfc_can_disctmo(vport); |
| 6403 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6404 | out: |
| 6405 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6406 | } |
| 6407 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6408 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6409 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6410 | * @vport: pointer to a virtual N_Port data structure. |
| 6411 | * @ndlp: pointer to a node-list data structure. |
| 6412 | * @retry: number of retries to the command IOCB. |
| 6413 | * |
| 6414 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 6415 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 6416 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 6417 | * IOCB will be sent off HBA at any given time. |
| 6418 | * |
| 6419 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6420 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6421 | * will be stored into the context1 field of the IOCB for the completion |
| 6422 | * callback function to the FDISC ELS command. |
| 6423 | * |
| 6424 | * Return code |
| 6425 | * 0 - Successfully issued fdisc iocb command |
| 6426 | * 1 - Failed to issue fdisc iocb command |
| 6427 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6428 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6429 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 6430 | uint8_t retry) |
| 6431 | { |
| 6432 | struct lpfc_hba *phba = vport->phba; |
| 6433 | IOCB_t *icmd; |
| 6434 | struct lpfc_iocbq *elsiocb; |
| 6435 | struct serv_parm *sp; |
| 6436 | uint8_t *pcmd; |
| 6437 | uint16_t cmdsize; |
| 6438 | int did = ndlp->nlp_DID; |
| 6439 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6440 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6441 | vport->port_state = LPFC_FDISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6442 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 6443 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 6444 | ELS_CMD_FDISC); |
| 6445 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6446 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6447 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6448 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6449 | return 1; |
| 6450 | } |
| 6451 | |
| 6452 | icmd = &elsiocb->iocb; |
| 6453 | icmd->un.elsreq64.myID = 0; |
| 6454 | icmd->un.elsreq64.fl = 1; |
| 6455 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6456 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 6457 | /* FDISC needs to be 1 for WQE VPI */ |
| 6458 | elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1; |
| 6459 | elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ; |
| 6460 | /* Set the ulpContext to the vpi */ |
| 6461 | elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base; |
| 6462 | } else { |
| 6463 | /* For FDISC, Let FDISC rsp set the NPortID for this VPI */ |
| 6464 | icmd->ulpCt_h = 1; |
| 6465 | icmd->ulpCt_l = 0; |
| 6466 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6467 | |
| 6468 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6469 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 6470 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 6471 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 6472 | sp = (struct serv_parm *) pcmd; |
| 6473 | /* Setup CSPs accordingly for Fabric */ |
| 6474 | sp->cmn.e_d_tov = 0; |
| 6475 | sp->cmn.w2.r_a_tov = 0; |
| 6476 | sp->cls1.classValid = 0; |
| 6477 | sp->cls2.seqDelivery = 1; |
| 6478 | sp->cls3.seqDelivery = 1; |
| 6479 | |
| 6480 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 6481 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 6482 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 6483 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 6484 | memcpy(pcmd, &vport->fc_portname, 8); |
| 6485 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6486 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6487 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 6488 | |
| 6489 | lpfc_set_disctmo(vport); |
| 6490 | |
| 6491 | phba->fc_stat.elsXmitFDISC++; |
| 6492 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 6493 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6494 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6495 | "Issue FDISC: did:x%x", |
| 6496 | did, 0, 0); |
| 6497 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6498 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 6499 | if (rc == IOCB_ERROR) { |
| 6500 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6501 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6502 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6503 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6504 | return 1; |
| 6505 | } |
| 6506 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6507 | return 0; |
| 6508 | } |
| 6509 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6510 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6511 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6512 | * @phba: pointer to lpfc hba data structure. |
| 6513 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6514 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6515 | * |
| 6516 | * This routine is the completion callback function to the issuing of a LOGO |
| 6517 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 6518 | * reference count held on ndlp for this completion function, indicating that |
| 6519 | * the reference to the ndlp is no long needed. Note that the |
| 6520 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 6521 | * callback function and an additional explicit ndlp reference decrementation |
| 6522 | * will trigger the actual release of the ndlp. |
| 6523 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6524 | static void |
| 6525 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6526 | struct lpfc_iocbq *rspiocb) |
| 6527 | { |
| 6528 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6529 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6530 | struct lpfc_nodelist *ndlp; |
| 6531 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6532 | |
| 6533 | irsp = &rspiocb->iocb; |
| 6534 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6535 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 6536 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6537 | |
| 6538 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6539 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6540 | |
| 6541 | /* Trigger the release of the ndlp after logo */ |
| 6542 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6543 | } |
| 6544 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6545 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6546 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6547 | * @vport: pointer to a virtual N_Port data structure. |
| 6548 | * @ndlp: pointer to a node-list data structure. |
| 6549 | * |
| 6550 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 6551 | * |
| 6552 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6553 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6554 | * will be stored into the context1 field of the IOCB for the completion |
| 6555 | * callback function to the LOGO ELS command. |
| 6556 | * |
| 6557 | * Return codes |
| 6558 | * 0 - Successfully issued logo off the @vport |
| 6559 | * 1 - Failed to issue logo off the @vport |
| 6560 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6561 | int |
| 6562 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 6563 | { |
| 6564 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6565 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6566 | IOCB_t *icmd; |
| 6567 | struct lpfc_iocbq *elsiocb; |
| 6568 | uint8_t *pcmd; |
| 6569 | uint16_t cmdsize; |
| 6570 | |
| 6571 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 6572 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 6573 | ELS_CMD_LOGO); |
| 6574 | if (!elsiocb) |
| 6575 | return 1; |
| 6576 | |
| 6577 | icmd = &elsiocb->iocb; |
| 6578 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6579 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 6580 | pcmd += sizeof(uint32_t); |
| 6581 | |
| 6582 | /* Fill in LOGO payload */ |
| 6583 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 6584 | pcmd += sizeof(uint32_t); |
| 6585 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 6586 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6587 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6588 | "Issue LOGO npiv did:x%x flg:x%x", |
| 6589 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 6590 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6591 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 6592 | spin_lock_irq(shost->host_lock); |
| 6593 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 6594 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6595 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 6596 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6597 | spin_lock_irq(shost->host_lock); |
| 6598 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 6599 | spin_unlock_irq(shost->host_lock); |
| 6600 | lpfc_els_free_iocb(phba, elsiocb); |
| 6601 | return 1; |
| 6602 | } |
| 6603 | return 0; |
| 6604 | } |
| 6605 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6606 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6607 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6608 | * @ptr: holder for the timer function associated data. |
| 6609 | * |
| 6610 | * This routine is invoked by the fabric iocb block timer after |
| 6611 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 6612 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 6613 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 6614 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 6615 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 6616 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6617 | void |
| 6618 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 6619 | { |
| 6620 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 6621 | unsigned long iflags; |
| 6622 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6623 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6624 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 6625 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 6626 | if (!tmo_posted) |
| 6627 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 6628 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 6629 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6630 | if (!tmo_posted) |
| 6631 | lpfc_worker_wake_up(phba); |
| 6632 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6633 | } |
| 6634 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6635 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6636 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6637 | * @phba: pointer to lpfc hba data structure. |
| 6638 | * |
| 6639 | * This routine issues one fabric iocb from the driver internal list to |
| 6640 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 6641 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 6642 | * remove one pending fabric iocb from the driver internal list and invokes |
| 6643 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 6644 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6645 | static void |
| 6646 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 6647 | { |
| 6648 | struct lpfc_iocbq *iocb; |
| 6649 | unsigned long iflags; |
| 6650 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6651 | IOCB_t *cmd; |
| 6652 | |
| 6653 | repeat: |
| 6654 | iocb = NULL; |
| 6655 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6656 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6657 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 6658 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 6659 | list); |
| 6660 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6661 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6662 | atomic_inc(&phba->fabric_iocb_count); |
| 6663 | } |
| 6664 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6665 | if (iocb) { |
| 6666 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6667 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6668 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6669 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6670 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6671 | "Fabric sched1: ste:x%x", |
| 6672 | iocb->vport->port_state, 0, 0); |
| 6673 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6674 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6675 | |
| 6676 | if (ret == IOCB_ERROR) { |
| 6677 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6678 | iocb->fabric_iocb_cmpl = NULL; |
| 6679 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6680 | cmd = &iocb->iocb; |
| 6681 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6682 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6683 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 6684 | |
| 6685 | atomic_dec(&phba->fabric_iocb_count); |
| 6686 | goto repeat; |
| 6687 | } |
| 6688 | } |
| 6689 | |
| 6690 | return; |
| 6691 | } |
| 6692 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6693 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6694 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6695 | * @phba: pointer to lpfc hba data structure. |
| 6696 | * |
| 6697 | * This routine unblocks the issuing fabric iocb command. The function |
| 6698 | * will clear the fabric iocb block bit and then invoke the routine |
| 6699 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 6700 | * from the driver internal fabric iocb list. |
| 6701 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6702 | void |
| 6703 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 6704 | { |
| 6705 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6706 | |
| 6707 | lpfc_resume_fabric_iocbs(phba); |
| 6708 | return; |
| 6709 | } |
| 6710 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6711 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6712 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6713 | * @phba: pointer to lpfc hba data structure. |
| 6714 | * |
| 6715 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 6716 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 6717 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 6718 | * fabric iocb will be issued out of the HBA. |
| 6719 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6720 | static void |
| 6721 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 6722 | { |
| 6723 | int blocked; |
| 6724 | |
| 6725 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6726 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6727 | if (!blocked) |
| 6728 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); |
| 6729 | |
| 6730 | return; |
| 6731 | } |
| 6732 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6733 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6734 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6735 | * @phba: pointer to lpfc hba data structure. |
| 6736 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6737 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6738 | * |
| 6739 | * This routine is the callback function that is put to the fabric iocb's |
| 6740 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 6741 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 6742 | * function first restores and invokes the original iocb's callback function |
| 6743 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 6744 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 6745 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6746 | static void |
| 6747 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6748 | struct lpfc_iocbq *rspiocb) |
| 6749 | { |
| 6750 | struct ls_rjt stat; |
| 6751 | |
| 6752 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 6753 | BUG(); |
| 6754 | |
| 6755 | switch (rspiocb->iocb.ulpStatus) { |
| 6756 | case IOSTAT_NPORT_RJT: |
| 6757 | case IOSTAT_FABRIC_RJT: |
| 6758 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 6759 | lpfc_block_fabric_iocbs(phba); |
| 6760 | } |
| 6761 | break; |
| 6762 | |
| 6763 | case IOSTAT_NPORT_BSY: |
| 6764 | case IOSTAT_FABRIC_BSY: |
| 6765 | lpfc_block_fabric_iocbs(phba); |
| 6766 | break; |
| 6767 | |
| 6768 | case IOSTAT_LS_RJT: |
| 6769 | stat.un.lsRjtError = |
| 6770 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 6771 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 6772 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 6773 | lpfc_block_fabric_iocbs(phba); |
| 6774 | break; |
| 6775 | } |
| 6776 | |
| 6777 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 6778 | BUG(); |
| 6779 | |
| 6780 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 6781 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 6782 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6783 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 6784 | |
| 6785 | atomic_dec(&phba->fabric_iocb_count); |
| 6786 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6787 | /* Post any pending iocbs to HBA */ |
| 6788 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6789 | } |
| 6790 | } |
| 6791 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6792 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6793 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6794 | * @phba: pointer to lpfc hba data structure. |
| 6795 | * @iocb: pointer to lpfc command iocb data structure. |
| 6796 | * |
| 6797 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 6798 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 6799 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 6800 | * any given time. As such, this function will first check to see whether there |
| 6801 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 6802 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 6803 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 6804 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 6805 | * |
| 6806 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 6807 | * order. The problem is caused by the construction of the "ready" boolen does |
| 6808 | * not include the condition that the internal fabric IOCB list is empty. As |
| 6809 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 6810 | * ahead of the fabric IOCBs in the internal list. |
| 6811 | * |
| 6812 | * Return code |
| 6813 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 6814 | * IOCB_ERROR - failed to issue fabric iocb |
| 6815 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6816 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6817 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 6818 | { |
| 6819 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6820 | int ready; |
| 6821 | int ret; |
| 6822 | |
| 6823 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 6824 | BUG(); |
| 6825 | |
| 6826 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6827 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 6828 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6829 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6830 | if (ready) |
| 6831 | /* Increment fabric iocb count to hold the position */ |
| 6832 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6833 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6834 | if (ready) { |
| 6835 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6836 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6837 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6838 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6839 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6840 | "Fabric sched2: ste:x%x", |
| 6841 | iocb->vport->port_state, 0, 0); |
| 6842 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6843 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6844 | |
| 6845 | if (ret == IOCB_ERROR) { |
| 6846 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6847 | iocb->fabric_iocb_cmpl = NULL; |
| 6848 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6849 | atomic_dec(&phba->fabric_iocb_count); |
| 6850 | } |
| 6851 | } else { |
| 6852 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6853 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 6854 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6855 | ret = IOCB_SUCCESS; |
| 6856 | } |
| 6857 | return ret; |
| 6858 | } |
| 6859 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6860 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6861 | * 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] | 6862 | * @vport: pointer to a virtual N_Port data structure. |
| 6863 | * |
| 6864 | * This routine aborts all the IOCBs associated with a @vport from the |
| 6865 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6866 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6867 | * list, removes each IOCB associated with the @vport off the list, set the |
| 6868 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6869 | * associated with the IOCB. |
| 6870 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6871 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6872 | { |
| 6873 | LIST_HEAD(completions); |
| 6874 | struct lpfc_hba *phba = vport->phba; |
| 6875 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6876 | |
| 6877 | spin_lock_irq(&phba->hbalock); |
| 6878 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6879 | list) { |
| 6880 | |
| 6881 | if (piocb->vport != vport) |
| 6882 | continue; |
| 6883 | |
| 6884 | list_move_tail(&piocb->list, &completions); |
| 6885 | } |
| 6886 | spin_unlock_irq(&phba->hbalock); |
| 6887 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6888 | /* Cancel all the IOCBs from the completions list */ |
| 6889 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6890 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6891 | } |
| 6892 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6893 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6894 | * 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] | 6895 | * @ndlp: pointer to a node-list data structure. |
| 6896 | * |
| 6897 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 6898 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6899 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6900 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 6901 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6902 | * associated with the IOCB. |
| 6903 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6904 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 6905 | { |
| 6906 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6907 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6908 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6909 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6910 | |
| 6911 | spin_lock_irq(&phba->hbalock); |
| 6912 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6913 | list) { |
| 6914 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 6915 | |
| 6916 | list_move_tail(&piocb->list, &completions); |
| 6917 | } |
| 6918 | } |
| 6919 | spin_unlock_irq(&phba->hbalock); |
| 6920 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6921 | /* Cancel all the IOCBs from the completions list */ |
| 6922 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6923 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6924 | } |
| 6925 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6926 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6927 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6928 | * @phba: pointer to lpfc hba data structure. |
| 6929 | * |
| 6930 | * This routine aborts all the IOCBs currently on the driver internal |
| 6931 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 6932 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 6933 | * list, removes IOCBs off the list, set the status feild to |
| 6934 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 6935 | * the IOCB. |
| 6936 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6937 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 6938 | { |
| 6939 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6940 | |
| 6941 | spin_lock_irq(&phba->hbalock); |
| 6942 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 6943 | spin_unlock_irq(&phba->hbalock); |
| 6944 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6945 | /* Cancel all the IOCBs from the completions list */ |
| 6946 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6947 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6948 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6949 | |
| 6950 | /** |
| 6951 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 6952 | * @phba: pointer to lpfc hba data structure. |
| 6953 | * @axri: pointer to the els xri abort wcqe structure. |
| 6954 | * |
| 6955 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 6956 | * ELS aborted xri. |
| 6957 | **/ |
| 6958 | void |
| 6959 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 6960 | struct sli4_wcqe_xri_aborted *axri) |
| 6961 | { |
| 6962 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
| 6963 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 6964 | unsigned long iflag = 0; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 6965 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6966 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 6967 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 6968 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6969 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 6970 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 6971 | if (sglq_entry->sli4_xritag == xri) { |
| 6972 | list_del(&sglq_entry->list); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6973 | list_add_tail(&sglq_entry->list, |
| 6974 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 6975 | sglq_entry->state = SGL_FREED; |
| 6976 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6977 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 6978 | |
| 6979 | /* Check if TXQ queue needs to be serviced */ |
| 6980 | if (pring->txq_cnt) |
| 6981 | lpfc_worker_wake_up(phba); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6982 | return; |
| 6983 | } |
| 6984 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 6985 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 6986 | sglq_entry = __lpfc_get_active_sglq(phba, xri); |
| 6987 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { |
| 6988 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 6989 | return; |
| 6990 | } |
| 6991 | sglq_entry->state = SGL_XRI_ABORTED; |
| 6992 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 6993 | return; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6994 | } |