| 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> |
| 24 | #include <linux/interrupt.h> |
| 25 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 26 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 27 | #include <scsi/scsi_device.h> |
| 28 | #include <scsi/scsi_host.h> |
| 29 | #include <scsi/scsi_transport_fc.h> |
| 30 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 31 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 32 | #include "lpfc_hw.h" |
| 33 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 34 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 35 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 36 | #include "lpfc_disc.h" |
| 37 | #include "lpfc_scsi.h" |
| 38 | #include "lpfc.h" |
| 39 | #include "lpfc_logmsg.h" |
| 40 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 41 | #include "lpfc_vport.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 42 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 43 | |
| 44 | static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *, |
| 45 | struct lpfc_iocbq *); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 46 | static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *, |
| 47 | struct lpfc_iocbq *); |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 48 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport); |
| 49 | static int lpfc_issue_els_fdisc(struct lpfc_vport *vport, |
| 50 | struct lpfc_nodelist *ndlp, uint8_t retry); |
| 51 | static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba, |
| 52 | struct lpfc_iocbq *iocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 53 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 54 | static int lpfc_max_els_tries = 3; |
| 55 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 56 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 57 | * lpfc_els_chk_latt - Check host link attention event for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 58 | * @vport: pointer to a host virtual N_Port data structure. |
| 59 | * |
| 60 | * This routine checks whether there is an outstanding host link |
| 61 | * attention event during the discovery process with the @vport. It is done |
| 62 | * by reading the HBA's Host Attention (HA) register. If there is any host |
| 63 | * link attention events during this @vport's discovery process, the @vport |
| 64 | * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall |
| 65 | * be issued if the link state is not already in host link cleared state, |
| 66 | * and a return code shall indicate whether the host link attention event |
| 67 | * had happened. |
| 68 | * |
| 69 | * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport |
| 70 | * state in LPFC_VPORT_READY, the request for checking host link attention |
| 71 | * event will be ignored and a return code shall indicate no host link |
| 72 | * attention event had happened. |
| 73 | * |
| 74 | * Return codes |
| 75 | * 0 - no host link attention event happened |
| 76 | * 1 - host link attention event happened |
| 77 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 78 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 79 | lpfc_els_chk_latt(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 80 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 81 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 82 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 83 | uint32_t ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 84 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 85 | if (vport->port_state >= LPFC_VPORT_READY || |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 86 | phba->link_state == LPFC_LINK_DOWN || |
| 87 | phba->sli_rev > LPFC_SLI_REV3) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 88 | return 0; |
| 89 | |
| 90 | /* Read the HBA Host Attention Register */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 91 | ha_copy = readl(phba->HAregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 92 | |
| 93 | if (!(ha_copy & HA_LATT)) |
| 94 | return 0; |
| 95 | |
| 96 | /* Pending Link Event during Discovery */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 97 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 98 | "0237 Pending Link Event during " |
| 99 | "Discovery: State x%x\n", |
| 100 | phba->pport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 101 | |
| 102 | /* CLEAR_LA should re-enable link attention events and |
| 103 | * we should then imediately take a LATT event. The |
| 104 | * LATT processing should call lpfc_linkdown() which |
| 105 | * will cleanup any left over in-progress discovery |
| 106 | * events. |
| 107 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 108 | spin_lock_irq(shost->host_lock); |
| 109 | vport->fc_flag |= FC_ABORT_DISCOVERY; |
| 110 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 111 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 112 | if (phba->link_state != LPFC_CLEAR_LA) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 113 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 114 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 115 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 116 | } |
| 117 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 118 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 119 | * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 120 | * @vport: pointer to a host virtual N_Port data structure. |
| 121 | * @expectRsp: flag indicating whether response is expected. |
| 122 | * @cmdSize: size of the ELS command. |
| 123 | * @retry: number of retries to the command IOCB when it fails. |
| 124 | * @ndlp: pointer to a node-list data structure. |
| 125 | * @did: destination identifier. |
| 126 | * @elscmd: the ELS command code. |
| 127 | * |
| 128 | * This routine is used for allocating a lpfc-IOCB data structure from |
| 129 | * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters |
| 130 | * passed into the routine for discovery state machine to issue an Extended |
| 131 | * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation |
| 132 | * and preparation routine that is used by all the discovery state machine |
| 133 | * routines and the ELS command-specific fields will be later set up by |
| 134 | * the individual discovery machine routines after calling this routine |
| 135 | * allocating and preparing a generic IOCB data structure. It fills in the |
| 136 | * Buffer Descriptor Entries (BDEs), allocates buffers for both command |
| 137 | * payload and response payload (if expected). The reference count on the |
| 138 | * ndlp is incremented by 1 and the reference to the ndlp is put into |
| 139 | * context1 of the IOCB data structure for this IOCB to hold the ndlp |
| 140 | * reference for the command's callback function to access later. |
| 141 | * |
| 142 | * Return code |
| 143 | * Pointer to the newly allocated/prepared els iocb data structure |
| 144 | * NULL - when els iocb data structure allocation/preparation failed |
| 145 | **/ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 146 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 147 | lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, |
| 148 | uint16_t cmdSize, uint8_t retry, |
| 149 | struct lpfc_nodelist *ndlp, uint32_t did, |
| 150 | uint32_t elscmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 151 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 152 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 153 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 154 | struct lpfc_dmabuf *pcmd, *prsp, *pbuflist; |
| 155 | struct ulp_bde64 *bpl; |
| 156 | IOCB_t *icmd; |
| 157 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 158 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 159 | if (!lpfc_is_link_up(phba)) |
| 160 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 161 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 162 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 163 | elsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 164 | |
| 165 | if (elsiocb == NULL) |
| 166 | return NULL; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 167 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 168 | /* |
| 169 | * If this command is for fabric controller and HBA running |
| 170 | * in FIP mode send FLOGI, FDISC and LOGO as FIP frames. |
| 171 | */ |
| 172 | if ((did == Fabric_DID) && |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 173 | (phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 174 | ((elscmd == ELS_CMD_FLOGI) || |
| 175 | (elscmd == ELS_CMD_FDISC) || |
| 176 | (elscmd == ELS_CMD_LOGO))) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 177 | switch (elscmd) { |
| 178 | case ELS_CMD_FLOGI: |
| 179 | elsiocb->iocb_flag |= ((ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT) |
| 180 | & LPFC_FIP_ELS_ID_MASK); |
| 181 | break; |
| 182 | case ELS_CMD_FDISC: |
| 183 | elsiocb->iocb_flag |= ((ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT) |
| 184 | & LPFC_FIP_ELS_ID_MASK); |
| 185 | break; |
| 186 | case ELS_CMD_LOGO: |
| 187 | elsiocb->iocb_flag |= ((ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT) |
| 188 | & LPFC_FIP_ELS_ID_MASK); |
| 189 | break; |
| 190 | } |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 191 | else |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 192 | elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 193 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 194 | icmd = &elsiocb->iocb; |
| 195 | |
| 196 | /* fill in BDEs for command */ |
| 197 | /* Allocate buffer for command payload */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 198 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 199 | if (pcmd) |
| 200 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 201 | if (!pcmd || !pcmd->virt) |
| 202 | goto els_iocb_free_pcmb_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 203 | |
| 204 | INIT_LIST_HEAD(&pcmd->list); |
| 205 | |
| 206 | /* Allocate buffer for response payload */ |
| 207 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 208 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 209 | if (prsp) |
| 210 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 211 | &prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 212 | if (!prsp || !prsp->virt) |
| 213 | goto els_iocb_free_prsp_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 214 | INIT_LIST_HEAD(&prsp->list); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 215 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 216 | prsp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 217 | |
| 218 | /* Allocate buffer for Buffer ptr list */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 219 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 220 | if (pbuflist) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 221 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 222 | &pbuflist->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 223 | if (!pbuflist || !pbuflist->virt) |
| 224 | goto els_iocb_free_pbuf_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 225 | |
| 226 | INIT_LIST_HEAD(&pbuflist->list); |
| 227 | |
| 228 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 229 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 230 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 231 | icmd->un.elsreq64.remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 232 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 233 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 234 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 235 | icmd->ulpTimeout = phba->fc_ratov * 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 236 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 237 | icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 238 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; |
| 239 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 240 | icmd->ulpBdeCount = 1; |
| 241 | icmd->ulpLe = 1; |
| 242 | icmd->ulpClass = CLASS3; |
| 243 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 244 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 245 | icmd->un.elsreq64.myID = vport->fc_myDID; |
| 246 | |
| 247 | /* For ELS_REQUEST64_CR, use the VPI by default */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 248 | icmd->ulpContext = vport->vpi + phba->vpi_base; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 249 | icmd->ulpCt_h = 0; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 250 | /* The CT field must be 0=INVALID_RPI for the ECHO cmd */ |
| 251 | if (elscmd == ELS_CMD_ECHO) |
| 252 | icmd->ulpCt_l = 0; /* context = invalid RPI */ |
| 253 | else |
| 254 | icmd->ulpCt_l = 1; /* context = VPI */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 255 | } |
| 256 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 257 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
| 258 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); |
| 259 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); |
| 260 | bpl->tus.f.bdeSize = cmdSize; |
| 261 | bpl->tus.f.bdeFlags = 0; |
| 262 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 263 | |
| 264 | if (expectRsp) { |
| 265 | bpl++; |
| 266 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); |
| 267 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); |
| 268 | bpl->tus.f.bdeSize = FCELSSIZE; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 269 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 270 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 271 | } |
| 272 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 273 | /* prevent preparing iocb with NULL ndlp reference */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 274 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 275 | if (!elsiocb->context1) |
| 276 | goto els_iocb_free_pbuf_exit; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 277 | elsiocb->context2 = pcmd; |
| 278 | elsiocb->context3 = pbuflist; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 279 | elsiocb->retry = retry; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 280 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 281 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
| 282 | |
| 283 | if (prsp) { |
| 284 | list_add(&prsp->list, &pcmd->list); |
| 285 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 286 | if (expectRsp) { |
| 287 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 288 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 289 | "0116 Xmit ELS command x%x to remote " |
| 290 | "NPORT x%x I/O tag: x%x, port state: x%x\n", |
| 291 | elscmd, did, elsiocb->iotag, |
| 292 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 293 | } else { |
| 294 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 295 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 296 | "0117 Xmit ELS response x%x to remote " |
| 297 | "NPORT x%x I/O tag: x%x, size: x%x\n", |
| 298 | elscmd, ndlp->nlp_DID, elsiocb->iotag, |
| 299 | cmdSize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 300 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 301 | return elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 302 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 303 | els_iocb_free_pbuf_exit: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 304 | if (expectRsp) |
| 305 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 306 | kfree(pbuflist); |
| 307 | |
| 308 | els_iocb_free_prsp_exit: |
| 309 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 310 | kfree(prsp); |
| 311 | |
| 312 | els_iocb_free_pcmb_exit: |
| 313 | kfree(pcmd); |
| 314 | lpfc_sli_release_iocbq(phba, elsiocb); |
| 315 | return NULL; |
| 316 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 317 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 318 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 319 | * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 320 | * @vport: pointer to a host virtual N_Port data structure. |
| 321 | * |
| 322 | * This routine issues a fabric registration login for a @vport. An |
| 323 | * active ndlp node with Fabric_DID must already exist for this @vport. |
| 324 | * The routine invokes two mailbox commands to carry out fabric registration |
| 325 | * login through the HBA firmware: the first mailbox command requests the |
| 326 | * HBA to perform link configuration for the @vport; and the second mailbox |
| 327 | * command requests the HBA to perform the actual fabric registration login |
| 328 | * with the @vport. |
| 329 | * |
| 330 | * Return code |
| 331 | * 0 - successfully issued fabric registration login for @vport |
| 332 | * -ENXIO -- failed to issue fabric registration login for @vport |
| 333 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 334 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 335 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
| 336 | { |
| 337 | struct lpfc_hba *phba = vport->phba; |
| 338 | LPFC_MBOXQ_t *mbox; |
| 339 | struct lpfc_dmabuf *mp; |
| 340 | struct lpfc_nodelist *ndlp; |
| 341 | struct serv_parm *sp; |
| 342 | int rc; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 343 | int err = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 344 | |
| 345 | sp = &phba->fc_fabparam; |
| 346 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 347 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 348 | err = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 349 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 350 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 351 | |
| 352 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 353 | if (!mbox) { |
| 354 | err = 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 355 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 356 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 357 | |
| 358 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 359 | lpfc_config_link(phba, mbox); |
| 360 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 361 | mbox->vport = vport; |
| 362 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 363 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 364 | if (rc == MBX_NOT_FINISHED) { |
| 365 | err = 3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 366 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 367 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 368 | |
| 369 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 370 | if (!mbox) { |
| 371 | err = 4; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 372 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 373 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 374 | 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] | 375 | if (rc) { |
| 376 | err = 5; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 377 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 378 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 379 | |
| 380 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; |
| 381 | mbox->vport = vport; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 382 | /* increment the reference count on ndlp to hold reference |
| 383 | * for the callback routine. |
| 384 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 385 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 386 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 387 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 388 | if (rc == MBX_NOT_FINISHED) { |
| 389 | err = 6; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 390 | goto fail_issue_reg_login; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 391 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 392 | |
| 393 | return 0; |
| 394 | |
| 395 | fail_issue_reg_login: |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 396 | /* decrement the reference count on ndlp just incremented |
| 397 | * for the failed mbox command. |
| 398 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 399 | lpfc_nlp_put(ndlp); |
| 400 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 401 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 402 | kfree(mp); |
| 403 | fail_free_mbox: |
| 404 | mempool_free(mbox, phba->mbox_mem_pool); |
| 405 | |
| 406 | fail: |
| 407 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 408 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 409 | "0249 Cannot issue Register Fabric login: Err %d\n", err); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 410 | return -ENXIO; |
| 411 | } |
| 412 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 413 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 414 | * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login |
| 415 | * @vport: pointer to a host virtual N_Port data structure. |
| 416 | * |
| 417 | * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for |
| 418 | * the @vport. This mailbox command is necessary for FCoE only. |
| 419 | * |
| 420 | * Return code |
| 421 | * 0 - successfully issued REG_VFI for @vport |
| 422 | * A failure code otherwise. |
| 423 | **/ |
| 424 | static int |
| 425 | lpfc_issue_reg_vfi(struct lpfc_vport *vport) |
| 426 | { |
| 427 | struct lpfc_hba *phba = vport->phba; |
| 428 | LPFC_MBOXQ_t *mboxq; |
| 429 | struct lpfc_nodelist *ndlp; |
| 430 | struct serv_parm *sp; |
| 431 | struct lpfc_dmabuf *dmabuf; |
| 432 | int rc = 0; |
| 433 | |
| 434 | sp = &phba->fc_fabparam; |
| 435 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 436 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
| 437 | rc = -ENODEV; |
| 438 | goto fail; |
| 439 | } |
| 440 | |
| 441 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 442 | if (!dmabuf) { |
| 443 | rc = -ENOMEM; |
| 444 | goto fail; |
| 445 | } |
| 446 | dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys); |
| 447 | if (!dmabuf->virt) { |
| 448 | rc = -ENOMEM; |
| 449 | goto fail_free_dmabuf; |
| 450 | } |
| 451 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 452 | if (!mboxq) { |
| 453 | rc = -ENOMEM; |
| 454 | goto fail_free_coherent; |
| 455 | } |
| 456 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 457 | memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam)); |
| 458 | lpfc_reg_vfi(mboxq, vport, dmabuf->phys); |
| 459 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi; |
| 460 | mboxq->vport = vport; |
| 461 | mboxq->context1 = dmabuf; |
| 462 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 463 | if (rc == MBX_NOT_FINISHED) { |
| 464 | rc = -ENXIO; |
| 465 | goto fail_free_mbox; |
| 466 | } |
| 467 | return 0; |
| 468 | |
| 469 | fail_free_mbox: |
| 470 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 471 | fail_free_coherent: |
| 472 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 473 | fail_free_dmabuf: |
| 474 | kfree(dmabuf); |
| 475 | fail: |
| 476 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 477 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 478 | "0289 Issue Register VFI failed: Err %d\n", rc); |
| 479 | return rc; |
| 480 | } |
| 481 | |
| 482 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 483 | * 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] | 484 | * @vport: pointer to a host virtual N_Port data structure. |
| 485 | * @ndlp: pointer to a node-list data structure. |
| 486 | * @sp: pointer to service parameter data structure. |
| 487 | * @irsp: pointer to the IOCB within the lpfc response IOCB. |
| 488 | * |
| 489 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 490 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric |
| 491 | * port in a fabric topology. It properly sets up the parameters to the @ndlp |
| 492 | * from the IOCB response. It also check the newly assigned N_Port ID to the |
| 493 | * @vport against the previously assigned N_Port ID. If it is different from |
| 494 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine |
| 495 | * is invoked on all the remaining nodes with the @vport to unregister the |
| 496 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() |
| 497 | * is invoked to register login to the fabric. |
| 498 | * |
| 499 | * Return code |
| 500 | * 0 - Success (currently, always return 0) |
| 501 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 502 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 503 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 504 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 505 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 506 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 507 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 508 | struct lpfc_nodelist *np; |
| 509 | struct lpfc_nodelist *next_np; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 510 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 511 | spin_lock_irq(shost->host_lock); |
| 512 | vport->fc_flag |= FC_FABRIC; |
| 513 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 514 | |
| 515 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 516 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 517 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 518 | |
| 519 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 520 | |
| 521 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 522 | spin_lock_irq(shost->host_lock); |
| 523 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 524 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 525 | } else { |
| 526 | /* |
| 527 | * If we are a N-port connected to a Fabric, fixup sparam's so |
| 528 | * logins to devices on remote loops work. |
| 529 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 530 | vport->fc_sparam.cmn.altBbCredit = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 531 | } |
| 532 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 533 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 534 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 535 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 536 | ndlp->nlp_class_sup = 0; |
| 537 | if (sp->cls1.classValid) |
| 538 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 539 | if (sp->cls2.classValid) |
| 540 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 541 | if (sp->cls3.classValid) |
| 542 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 543 | if (sp->cls4.classValid) |
| 544 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 545 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 546 | sp->cmn.bbRcvSizeLsb; |
| 547 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 548 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 549 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 550 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 551 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 552 | LOG_ELS | LOG_VPORT, |
| 553 | "1816 FLOGI NPIV supported, " |
| 554 | "response data 0x%x\n", |
| 555 | sp->cmn.response_multiple_NPort); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 556 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 557 | } else { |
| 558 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 559 | to call reg_vnpid atleast for the physcial host */ |
| 560 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 561 | LOG_ELS | LOG_VPORT, |
| 562 | "1817 Fabric does not support NPIV " |
| 563 | "- configuring single port mode.\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 564 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 569 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 570 | |
| 571 | /* If our NportID changed, we need to ensure all |
| 572 | * remaining NPORTs get unreg_login'ed. |
| 573 | */ |
| 574 | list_for_each_entry_safe(np, next_np, |
| 575 | &vport->fc_nodes, nlp_listp) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 576 | if (!NLP_CHK_NODE_ACT(np)) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 577 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 578 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 579 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 580 | continue; |
| 581 | spin_lock_irq(shost->host_lock); |
| 582 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 583 | spin_unlock_irq(shost->host_lock); |
| 584 | lpfc_unreg_rpi(vport, np); |
| 585 | } |
| 586 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 587 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 588 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 589 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 590 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 591 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 592 | /* |
| 593 | * If VPI is unreged, driver need to do INIT_VPI |
| 594 | * before re-registering |
| 595 | */ |
| 596 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 597 | spin_lock_irq(shost->host_lock); |
| 598 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 599 | spin_unlock_irq(shost->host_lock); |
| 600 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 601 | } |
| 602 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 603 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 604 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
| 605 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 606 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 607 | lpfc_register_new_vport(phba, vport, ndlp); |
| 608 | else |
| 609 | lpfc_issue_fabric_reglogin(vport); |
| 610 | } else { |
| 611 | ndlp->nlp_type |= NLP_FABRIC; |
| 612 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 613 | if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) && |
| 614 | (vport->vpi_state & LPFC_VPI_REGISTERED)) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 615 | lpfc_start_fdiscs(phba); |
| 616 | lpfc_do_scr_ns_plogi(phba, vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 617 | } else if (vport->fc_flag & FC_VFI_REGISTERED) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 618 | lpfc_issue_init_vpi(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 619 | else |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 620 | lpfc_issue_reg_vfi(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 621 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 622 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 623 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 624 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 625 | * 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] | 626 | * @vport: pointer to a host virtual N_Port data structure. |
| 627 | * @ndlp: pointer to a node-list data structure. |
| 628 | * @sp: pointer to service parameter data structure. |
| 629 | * |
| 630 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 631 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 632 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 633 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 634 | * the received N_Port Name lexicographically, this node shall assign local |
| 635 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 636 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 637 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 638 | * N_Port IDs. |
| 639 | * |
| 640 | * Return code |
| 641 | * 0 - Success |
| 642 | * -ENXIO - Fail |
| 643 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 644 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 645 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 646 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 647 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 648 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 649 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 650 | LPFC_MBOXQ_t *mbox; |
| 651 | int rc; |
| 652 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 653 | spin_lock_irq(shost->host_lock); |
| 654 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 655 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 656 | |
| 657 | phba->fc_edtov = FF_DEF_EDTOV; |
| 658 | phba->fc_ratov = FF_DEF_RATOV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 659 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 660 | sizeof(vport->fc_portname)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 661 | if (rc >= 0) { |
| 662 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 663 | spin_lock_irq(shost->host_lock); |
| 664 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 665 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 666 | |
| 667 | /* |
| 668 | * N_Port ID cannot be 0, set our to LocalID the other |
| 669 | * side will be RemoteID. |
| 670 | */ |
| 671 | |
| 672 | /* not equal */ |
| 673 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 674 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 675 | |
| 676 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 677 | if (!mbox) |
| 678 | goto fail; |
| 679 | |
| 680 | lpfc_config_link(phba, mbox); |
| 681 | |
| 682 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 683 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 684 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 685 | if (rc == MBX_NOT_FINISHED) { |
| 686 | mempool_free(mbox, phba->mbox_mem_pool); |
| 687 | goto fail; |
| 688 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 689 | /* Decrement ndlp reference count indicating that ndlp can be |
| 690 | * safely released when other references to it are done. |
| 691 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 692 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 693 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 694 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 695 | if (!ndlp) { |
| 696 | /* |
| 697 | * Cannot find existing Fabric ndlp, so allocate a |
| 698 | * new one |
| 699 | */ |
| 700 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 701 | if (!ndlp) |
| 702 | goto fail; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 703 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 704 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 705 | ndlp = lpfc_enable_node(vport, ndlp, |
| 706 | NLP_STE_UNUSED_NODE); |
| 707 | if(!ndlp) |
| 708 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 712 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 713 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 714 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 715 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 716 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 717 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 718 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 719 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 720 | } else |
| 721 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 722 | * count indicating that ndlp can be released when other |
| 723 | * references to it are done. |
| 724 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 725 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 726 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 727 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 728 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 729 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 730 | spin_lock_irq(shost->host_lock); |
| 731 | vport->fc_flag |= FC_PT2PT; |
| 732 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 733 | |
| 734 | /* Start discovery - this should just do CLEAR_LA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 735 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 736 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 737 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 738 | return -ENXIO; |
| 739 | } |
| 740 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 741 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 742 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 743 | * @phba: pointer to lpfc hba data structure. |
| 744 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 745 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 746 | * |
| 747 | * This routine is the top-level completion callback function for issuing |
| 748 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 749 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 750 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 751 | * returning 1), the command IOCB will be released and function returned. |
| 752 | * If the retry attempt has been given up (possibly reach the maximum |
| 753 | * number of retries), one additional decrement of ndlp reference shall be |
| 754 | * invoked before going out after releasing the command IOCB. This will |
| 755 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 756 | * invoke one decrement of ndlp reference count). If no error reported in |
| 757 | * the IOCB status, the command Port ID field is used to determine whether |
| 758 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 759 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 760 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 761 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 762 | * specific topology completion conditions. |
| 763 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 764 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 765 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 766 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 767 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 768 | struct lpfc_vport *vport = cmdiocb->vport; |
| 769 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 770 | IOCB_t *irsp = &rspiocb->iocb; |
| 771 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 772 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 773 | struct serv_parm *sp; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame^] | 774 | uint16_t fcf_index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 775 | int rc; |
| 776 | |
| 777 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 778 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 779 | /* One additional decrement on node reference count to |
| 780 | * trigger the release of the node |
| 781 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 782 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 783 | goto out; |
| 784 | } |
| 785 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 786 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 787 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 788 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 789 | vport->port_state); |
| 790 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 791 | if (irsp->ulpStatus) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame^] | 792 | /* |
| 793 | * In case of FIP mode, perform round robin FCF failover |
| 794 | * due to new FCF discovery |
| 795 | */ |
| 796 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && |
| 797 | (phba->fcf.fcf_flag & FCF_DISCOVERY)) { |
| 798 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
| 799 | "2611 FLOGI failed on registered " |
| 800 | "FCF record fcf_index:%d, trying " |
| 801 | "to perform round robin failover\n", |
| 802 | phba->fcf.current_rec.fcf_indx); |
| 803 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
| 804 | if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) { |
| 805 | /* |
| 806 | * Exhausted the eligible FCF record list, |
| 807 | * fail through to retry FLOGI on current |
| 808 | * FCF record. |
| 809 | */ |
| 810 | lpfc_printf_log(phba, KERN_WARNING, |
| 811 | LOG_FIP | LOG_ELS, |
| 812 | "2760 FLOGI exhausted FCF " |
| 813 | "round robin failover list, " |
| 814 | "retry FLOGI on the current " |
| 815 | "registered FCF index:%d\n", |
| 816 | phba->fcf.current_rec.fcf_indx); |
| 817 | spin_lock_irq(&phba->hbalock); |
| 818 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
| 819 | spin_unlock_irq(&phba->hbalock); |
| 820 | } else { |
| 821 | rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, |
| 822 | fcf_index); |
| 823 | if (rc) { |
| 824 | lpfc_printf_log(phba, KERN_WARNING, |
| 825 | LOG_FIP | LOG_ELS, |
| 826 | "2761 FLOGI round " |
| 827 | "robin FCF failover " |
| 828 | "read FCF failed " |
| 829 | "rc:x%x, fcf_index:" |
| 830 | "%d\n", rc, |
| 831 | phba->fcf.current_rec.fcf_indx); |
| 832 | spin_lock_irq(&phba->hbalock); |
| 833 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
| 834 | spin_unlock_irq(&phba->hbalock); |
| 835 | } else |
| 836 | goto out; |
| 837 | } |
| 838 | } |
| 839 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 840 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 841 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 842 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 843 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 844 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 845 | spin_lock_irq(shost->host_lock); |
| 846 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 847 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 848 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 849 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 850 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 851 | * alpa map would take too long otherwise. |
| 852 | */ |
| 853 | if (phba->alpa_map[0] == 0) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 854 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | /* FLOGI failure */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 858 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 859 | "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 860 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 861 | irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 862 | goto flogifail; |
| 863 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 864 | spin_lock_irq(shost->host_lock); |
| 865 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
| 866 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 867 | |
| 868 | /* |
| 869 | * The FLogI succeeded. Sync the data for the CPU before |
| 870 | * accessing it. |
| 871 | */ |
| 872 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 873 | |
| 874 | sp = prsp->virt + sizeof(uint32_t); |
| 875 | |
| 876 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 877 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 878 | "0101 FLOGI completes successfully " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 879 | "Data: x%x x%x x%x x%x\n", |
| 880 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
| 881 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 882 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 883 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 884 | /* |
| 885 | * If Common Service Parameters indicate Nport |
| 886 | * we are point to point, if Fport we are Fabric. |
| 887 | */ |
| 888 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 889 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 890 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 891 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 892 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame^] | 893 | if (!rc) { |
| 894 | /* Mark the FCF discovery process done */ |
| 895 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | LOG_ELS, |
| 896 | "2769 FLOGI successful on FCF record: " |
| 897 | "current_fcf_index:x%x, terminate FCF " |
| 898 | "round robin failover process\n", |
| 899 | phba->fcf.current_rec.fcf_indx); |
| 900 | spin_lock_irq(&phba->hbalock); |
| 901 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; |
| 902 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 903 | goto out; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame^] | 904 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | flogifail: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 908 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 909 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 910 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 911 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 912 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 913 | |
| 914 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 915 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 916 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 917 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && |
| 918 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) && |
| 919 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 920 | /* If FLOGI failed enable link interrupt. */ |
| 921 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 922 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 923 | out: |
| 924 | lpfc_els_free_iocb(phba, cmdiocb); |
| 925 | } |
| 926 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 927 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 928 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 929 | * @vport: pointer to a host virtual N_Port data structure. |
| 930 | * @ndlp: pointer to a node-list data structure. |
| 931 | * @retry: number of retries to the command IOCB. |
| 932 | * |
| 933 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 934 | * for a @vport. The initiator service parameters are put into the payload |
| 935 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 936 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 937 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 938 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 939 | * |
| 940 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 941 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 942 | * will be stored into the context1 field of the IOCB for the completion |
| 943 | * callback function to the FLOGI ELS command. |
| 944 | * |
| 945 | * Return code |
| 946 | * 0 - successfully issued flogi iocb for @vport |
| 947 | * 1 - failed to issue flogi iocb for @vport |
| 948 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 949 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 950 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 951 | uint8_t retry) |
| 952 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 953 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 954 | struct serv_parm *sp; |
| 955 | IOCB_t *icmd; |
| 956 | struct lpfc_iocbq *elsiocb; |
| 957 | struct lpfc_sli_ring *pring; |
| 958 | uint8_t *pcmd; |
| 959 | uint16_t cmdsize; |
| 960 | uint32_t tmo; |
| 961 | int rc; |
| 962 | |
| 963 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 964 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 965 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 966 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 967 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 968 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 969 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 970 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 971 | |
| 972 | icmd = &elsiocb->iocb; |
| 973 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 974 | |
| 975 | /* For FLOGI request, remainder of payload is service parameters */ |
| 976 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 977 | pcmd += sizeof(uint32_t); |
| 978 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 979 | sp = (struct serv_parm *) pcmd; |
| 980 | |
| 981 | /* Setup CSPs accordingly for Fabric */ |
| 982 | sp->cmn.e_d_tov = 0; |
| 983 | sp->cmn.w2.r_a_tov = 0; |
| 984 | sp->cls1.classValid = 0; |
| 985 | sp->cls2.seqDelivery = 1; |
| 986 | sp->cls3.seqDelivery = 1; |
| 987 | if (sp->cmn.fcphLow < FC_PH3) |
| 988 | sp->cmn.fcphLow = FC_PH3; |
| 989 | if (sp->cmn.fcphHigh < FC_PH3) |
| 990 | sp->cmn.fcphHigh = FC_PH3; |
| 991 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 992 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 993 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 994 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 995 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 996 | /* Set the fcfi to the fcfi we registered with */ |
| 997 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 998 | } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 999 | sp->cmn.request_multiple_Nport = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1000 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 1001 | icmd->ulpCt_h = 1; |
| 1002 | icmd->ulpCt_l = 0; |
| 1003 | } |
| 1004 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1005 | if (phba->fc_topology != TOPOLOGY_LOOP) { |
| 1006 | icmd->un.elsreq64.myID = 0; |
| 1007 | icmd->un.elsreq64.fl = 1; |
| 1008 | } |
| 1009 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1010 | tmo = phba->fc_ratov; |
| 1011 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1012 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1013 | phba->fc_ratov = tmo; |
| 1014 | |
| 1015 | phba->fc_stat.elsXmitFLOGI++; |
| 1016 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1017 | |
| 1018 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1019 | "Issue FLOGI: opt:x%x", |
| 1020 | phba->sli3_options, 0, 0); |
| 1021 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1022 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1023 | if (rc == IOCB_ERROR) { |
| 1024 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1025 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1026 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1027 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1028 | } |
| 1029 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1030 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1031 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1032 | * @phba: pointer to lpfc hba data structure. |
| 1033 | * |
| 1034 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 1035 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 1036 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 1037 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 1038 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 1039 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 1040 | * |
| 1041 | * Return code |
| 1042 | * 0 - Sucessfully issued abort iocb on all outstanding flogis (Always 0) |
| 1043 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1044 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1045 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1046 | { |
| 1047 | struct lpfc_sli_ring *pring; |
| 1048 | struct lpfc_iocbq *iocb, *next_iocb; |
| 1049 | struct lpfc_nodelist *ndlp; |
| 1050 | IOCB_t *icmd; |
| 1051 | |
| 1052 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 1053 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1054 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 1055 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1056 | |
| 1057 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 1058 | |
| 1059 | /* |
| 1060 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 1061 | * searching for. |
| 1062 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1063 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1064 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 1065 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1066 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR && |
| 1067 | icmd->un.elsreq64.bdl.ulpIoTag32) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1068 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1069 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 1070 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1071 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1072 | } |
| 1073 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1074 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1075 | |
| 1076 | return 0; |
| 1077 | } |
| 1078 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1079 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1080 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1081 | * @vport: pointer to a host virtual N_Port data structure. |
| 1082 | * |
| 1083 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 1084 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1085 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1086 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1087 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 1088 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 1089 | * @vport. |
| 1090 | * |
| 1091 | * Return code |
| 1092 | * 0 - failed to issue initial flogi for @vport |
| 1093 | * 1 - successfully issued initial flogi for @vport |
| 1094 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1095 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1096 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1097 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1098 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1099 | struct lpfc_nodelist *ndlp; |
| 1100 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1101 | vport->port_state = LPFC_FLOGI; |
| 1102 | lpfc_set_disctmo(vport); |
| 1103 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1104 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1105 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1106 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1107 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1108 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1109 | if (!ndlp) |
| 1110 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1111 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1112 | /* Set the node type */ |
| 1113 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1114 | /* Put ndlp onto node list */ |
| 1115 | lpfc_enqueue_node(vport, ndlp); |
| 1116 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1117 | /* re-setup ndlp without removing from node list */ |
| 1118 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1119 | if (!ndlp) |
| 1120 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1121 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1122 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1123 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1124 | /* This decrement of reference count to node shall kick off |
| 1125 | * the release of the node. |
| 1126 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1127 | lpfc_nlp_put(ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1128 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1129 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1130 | } |
| 1131 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1132 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1133 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1134 | * @vport: pointer to a host virtual N_Port data structure. |
| 1135 | * |
| 1136 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 1137 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1138 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1139 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1140 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 1141 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 1142 | * @vport. |
| 1143 | * |
| 1144 | * Return code |
| 1145 | * 0 - failed to issue initial fdisc for @vport |
| 1146 | * 1 - successfully issued initial fdisc for @vport |
| 1147 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1148 | int |
| 1149 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 1150 | { |
| 1151 | struct lpfc_hba *phba = vport->phba; |
| 1152 | struct lpfc_nodelist *ndlp; |
| 1153 | |
| 1154 | /* First look for the Fabric ndlp */ |
| 1155 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1156 | if (!ndlp) { |
| 1157 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 1158 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1159 | if (!ndlp) |
| 1160 | return 0; |
| 1161 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1162 | /* Put ndlp onto node list */ |
| 1163 | lpfc_enqueue_node(vport, ndlp); |
| 1164 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1165 | /* re-setup ndlp without removing from node list */ |
| 1166 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1167 | if (!ndlp) |
| 1168 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1169 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1170 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1171 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1172 | /* decrement node reference count to trigger the release of |
| 1173 | * the node. |
| 1174 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1175 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1176 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1177 | } |
| 1178 | return 1; |
| 1179 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1180 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1181 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1182 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1183 | * @vport: pointer to a host virtual N_Port data structure. |
| 1184 | * |
| 1185 | * This routine checks whether there are more remaining Port Logins |
| 1186 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1187 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1188 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1189 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1190 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1191 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1192 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1193 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1194 | { |
| 1195 | int sentplogi; |
| 1196 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1197 | if (vport->num_disc_nodes) |
| 1198 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1199 | |
| 1200 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1201 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1202 | "0232 Continue discovery with %d PLOGIs to go " |
| 1203 | "Data: x%x x%x x%x\n", |
| 1204 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1205 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1206 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1207 | if (vport->fc_flag & FC_NLP_MORE) |
| 1208 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 1209 | sentplogi = lpfc_els_disc_plogi(vport); |
| 1210 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1211 | return; |
| 1212 | } |
| 1213 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1214 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1215 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1216 | * @phba: pointer to lpfc hba data structure. |
| 1217 | * @prsp: pointer to response IOCB payload. |
| 1218 | * @ndlp: pointer to a node-list data structure. |
| 1219 | * |
| 1220 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1221 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1222 | * The following cases are considered N_Port confirmed: |
| 1223 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1224 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1225 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1226 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1227 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1228 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1229 | * on that node to release the RPI associated with the node; 2) if there is |
| 1230 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1231 | * into, a new node shall be allocated (or activated). In either case, the |
| 1232 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1233 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1234 | * its pointer returned as the confirmed node. |
| 1235 | * |
| 1236 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1237 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1238 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1239 | * into an inactive state on the vport node list and the vport node list |
| 1240 | * management algorithm does not allow two node with a same DID. |
| 1241 | * |
| 1242 | * Return code |
| 1243 | * pointer to the PLOGI N_Port @ndlp |
| 1244 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1245 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1246 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1247 | struct lpfc_nodelist *ndlp) |
| 1248 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1249 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1250 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1251 | struct lpfc_rport_data *rdata; |
| 1252 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1253 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1254 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1255 | uint32_t rc, keepDID = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1256 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1257 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1258 | * by WWPN. Just return the ndlp that was given to us. |
| 1259 | */ |
| 1260 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1261 | return ndlp; |
| 1262 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1263 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1264 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1265 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1266 | /* 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] | 1267 | * we have for that ndlp. If not, we have some work to do. |
| 1268 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1269 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1270 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1271 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1272 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1273 | |
| 1274 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1275 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1276 | sizeof(struct lpfc_name)); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1277 | if (!rc) |
| 1278 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1279 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
| 1280 | if (!new_ndlp) |
| 1281 | return ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1282 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1283 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1284 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1285 | sizeof(struct lpfc_name)); |
| 1286 | if (!rc) |
| 1287 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1288 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1289 | NLP_STE_UNUSED_NODE); |
| 1290 | if (!new_ndlp) |
| 1291 | return ndlp; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1292 | keepDID = new_ndlp->nlp_DID; |
| 1293 | } else |
| 1294 | keepDID = new_ndlp->nlp_DID; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1295 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1296 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1297 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1298 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1299 | |
| 1300 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) |
| 1301 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 1302 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 1303 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1304 | /* 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] | 1305 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1306 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1307 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1308 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1309 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1310 | * to put ndlp on UNUSED list and try to free it. |
| 1311 | */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1312 | |
| 1313 | /* Fix up the rport accordingly */ |
| 1314 | rport = ndlp->rport; |
| 1315 | if (rport) { |
| 1316 | rdata = rport->dd_data; |
| 1317 | if (rdata->pnode == ndlp) { |
| 1318 | lpfc_nlp_put(ndlp); |
| 1319 | ndlp->rport = NULL; |
| 1320 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1321 | new_ndlp->rport = rport; |
| 1322 | } |
| 1323 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1324 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1325 | /* We shall actually free the ndlp with both nlp_DID and |
| 1326 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1327 | * nodelist never to be used. |
| 1328 | */ |
| 1329 | if (ndlp->nlp_DID == 0) { |
| 1330 | spin_lock_irq(&phba->ndlp_lock); |
| 1331 | NLP_SET_FREE_REQ(ndlp); |
| 1332 | spin_unlock_irq(&phba->ndlp_lock); |
| 1333 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1334 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1335 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1336 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1337 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1338 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1339 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1340 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1341 | /* Two ndlps cannot have the same did */ |
| 1342 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1343 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1344 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1345 | return new_ndlp; |
| 1346 | } |
| 1347 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1348 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1349 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1350 | * @vport: pointer to a host virtual N_Port data structure. |
| 1351 | * |
| 1352 | * This routine checks whether more Registration State Change |
| 1353 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1354 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1355 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1356 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1357 | * handling the RSCNs. |
| 1358 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1359 | void |
| 1360 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1361 | { |
| 1362 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1363 | |
| 1364 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1365 | /* |
| 1366 | * Check to see if more RSCNs came in while we were |
| 1367 | * processing this one. |
| 1368 | */ |
| 1369 | if (vport->fc_rscn_id_cnt || |
| 1370 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1371 | lpfc_els_handle_rscn(vport); |
| 1372 | else { |
| 1373 | spin_lock_irq(shost->host_lock); |
| 1374 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1375 | spin_unlock_irq(shost->host_lock); |
| 1376 | } |
| 1377 | } |
| 1378 | } |
| 1379 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1380 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1381 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1382 | * @phba: pointer to lpfc hba data structure. |
| 1383 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1384 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1385 | * |
| 1386 | * This routine is the completion callback function for issuing the Port |
| 1387 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1388 | * ndlp on the vport node list that matches the remote node ID from the |
| 1389 | * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply |
| 1390 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1391 | * checked for error conditons. If there is error status reported, PLOGI |
| 1392 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1393 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1394 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1395 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1396 | * there are additional N_Port nodes with the vport that need to perform |
| 1397 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1398 | * PLOGIs. |
| 1399 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1400 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1401 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1402 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1403 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1404 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1405 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1406 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1407 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1408 | struct lpfc_dmabuf *prsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1409 | int disc, rc, did, type; |
| 1410 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1411 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1412 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1413 | |
| 1414 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1415 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1416 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1417 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1418 | irsp->un.elsreq64.remoteID); |
| 1419 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1420 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1421 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1422 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1423 | "0136 PLOGI completes to NPort x%x " |
| 1424 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1425 | irsp->un.elsreq64.remoteID, |
| 1426 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1427 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1428 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1429 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1430 | |
| 1431 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1432 | * is being used during discovery. |
| 1433 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1434 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1435 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1436 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1437 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1438 | rc = 0; |
| 1439 | |
| 1440 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1441 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1442 | "0102 PLOGI completes to NPort x%x " |
| 1443 | "Data: x%x x%x x%x x%x x%x\n", |
| 1444 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1445 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1446 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1447 | if (lpfc_els_chk_latt(vport)) { |
| 1448 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1449 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1450 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1451 | goto out; |
| 1452 | } |
| 1453 | |
| 1454 | /* ndlp could be freed in DSM, save these values now */ |
| 1455 | type = ndlp->nlp_type; |
| 1456 | did = ndlp->nlp_DID; |
| 1457 | |
| 1458 | if (irsp->ulpStatus) { |
| 1459 | /* Check for retry */ |
| 1460 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1461 | /* ELS command is being retried */ |
| 1462 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1463 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1464 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1465 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1466 | } |
| 1467 | goto out; |
| 1468 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1469 | /* PLOGI failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1470 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1471 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", |
| 1472 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1473 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1474 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1475 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1476 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1477 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1478 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1479 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1480 | } else { |
| 1481 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1482 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1483 | cmdiocb->context2)->list.next, |
| 1484 | struct lpfc_dmabuf, list); |
| 1485 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1486 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1487 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1488 | } |
| 1489 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1490 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1491 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1492 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1493 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1494 | if (vport->num_disc_nodes == 0) { |
| 1495 | spin_lock_irq(shost->host_lock); |
| 1496 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1497 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1498 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1499 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1500 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1501 | } |
| 1502 | } |
| 1503 | |
| 1504 | out: |
| 1505 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1506 | return; |
| 1507 | } |
| 1508 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1509 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1510 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1511 | * @vport: pointer to a host virtual N_Port data structure. |
| 1512 | * @did: destination port identifier. |
| 1513 | * @retry: number of retries to the command IOCB. |
| 1514 | * |
| 1515 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1516 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1517 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1518 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1519 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1520 | * |
| 1521 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1522 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1523 | * will be stored into the context1 field of the IOCB for the completion |
| 1524 | * callback function to the PLOGI ELS command. |
| 1525 | * |
| 1526 | * Return code |
| 1527 | * 0 - Successfully issued a plogi for @vport |
| 1528 | * 1 - failed to issue a plogi for @vport |
| 1529 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1530 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1531 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1532 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1533 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1534 | struct serv_parm *sp; |
| 1535 | IOCB_t *icmd; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1536 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1537 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1538 | struct lpfc_sli *psli; |
| 1539 | uint8_t *pcmd; |
| 1540 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1541 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1542 | |
| 1543 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1544 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1545 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1546 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1547 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1548 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1549 | /* 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] | 1550 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1551 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1552 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1553 | if (!elsiocb) |
| 1554 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1555 | |
| 1556 | icmd = &elsiocb->iocb; |
| 1557 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1558 | |
| 1559 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1560 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1561 | pcmd += sizeof(uint32_t); |
| 1562 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1563 | sp = (struct serv_parm *) pcmd; |
| 1564 | |
| 1565 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1566 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1567 | |
| 1568 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1569 | sp->cmn.fcphHigh = FC_PH3; |
| 1570 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1571 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1572 | "Issue PLOGI: did:x%x", |
| 1573 | did, 0, 0); |
| 1574 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1575 | phba->fc_stat.elsXmitPLOGI++; |
| 1576 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1577 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1578 | |
| 1579 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1580 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1581 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1582 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1583 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1584 | } |
| 1585 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1586 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1587 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1588 | * @phba: pointer to lpfc hba data structure. |
| 1589 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1590 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1591 | * |
| 1592 | * This routine is the completion callback function for a Process Login |
| 1593 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 1594 | * status. If there is error status reported, PRLI retry shall be attempted |
| 1595 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 1596 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 1597 | * ndlp to mark the PRLI completion. |
| 1598 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1599 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1600 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1601 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1602 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1603 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1604 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1605 | IOCB_t *irsp; |
| 1606 | struct lpfc_sli *psli; |
| 1607 | struct lpfc_nodelist *ndlp; |
| 1608 | |
| 1609 | psli = &phba->sli; |
| 1610 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1611 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1612 | |
| 1613 | irsp = &(rspiocb->iocb); |
| 1614 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1615 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1616 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1617 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1618 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1619 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1620 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 1621 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1622 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1623 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1624 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1625 | "0103 PRLI completes to NPort x%x " |
| 1626 | "Data: x%x x%x x%x x%x\n", |
| 1627 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1628 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1629 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1630 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1631 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1632 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1633 | goto out; |
| 1634 | |
| 1635 | if (irsp->ulpStatus) { |
| 1636 | /* Check for retry */ |
| 1637 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1638 | /* ELS command is being retried */ |
| 1639 | goto out; |
| 1640 | } |
| 1641 | /* PRLI failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1642 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1643 | "2754 PRLI failure DID:%06X Status:x%x/x%x\n", |
| 1644 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1645 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1646 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1647 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1648 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1649 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1650 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1651 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1652 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1653 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1654 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1655 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1656 | out: |
| 1657 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1658 | return; |
| 1659 | } |
| 1660 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1661 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1662 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1663 | * @vport: pointer to a host virtual N_Port data structure. |
| 1664 | * @ndlp: pointer to a node-list data structure. |
| 1665 | * @retry: number of retries to the command IOCB. |
| 1666 | * |
| 1667 | * This routine issues a Process Login (PRLI) ELS command for the |
| 1668 | * @vport. The PRLI service parameters are set up in the payload of the |
| 1669 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 1670 | * is put to the IOCB completion callback func field before invoking the |
| 1671 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 1672 | * |
| 1673 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1674 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1675 | * will be stored into the context1 field of the IOCB for the completion |
| 1676 | * callback function to the PRLI ELS command. |
| 1677 | * |
| 1678 | * Return code |
| 1679 | * 0 - successfully issued prli iocb command for @vport |
| 1680 | * 1 - failed to issue prli iocb command for @vport |
| 1681 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1682 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1683 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1684 | uint8_t retry) |
| 1685 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1686 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1687 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1688 | PRLI *npr; |
| 1689 | IOCB_t *icmd; |
| 1690 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1691 | uint8_t *pcmd; |
| 1692 | uint16_t cmdsize; |
| 1693 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1694 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1695 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1696 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1697 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1698 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1699 | |
| 1700 | icmd = &elsiocb->iocb; |
| 1701 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1702 | |
| 1703 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1704 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1705 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1706 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1707 | |
| 1708 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 1709 | npr = (PRLI *) pcmd; |
| 1710 | /* |
| 1711 | * If our firmware version is 3.20 or later, |
| 1712 | * set the following bits for FC-TAPE support. |
| 1713 | */ |
| 1714 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 1715 | npr->ConfmComplAllowed = 1; |
| 1716 | npr->Retry = 1; |
| 1717 | npr->TaskRetryIdReq = 1; |
| 1718 | } |
| 1719 | npr->estabImagePair = 1; |
| 1720 | npr->readXferRdyDis = 1; |
| 1721 | |
| 1722 | /* For FCP support */ |
| 1723 | npr->prliType = PRLI_FCP_TYPE; |
| 1724 | npr->initiatorFunc = 1; |
| 1725 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1726 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1727 | "Issue PRLI: did:x%x", |
| 1728 | ndlp->nlp_DID, 0, 0); |
| 1729 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1730 | phba->fc_stat.elsXmitPRLI++; |
| 1731 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1732 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1733 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1734 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1735 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 1736 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1737 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1738 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1739 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1740 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1741 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1742 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1743 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1744 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1745 | } |
| 1746 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1747 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1748 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1749 | * @vport: pointer to a host virtual N_Port data structure. |
| 1750 | * |
| 1751 | * This routine performs Registration State Change Notification (RSCN) |
| 1752 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 1753 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 1754 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 1755 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 1756 | * invoked to check and handle possible more RSCN came in during the period |
| 1757 | * of processing the current ones. |
| 1758 | **/ |
| 1759 | static void |
| 1760 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 1761 | { |
| 1762 | lpfc_can_disctmo(vport); |
| 1763 | |
| 1764 | /* RSCN discovery */ |
| 1765 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 1766 | if (vport->fc_npr_cnt) |
| 1767 | if (lpfc_els_disc_plogi(vport)) |
| 1768 | return; |
| 1769 | |
| 1770 | lpfc_end_rscn(vport); |
| 1771 | } |
| 1772 | |
| 1773 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1774 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1775 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 1776 | * |
| 1777 | * This function is called when the final ADISC is completed during discovery. |
| 1778 | * This function handles clearing link attention or issuing reg_vpi depending |
| 1779 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 1780 | * discovery. |
| 1781 | * This function is called with no locks held. |
| 1782 | **/ |
| 1783 | static void |
| 1784 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 1785 | { |
| 1786 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1787 | struct lpfc_hba *phba = vport->phba; |
| 1788 | |
| 1789 | /* |
| 1790 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 1791 | * and continue discovery. |
| 1792 | */ |
| 1793 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1794 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 1795 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1796 | lpfc_issue_reg_vpi(phba, vport); |
| 1797 | return; |
| 1798 | } |
| 1799 | /* |
| 1800 | * For SLI2, we need to set port_state to READY |
| 1801 | * and continue discovery. |
| 1802 | */ |
| 1803 | if (vport->port_state < LPFC_VPORT_READY) { |
| 1804 | /* If we get here, there is nothing to ADISC */ |
| 1805 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1806 | lpfc_issue_clear_la(phba, vport); |
| 1807 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 1808 | vport->num_disc_nodes = 0; |
| 1809 | /* go thru NPR list, issue ELS PLOGIs */ |
| 1810 | if (vport->fc_npr_cnt) |
| 1811 | lpfc_els_disc_plogi(vport); |
| 1812 | if (!vport->num_disc_nodes) { |
| 1813 | spin_lock_irq(shost->host_lock); |
| 1814 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1815 | spin_unlock_irq(shost->host_lock); |
| 1816 | lpfc_can_disctmo(vport); |
| 1817 | lpfc_end_rscn(vport); |
| 1818 | } |
| 1819 | } |
| 1820 | vport->port_state = LPFC_VPORT_READY; |
| 1821 | } else |
| 1822 | lpfc_rscn_disc(vport); |
| 1823 | } |
| 1824 | |
| 1825 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1826 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1827 | * @vport: pointer to a host virtual N_Port data structure. |
| 1828 | * |
| 1829 | * This routine determines whether there are more ndlps on a @vport |
| 1830 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 1831 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 1832 | * remaining nodes which need to have ADISC sent. |
| 1833 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1834 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1835 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1836 | { |
| 1837 | int sentadisc; |
| 1838 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1839 | if (vport->num_disc_nodes) |
| 1840 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1841 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1842 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1843 | "0210 Continue discovery with %d ADISCs to go " |
| 1844 | "Data: x%x x%x x%x\n", |
| 1845 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 1846 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1847 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1848 | if (vport->fc_flag & FC_NLP_MORE) { |
| 1849 | lpfc_set_disctmo(vport); |
| 1850 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 1851 | sentadisc = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1852 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1853 | if (!vport->num_disc_nodes) |
| 1854 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1855 | return; |
| 1856 | } |
| 1857 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1858 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1859 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1860 | * @phba: pointer to lpfc hba data structure. |
| 1861 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1862 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1863 | * |
| 1864 | * This routine is the completion function for issuing the Address Discover |
| 1865 | * (ADISC) command. It first checks to see whether link went down during |
| 1866 | * the discovery process. If so, the node will be marked as node port |
| 1867 | * recovery for issuing discover IOCB by the link attention handler and |
| 1868 | * exit. Otherwise, the response status is checked. If error was reported |
| 1869 | * in the response status, the ADISC command shall be retried by invoking |
| 1870 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 1871 | * the response status, the state machine is invoked to set transition |
| 1872 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 1873 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1874 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1875 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1876 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1877 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1878 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1879 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1880 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1881 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1882 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1883 | |
| 1884 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1885 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1886 | |
| 1887 | irsp = &(rspiocb->iocb); |
| 1888 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1889 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1890 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1891 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 1892 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1893 | ndlp->nlp_DID); |
| 1894 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1895 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1896 | * is being used during discovery. |
| 1897 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1898 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1899 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1900 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1901 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1902 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1903 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1904 | "0104 ADISC completes to NPort x%x " |
| 1905 | "Data: x%x x%x x%x x%x x%x\n", |
| 1906 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1907 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1908 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1909 | if (lpfc_els_chk_latt(vport)) { |
| 1910 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1911 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1912 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1913 | goto out; |
| 1914 | } |
| 1915 | |
| 1916 | if (irsp->ulpStatus) { |
| 1917 | /* Check for retry */ |
| 1918 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1919 | /* ELS command is being retried */ |
| 1920 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1921 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1922 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1923 | spin_unlock_irq(shost->host_lock); |
| 1924 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1925 | } |
| 1926 | goto out; |
| 1927 | } |
| 1928 | /* ADISC failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1929 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1930 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", |
| 1931 | ndlp->nlp_DID, irsp->ulpStatus, |
| 1932 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1933 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1934 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1935 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1936 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1937 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1938 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1939 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1940 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1941 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1942 | /* Check to see if there are more ADISCs to be sent */ |
| 1943 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1944 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1945 | out: |
| 1946 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1947 | return; |
| 1948 | } |
| 1949 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1950 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1951 | * 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] | 1952 | * @vport: pointer to a virtual N_Port data structure. |
| 1953 | * @ndlp: pointer to a node-list data structure. |
| 1954 | * @retry: number of retries to the command IOCB. |
| 1955 | * |
| 1956 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 1957 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 1958 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 1959 | * to issue the ADISC ELS command. |
| 1960 | * |
| 1961 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1962 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1963 | * will be stored into the context1 field of the IOCB for the completion |
| 1964 | * callback function to the ADISC ELS command. |
| 1965 | * |
| 1966 | * Return code |
| 1967 | * 0 - successfully issued adisc |
| 1968 | * 1 - failed to issue adisc |
| 1969 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1970 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1971 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1972 | uint8_t retry) |
| 1973 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1974 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1975 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1976 | ADISC *ap; |
| 1977 | IOCB_t *icmd; |
| 1978 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1979 | uint8_t *pcmd; |
| 1980 | uint16_t cmdsize; |
| 1981 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1982 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1983 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1984 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1985 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1986 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1987 | |
| 1988 | icmd = &elsiocb->iocb; |
| 1989 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1990 | |
| 1991 | /* For ADISC request, remainder of payload is service parameters */ |
| 1992 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1993 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1994 | |
| 1995 | /* Fill in ADISC payload */ |
| 1996 | ap = (ADISC *) pcmd; |
| 1997 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1998 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 1999 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2000 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2001 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2002 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2003 | "Issue ADISC: did:x%x", |
| 2004 | ndlp->nlp_DID, 0, 0); |
| 2005 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2006 | phba->fc_stat.elsXmitADISC++; |
| 2007 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2008 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2009 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2010 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2011 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2012 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2013 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2014 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2015 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2016 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2017 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2018 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2019 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2020 | } |
| 2021 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2022 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2023 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2024 | * @phba: pointer to lpfc hba data structure. |
| 2025 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2026 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2027 | * |
| 2028 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 2029 | * command. If no error status was reported from the LOGO response, the |
| 2030 | * state machine of the associated ndlp shall be invoked for transition with |
| 2031 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 2032 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 2033 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2034 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2035 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2036 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2037 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2038 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2039 | struct lpfc_vport *vport = ndlp->vport; |
| 2040 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2041 | IOCB_t *irsp; |
| 2042 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2043 | |
| 2044 | psli = &phba->sli; |
| 2045 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 2046 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 2047 | |
| 2048 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2049 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2050 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2051 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2052 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2053 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2054 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 2055 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2056 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2057 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2058 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2059 | "0105 LOGO completes to NPort x%x " |
| 2060 | "Data: x%x x%x x%x x%x\n", |
| 2061 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2062 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2063 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2064 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2065 | goto out; |
| 2066 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2067 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 2068 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 2069 | * which should abort all outstanding IOs. |
| 2070 | */ |
| 2071 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2072 | NLP_EVT_DEVICE_RM); |
| 2073 | goto out; |
| 2074 | } |
| 2075 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2076 | if (irsp->ulpStatus) { |
| 2077 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2078 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2079 | /* ELS command is being retried */ |
| 2080 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2081 | /* LOGO failed */ |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2082 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2083 | "2756 LOGO failure DID:%06X Status:x%x/x%x\n", |
| 2084 | ndlp->nlp_DID, irsp->ulpStatus, |
| 2085 | irsp->un.ulpWord[4]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2086 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2087 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2088 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2089 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2090 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2091 | NLP_EVT_CMPL_LOGO); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2092 | } else |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2093 | /* Good status, call state machine. |
| 2094 | * This will unregister the rpi if needed. |
| 2095 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2096 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2097 | NLP_EVT_CMPL_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2098 | out: |
| 2099 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2100 | return; |
| 2101 | } |
| 2102 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2103 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2104 | * 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] | 2105 | * @vport: pointer to a virtual N_Port data structure. |
| 2106 | * @ndlp: pointer to a node-list data structure. |
| 2107 | * @retry: number of retries to the command IOCB. |
| 2108 | * |
| 2109 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2110 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2111 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2112 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2113 | * |
| 2114 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2115 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2116 | * will be stored into the context1 field of the IOCB for the completion |
| 2117 | * callback function to the LOGO ELS command. |
| 2118 | * |
| 2119 | * Return code |
| 2120 | * 0 - successfully issued logo |
| 2121 | * 1 - failed to issue logo |
| 2122 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2123 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2124 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2125 | uint8_t retry) |
| 2126 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2127 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2128 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2129 | IOCB_t *icmd; |
| 2130 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2131 | uint8_t *pcmd; |
| 2132 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2133 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2134 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2135 | spin_lock_irq(shost->host_lock); |
| 2136 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2137 | spin_unlock_irq(shost->host_lock); |
| 2138 | return 0; |
| 2139 | } |
| 2140 | spin_unlock_irq(shost->host_lock); |
| 2141 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2142 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2143 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2144 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2145 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2146 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2147 | |
| 2148 | icmd = &elsiocb->iocb; |
| 2149 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2150 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2151 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2152 | |
| 2153 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2154 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2155 | pcmd += sizeof(uint32_t); |
| 2156 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2157 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2158 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2159 | "Issue LOGO: did:x%x", |
| 2160 | ndlp->nlp_DID, 0, 0); |
| 2161 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2162 | phba->fc_stat.elsXmitLOGO++; |
| 2163 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2164 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2165 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2166 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2167 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2168 | |
| 2169 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2170 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2171 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2172 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2173 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2174 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2175 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2176 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2177 | } |
| 2178 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2179 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2180 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2181 | * @phba: pointer to lpfc hba data structure. |
| 2182 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2183 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2184 | * |
| 2185 | * This routine is a generic completion callback function for ELS commands. |
| 2186 | * Specifically, it is the callback function which does not need to perform |
| 2187 | * any command specific operations. It is currently used by the ELS command |
| 2188 | * issuing routines for the ELS State Change Request (SCR), |
| 2189 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 2190 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2191 | * certain debug loggings, this callback function simply invokes the |
| 2192 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2193 | * discovery process. |
| 2194 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2195 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2196 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2197 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2198 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2199 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2200 | IOCB_t *irsp; |
| 2201 | |
| 2202 | irsp = &rspiocb->iocb; |
| 2203 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2204 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2205 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2206 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2207 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2208 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2209 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2210 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2211 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2212 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2213 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2214 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2215 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2216 | return; |
| 2217 | } |
| 2218 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2219 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2220 | * 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] | 2221 | * @vport: pointer to a host virtual N_Port data structure. |
| 2222 | * @nportid: N_Port identifier to the remote node. |
| 2223 | * @retry: number of retries to the command IOCB. |
| 2224 | * |
| 2225 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2226 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2227 | * first search the @vport node list to find the matching ndlp. If no such |
| 2228 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2229 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2230 | * routine is invoked to send the SCR IOCB. |
| 2231 | * |
| 2232 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2233 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2234 | * will be stored into the context1 field of the IOCB for the completion |
| 2235 | * callback function to the SCR ELS command. |
| 2236 | * |
| 2237 | * Return code |
| 2238 | * 0 - Successfully issued scr command |
| 2239 | * 1 - Failed to issue scr command |
| 2240 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2241 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2242 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2243 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2244 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2245 | IOCB_t *icmd; |
| 2246 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2247 | struct lpfc_sli *psli; |
| 2248 | uint8_t *pcmd; |
| 2249 | uint16_t cmdsize; |
| 2250 | struct lpfc_nodelist *ndlp; |
| 2251 | |
| 2252 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2253 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2254 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2255 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2256 | if (!ndlp) { |
| 2257 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2258 | if (!ndlp) |
| 2259 | return 1; |
| 2260 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2261 | lpfc_enqueue_node(vport, ndlp); |
| 2262 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2263 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2264 | if (!ndlp) |
| 2265 | return 1; |
| 2266 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2267 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2268 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2269 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2270 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2271 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2272 | /* This will trigger the release of the node just |
| 2273 | * allocated |
| 2274 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2275 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2276 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2277 | } |
| 2278 | |
| 2279 | icmd = &elsiocb->iocb; |
| 2280 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2281 | |
| 2282 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2283 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2284 | |
| 2285 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2286 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2287 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2288 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2289 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2290 | "Issue SCR: did:x%x", |
| 2291 | ndlp->nlp_DID, 0, 0); |
| 2292 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2293 | phba->fc_stat.elsXmitSCR++; |
| 2294 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2295 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2296 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2297 | /* The additional lpfc_nlp_put will cause the following |
| 2298 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2299 | * the node. |
| 2300 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2301 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2302 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2303 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2304 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2305 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2306 | * trigger the release of node. |
| 2307 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2308 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2309 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2310 | } |
| 2311 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2312 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2313 | * 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] | 2314 | * @vport: pointer to a host virtual N_Port data structure. |
| 2315 | * @nportid: N_Port identifier to the remote node. |
| 2316 | * @retry: number of retries to the command IOCB. |
| 2317 | * |
| 2318 | * This routine issues a Fibre Channel Address Resolution Response |
| 2319 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2320 | * is passed into the function. It first search the @vport node list to find |
| 2321 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2322 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2323 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2324 | * |
| 2325 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2326 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2327 | * will be stored into the context1 field of the IOCB for the completion |
| 2328 | * callback function to the PARPR ELS command. |
| 2329 | * |
| 2330 | * Return code |
| 2331 | * 0 - Successfully issued farpr command |
| 2332 | * 1 - Failed to issue farpr command |
| 2333 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2334 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2335 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2336 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2337 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2338 | IOCB_t *icmd; |
| 2339 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2340 | struct lpfc_sli *psli; |
| 2341 | FARP *fp; |
| 2342 | uint8_t *pcmd; |
| 2343 | uint32_t *lp; |
| 2344 | uint16_t cmdsize; |
| 2345 | struct lpfc_nodelist *ondlp; |
| 2346 | struct lpfc_nodelist *ndlp; |
| 2347 | |
| 2348 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2349 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2350 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2351 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2352 | if (!ndlp) { |
| 2353 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2354 | if (!ndlp) |
| 2355 | return 1; |
| 2356 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2357 | lpfc_enqueue_node(vport, ndlp); |
| 2358 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2359 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2360 | if (!ndlp) |
| 2361 | return 1; |
| 2362 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2363 | |
| 2364 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2365 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2366 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2367 | /* This will trigger the release of the node just |
| 2368 | * allocated |
| 2369 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2370 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2371 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2372 | } |
| 2373 | |
| 2374 | icmd = &elsiocb->iocb; |
| 2375 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2376 | |
| 2377 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2378 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2379 | |
| 2380 | /* Fill in FARPR payload */ |
| 2381 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2382 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2383 | lp = (uint32_t *) pcmd; |
| 2384 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2385 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2386 | fp->Rflags = 0; |
| 2387 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2388 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2389 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2390 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2391 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2392 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2393 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2394 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2395 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2396 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2397 | } |
| 2398 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2399 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2400 | "Issue FARPR: did:x%x", |
| 2401 | ndlp->nlp_DID, 0, 0); |
| 2402 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2403 | phba->fc_stat.elsXmitFARPR++; |
| 2404 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2405 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2406 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2407 | /* The additional lpfc_nlp_put will cause the following |
| 2408 | * lpfc_els_free_iocb routine to trigger the release of |
| 2409 | * the node. |
| 2410 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2411 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2412 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2413 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2414 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2415 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2416 | * trigger the release of the node. |
| 2417 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2418 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2419 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2420 | } |
| 2421 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2422 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2423 | * 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] | 2424 | * @vport: pointer to a host virtual N_Port data structure. |
| 2425 | * @nlp: pointer to a node-list data structure. |
| 2426 | * |
| 2427 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2428 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2429 | * removes the ELS retry event if it presents. In addition, if the |
| 2430 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2431 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2432 | * ADISC. |
| 2433 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2434 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2435 | 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] | 2436 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2437 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2438 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2439 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2440 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2441 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2442 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2443 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2444 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2445 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2446 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2447 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2448 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2449 | /* Decrement nlp reference count held for the delayed retry */ |
| 2450 | evtp = &nlp->els_retry_evt; |
| 2451 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2452 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2453 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2454 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2455 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2456 | spin_unlock_irq(shost->host_lock); |
| 2457 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2458 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2459 | /* Check if there are more ADISCs to be sent */ |
| 2460 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2461 | } else { |
| 2462 | /* Check if there are more PLOGIs to be sent */ |
| 2463 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2464 | if (vport->num_disc_nodes == 0) { |
| 2465 | spin_lock_irq(shost->host_lock); |
| 2466 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2467 | spin_unlock_irq(shost->host_lock); |
| 2468 | lpfc_can_disctmo(vport); |
| 2469 | lpfc_end_rscn(vport); |
| 2470 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2471 | } |
| 2472 | } |
| 2473 | } |
| 2474 | return; |
| 2475 | } |
| 2476 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2477 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2478 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2479 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2480 | * |
| 2481 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2482 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2483 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2484 | * adds the delayed events to the HBA work list and invokes the |
| 2485 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2486 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2487 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2488 | * reference to ndlp will still be available when the worker thread gets |
| 2489 | * to the event associated with the ndlp. |
| 2490 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2491 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2492 | lpfc_els_retry_delay(unsigned long ptr) |
| 2493 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2494 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2495 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2496 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2497 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2498 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2499 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2500 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2501 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2502 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2503 | return; |
| 2504 | } |
| 2505 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2506 | /* We need to hold the node by incrementing the reference |
| 2507 | * count until the queued work is done |
| 2508 | */ |
| 2509 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2510 | if (evtp->evt_arg1) { |
| 2511 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2512 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2513 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2514 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2515 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 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_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2521 | * @ndlp: pointer to a node-list data structure. |
| 2522 | * |
| 2523 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 2524 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 2525 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 2526 | * function according to the delayed ELS command to retry the command. |
| 2527 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2528 | void |
| 2529 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 2530 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2531 | struct lpfc_vport *vport = ndlp->vport; |
| 2532 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2533 | uint32_t cmd, did, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2534 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2535 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2536 | did = ndlp->nlp_DID; |
| 2537 | cmd = ndlp->nlp_last_elscmd; |
| 2538 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2539 | |
| 2540 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2541 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2542 | return; |
| 2543 | } |
| 2544 | |
| 2545 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2546 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 2547 | /* |
| 2548 | * If a discovery event readded nlp_delayfunc after timer |
| 2549 | * firing and before processing the timer, cancel the |
| 2550 | * nlp_delayfunc. |
| 2551 | */ |
| 2552 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2553 | retry = ndlp->nlp_retry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 2554 | ndlp->nlp_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2555 | |
| 2556 | switch (cmd) { |
| 2557 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2558 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2559 | break; |
| 2560 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2561 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2562 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2563 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2564 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2565 | break; |
| 2566 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2567 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2568 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2569 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2570 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2571 | break; |
| 2572 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2573 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2574 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2575 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2576 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2577 | break; |
| 2578 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2579 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2580 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2581 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2582 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2583 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2584 | case ELS_CMD_FDISC: |
| 2585 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
| 2586 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2587 | } |
| 2588 | return; |
| 2589 | } |
| 2590 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2591 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2592 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2593 | * @phba: pointer to lpfc hba data structure. |
| 2594 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2595 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2596 | * |
| 2597 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 2598 | * failed. The following ELS IOCBs use this function for retrying the command |
| 2599 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 2600 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 2601 | * returned error status, it makes the decision whether a retry shall be |
| 2602 | * issued for the command, and whether a retry shall be made immediately or |
| 2603 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 2604 | * is called to retry the command. In the later case, the ELS command shall |
| 2605 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 2606 | * ndlp for the delayed command issusing. |
| 2607 | * |
| 2608 | * Return code |
| 2609 | * 0 - No retry of els command is made |
| 2610 | * 1 - Immediate or delayed retry of els command is made |
| 2611 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2612 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2613 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2614 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2615 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2616 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2617 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2618 | IOCB_t *irsp = &rspiocb->iocb; |
| 2619 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2620 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2621 | uint32_t *elscmd; |
| 2622 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2623 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2624 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2625 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2626 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2627 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2628 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2629 | /* Note: context2 may be 0 for internal driver abort |
| 2630 | * of delays ELS command. |
| 2631 | */ |
| 2632 | |
| 2633 | if (pcmd && pcmd->virt) { |
| 2634 | elscmd = (uint32_t *) (pcmd->virt); |
| 2635 | cmd = *elscmd++; |
| 2636 | } |
| 2637 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2638 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2639 | did = ndlp->nlp_DID; |
| 2640 | else { |
| 2641 | /* We should only hit this case for retrying PLOGI */ |
| 2642 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2643 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2644 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 2645 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2646 | return 1; |
| 2647 | } |
| 2648 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2649 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2650 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 2651 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 2652 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2653 | switch (irsp->ulpStatus) { |
| 2654 | case IOSTAT_FCP_RSP_ERROR: |
| 2655 | case IOSTAT_REMOTE_STOP: |
| 2656 | break; |
| 2657 | |
| 2658 | case IOSTAT_LOCAL_REJECT: |
| 2659 | switch ((irsp->un.ulpWord[4] & 0xff)) { |
| 2660 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2661 | if (cmd == ELS_CMD_FLOGI) { |
| 2662 | if (PCI_DEVICE_ID_HORNET == |
| 2663 | phba->pcidev->device) { |
| 2664 | phba->fc_topology = TOPOLOGY_LOOP; |
| 2665 | phba->pport->fc_myDID = 0; |
| 2666 | phba->alpa_map[0] = 0; |
| 2667 | phba->alpa_map[1] = 0; |
| 2668 | } |
| 2669 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2670 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2671 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2672 | retry = 1; |
| 2673 | break; |
| 2674 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2675 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2676 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2677 | "0124 Retry illegal cmd x%x " |
| 2678 | "retry:x%x delay:x%x\n", |
| 2679 | cmd, cmdiocb->retry, delay); |
| 2680 | retry = 1; |
| 2681 | /* All command's retry policy */ |
| 2682 | maxretry = 8; |
| 2683 | if (cmdiocb->retry > 2) |
| 2684 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2685 | break; |
| 2686 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2687 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2688 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2689 | retry = 1; |
| 2690 | if (cmdiocb->retry > 100) |
| 2691 | delay = 100; |
| 2692 | maxretry = 250; |
| 2693 | break; |
| 2694 | |
| 2695 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2696 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2697 | retry = 1; |
| 2698 | break; |
| 2699 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2700 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2701 | case IOERR_INVALID_RPI: |
| 2702 | retry = 1; |
| 2703 | break; |
| 2704 | } |
| 2705 | break; |
| 2706 | |
| 2707 | case IOSTAT_NPORT_RJT: |
| 2708 | case IOSTAT_FABRIC_RJT: |
| 2709 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 2710 | retry = 1; |
| 2711 | break; |
| 2712 | } |
| 2713 | break; |
| 2714 | |
| 2715 | case IOSTAT_NPORT_BSY: |
| 2716 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2717 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2718 | retry = 1; |
| 2719 | break; |
| 2720 | |
| 2721 | case IOSTAT_LS_RJT: |
| 2722 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 2723 | /* Added for Vendor specifc support |
| 2724 | * Just keep retrying for these Rsn / Exp codes |
| 2725 | */ |
| 2726 | switch (stat.un.b.lsRjtRsnCode) { |
| 2727 | case LSRJT_UNABLE_TPC: |
| 2728 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2729 | LSEXP_CMD_IN_PROGRESS) { |
| 2730 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2731 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2732 | maxretry = 48; |
| 2733 | } |
| 2734 | retry = 1; |
| 2735 | break; |
| 2736 | } |
| 2737 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2738 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2739 | maxretry = lpfc_max_els_tries + 1; |
| 2740 | retry = 1; |
| 2741 | break; |
| 2742 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2743 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2744 | (cmd == ELS_CMD_FDISC) && |
| 2745 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2746 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2747 | "0125 FDISC Failed (x%x). " |
| 2748 | "Fabric out of resources\n", |
| 2749 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2750 | lpfc_vport_set_state(vport, |
| 2751 | FC_VPORT_NO_FABRIC_RSCS); |
| 2752 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2753 | break; |
| 2754 | |
| 2755 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2756 | if ((cmd == ELS_CMD_PLOGI) || |
| 2757 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2758 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2759 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2760 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2761 | /* FDISC retry policy */ |
| 2762 | maxretry = 48; |
| 2763 | if (cmdiocb->retry >= 32) |
| 2764 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2765 | } |
| 2766 | retry = 1; |
| 2767 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2768 | |
| 2769 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2770 | /* There are some cases where switches return this |
| 2771 | * error when they are not ready and should be returning |
| 2772 | * Logical Busy. We should delay every time. |
| 2773 | */ |
| 2774 | if (cmd == ELS_CMD_FDISC && |
| 2775 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 2776 | maxretry = 3; |
| 2777 | delay = 1000; |
| 2778 | retry = 1; |
| 2779 | break; |
| 2780 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2781 | case LSRJT_PROTOCOL_ERR: |
| 2782 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2783 | (cmd == ELS_CMD_FDISC) && |
| 2784 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 2785 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 2786 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2787 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2788 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2789 | "Fabric Detected Bad WWN\n", |
| 2790 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2791 | lpfc_vport_set_state(vport, |
| 2792 | FC_VPORT_FABRIC_REJ_WWN); |
| 2793 | } |
| 2794 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2795 | } |
| 2796 | break; |
| 2797 | |
| 2798 | case IOSTAT_INTERMED_RSP: |
| 2799 | case IOSTAT_BA_RJT: |
| 2800 | break; |
| 2801 | |
| 2802 | default: |
| 2803 | break; |
| 2804 | } |
| 2805 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2806 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2807 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2808 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2809 | if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 2810 | (phba->fc_topology != TOPOLOGY_LOOP) && |
| 2811 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2812 | /* FLOGI retry policy */ |
| 2813 | retry = 1; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2814 | /* retry forever */ |
| 2815 | maxretry = 0; |
| 2816 | if (cmdiocb->retry >= 100) |
| 2817 | delay = 5000; |
| 2818 | else if (cmdiocb->retry >= 32) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2819 | delay = 1000; |
| 2820 | } |
| 2821 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2822 | cmdiocb->retry++; |
| 2823 | if (maxretry && (cmdiocb->retry >= maxretry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2824 | phba->fc_stat.elsRetryExceeded++; |
| 2825 | retry = 0; |
| 2826 | } |
| 2827 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2828 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 2829 | retry = 0; |
| 2830 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2831 | if (retry) { |
| 2832 | |
| 2833 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2834 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2835 | "0107 Retry ELS command x%x to remote " |
| 2836 | "NPORT x%x Data: x%x x%x\n", |
| 2837 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2838 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2839 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 2840 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 2841 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { |
| 2842 | /* Don't reset timer for no resources */ |
| 2843 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2844 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2845 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2846 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2847 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2848 | } |
| 2849 | |
| 2850 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2851 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2852 | phba->fc_stat.elsDelayRetry++; |
| 2853 | ndlp->nlp_retry = cmdiocb->retry; |
| 2854 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2855 | /* delay is specified in milliseconds */ |
| 2856 | mod_timer(&ndlp->nlp_delayfunc, |
| 2857 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2858 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2859 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2860 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2861 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2862 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2863 | if (cmd == ELS_CMD_PRLI) |
| 2864 | lpfc_nlp_set_state(vport, ndlp, |
| 2865 | NLP_STE_REG_LOGIN_ISSUE); |
| 2866 | else |
| 2867 | lpfc_nlp_set_state(vport, ndlp, |
| 2868 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2869 | ndlp->nlp_last_elscmd = cmd; |
| 2870 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2871 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2872 | } |
| 2873 | switch (cmd) { |
| 2874 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2875 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2876 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2877 | case ELS_CMD_FDISC: |
| 2878 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 2879 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2880 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2881 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2882 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2883 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2884 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2885 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2886 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2887 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2888 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2889 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2890 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 2891 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2892 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2893 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2894 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2895 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 2896 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2897 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2898 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2899 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2900 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 2901 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2902 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2903 | } |
| 2904 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2905 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2906 | if (logerr) { |
| 2907 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2908 | "0137 No retry ELS command x%x to remote " |
| 2909 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 2910 | cmd, did, irsp->ulpStatus, |
| 2911 | irsp->un.ulpWord[4]); |
| 2912 | } |
| 2913 | else { |
| 2914 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2915 | "0108 No retry ELS command x%x to remote " |
| 2916 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 2917 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 2918 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2919 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2920 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2921 | } |
| 2922 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2923 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2924 | * 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] | 2925 | * @phba: pointer to lpfc hba data structure. |
| 2926 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 2927 | * |
| 2928 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 2929 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 2930 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 2931 | * response of the command IOCB. If so, it will be released before releasing |
| 2932 | * the lpfc DMA buffer associated with the IOCB itself. |
| 2933 | * |
| 2934 | * Return code |
| 2935 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2936 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2937 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2938 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 2939 | { |
| 2940 | struct lpfc_dmabuf *buf_ptr; |
| 2941 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2942 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2943 | if (!list_empty(&buf_ptr1->list)) { |
| 2944 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 2945 | struct lpfc_dmabuf, |
| 2946 | list); |
| 2947 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2948 | kfree(buf_ptr); |
| 2949 | } |
| 2950 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 2951 | kfree(buf_ptr1); |
| 2952 | return 0; |
| 2953 | } |
| 2954 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2955 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2956 | * 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] | 2957 | * @phba: pointer to lpfc hba data structure. |
| 2958 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 2959 | * |
| 2960 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 2961 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 2962 | * pool. |
| 2963 | * |
| 2964 | * Return code |
| 2965 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2966 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2967 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2968 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 2969 | { |
| 2970 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2971 | kfree(buf_ptr); |
| 2972 | return 0; |
| 2973 | } |
| 2974 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2975 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2976 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2977 | * @phba: pointer to lpfc hba data structure. |
| 2978 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 2979 | * |
| 2980 | * This routine frees a command IOCB and its associated resources. The |
| 2981 | * command IOCB data structure contains the reference to various associated |
| 2982 | * resources, these fields must be set to NULL if the associated reference |
| 2983 | * not present: |
| 2984 | * context1 - reference to ndlp |
| 2985 | * context2 - reference to cmd |
| 2986 | * context2->next - reference to rsp |
| 2987 | * context3 - reference to bpl |
| 2988 | * |
| 2989 | * It first properly decrements the reference count held on ndlp for the |
| 2990 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 2991 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 2992 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 2993 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 2994 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 2995 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 2996 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 2997 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 2998 | * |
| 2999 | * Return code |
| 3000 | * 0 - Success (currently, always return 0) |
| 3001 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3002 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3003 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3004 | { |
| 3005 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3006 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3007 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3008 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 3009 | if (ndlp) { |
| 3010 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 3011 | lpfc_nlp_put(ndlp); |
| 3012 | |
| 3013 | /* If the ndlp is not being used by another discovery |
| 3014 | * thread, free it. |
| 3015 | */ |
| 3016 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3017 | /* If ndlp is being used by another discovery |
| 3018 | * thread, just clear NLP_DEFER_RM |
| 3019 | */ |
| 3020 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 3021 | } |
| 3022 | } |
| 3023 | else |
| 3024 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3025 | elsiocb->context1 = NULL; |
| 3026 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3027 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 3028 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3029 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 3030 | /* Firmware could still be in progress of DMAing |
| 3031 | * payload, so don't free data buffer till after |
| 3032 | * a hbeat. |
| 3033 | */ |
| 3034 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 3035 | buf_ptr = elsiocb->context2; |
| 3036 | elsiocb->context2 = NULL; |
| 3037 | if (buf_ptr) { |
| 3038 | buf_ptr1 = NULL; |
| 3039 | spin_lock_irq(&phba->hbalock); |
| 3040 | if (!list_empty(&buf_ptr->list)) { |
| 3041 | list_remove_head(&buf_ptr->list, |
| 3042 | buf_ptr1, struct lpfc_dmabuf, |
| 3043 | list); |
| 3044 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 3045 | list_add_tail(&buf_ptr1->list, |
| 3046 | &phba->elsbuf); |
| 3047 | phba->elsbuf_cnt++; |
| 3048 | } |
| 3049 | INIT_LIST_HEAD(&buf_ptr->list); |
| 3050 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 3051 | phba->elsbuf_cnt++; |
| 3052 | spin_unlock_irq(&phba->hbalock); |
| 3053 | } |
| 3054 | } else { |
| 3055 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 3056 | lpfc_els_free_data(phba, buf_ptr1); |
| 3057 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3058 | } |
| 3059 | |
| 3060 | if (elsiocb->context3) { |
| 3061 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3062 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3063 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3064 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3065 | return 0; |
| 3066 | } |
| 3067 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3068 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3069 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3070 | * @phba: pointer to lpfc hba data structure. |
| 3071 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3072 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3073 | * |
| 3074 | * This routine is the completion callback function to the Logout (LOGO) |
| 3075 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 3076 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 3077 | * release the ndlp if it has the last reference remaining (reference count |
| 3078 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 3079 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 3080 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 3081 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 3082 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 3083 | * IOCB data structure. |
| 3084 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3085 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3086 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3087 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3088 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3089 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3090 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3091 | IOCB_t *irsp; |
| 3092 | |
| 3093 | irsp = &rspiocb->iocb; |
| 3094 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3095 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 3096 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3097 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3098 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3099 | "0109 ACC to LOGO completes to NPort x%x " |
| 3100 | "Data: x%x x%x x%x\n", |
| 3101 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3102 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3103 | |
| 3104 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 3105 | /* NPort Recovery mode or node is just allocated */ |
| 3106 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3107 | /* If the ndlp is being used by another discovery |
| 3108 | * thread, just unregister the RPI. |
| 3109 | */ |
| 3110 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3111 | } else { |
| 3112 | /* Indicate the node has already released, should |
| 3113 | * not reference to it from within lpfc_els_free_iocb. |
| 3114 | */ |
| 3115 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3116 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3117 | } |
| 3118 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3119 | return; |
| 3120 | } |
| 3121 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3122 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3123 | * 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] | 3124 | * @phba: pointer to lpfc hba data structure. |
| 3125 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 3126 | * |
| 3127 | * This routine is the completion callback function for unregister default |
| 3128 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 3129 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 3130 | * decrements the ndlp reference count held for this completion callback |
| 3131 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 3132 | * whether there is only one reference left on the ndlp. If so, it will |
| 3133 | * perform one more decrement and trigger the release of the ndlp. |
| 3134 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3135 | void |
| 3136 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3137 | { |
| 3138 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3139 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3140 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3141 | /* |
| 3142 | * This routine is used to register and unregister in previous SLI |
| 3143 | * modes. |
| 3144 | */ |
| 3145 | if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) && |
| 3146 | (phba->sli_rev == LPFC_SLI_REV4)) |
| 3147 | lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi); |
| 3148 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3149 | pmb->context1 = NULL; |
| 3150 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3151 | kfree(mp); |
| 3152 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3153 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3154 | lpfc_nlp_put(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3155 | /* This is the end of the default RPI cleanup logic for this |
| 3156 | * ndlp. If no other discovery threads are using this ndlp. |
| 3157 | * we should free all resources associated with it. |
| 3158 | */ |
| 3159 | lpfc_nlp_not_used(ndlp); |
| 3160 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3161 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3162 | return; |
| 3163 | } |
| 3164 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3165 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3166 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3167 | * @phba: pointer to lpfc hba data structure. |
| 3168 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3169 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3170 | * |
| 3171 | * This routine is the completion callback function for ELS Response IOCB |
| 3172 | * command. In normal case, this callback function just properly sets the |
| 3173 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 3174 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 3175 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 3176 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 3177 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 3178 | * routine shall be invoked trying to release the ndlp if no other threads |
| 3179 | * are currently referring it. |
| 3180 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3181 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3182 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3183 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3184 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3185 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3186 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 3187 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3188 | IOCB_t *irsp; |
| 3189 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3190 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3191 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3192 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3193 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3194 | irsp = &rspiocb->iocb; |
| 3195 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3196 | if (cmdiocb->context_un.mbox) |
| 3197 | mbox = cmdiocb->context_un.mbox; |
| 3198 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3199 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 3200 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 3201 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3202 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3203 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3204 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3205 | /* A LS_RJT associated with Default RPI cleanup has its own |
| 3206 | * seperate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3207 | */ |
| 3208 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 3209 | ls_rjt = 1; |
| 3210 | } |
| 3211 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3212 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3213 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3214 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3215 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3216 | if (mp) { |
| 3217 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3218 | kfree(mp); |
| 3219 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3220 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3221 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3222 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3223 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3224 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3225 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3226 | /* Indicate the node has already released, |
| 3227 | * should not reference to it from within |
| 3228 | * the routine lpfc_els_free_iocb. |
| 3229 | */ |
| 3230 | cmdiocb->context1 = NULL; |
| 3231 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3232 | goto out; |
| 3233 | } |
| 3234 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3235 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3236 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3237 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3238 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3239 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3240 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3241 | "0110 ELS response tag x%x completes " |
| 3242 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3243 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3244 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3245 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3246 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3247 | if (mbox) { |
| 3248 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3249 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3250 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3251 | /* Increment reference count to ndlp to hold the |
| 3252 | * reference to ndlp for the callback function. |
| 3253 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3254 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3255 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3256 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3257 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3258 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3259 | } |
| 3260 | else { |
| 3261 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3262 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3263 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3264 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3265 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3266 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3267 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3268 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3269 | else |
| 3270 | /* Decrement the ndlp reference count we |
| 3271 | * set for this failed mailbox command. |
| 3272 | */ |
| 3273 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3274 | |
| 3275 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3276 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3277 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3278 | "Data: x%x x%x x%x\n", |
| 3279 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3280 | ndlp->nlp_rpi); |
| 3281 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3282 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3283 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3284 | /* Indicate node has already been released, |
| 3285 | * should not reference to it from within |
| 3286 | * the routine lpfc_els_free_iocb. |
| 3287 | */ |
| 3288 | cmdiocb->context1 = NULL; |
| 3289 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3290 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3291 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3292 | if (!lpfc_error_lost_link(irsp) && |
| 3293 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3294 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3295 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3296 | /* Indicate node has already been |
| 3297 | * released, should not reference |
| 3298 | * to it from within the routine |
| 3299 | * lpfc_els_free_iocb. |
| 3300 | */ |
| 3301 | cmdiocb->context1 = NULL; |
| 3302 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3303 | } |
| 3304 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3305 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3306 | if (mp) { |
| 3307 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3308 | kfree(mp); |
| 3309 | } |
| 3310 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3311 | } |
| 3312 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3313 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3314 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3315 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3316 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3317 | |
| 3318 | /* If the node is not being used by another discovery thread, |
| 3319 | * and we are sending a reject, we are done with it. |
| 3320 | * Release driver reference count here and free associated |
| 3321 | * resources. |
| 3322 | */ |
| 3323 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3324 | if (lpfc_nlp_not_used(ndlp)) |
| 3325 | /* Indicate node has already been released, |
| 3326 | * should not reference to it from within |
| 3327 | * the routine lpfc_els_free_iocb. |
| 3328 | */ |
| 3329 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3330 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3331 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3332 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3333 | return; |
| 3334 | } |
| 3335 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3336 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3337 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3338 | * @vport: pointer to a host virtual N_Port data structure. |
| 3339 | * @flag: the els command code to be accepted. |
| 3340 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3341 | * @ndlp: pointer to a node-list data structure. |
| 3342 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3343 | * |
| 3344 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3345 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3346 | * specific ACC response command to be issued and invokes the |
| 3347 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3348 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3349 | * field of the IOCB for the completion callback function to issue the |
| 3350 | * mailbox command to the HBA later when callback is invoked. |
| 3351 | * |
| 3352 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3353 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3354 | * will be stored into the context1 field of the IOCB for the completion |
| 3355 | * callback function to the corresponding response ELS IOCB command. |
| 3356 | * |
| 3357 | * Return code |
| 3358 | * 0 - Successfully issued acc response |
| 3359 | * 1 - Failed to issue acc response |
| 3360 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3361 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3362 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3363 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3364 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3365 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3366 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3367 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3368 | IOCB_t *icmd; |
| 3369 | IOCB_t *oldcmd; |
| 3370 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3371 | struct lpfc_sli *psli; |
| 3372 | uint8_t *pcmd; |
| 3373 | uint16_t cmdsize; |
| 3374 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3375 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3376 | |
| 3377 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3378 | oldcmd = &oldiocb->iocb; |
| 3379 | |
| 3380 | switch (flag) { |
| 3381 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3382 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3383 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3384 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3385 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3386 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3387 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3388 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3389 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3390 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3391 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3392 | icmd = &elsiocb->iocb; |
| 3393 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3394 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3395 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3396 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3397 | |
| 3398 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3399 | "Issue ACC: did:x%x flg:x%x", |
| 3400 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3401 | break; |
| 3402 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3403 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3404 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3405 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3406 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3407 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3408 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3409 | icmd = &elsiocb->iocb; |
| 3410 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3411 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3412 | |
| 3413 | if (mbox) |
| 3414 | elsiocb->context_un.mbox = mbox; |
| 3415 | |
| 3416 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3417 | pcmd += sizeof(uint32_t); |
| 3418 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3419 | |
| 3420 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3421 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 3422 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3423 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3424 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3425 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3426 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3427 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3428 | if (!elsiocb) |
| 3429 | return 1; |
| 3430 | |
| 3431 | icmd = &elsiocb->iocb; |
| 3432 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3433 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3434 | |
| 3435 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3436 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3437 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 3438 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 3439 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3440 | |
| 3441 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3442 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 3443 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3444 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3445 | default: |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3446 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3447 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3448 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3449 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3450 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
| 3451 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", |
| 3452 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3453 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3454 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3455 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3456 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3457 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3458 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3459 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 3460 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3461 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3462 | } |
| 3463 | |
| 3464 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3465 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3466 | if (rc == IOCB_ERROR) { |
| 3467 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3468 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3469 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3470 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3471 | } |
| 3472 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3473 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3474 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3475 | * @vport: pointer to a virtual N_Port data structure. |
| 3476 | * @rejectError: |
| 3477 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3478 | * @ndlp: pointer to a node-list data structure. |
| 3479 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3480 | * |
| 3481 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 3482 | * command. If a @mbox pointer is passed in, it will be put into the |
| 3483 | * context_un.mbox field of the IOCB for the completion callback function |
| 3484 | * to issue to the HBA later. |
| 3485 | * |
| 3486 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3487 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3488 | * will be stored into the context1 field of the IOCB for the completion |
| 3489 | * callback function to the reject response ELS IOCB command. |
| 3490 | * |
| 3491 | * Return code |
| 3492 | * 0 - Successfully issued reject response |
| 3493 | * 1 - Failed to issue reject response |
| 3494 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3495 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3496 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3497 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 3498 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3499 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3500 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3501 | IOCB_t *icmd; |
| 3502 | IOCB_t *oldcmd; |
| 3503 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3504 | struct lpfc_sli *psli; |
| 3505 | uint8_t *pcmd; |
| 3506 | uint16_t cmdsize; |
| 3507 | int rc; |
| 3508 | |
| 3509 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3510 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3511 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3512 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3513 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3514 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3515 | |
| 3516 | icmd = &elsiocb->iocb; |
| 3517 | oldcmd = &oldiocb->iocb; |
| 3518 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3519 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3520 | |
| 3521 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3522 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3523 | *((uint32_t *) (pcmd)) = rejectError; |
| 3524 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3525 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3526 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3527 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3528 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3529 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3530 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 3531 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 3532 | "rpi x%x\n", |
| 3533 | rejectError, elsiocb->iotag, |
| 3534 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 3535 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3536 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3537 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 3538 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 3539 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3540 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3541 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3542 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3543 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3544 | if (rc == IOCB_ERROR) { |
| 3545 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3546 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3547 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3548 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3549 | } |
| 3550 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3551 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3552 | * 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] | 3553 | * @vport: pointer to a virtual N_Port data structure. |
| 3554 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3555 | * @ndlp: pointer to a node-list data structure. |
| 3556 | * |
| 3557 | * This routine prepares and issues an Accept (ACC) response to Address |
| 3558 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 3559 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3560 | * |
| 3561 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3562 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3563 | * will be stored into the context1 field of the IOCB for the completion |
| 3564 | * callback function to the ADISC Accept response ELS IOCB command. |
| 3565 | * |
| 3566 | * Return code |
| 3567 | * 0 - Successfully issued acc adisc response |
| 3568 | * 1 - Failed to issue adisc acc response |
| 3569 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3570 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3571 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 3572 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3573 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3574 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3575 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3576 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3577 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3578 | uint8_t *pcmd; |
| 3579 | uint16_t cmdsize; |
| 3580 | int rc; |
| 3581 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3582 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3583 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3584 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3585 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3586 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3587 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3588 | icmd = &elsiocb->iocb; |
| 3589 | oldcmd = &oldiocb->iocb; |
| 3590 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3591 | |
| 3592 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3593 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3594 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 3595 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 3596 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3597 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3598 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3599 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3600 | |
| 3601 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3602 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3603 | |
| 3604 | ap = (ADISC *) (pcmd); |
| 3605 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3606 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3607 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3608 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3609 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3610 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3611 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 3612 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3613 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3614 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3615 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3616 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3617 | if (rc == IOCB_ERROR) { |
| 3618 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3619 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3620 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3621 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3622 | } |
| 3623 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3624 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3625 | * 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] | 3626 | * @vport: pointer to a virtual N_Port data structure. |
| 3627 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3628 | * @ndlp: pointer to a node-list data structure. |
| 3629 | * |
| 3630 | * This routine prepares and issues an Accept (ACC) response to Process |
| 3631 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 3632 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3633 | * |
| 3634 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3635 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3636 | * will be stored into the context1 field of the IOCB for the completion |
| 3637 | * callback function to the PRLI Accept response ELS IOCB command. |
| 3638 | * |
| 3639 | * Return code |
| 3640 | * 0 - Successfully issued acc prli response |
| 3641 | * 1 - Failed to issue acc prli response |
| 3642 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3643 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3644 | 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] | 3645 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3646 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3647 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3648 | PRLI *npr; |
| 3649 | lpfc_vpd_t *vpd; |
| 3650 | IOCB_t *icmd; |
| 3651 | IOCB_t *oldcmd; |
| 3652 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3653 | struct lpfc_sli *psli; |
| 3654 | uint8_t *pcmd; |
| 3655 | uint16_t cmdsize; |
| 3656 | int rc; |
| 3657 | |
| 3658 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3659 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3660 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3661 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3662 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3663 | if (!elsiocb) |
| 3664 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3665 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3666 | icmd = &elsiocb->iocb; |
| 3667 | oldcmd = &oldiocb->iocb; |
| 3668 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3669 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3670 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3671 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 3672 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 3673 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3674 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3675 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3676 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3677 | |
| 3678 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3679 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3680 | |
| 3681 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3682 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3683 | |
| 3684 | npr = (PRLI *) pcmd; |
| 3685 | vpd = &phba->vpd; |
| 3686 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3687 | * If the remote port is a target and our firmware version is 3.20 or |
| 3688 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3689 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3690 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 3691 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3692 | npr->ConfmComplAllowed = 1; |
| 3693 | npr->Retry = 1; |
| 3694 | npr->TaskRetryIdReq = 1; |
| 3695 | } |
| 3696 | |
| 3697 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 3698 | npr->estabImagePair = 1; |
| 3699 | npr->readXferRdyDis = 1; |
| 3700 | npr->ConfmComplAllowed = 1; |
| 3701 | |
| 3702 | npr->prliType = PRLI_FCP_TYPE; |
| 3703 | npr->initiatorFunc = 1; |
| 3704 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3705 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3706 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 3707 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3708 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3709 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3710 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3711 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3712 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3713 | if (rc == IOCB_ERROR) { |
| 3714 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3715 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3716 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3717 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3718 | } |
| 3719 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3720 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3721 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3722 | * @vport: pointer to a virtual N_Port data structure. |
| 3723 | * @format: rnid command format. |
| 3724 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3725 | * @ndlp: pointer to a node-list data structure. |
| 3726 | * |
| 3727 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 3728 | * (ACC) response. It constructs the RNID ACC response command according to |
| 3729 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 3730 | * issue the response. Note that this command does not need to hold the ndlp |
| 3731 | * reference count for the callback. So, the ndlp reference count taken by |
| 3732 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 3733 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 3734 | * there is no ndlp reference available. |
| 3735 | * |
| 3736 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3737 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3738 | * will be stored into the context1 field of the IOCB for the completion |
| 3739 | * callback function. However, for the RNID Accept Response ELS command, |
| 3740 | * this is undone later by this routine after the IOCB is allocated. |
| 3741 | * |
| 3742 | * Return code |
| 3743 | * 0 - Successfully issued acc rnid response |
| 3744 | * 1 - Failed to issue acc rnid response |
| 3745 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3746 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3747 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3748 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3749 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3750 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3751 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3752 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3753 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3754 | struct lpfc_sli *psli; |
| 3755 | uint8_t *pcmd; |
| 3756 | uint16_t cmdsize; |
| 3757 | int rc; |
| 3758 | |
| 3759 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3760 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 3761 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3762 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3763 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3764 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3765 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3766 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3767 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3768 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3769 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3770 | icmd = &elsiocb->iocb; |
| 3771 | oldcmd = &oldiocb->iocb; |
| 3772 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3773 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3774 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3775 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 3776 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3777 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3778 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3779 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3780 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3781 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3782 | rn = (RNID *) (pcmd); |
| 3783 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3784 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 3785 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3786 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3787 | switch (format) { |
| 3788 | case 0: |
| 3789 | rn->SpecificLen = 0; |
| 3790 | break; |
| 3791 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3792 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3793 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3794 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3795 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 3796 | rn->un.topologyDisc.physPort = 0; |
| 3797 | rn->un.topologyDisc.attachedNodes = 0; |
| 3798 | break; |
| 3799 | default: |
| 3800 | rn->CommonLen = 0; |
| 3801 | rn->SpecificLen = 0; |
| 3802 | break; |
| 3803 | } |
| 3804 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3805 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3806 | "Issue ACC RNID: did:x%x flg:x%x", |
| 3807 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3808 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3809 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3810 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3811 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3812 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 3813 | * it could be freed */ |
| 3814 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3815 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3816 | if (rc == IOCB_ERROR) { |
| 3817 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3818 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3819 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3820 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3821 | } |
| 3822 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3823 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3824 | * 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] | 3825 | * @vport: pointer to a host virtual N_Port data structure. |
| 3826 | * |
| 3827 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 3828 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 3829 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 3830 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 3831 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 3832 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 3833 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 3834 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 3835 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 3836 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 3837 | * no more ADISC need to be sent. |
| 3838 | * |
| 3839 | * Return code |
| 3840 | * The number of N_Ports with adisc issued. |
| 3841 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3842 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3843 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3844 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3845 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3846 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3847 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3848 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3849 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3850 | 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] | 3851 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3852 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3853 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3854 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3855 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3856 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3857 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3858 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3859 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3860 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 3861 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3862 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3863 | vport->num_disc_nodes++; |
| 3864 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3865 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3866 | spin_lock_irq(shost->host_lock); |
| 3867 | vport->fc_flag |= FC_NLP_MORE; |
| 3868 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3869 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3870 | } |
| 3871 | } |
| 3872 | } |
| 3873 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3874 | spin_lock_irq(shost->host_lock); |
| 3875 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3876 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3877 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3878 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3879 | } |
| 3880 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3881 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3882 | * 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] | 3883 | * @vport: pointer to a host virtual N_Port data structure. |
| 3884 | * |
| 3885 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 3886 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 3887 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 3888 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 3889 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 3890 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 3891 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 3892 | * later pick up. On the other hand, after walking through all the ndlps with |
| 3893 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 3894 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 3895 | * PLOGI need to be sent. |
| 3896 | * |
| 3897 | * Return code |
| 3898 | * The number of N_Ports with plogi issued. |
| 3899 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3900 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3901 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3902 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3903 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3904 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3905 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3906 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3907 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 3908 | 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] | 3909 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3910 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3911 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3912 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3913 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 3914 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 3915 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3916 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 3917 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3918 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3919 | vport->num_disc_nodes++; |
| 3920 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3921 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3922 | spin_lock_irq(shost->host_lock); |
| 3923 | vport->fc_flag |= FC_NLP_MORE; |
| 3924 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3925 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3926 | } |
| 3927 | } |
| 3928 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3929 | if (sentplogi) { |
| 3930 | lpfc_set_disctmo(vport); |
| 3931 | } |
| 3932 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3933 | spin_lock_irq(shost->host_lock); |
| 3934 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3935 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3936 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3937 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3938 | } |
| 3939 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3940 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3941 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3942 | * @vport: pointer to a host virtual N_Port data structure. |
| 3943 | * |
| 3944 | * This routine cleans up any Registration State Change Notification |
| 3945 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 3946 | * @vport together with the host_lock is used to prevent multiple thread |
| 3947 | * trying to access the RSCN array on a same @vport at the same time. |
| 3948 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3949 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3950 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3951 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3952 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3953 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3954 | int i; |
| 3955 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3956 | spin_lock_irq(shost->host_lock); |
| 3957 | if (vport->fc_rscn_flush) { |
| 3958 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3959 | spin_unlock_irq(shost->host_lock); |
| 3960 | return; |
| 3961 | } |
| 3962 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 3963 | vport->fc_rscn_flush = 1; |
| 3964 | spin_unlock_irq(shost->host_lock); |
| 3965 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3966 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3967 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3968 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3969 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3970 | spin_lock_irq(shost->host_lock); |
| 3971 | vport->fc_rscn_id_cnt = 0; |
| 3972 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 3973 | spin_unlock_irq(shost->host_lock); |
| 3974 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3975 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 3976 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3977 | } |
| 3978 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3979 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3980 | * 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] | 3981 | * @vport: pointer to a host virtual N_Port data structure. |
| 3982 | * @did: remote destination port identifier. |
| 3983 | * |
| 3984 | * This routine checks whether there is any pending Registration State |
| 3985 | * Configuration Notification (RSCN) to a @did on @vport. |
| 3986 | * |
| 3987 | * Return code |
| 3988 | * None zero - The @did matched with a pending rscn |
| 3989 | * 0 - not able to match @did with a pending rscn |
| 3990 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3991 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3992 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3993 | { |
| 3994 | D_ID ns_did; |
| 3995 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3996 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3997 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3998 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3999 | |
| 4000 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4001 | |
| 4002 | /* Never match fabric nodes for RSCNs */ |
| 4003 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4004 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4005 | |
| 4006 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4007 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4008 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4009 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4010 | spin_lock_irq(shost->host_lock); |
| 4011 | if (vport->fc_rscn_flush) { |
| 4012 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4013 | spin_unlock_irq(shost->host_lock); |
| 4014 | return 0; |
| 4015 | } |
| 4016 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4017 | vport->fc_rscn_flush = 1; |
| 4018 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4019 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4020 | lp = vport->fc_rscn_id_list[i]->virt; |
| 4021 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4022 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4023 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4024 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 4025 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4026 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 4027 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4028 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4029 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 4030 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4031 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4032 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4033 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4034 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 4035 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4036 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4037 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4038 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4039 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4040 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4041 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4042 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4043 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4044 | } |
| 4045 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4046 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4047 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4048 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4049 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4050 | return_did_out: |
| 4051 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 4052 | vport->fc_rscn_flush = 0; |
| 4053 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4054 | } |
| 4055 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4056 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4057 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4058 | * @vport: pointer to a host virtual N_Port data structure. |
| 4059 | * |
| 4060 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 4061 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 4062 | * State Change Notification). |
| 4063 | * |
| 4064 | * Return code |
| 4065 | * 0 - Successful (currently alway return 0) |
| 4066 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4067 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4068 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4069 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4070 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4071 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4072 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4073 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4074 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4075 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 4076 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4077 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4078 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4079 | NLP_EVT_DEVICE_RECOVERY); |
| 4080 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4081 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4082 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4083 | } |
| 4084 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4085 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4086 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4087 | * @vport: pointer to a host virtual N_Port data structure. |
| 4088 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4089 | * |
| 4090 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 4091 | * applications. |
| 4092 | */ |
| 4093 | static void |
| 4094 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 4095 | struct lpfc_iocbq *cmdiocb) |
| 4096 | { |
| 4097 | struct lpfc_dmabuf *pcmd; |
| 4098 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4099 | uint32_t *payload_ptr; |
| 4100 | uint32_t payload_len; |
| 4101 | struct lpfc_rscn_event_header *rscn_event_data; |
| 4102 | |
| 4103 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4104 | payload_ptr = (uint32_t *) pcmd->virt; |
| 4105 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 4106 | |
| 4107 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 4108 | payload_len, GFP_KERNEL); |
| 4109 | if (!rscn_event_data) { |
| 4110 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4111 | "0147 Failed to allocate memory for RSCN event\n"); |
| 4112 | return; |
| 4113 | } |
| 4114 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 4115 | rscn_event_data->payload_length = payload_len; |
| 4116 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 4117 | payload_len); |
| 4118 | |
| 4119 | fc_host_post_vendor_event(shost, |
| 4120 | fc_get_event_number(), |
| 4121 | sizeof(struct lpfc_els_event_header) + payload_len, |
| 4122 | (char *)rscn_event_data, |
| 4123 | LPFC_NL_VENDOR_ID); |
| 4124 | |
| 4125 | kfree(rscn_event_data); |
| 4126 | } |
| 4127 | |
| 4128 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4129 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4130 | * @vport: pointer to a host virtual N_Port data structure. |
| 4131 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4132 | * @ndlp: pointer to a node-list data structure. |
| 4133 | * |
| 4134 | * This routine processes an unsolicited RSCN (Registration State Change |
| 4135 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 4136 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 4137 | * discover state machine is about to begin discovery, it just accepts the |
| 4138 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 4139 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 4140 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 4141 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 4142 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 4143 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 4144 | * routine is invoked to handle the RSCN event. |
| 4145 | * |
| 4146 | * Return code |
| 4147 | * 0 - Just sent the acc response |
| 4148 | * 1 - Sent the acc response and waited for name server completion |
| 4149 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4150 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4151 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4152 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4153 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4154 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4155 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4156 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4157 | uint32_t *lp, *datap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4158 | IOCB_t *icmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4159 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4160 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4161 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4162 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4163 | |
| 4164 | icmd = &cmdiocb->iocb; |
| 4165 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4166 | lp = (uint32_t *) pcmd->virt; |
| 4167 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4168 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4169 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4170 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4171 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4172 | "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] | 4173 | vport->fc_flag, payload_len, *lp, |
| 4174 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4175 | |
| 4176 | /* Send an RSCN event to the management application */ |
| 4177 | lpfc_send_rscn_event(vport, cmdiocb); |
| 4178 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4179 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4180 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4181 | FCH_EVT_RSCN, lp[i]); |
| 4182 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4183 | /* If we are about to begin discovery, just ACC the RSCN. |
| 4184 | * Discovery processing will satisfy it. |
| 4185 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4186 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4187 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4188 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 4189 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4190 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4191 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4192 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4193 | } |
| 4194 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4195 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 4196 | * just ACC and ignore it. |
| 4197 | */ |
| 4198 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4199 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4200 | i = payload_len; |
| 4201 | datap = lp; |
| 4202 | while (i > 0) { |
| 4203 | nportid = *datap++; |
| 4204 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 4205 | i -= sizeof(uint32_t); |
| 4206 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4207 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 4208 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4209 | } |
| 4210 | if (rscn_id == hba_id) { |
| 4211 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4212 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4213 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4214 | "Data: x%x x%x x%x x%x\n", |
| 4215 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4216 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4217 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4218 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 4219 | ndlp->nlp_DID, vport->port_state, |
| 4220 | ndlp->nlp_flag); |
| 4221 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4222 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4223 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4224 | return 0; |
| 4225 | } |
| 4226 | } |
| 4227 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4228 | spin_lock_irq(shost->host_lock); |
| 4229 | if (vport->fc_rscn_flush) { |
| 4230 | /* Another thread is walking fc_rscn_id_list on this vport */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4231 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 4232 | spin_unlock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4233 | /* Send back ACC */ |
| 4234 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4235 | return 0; |
| 4236 | } |
| 4237 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4238 | vport->fc_rscn_flush = 1; |
| 4239 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4240 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4241 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4242 | /* If we are already processing an RSCN, save the received |
| 4243 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 4244 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4245 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4246 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4247 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 4248 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4249 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4250 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4251 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 4252 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4253 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4254 | vport->fc_flag |= FC_RSCN_MODE; |
| 4255 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4256 | if (rscn_cnt) { |
| 4257 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 4258 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 4259 | } |
| 4260 | if ((rscn_cnt) && |
| 4261 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 4262 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4263 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4264 | memcpy(((uint8_t *)cmd) + length, lp, |
| 4265 | payload_len); |
| 4266 | } else { |
| 4267 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 4268 | vport->fc_rscn_id_cnt++; |
| 4269 | /* If we zero, cmdiocb->context2, the calling |
| 4270 | * routine will not try to free it. |
| 4271 | */ |
| 4272 | cmdiocb->context2 = NULL; |
| 4273 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4274 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4275 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4276 | "0235 Deferred RSCN " |
| 4277 | "Data: x%x x%x x%x\n", |
| 4278 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4279 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4280 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4281 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 4282 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4283 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4284 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4285 | "0234 ReDiscovery RSCN " |
| 4286 | "Data: x%x x%x x%x\n", |
| 4287 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4288 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4289 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4290 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4291 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4292 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4293 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4294 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4295 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4296 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4297 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4298 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4299 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4300 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4301 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4302 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 4303 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4304 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4305 | spin_lock_irq(shost->host_lock); |
| 4306 | vport->fc_flag |= FC_RSCN_MODE; |
| 4307 | spin_unlock_irq(shost->host_lock); |
| 4308 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4309 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4310 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4311 | /* |
| 4312 | * If we zero, cmdiocb->context2, the calling routine will |
| 4313 | * not try to free it. |
| 4314 | */ |
| 4315 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4316 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4317 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4318 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4319 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4320 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4321 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4322 | } |
| 4323 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4324 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4325 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4326 | * @vport: pointer to a host virtual N_Port data structure. |
| 4327 | * |
| 4328 | * This routine handles the Registration State Configuration Notification |
| 4329 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 4330 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 4331 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 4332 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 4333 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 4334 | * RSCN activities with the @vport. |
| 4335 | * |
| 4336 | * Return code |
| 4337 | * 0 - Cleaned up rscn on the @vport |
| 4338 | * 1 - Wait for plogi to name server before proceed |
| 4339 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4340 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4341 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4342 | { |
| 4343 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4344 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4345 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4346 | /* Ignore RSCN if the port is being torn down. */ |
| 4347 | if (vport->load_flag & FC_UNLOADING) { |
| 4348 | lpfc_els_flush_rscn(vport); |
| 4349 | return 0; |
| 4350 | } |
| 4351 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4352 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4353 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4354 | |
| 4355 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4356 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4357 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 4358 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 4359 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4360 | |
| 4361 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4362 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4363 | vport->num_disc_nodes = 0; |
| 4364 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4365 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4366 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 4367 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4368 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4369 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4370 | /* Wait for NameServer query cmpl before we can |
| 4371 | continue */ |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4372 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4373 | } else { |
| 4374 | /* If login to NameServer does not exist, issue one */ |
| 4375 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4376 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4377 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4378 | /* Wait for NameServer login cmpl before we can |
| 4379 | continue */ |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4380 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4381 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4382 | if (ndlp) { |
| 4383 | ndlp = lpfc_enable_node(vport, ndlp, |
| 4384 | NLP_STE_PLOGI_ISSUE); |
| 4385 | if (!ndlp) { |
| 4386 | lpfc_els_flush_rscn(vport); |
| 4387 | return 0; |
| 4388 | } |
| 4389 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4390 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4391 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4392 | if (!ndlp) { |
| 4393 | lpfc_els_flush_rscn(vport); |
| 4394 | return 0; |
| 4395 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4396 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4397 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4398 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4399 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4400 | ndlp->nlp_type |= NLP_FABRIC; |
| 4401 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 4402 | /* Wait for NameServer login cmpl before we can |
| 4403 | * continue |
| 4404 | */ |
| 4405 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4406 | } |
| 4407 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4408 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4409 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4410 | } |
| 4411 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4412 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4413 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4414 | * @vport: pointer to a host virtual N_Port data structure. |
| 4415 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4416 | * @ndlp: pointer to a node-list data structure. |
| 4417 | * |
| 4418 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 4419 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 4420 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 4421 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 4422 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 4423 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 4424 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 4425 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 4426 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 4427 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 4428 | * higher priority (as the winning port) and will initiate PLOGI and |
| 4429 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 4430 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 4431 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 4432 | * |
| 4433 | * Return code |
| 4434 | * 0 - Successfully processed the unsolicited flogi |
| 4435 | * 1 - Failed to process the unsolicited flogi |
| 4436 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4437 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4438 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4439 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4440 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4441 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4442 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4443 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4444 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 4445 | IOCB_t *icmd = &cmdiocb->iocb; |
| 4446 | struct serv_parm *sp; |
| 4447 | LPFC_MBOXQ_t *mbox; |
| 4448 | struct ls_rjt stat; |
| 4449 | uint32_t cmd, did; |
| 4450 | int rc; |
| 4451 | |
| 4452 | cmd = *lp++; |
| 4453 | sp = (struct serv_parm *) lp; |
| 4454 | |
| 4455 | /* FLOGI received */ |
| 4456 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4457 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4458 | |
| 4459 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 4460 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 4461 | did = icmd->un.elsreq64.remoteID; |
| 4462 | |
| 4463 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 4464 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4465 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4466 | "0113 An FLOGI ELS command x%x was " |
| 4467 | "received from DID x%x in Loop Mode\n", |
| 4468 | cmd, did); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4469 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4470 | } |
| 4471 | |
| 4472 | did = Fabric_DID; |
| 4473 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 4474 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4475 | /* For a FLOGI we accept, then if our portname is greater |
| 4476 | * then the remote portname we initiate Nport login. |
| 4477 | */ |
| 4478 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4479 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4480 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4481 | |
| 4482 | if (!rc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4483 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4484 | if (!mbox) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4485 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4486 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4487 | lpfc_linkdown(phba); |
| 4488 | lpfc_init_link(phba, mbox, |
| 4489 | phba->cfg_topology, |
| 4490 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4491 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4492 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4493 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4494 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4495 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4496 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4497 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4498 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4499 | return 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4500 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4501 | spin_lock_irq(shost->host_lock); |
| 4502 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 4503 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4504 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4505 | spin_lock_irq(shost->host_lock); |
| 4506 | vport->fc_flag |= FC_PT2PT; |
| 4507 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 4508 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4509 | } else { |
| 4510 | /* Reject this request because invalid parameters */ |
| 4511 | stat.un.b.lsRjtRsvd0 = 0; |
| 4512 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4513 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 4514 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4515 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4516 | NULL); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4517 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4518 | } |
| 4519 | |
| 4520 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4521 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4522 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4523 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4524 | } |
| 4525 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4526 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4527 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4528 | * @vport: pointer to a host virtual N_Port data structure. |
| 4529 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4530 | * @ndlp: pointer to a node-list data structure. |
| 4531 | * |
| 4532 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 4533 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 4534 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 4535 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 4536 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 4537 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 4538 | * |
| 4539 | * Return code |
| 4540 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 4541 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4542 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4543 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4544 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4545 | { |
| 4546 | struct lpfc_dmabuf *pcmd; |
| 4547 | uint32_t *lp; |
| 4548 | IOCB_t *icmd; |
| 4549 | RNID *rn; |
| 4550 | struct ls_rjt stat; |
| 4551 | uint32_t cmd, did; |
| 4552 | |
| 4553 | icmd = &cmdiocb->iocb; |
| 4554 | did = icmd->un.elsreq64.remoteID; |
| 4555 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4556 | lp = (uint32_t *) pcmd->virt; |
| 4557 | |
| 4558 | cmd = *lp++; |
| 4559 | rn = (RNID *) lp; |
| 4560 | |
| 4561 | /* RNID received */ |
| 4562 | |
| 4563 | switch (rn->Format) { |
| 4564 | case 0: |
| 4565 | case RNID_TOPOLOGY_DISC: |
| 4566 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4567 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4568 | break; |
| 4569 | default: |
| 4570 | /* Reject this request because format not supported */ |
| 4571 | stat.un.b.lsRjtRsvd0 = 0; |
| 4572 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4573 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4574 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4575 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4576 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4577 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4578 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4579 | } |
| 4580 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4581 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4582 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4583 | * @vport: pointer to a host virtual N_Port data structure. |
| 4584 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4585 | * @ndlp: pointer to a node-list data structure. |
| 4586 | * |
| 4587 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 4588 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 4589 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 4590 | * |
| 4591 | * Return code |
| 4592 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 4593 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4594 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4595 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4596 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4597 | { |
| 4598 | struct ls_rjt stat; |
| 4599 | |
| 4600 | /* For now, unconditionally reject this command */ |
| 4601 | stat.un.b.lsRjtRsvd0 = 0; |
| 4602 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4603 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4604 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4605 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4606 | return 0; |
| 4607 | } |
| 4608 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4609 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4610 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb |
| 4611 | * @vport: pointer to a host virtual N_Port data structure. |
| 4612 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4613 | * @ndlp: pointer to a node-list data structure. |
| 4614 | * |
| 4615 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB |
| 4616 | * received as an ELS unsolicited event. A request to RRQ shall only |
| 4617 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder |
| 4618 | * Nx_Port N_Port_ID of the target Exchange is the same as the |
| 4619 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is |
| 4620 | * not accepted, an LS_RJT with reason code "Unable to perform |
| 4621 | * command request" and reason code explanation "Invalid Originator |
| 4622 | * S_ID" shall be returned. For now, we just unconditionally accept |
| 4623 | * RRQ from the target. |
| 4624 | **/ |
| 4625 | static void |
| 4626 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4627 | struct lpfc_nodelist *ndlp) |
| 4628 | { |
| 4629 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| 4630 | } |
| 4631 | |
| 4632 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4633 | * 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] | 4634 | * @phba: pointer to lpfc hba data structure. |
| 4635 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4636 | * |
| 4637 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 4638 | * mailbox command. This callback function is to actually send the Accept |
| 4639 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 4640 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 4641 | * mailbox command, constructs the RPS response with the link statistics |
| 4642 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 4643 | * response to the RPS. |
| 4644 | * |
| 4645 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4646 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4647 | * will be stored into the context1 field of the IOCB for the completion |
| 4648 | * callback function to the RPS Accept Response ELS IOCB command. |
| 4649 | * |
| 4650 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4651 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4652 | 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] | 4653 | { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4654 | MAILBOX_t *mb; |
| 4655 | IOCB_t *icmd; |
| 4656 | RPS_RSP *rps_rsp; |
| 4657 | uint8_t *pcmd; |
| 4658 | struct lpfc_iocbq *elsiocb; |
| 4659 | struct lpfc_nodelist *ndlp; |
| 4660 | uint16_t xri, status; |
| 4661 | uint32_t cmdsize; |
| 4662 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4663 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4664 | |
| 4665 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4666 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 4667 | pmb->context1 = NULL; |
| 4668 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4669 | |
| 4670 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4671 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4672 | return; |
| 4673 | } |
| 4674 | |
| 4675 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4676 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4677 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 4678 | lpfc_max_els_tries, ndlp, |
| 4679 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4680 | |
| 4681 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4682 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4683 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4684 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4685 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4686 | |
| 4687 | icmd = &elsiocb->iocb; |
| 4688 | icmd->ulpContext = xri; |
| 4689 | |
| 4690 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4691 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4692 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4693 | rps_rsp = (RPS_RSP *)pcmd; |
| 4694 | |
| 4695 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| 4696 | status = 0x10; |
| 4697 | else |
| 4698 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4699 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4700 | status |= 0x4; |
| 4701 | |
| 4702 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4703 | rps_rsp->portStatus = cpu_to_be16(status); |
| 4704 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 4705 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 4706 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 4707 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 4708 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 4709 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4710 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4711 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 4712 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 4713 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4714 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4715 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4716 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4717 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4718 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4719 | 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] | 4720 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4721 | return; |
| 4722 | } |
| 4723 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4724 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4725 | * lpfc_els_rcv_rps - Process an unsolicited rps iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4726 | * @vport: pointer to a host virtual N_Port data structure. |
| 4727 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4728 | * @ndlp: pointer to a node-list data structure. |
| 4729 | * |
| 4730 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 4731 | * ELS unsolicited event. It first checks the remote port state. If the |
| 4732 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 4733 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 4734 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 4735 | * for reading the HBA link statistics. It is for the callback function, |
| 4736 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 4737 | * to actually sending out RPS Accept (ACC) response. |
| 4738 | * |
| 4739 | * Return codes |
| 4740 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 4741 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4742 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4743 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4744 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4745 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4746 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4747 | uint32_t *lp; |
| 4748 | uint8_t flag; |
| 4749 | LPFC_MBOXQ_t *mbox; |
| 4750 | struct lpfc_dmabuf *pcmd; |
| 4751 | RPS *rps; |
| 4752 | struct ls_rjt stat; |
| 4753 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4754 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4755 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 4756 | /* reject the unsolicited RPS request and done with it */ |
| 4757 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4758 | |
| 4759 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4760 | lp = (uint32_t *) pcmd->virt; |
| 4761 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 4762 | rps = (RPS *) lp; |
| 4763 | |
| 4764 | if ((flag == 0) || |
| 4765 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4766 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4767 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4768 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4769 | printk("Fix me....\n"); |
| 4770 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4771 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 4772 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4773 | lpfc_read_lnk_stat(phba, mbox); |
| 4774 | mbox->context1 = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4775 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4776 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4777 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4778 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4779 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4780 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4781 | /* Mbox completion will send ELS Response */ |
| 4782 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4783 | /* Decrement reference count used for the failed mbox |
| 4784 | * command. |
| 4785 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4786 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4787 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4788 | } |
| 4789 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4790 | |
| 4791 | reject_out: |
| 4792 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4793 | stat.un.b.lsRjtRsvd0 = 0; |
| 4794 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4795 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4796 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4797 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4798 | return 0; |
| 4799 | } |
| 4800 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4801 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4802 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4803 | * @vport: pointer to a host virtual N_Port data structure. |
| 4804 | * @cmdsize: size of the ELS command. |
| 4805 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4806 | * @ndlp: pointer to a node-list data structure. |
| 4807 | * |
| 4808 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 4809 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 4810 | * |
| 4811 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4812 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4813 | * will be stored into the context1 field of the IOCB for the completion |
| 4814 | * callback function to the RPL Accept Response ELS command. |
| 4815 | * |
| 4816 | * Return code |
| 4817 | * 0 - Successfully issued ACC RPL ELS command |
| 4818 | * 1 - Failed to issue ACC RPL ELS command |
| 4819 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4820 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4821 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 4822 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4823 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4824 | struct lpfc_hba *phba = vport->phba; |
| 4825 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4826 | RPL_RSP rpl_rsp; |
| 4827 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4828 | uint8_t *pcmd; |
| 4829 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4830 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4831 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4832 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4833 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4834 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4835 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4836 | icmd = &elsiocb->iocb; |
| 4837 | oldcmd = &oldiocb->iocb; |
| 4838 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 4839 | |
| 4840 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4841 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4842 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4843 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 4844 | pcmd += sizeof(uint16_t); |
| 4845 | |
| 4846 | /* Setup the RPL ACC payload */ |
| 4847 | rpl_rsp.listLen = be32_to_cpu(1); |
| 4848 | rpl_rsp.index = 0; |
| 4849 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4850 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 4851 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4852 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4853 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4854 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4855 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4856 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 4857 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 4858 | "rpi x%x\n", |
| 4859 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4860 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4861 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4862 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4863 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4864 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 4865 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4866 | lpfc_els_free_iocb(phba, elsiocb); |
| 4867 | return 1; |
| 4868 | } |
| 4869 | return 0; |
| 4870 | } |
| 4871 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4872 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4873 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4874 | * @vport: pointer to a host virtual N_Port data structure. |
| 4875 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4876 | * @ndlp: pointer to a node-list data structure. |
| 4877 | * |
| 4878 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 4879 | * unsolicited event. It first checks the remote port state. If the remote |
| 4880 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 4881 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 4882 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 4883 | * to accept the RPL. |
| 4884 | * |
| 4885 | * Return code |
| 4886 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 4887 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4888 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4889 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4890 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4891 | { |
| 4892 | struct lpfc_dmabuf *pcmd; |
| 4893 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4894 | uint32_t maxsize; |
| 4895 | uint16_t cmdsize; |
| 4896 | RPL *rpl; |
| 4897 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4898 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4899 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 4900 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4901 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4902 | stat.un.b.lsRjtRsvd0 = 0; |
| 4903 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4904 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4905 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4906 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4907 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4908 | /* rejected the unsolicited RPL request and done with it */ |
| 4909 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4910 | } |
| 4911 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4912 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4913 | lp = (uint32_t *) pcmd->virt; |
| 4914 | rpl = (RPL *) (lp + 1); |
| 4915 | |
| 4916 | maxsize = be32_to_cpu(rpl->maxsize); |
| 4917 | |
| 4918 | /* We support only one port */ |
| 4919 | if ((rpl->index == 0) && |
| 4920 | ((maxsize == 0) || |
| 4921 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 4922 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4923 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4924 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 4925 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4926 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4927 | |
| 4928 | return 0; |
| 4929 | } |
| 4930 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4931 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4932 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4933 | * @vport: pointer to a virtual N_Port data structure. |
| 4934 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4935 | * @ndlp: pointer to a node-list data structure. |
| 4936 | * |
| 4937 | * This routine processes Fibre Channel Address Resolution Protocol |
| 4938 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 4939 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 4940 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 4941 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 4942 | * remote PortName is compared against the FC PortName stored in the @vport |
| 4943 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 4944 | * compared against the FC NodeName stored in the @vport data structure. |
| 4945 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 4946 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 4947 | * invoked to send out FARP Response to the remote node. Before sending the |
| 4948 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 4949 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 4950 | * routine is invoked to log into the remote port first. |
| 4951 | * |
| 4952 | * Return code |
| 4953 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 4954 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4955 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4956 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4957 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4958 | { |
| 4959 | struct lpfc_dmabuf *pcmd; |
| 4960 | uint32_t *lp; |
| 4961 | IOCB_t *icmd; |
| 4962 | FARP *fp; |
| 4963 | uint32_t cmd, cnt, did; |
| 4964 | |
| 4965 | icmd = &cmdiocb->iocb; |
| 4966 | did = icmd->un.elsreq64.remoteID; |
| 4967 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4968 | lp = (uint32_t *) pcmd->virt; |
| 4969 | |
| 4970 | cmd = *lp++; |
| 4971 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4972 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4973 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4974 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4975 | /* We will only support match on WWPN or WWNN */ |
| 4976 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4977 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4978 | } |
| 4979 | |
| 4980 | cnt = 0; |
| 4981 | /* If this FARP command is searching for my portname */ |
| 4982 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4983 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4984 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4985 | cnt = 1; |
| 4986 | } |
| 4987 | |
| 4988 | /* If this FARP command is searching for my nodename */ |
| 4989 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4990 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4991 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4992 | cnt = 1; |
| 4993 | } |
| 4994 | |
| 4995 | if (cnt) { |
| 4996 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 4997 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 4998 | /* Log back into the node before sending the FARP. */ |
| 4999 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5000 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5001 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 5002 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5003 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5004 | } |
| 5005 | |
| 5006 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5007 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 5008 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5009 | } |
| 5010 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5011 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5012 | } |
| 5013 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5014 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5015 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5016 | * @vport: pointer to a host virtual N_Port data structure. |
| 5017 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5018 | * @ndlp: pointer to a node-list data structure. |
| 5019 | * |
| 5020 | * This routine processes Fibre Channel Address Resolution Protocol |
| 5021 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 5022 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 5023 | * the FARP response request. |
| 5024 | * |
| 5025 | * Return code |
| 5026 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 5027 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5028 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5029 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5030 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5031 | { |
| 5032 | struct lpfc_dmabuf *pcmd; |
| 5033 | uint32_t *lp; |
| 5034 | IOCB_t *icmd; |
| 5035 | uint32_t cmd, did; |
| 5036 | |
| 5037 | icmd = &cmdiocb->iocb; |
| 5038 | did = icmd->un.elsreq64.remoteID; |
| 5039 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 5040 | lp = (uint32_t *) pcmd->virt; |
| 5041 | |
| 5042 | cmd = *lp++; |
| 5043 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5044 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5045 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5046 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5047 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5048 | |
| 5049 | return 0; |
| 5050 | } |
| 5051 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5052 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5053 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5054 | * @vport: pointer to a host virtual N_Port data structure. |
| 5055 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5056 | * @fan_ndlp: pointer to a node-list data structure. |
| 5057 | * |
| 5058 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 5059 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 5060 | * only be processed on a physical port (i.e., the @vport represents the |
| 5061 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 5062 | * compared against those in the phba data structure. If any of those is |
| 5063 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 5064 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 5065 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 5066 | * is invoked to register login to the fabric. |
| 5067 | * |
| 5068 | * Return code |
| 5069 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 5070 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5071 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5072 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 5073 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5074 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5075 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5076 | uint32_t *lp; |
| 5077 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5078 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5079 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 5080 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 5081 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5082 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5083 | if ((vport == phba->pport) && |
| 5084 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5085 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5086 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5087 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5088 | sizeof(struct lpfc_name)))) { |
| 5089 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5090 | lpfc_initial_flogi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5091 | } else { |
| 5092 | /* FAN verified - skip FLOGI */ |
| 5093 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5094 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5095 | lpfc_issue_fabric_reglogin(vport); |
| 5096 | else |
| 5097 | lpfc_issue_reg_vfi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5098 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5099 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5100 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 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_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5105 | * @ptr: holder for the timer function associated data. |
| 5106 | * |
| 5107 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 5108 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 5109 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 5110 | * up the worker thread. It is for the worker thread to invoke the routine |
| 5111 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 5112 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5113 | void |
| 5114 | lpfc_els_timeout(unsigned long ptr) |
| 5115 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5116 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 5117 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5118 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5119 | unsigned long iflag; |
| 5120 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5121 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5122 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
| 5123 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5124 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5125 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5126 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5127 | if (!tmo_posted) |
| 5128 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5129 | return; |
| 5130 | } |
| 5131 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5132 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5133 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5134 | * @vport: pointer to a virtual N_Port data structure. |
| 5135 | * |
| 5136 | * This routine is the actual handler function that processes an ELS timeout |
| 5137 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 5138 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 5139 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5140 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5141 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5142 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5143 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5144 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5145 | struct lpfc_sli_ring *pring; |
| 5146 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5147 | IOCB_t *cmd = NULL; |
| 5148 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5149 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5150 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5151 | uint32_t remote_ID = 0xffffffff; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5152 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5153 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5154 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 5155 | |
| 5156 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5157 | |
| 5158 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5159 | cmd = &piocb->iocb; |
| 5160 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5161 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 5162 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 5163 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5164 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5165 | |
| 5166 | if (piocb->vport != vport) |
| 5167 | continue; |
| 5168 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5169 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5170 | if (pcmd) |
| 5171 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5172 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5173 | if (els_command == ELS_CMD_FARP || |
| 5174 | els_command == ELS_CMD_FARPR || |
| 5175 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5176 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5177 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5178 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5179 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5180 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5181 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5182 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5183 | continue; |
| 5184 | } |
| 5185 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5186 | remote_ID = 0xffffffff; |
| 5187 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5188 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5189 | else { |
| 5190 | struct lpfc_nodelist *ndlp; |
| 5191 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5192 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5193 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5194 | } |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5195 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5196 | "0127 ELS timeout Data: x%x x%x x%x " |
| 5197 | "x%x\n", els_command, |
| 5198 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5199 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5200 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5201 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 5202 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5203 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
| 5204 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5205 | } |
| 5206 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5207 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5208 | * 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] | 5209 | * @vport: pointer to a host virtual N_Port data structure. |
| 5210 | * |
| 5211 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5212 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 5213 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5214 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5215 | * the IOCBs with a non-NULL completion callback function, the callback |
| 5216 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5217 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 5218 | * callback function, the IOCB will simply be released. Finally, it walks |
| 5219 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 5220 | * completion queue IOCB that is associated with the @vport and is not |
| 5221 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 5222 | * part of the discovery state machine) out to HBA by invoking the |
| 5223 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 5224 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 5225 | * the IOCBs are aborted when this function returns. |
| 5226 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5227 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5228 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5229 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5230 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5231 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5232 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5233 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5234 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5235 | |
| 5236 | lpfc_fabric_abort_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5237 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5238 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5239 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5240 | cmd = &piocb->iocb; |
| 5241 | |
| 5242 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5243 | continue; |
| 5244 | } |
| 5245 | |
| 5246 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5247 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5248 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5249 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5250 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5251 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5252 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5253 | if (piocb->vport != vport) |
| 5254 | continue; |
| 5255 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5256 | list_move_tail(&piocb->list, &completions); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5257 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5258 | } |
| 5259 | |
| 5260 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5261 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5262 | continue; |
| 5263 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5264 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5265 | if (piocb->vport != vport) |
| 5266 | continue; |
| 5267 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5268 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5269 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5270 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5271 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5272 | /* Cancell all the IOCBs from the completions list */ |
| 5273 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5274 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5275 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5276 | return; |
| 5277 | } |
| 5278 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5279 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5280 | * 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] | 5281 | * @phba: pointer to lpfc hba data structure. |
| 5282 | * |
| 5283 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5284 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 5285 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5286 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5287 | * the IOCBs with the completion callback function associated, the callback |
| 5288 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5289 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 5290 | * callback function associated, the IOCB will simply be released. Finally, |
| 5291 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 5292 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 5293 | * management plane IOCBs that are not part of the discovery state machine) |
| 5294 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5295 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5296 | void |
| 5297 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 5298 | { |
| 5299 | LIST_HEAD(completions); |
| 5300 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 5301 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5302 | IOCB_t *cmd = NULL; |
| 5303 | |
| 5304 | lpfc_fabric_abort_hba(phba); |
| 5305 | spin_lock_irq(&phba->hbalock); |
| 5306 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5307 | cmd = &piocb->iocb; |
| 5308 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5309 | continue; |
| 5310 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
| 5311 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5312 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5313 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5314 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| 5315 | continue; |
| 5316 | list_move_tail(&piocb->list, &completions); |
| 5317 | pring->txq_cnt--; |
| 5318 | } |
| 5319 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5320 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5321 | continue; |
| 5322 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5323 | } |
| 5324 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5325 | |
| 5326 | /* Cancel all the IOCBs from the completions list */ |
| 5327 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5328 | IOERR_SLI_ABORTED); |
| 5329 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5330 | return; |
| 5331 | } |
| 5332 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5333 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5334 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5335 | * @phba: Pointer to hba context object. |
| 5336 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 5337 | * @rspiocbp: Pointer to response iocb which reported error. |
| 5338 | * |
| 5339 | * This function sends an event when there is an ELS command |
| 5340 | * failure. |
| 5341 | **/ |
| 5342 | void |
| 5343 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 5344 | struct lpfc_iocbq *cmdiocbp, |
| 5345 | struct lpfc_iocbq *rspiocbp) |
| 5346 | { |
| 5347 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 5348 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5349 | struct lpfc_lsrjt_event lsrjt_event; |
| 5350 | struct lpfc_fabric_event_header fabric_event; |
| 5351 | struct ls_rjt stat; |
| 5352 | struct lpfc_nodelist *ndlp; |
| 5353 | uint32_t *pcmd; |
| 5354 | |
| 5355 | ndlp = cmdiocbp->context1; |
| 5356 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 5357 | return; |
| 5358 | |
| 5359 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 5360 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 5361 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 5362 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 5363 | sizeof(struct lpfc_name)); |
| 5364 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 5365 | sizeof(struct lpfc_name)); |
| 5366 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 5367 | cmdiocbp->context2)->virt); |
| 5368 | lsrjt_event.command = *pcmd; |
| 5369 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 5370 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 5371 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 5372 | fc_host_post_vendor_event(shost, |
| 5373 | fc_get_event_number(), |
| 5374 | sizeof(lsrjt_event), |
| 5375 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5376 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5377 | return; |
| 5378 | } |
| 5379 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 5380 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 5381 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 5382 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 5383 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 5384 | else |
| 5385 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 5386 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 5387 | sizeof(struct lpfc_name)); |
| 5388 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 5389 | sizeof(struct lpfc_name)); |
| 5390 | fc_host_post_vendor_event(shost, |
| 5391 | fc_get_event_number(), |
| 5392 | sizeof(fabric_event), |
| 5393 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5394 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5395 | return; |
| 5396 | } |
| 5397 | |
| 5398 | } |
| 5399 | |
| 5400 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5401 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5402 | * @vport: Pointer to vport object. |
| 5403 | * @ndlp: Pointer FC node object. |
| 5404 | * @cmd: ELS command code. |
| 5405 | * |
| 5406 | * This function posts an event when there is an incoming |
| 5407 | * unsolicited ELS command. |
| 5408 | **/ |
| 5409 | static void |
| 5410 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 5411 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5412 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5413 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5414 | struct lpfc_els_event_header *els_data = NULL; |
| 5415 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5416 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5417 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5418 | if (*payload == ELS_CMD_LOGO) { |
| 5419 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 5420 | if (!logo_data) { |
| 5421 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5422 | "0148 Failed to allocate memory " |
| 5423 | "for LOGO event\n"); |
| 5424 | return; |
| 5425 | } |
| 5426 | els_data = &logo_data->header; |
| 5427 | } else { |
| 5428 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 5429 | GFP_KERNEL); |
| 5430 | if (!els_data) { |
| 5431 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5432 | "0149 Failed to allocate memory " |
| 5433 | "for ELS event\n"); |
| 5434 | return; |
| 5435 | } |
| 5436 | } |
| 5437 | els_data->event_type = FC_REG_ELS_EVENT; |
| 5438 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5439 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5440 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5441 | break; |
| 5442 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5443 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5444 | break; |
| 5445 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5446 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 5447 | break; |
| 5448 | case ELS_CMD_LOGO: |
| 5449 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 5450 | /* Copy the WWPN in the LOGO payload */ |
| 5451 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 5452 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5453 | break; |
| 5454 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 5455 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5456 | return; |
| 5457 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5458 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 5459 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 5460 | if (*payload == ELS_CMD_LOGO) { |
| 5461 | fc_host_post_vendor_event(shost, |
| 5462 | fc_get_event_number(), |
| 5463 | sizeof(struct lpfc_logo_event), |
| 5464 | (char *)logo_data, |
| 5465 | LPFC_NL_VENDOR_ID); |
| 5466 | kfree(logo_data); |
| 5467 | } else { |
| 5468 | fc_host_post_vendor_event(shost, |
| 5469 | fc_get_event_number(), |
| 5470 | sizeof(struct lpfc_els_event_header), |
| 5471 | (char *)els_data, |
| 5472 | LPFC_NL_VENDOR_ID); |
| 5473 | kfree(els_data); |
| 5474 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5475 | |
| 5476 | return; |
| 5477 | } |
| 5478 | |
| 5479 | |
| 5480 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5481 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5482 | * @phba: pointer to lpfc hba data structure. |
| 5483 | * @pring: pointer to a SLI ring. |
| 5484 | * @vport: pointer to a host virtual N_Port data structure. |
| 5485 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 5486 | * |
| 5487 | * This routine is used for processing the IOCB associated with a unsolicited |
| 5488 | * event. It first determines whether there is an existing ndlp that matches |
| 5489 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 5490 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 5491 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 5492 | * of the discovery state machine. |
| 5493 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5494 | static void |
| 5495 | 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] | 5496 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5497 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5498 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5499 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5500 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5501 | uint32_t *payload; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5502 | uint32_t cmd, did, newnode, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5503 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5504 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5505 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5506 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5507 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5508 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5509 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 5510 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5511 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5512 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5513 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5514 | did = icmd->un.rcvels.remoteID; |
| 5515 | if (icmd->ulpStatus) { |
| 5516 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5517 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 5518 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5519 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5520 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5521 | |
| 5522 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5523 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5524 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5525 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 5526 | /* Ignore traffic received during vport shutdown. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5527 | if (vport->load_flag & FC_UNLOADING) |
| 5528 | goto dropit; |
| 5529 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5530 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5531 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5532 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5533 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5534 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5535 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5536 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5537 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5538 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5539 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5540 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5541 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5542 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5543 | ndlp = lpfc_enable_node(vport, ndlp, |
| 5544 | NLP_STE_UNUSED_NODE); |
| 5545 | if (!ndlp) |
| 5546 | goto dropit; |
| 5547 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5548 | newnode = 1; |
| 5549 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 5550 | ndlp->nlp_type |= NLP_FABRIC; |
| 5551 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 5552 | /* This is similar to the new node path */ |
| 5553 | ndlp = lpfc_nlp_get(ndlp); |
| 5554 | if (!ndlp) |
| 5555 | goto dropit; |
| 5556 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5557 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5558 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5559 | |
| 5560 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5561 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5562 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5563 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5564 | |
| 5565 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 5566 | cmd &= ELS_CMD_MASK; |
| 5567 | } |
| 5568 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5569 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5570 | "0112 ELS command x%x received from NPORT x%x " |
| 5571 | "Data: x%x\n", cmd, did, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5572 | switch (cmd) { |
| 5573 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5574 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5575 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 5576 | did, vport->port_state, ndlp->nlp_flag); |
| 5577 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5578 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5579 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
| 5580 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5581 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5582 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5583 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 5584 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 5585 | rjt_err = LSRJT_UNABLE_TPC; |
| 5586 | break; |
| 5587 | } |
| 5588 | /* We get here, and drop thru, if we are PT2PT with |
| 5589 | * another NPort and the other side has initiated |
| 5590 | * the PLOGI before responding to our FLOGI. |
| 5591 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5592 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5593 | |
| 5594 | shost = lpfc_shost_from_vport(vport); |
| 5595 | spin_lock_irq(shost->host_lock); |
| 5596 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 5597 | spin_unlock_irq(shost->host_lock); |
| 5598 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5599 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5600 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5601 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5602 | break; |
| 5603 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5604 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5605 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 5606 | did, vport->port_state, ndlp->nlp_flag); |
| 5607 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5608 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5609 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5610 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5611 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5612 | break; |
| 5613 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5614 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5615 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 5616 | did, vport->port_state, ndlp->nlp_flag); |
| 5617 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5618 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5619 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5620 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5621 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5622 | break; |
| 5623 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5624 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5625 | break; |
| 5626 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5627 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5628 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 5629 | did, vport->port_state, ndlp->nlp_flag); |
| 5630 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5631 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5632 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5633 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5634 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5635 | break; |
| 5636 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5637 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5638 | break; |
| 5639 | case ELS_CMD_RSCN: |
| 5640 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5641 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5642 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5643 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5644 | break; |
| 5645 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5646 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5647 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 5648 | did, vport->port_state, ndlp->nlp_flag); |
| 5649 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5650 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5651 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5652 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5653 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5654 | break; |
| 5655 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5656 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5657 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5658 | break; |
| 5659 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5660 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5661 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 5662 | did, vport->port_state, ndlp->nlp_flag); |
| 5663 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5664 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5665 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5666 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5667 | break; |
| 5668 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5669 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5670 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5671 | break; |
| 5672 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5673 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5674 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 5675 | did, vport->port_state, ndlp->nlp_flag); |
| 5676 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5677 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5678 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5679 | break; |
| 5680 | case ELS_CMD_FARP: |
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 FARP: 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.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5686 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5687 | break; |
| 5688 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5689 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5690 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 5691 | did, vport->port_state, ndlp->nlp_flag); |
| 5692 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5693 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5694 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5695 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5696 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5697 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5698 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 5699 | did, vport->port_state, ndlp->nlp_flag); |
| 5700 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5701 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5702 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5703 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5704 | break; |
| 5705 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5706 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5707 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5708 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5709 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5710 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 5711 | did, vport->port_state, ndlp->nlp_flag); |
| 5712 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5713 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5714 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5715 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5716 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5717 | break; |
| 5718 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5719 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5720 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 5721 | did, vport->port_state, ndlp->nlp_flag); |
| 5722 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5723 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5724 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5725 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5726 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5727 | break; |
| 5728 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5729 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5730 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 5731 | did, vport->port_state, ndlp->nlp_flag); |
| 5732 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5733 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5734 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5735 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5736 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5737 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5738 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5739 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5740 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 5741 | did, vport->port_state, ndlp->nlp_flag); |
| 5742 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5743 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5744 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5745 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5746 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5747 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 5748 | case ELS_CMD_RRQ: |
| 5749 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5750 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", |
| 5751 | did, vport->port_state, ndlp->nlp_flag); |
| 5752 | |
| 5753 | phba->fc_stat.elsRcvRRQ++; |
| 5754 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); |
| 5755 | if (newnode) |
| 5756 | lpfc_nlp_put(ndlp); |
| 5757 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5758 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5759 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5760 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 5761 | cmd, did, vport->port_state); |
| 5762 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5763 | /* Unsupported ELS command, reject */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5764 | rjt_err = LSRJT_INVALID_CMD; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5765 | |
| 5766 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5767 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5768 | "0115 Unknown ELS command x%x " |
| 5769 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5770 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5771 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5772 | break; |
| 5773 | } |
| 5774 | |
| 5775 | /* check if need to LS_RJT received ELS cmd */ |
| 5776 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5777 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5778 | stat.un.b.lsRjtRsnCode = rjt_err; |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 5779 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5780 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 5781 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5782 | } |
| 5783 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5784 | lpfc_nlp_put(elsiocb->context1); |
| 5785 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5786 | return; |
| 5787 | |
| 5788 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5789 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5790 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5791 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5792 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5793 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5794 | phba->fc_stat.elsRcvDrop++; |
| 5795 | } |
| 5796 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5797 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5798 | * 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] | 5799 | * @phba: pointer to lpfc hba data structure. |
| 5800 | * @vpi: host virtual N_Port identifier. |
| 5801 | * |
| 5802 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 5803 | * @vpi. The function walks the HBA's vport list and returns the address |
| 5804 | * of the vport with the matching @vpi. |
| 5805 | * |
| 5806 | * Return code |
| 5807 | * NULL - No vport with the matching @vpi found |
| 5808 | * Otherwise - Address to the vport with the matching @vpi. |
| 5809 | **/ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5810 | struct lpfc_vport * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5811 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 5812 | { |
| 5813 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5814 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5815 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5816 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5817 | list_for_each_entry(vport, &phba->port_list, listentry) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5818 | if (vport->vpi == vpi) { |
| 5819 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5820 | return vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5821 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5822 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5823 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5824 | return NULL; |
| 5825 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5826 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5827 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5828 | * 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] | 5829 | * @phba: pointer to lpfc hba data structure. |
| 5830 | * @pring: pointer to a SLI ring. |
| 5831 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 5832 | * |
| 5833 | * This routine is used to process an unsolicited event received from a SLI |
| 5834 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 5835 | * associated with the unsolicited event is done by invoking the routine |
| 5836 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 5837 | * SLI ring on which the unsolicited event was received. |
| 5838 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5839 | void |
| 5840 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 5841 | struct lpfc_iocbq *elsiocb) |
| 5842 | { |
| 5843 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5844 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5845 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5846 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 5847 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5848 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5849 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5850 | elsiocb->context2 = NULL; |
| 5851 | elsiocb->context3 = NULL; |
| 5852 | |
| 5853 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 5854 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 5855 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 5856 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5857 | phba->fc_stat.NoRcvBuf++; |
| 5858 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5859 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5860 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5861 | return; |
| 5862 | } |
| 5863 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5864 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 5865 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 5866 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 5867 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 5868 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5869 | else |
| 5870 | vport = lpfc_find_vport_by_vpid(phba, |
| 5871 | icmd->unsli3.rcvsli3.vpi - phba->vpi_base); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5872 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5873 | /* If there are no BDEs associated |
| 5874 | * with this IOCB, there is nothing to do. |
| 5875 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5876 | if (icmd->ulpBdeCount == 0) |
| 5877 | return; |
| 5878 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5879 | /* type of ELS cmd is first 32bit word |
| 5880 | * in packet |
| 5881 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5882 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5883 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5884 | } else { |
| 5885 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 5886 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5887 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 5888 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5889 | } |
| 5890 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5891 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 5892 | /* |
| 5893 | * The different unsolicited event handlers would tell us |
| 5894 | * if they are done with "mp" by setting context2 to NULL. |
| 5895 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5896 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5897 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 5898 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5899 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5900 | |
| 5901 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5902 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5903 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5904 | elsiocb->context2 = bdeBuf2; |
| 5905 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5906 | /* free mp if we are done with it */ |
| 5907 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5908 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 5909 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5910 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5911 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5912 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5913 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5914 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5915 | * 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] | 5916 | * @phba: pointer to lpfc hba data structure. |
| 5917 | * @vport: pointer to a virtual N_Port data structure. |
| 5918 | * |
| 5919 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 5920 | * State Change Request (SCR) for a @vport. This routine will create an |
| 5921 | * ndlp for the Name Server associated to the @vport if such node does |
| 5922 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 5923 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 5924 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 5925 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 5926 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5927 | void |
| 5928 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 5929 | { |
| 5930 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
| 5931 | |
| 5932 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 5933 | if (!ndlp) { |
| 5934 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 5935 | if (!ndlp) { |
| 5936 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5937 | lpfc_disc_start(vport); |
| 5938 | return; |
| 5939 | } |
| 5940 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5941 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5942 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5943 | return; |
| 5944 | } |
| 5945 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5946 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5947 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 5948 | if (!ndlp) { |
| 5949 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5950 | lpfc_disc_start(vport); |
| 5951 | return; |
| 5952 | } |
| 5953 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5954 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5955 | "0348 NameServer login: node freed\n"); |
| 5956 | return; |
| 5957 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5958 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5959 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5960 | |
| 5961 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 5962 | |
| 5963 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 5964 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5965 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5966 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5967 | return; |
| 5968 | } |
| 5969 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5970 | if (vport->cfg_fdmi_on) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5971 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 5972 | GFP_KERNEL); |
| 5973 | if (ndlp_fdmi) { |
| 5974 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 5975 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5976 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
| 5977 | NLP_STE_PLOGI_ISSUE); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5978 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, |
| 5979 | 0); |
| 5980 | } |
| 5981 | } |
| 5982 | return; |
| 5983 | } |
| 5984 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5985 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5986 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5987 | * @phba: pointer to lpfc hba data structure. |
| 5988 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 5989 | * |
| 5990 | * This routine is the completion callback function to register new vport |
| 5991 | * mailbox command. If the new vport mailbox command completes successfully, |
| 5992 | * the fabric registration login shall be performed on physical port (the |
| 5993 | * new vport created is actually a physical port, with VPI 0) or the port |
| 5994 | * login to Name Server for State Change Request (SCR) will be performed |
| 5995 | * on virtual port (real virtual port, with VPI greater than 0). |
| 5996 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5997 | static void |
| 5998 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 5999 | { |
| 6000 | struct lpfc_vport *vport = pmb->vport; |
| 6001 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6002 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6003 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6004 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6005 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6006 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6007 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6008 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6009 | |
| 6010 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6011 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6012 | "0915 Register VPI failed: 0x%x\n", |
| 6013 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6014 | |
| 6015 | switch (mb->mbxStatus) { |
| 6016 | case 0x11: /* unsupported feature */ |
| 6017 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6018 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6019 | /* giving up on vport registration */ |
| 6020 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6021 | spin_lock_irq(shost->host_lock); |
| 6022 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 6023 | spin_unlock_irq(shost->host_lock); |
| 6024 | lpfc_can_disctmo(vport); |
| 6025 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6026 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
| 6027 | case 0x20: |
| 6028 | spin_lock_irq(shost->host_lock); |
| 6029 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 6030 | spin_unlock_irq(shost->host_lock); |
| 6031 | lpfc_init_vpi(phba, pmb, vport->vpi); |
| 6032 | pmb->vport = vport; |
| 6033 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 6034 | rc = lpfc_sli_issue_mbox(phba, pmb, |
| 6035 | MBX_NOWAIT); |
| 6036 | if (rc == MBX_NOT_FINISHED) { |
| 6037 | lpfc_printf_vlog(vport, |
| 6038 | KERN_ERR, LOG_MBOX, |
| 6039 | "2732 Failed to issue INIT_VPI" |
| 6040 | " mailbox command\n"); |
| 6041 | } else { |
| 6042 | lpfc_nlp_put(ndlp); |
| 6043 | return; |
| 6044 | } |
| 6045 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6046 | default: |
| 6047 | /* Try to recover from this error */ |
| 6048 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6049 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6050 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6051 | spin_unlock_irq(shost->host_lock); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6052 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 6053 | lpfc_initial_flogi(vport); |
| 6054 | else |
| 6055 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6056 | break; |
| 6057 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6058 | } else { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6059 | spin_lock_irq(shost->host_lock); |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 6060 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6061 | spin_unlock_irq(shost->host_lock); |
| 6062 | if (vport == phba->pport) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6063 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 6064 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6065 | else { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6066 | /* |
| 6067 | * If the physical port is instantiated using |
| 6068 | * FDISC, do not start vport discovery. |
| 6069 | */ |
| 6070 | if (vport->port_state != LPFC_FDISC) |
| 6071 | lpfc_start_fdiscs(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6072 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6073 | } |
| 6074 | } else |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6075 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6076 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6077 | |
| 6078 | /* Now, we decrement the ndlp reference count held for this |
| 6079 | * callback function |
| 6080 | */ |
| 6081 | lpfc_nlp_put(ndlp); |
| 6082 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6083 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6084 | return; |
| 6085 | } |
| 6086 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6087 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6088 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6089 | * @phba: pointer to lpfc hba data structure. |
| 6090 | * @vport: pointer to a host virtual N_Port data structure. |
| 6091 | * @ndlp: pointer to a node-list data structure. |
| 6092 | * |
| 6093 | * This routine registers the @vport as a new virtual port with a HBA. |
| 6094 | * It is done through a registering vpi mailbox command. |
| 6095 | **/ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6096 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6097 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 6098 | struct lpfc_nodelist *ndlp) |
| 6099 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6100 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6101 | LPFC_MBOXQ_t *mbox; |
| 6102 | |
| 6103 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6104 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6105 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6106 | mbox->vport = vport; |
| 6107 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 6108 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 6109 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6110 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6111 | /* mailbox command not success, decrement ndlp |
| 6112 | * reference count for this command |
| 6113 | */ |
| 6114 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6115 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6116 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6117 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6118 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6119 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6120 | } |
| 6121 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6122 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6123 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6124 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6125 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6126 | return; |
| 6127 | |
| 6128 | mbox_err_exit: |
| 6129 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6130 | spin_lock_irq(shost->host_lock); |
| 6131 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 6132 | spin_unlock_irq(shost->host_lock); |
| 6133 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6134 | } |
| 6135 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6136 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame^] | 6137 | * 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] | 6138 | * @phba: pointer to lpfc hba data structure. |
| 6139 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame^] | 6140 | * This routine cancels the retry delay timers to all the vports. |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6141 | **/ |
| 6142 | void |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame^] | 6143 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6144 | { |
| 6145 | struct lpfc_vport **vports; |
| 6146 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6147 | uint32_t link_state; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame^] | 6148 | int i; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6149 | |
| 6150 | /* Treat this failure as linkdown for all vports */ |
| 6151 | link_state = phba->link_state; |
| 6152 | lpfc_linkdown(phba); |
| 6153 | phba->link_state = link_state; |
| 6154 | |
| 6155 | vports = lpfc_create_vport_work_array(phba); |
| 6156 | |
| 6157 | if (vports) { |
| 6158 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 6159 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 6160 | if (ndlp) |
| 6161 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
| 6162 | lpfc_els_flush_cmd(vports[i]); |
| 6163 | } |
| 6164 | lpfc_destroy_vport_work_array(phba, vports); |
| 6165 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame^] | 6166 | } |
| 6167 | |
| 6168 | /** |
| 6169 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. |
| 6170 | * @phba: pointer to lpfc hba data structure. |
| 6171 | * |
| 6172 | * This routine abort all pending discovery commands and |
| 6173 | * start a timer to retry FLOGI for the physical port |
| 6174 | * discovery. |
| 6175 | **/ |
| 6176 | void |
| 6177 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) |
| 6178 | { |
| 6179 | struct lpfc_nodelist *ndlp; |
| 6180 | struct Scsi_Host *shost; |
| 6181 | |
| 6182 | /* Cancel the all vports retry delay retry timers */ |
| 6183 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6184 | |
| 6185 | /* If fabric require FLOGI, then re-instantiate physical login */ |
| 6186 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 6187 | if (!ndlp) |
| 6188 | return; |
| 6189 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6190 | shost = lpfc_shost_from_vport(phba->pport); |
| 6191 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); |
| 6192 | spin_lock_irq(shost->host_lock); |
| 6193 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 6194 | spin_unlock_irq(shost->host_lock); |
| 6195 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; |
| 6196 | phba->pport->port_state = LPFC_FLOGI; |
| 6197 | return; |
| 6198 | } |
| 6199 | |
| 6200 | /** |
| 6201 | * lpfc_fabric_login_reqd - Check if FLOGI required. |
| 6202 | * @phba: pointer to lpfc hba data structure. |
| 6203 | * @cmdiocb: pointer to FDISC command iocb. |
| 6204 | * @rspiocb: pointer to FDISC response iocb. |
| 6205 | * |
| 6206 | * This routine checks if a FLOGI is reguired for FDISC |
| 6207 | * to succeed. |
| 6208 | **/ |
| 6209 | static int |
| 6210 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, |
| 6211 | struct lpfc_iocbq *cmdiocb, |
| 6212 | struct lpfc_iocbq *rspiocb) |
| 6213 | { |
| 6214 | |
| 6215 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || |
| 6216 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) |
| 6217 | return 0; |
| 6218 | else |
| 6219 | return 1; |
| 6220 | } |
| 6221 | |
| 6222 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6223 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6224 | * @phba: pointer to lpfc hba data structure. |
| 6225 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6226 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6227 | * |
| 6228 | * This routine is the completion callback function to a Fabric Discover |
| 6229 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 6230 | * single threaded, each FDISC completion callback function will reset |
| 6231 | * the discovery timer for all vports such that the timers will not get |
| 6232 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 6233 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 6234 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 6235 | * assigned to the vport has been changed with the completion of the FDISC |
| 6236 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 6237 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 6238 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 6239 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 6240 | * Server for State Change Request (SCR). |
| 6241 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6242 | static void |
| 6243 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6244 | struct lpfc_iocbq *rspiocb) |
| 6245 | { |
| 6246 | struct lpfc_vport *vport = cmdiocb->vport; |
| 6247 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6248 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 6249 | struct lpfc_nodelist *np; |
| 6250 | struct lpfc_nodelist *next_np; |
| 6251 | IOCB_t *irsp = &rspiocb->iocb; |
| 6252 | struct lpfc_iocbq *piocb; |
| 6253 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6254 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6255 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 6256 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 6257 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6258 | /* Since all FDISCs are being single threaded, we |
| 6259 | * must reset the discovery timer for ALL vports |
| 6260 | * waiting to send FDISC when one completes. |
| 6261 | */ |
| 6262 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 6263 | lpfc_set_disctmo(piocb->vport); |
| 6264 | } |
| 6265 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6266 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6267 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 6268 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 6269 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6270 | if (irsp->ulpStatus) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6271 | |
| 6272 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { |
| 6273 | lpfc_retry_pport_discovery(phba); |
| 6274 | goto out; |
| 6275 | } |
| 6276 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6277 | /* Check for retry */ |
| 6278 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 6279 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6280 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6281 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6282 | "0126 FDISC failed. (%d/%d)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6283 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6284 | goto fdisc_failed; |
| 6285 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6286 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6287 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6288 | vport->fc_flag |= FC_FABRIC; |
| 6289 | if (vport->phba->fc_topology == TOPOLOGY_LOOP) |
| 6290 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 6291 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6292 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6293 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 6294 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
| 6295 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 6296 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 6297 | /* If our NportID changed, we need to ensure all |
| 6298 | * remaining NPORTs get unreg_login'ed so we can |
| 6299 | * issue unreg_vpi. |
| 6300 | */ |
| 6301 | list_for_each_entry_safe(np, next_np, |
| 6302 | &vport->fc_nodes, nlp_listp) { |
| 6303 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 6304 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 6305 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 6306 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6307 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6308 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6309 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6310 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6311 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6312 | lpfc_mbx_unreg_vpi(vport); |
| 6313 | spin_lock_irq(shost->host_lock); |
| 6314 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 6315 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6316 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6317 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6318 | } |
| 6319 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6320 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
| 6321 | lpfc_issue_init_vpi(vport); |
| 6322 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6323 | lpfc_register_new_vport(phba, vport, ndlp); |
| 6324 | else |
| 6325 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6326 | goto out; |
| 6327 | fdisc_failed: |
| 6328 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6329 | /* Cancel discovery timer */ |
| 6330 | lpfc_can_disctmo(vport); |
| 6331 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6332 | out: |
| 6333 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6334 | } |
| 6335 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6336 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6337 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6338 | * @vport: pointer to a virtual N_Port data structure. |
| 6339 | * @ndlp: pointer to a node-list data structure. |
| 6340 | * @retry: number of retries to the command IOCB. |
| 6341 | * |
| 6342 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 6343 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 6344 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 6345 | * IOCB will be sent off HBA at any given time. |
| 6346 | * |
| 6347 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6348 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6349 | * will be stored into the context1 field of the IOCB for the completion |
| 6350 | * callback function to the FDISC ELS command. |
| 6351 | * |
| 6352 | * Return code |
| 6353 | * 0 - Successfully issued fdisc iocb command |
| 6354 | * 1 - Failed to issue fdisc iocb command |
| 6355 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6356 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6357 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 6358 | uint8_t retry) |
| 6359 | { |
| 6360 | struct lpfc_hba *phba = vport->phba; |
| 6361 | IOCB_t *icmd; |
| 6362 | struct lpfc_iocbq *elsiocb; |
| 6363 | struct serv_parm *sp; |
| 6364 | uint8_t *pcmd; |
| 6365 | uint16_t cmdsize; |
| 6366 | int did = ndlp->nlp_DID; |
| 6367 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6368 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6369 | vport->port_state = LPFC_FDISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6370 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 6371 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 6372 | ELS_CMD_FDISC); |
| 6373 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6374 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6375 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6376 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6377 | return 1; |
| 6378 | } |
| 6379 | |
| 6380 | icmd = &elsiocb->iocb; |
| 6381 | icmd->un.elsreq64.myID = 0; |
| 6382 | icmd->un.elsreq64.fl = 1; |
| 6383 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6384 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 6385 | /* FDISC needs to be 1 for WQE VPI */ |
| 6386 | elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1; |
| 6387 | elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ; |
| 6388 | /* Set the ulpContext to the vpi */ |
| 6389 | elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base; |
| 6390 | } else { |
| 6391 | /* For FDISC, Let FDISC rsp set the NPortID for this VPI */ |
| 6392 | icmd->ulpCt_h = 1; |
| 6393 | icmd->ulpCt_l = 0; |
| 6394 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6395 | |
| 6396 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6397 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 6398 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 6399 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 6400 | sp = (struct serv_parm *) pcmd; |
| 6401 | /* Setup CSPs accordingly for Fabric */ |
| 6402 | sp->cmn.e_d_tov = 0; |
| 6403 | sp->cmn.w2.r_a_tov = 0; |
| 6404 | sp->cls1.classValid = 0; |
| 6405 | sp->cls2.seqDelivery = 1; |
| 6406 | sp->cls3.seqDelivery = 1; |
| 6407 | |
| 6408 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 6409 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 6410 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 6411 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 6412 | memcpy(pcmd, &vport->fc_portname, 8); |
| 6413 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6414 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6415 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 6416 | |
| 6417 | lpfc_set_disctmo(vport); |
| 6418 | |
| 6419 | phba->fc_stat.elsXmitFDISC++; |
| 6420 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 6421 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6422 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6423 | "Issue FDISC: did:x%x", |
| 6424 | did, 0, 0); |
| 6425 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6426 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 6427 | if (rc == IOCB_ERROR) { |
| 6428 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6429 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6430 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6431 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6432 | return 1; |
| 6433 | } |
| 6434 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6435 | return 0; |
| 6436 | } |
| 6437 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6438 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6439 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6440 | * @phba: pointer to lpfc hba data structure. |
| 6441 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6442 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6443 | * |
| 6444 | * This routine is the completion callback function to the issuing of a LOGO |
| 6445 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 6446 | * reference count held on ndlp for this completion function, indicating that |
| 6447 | * the reference to the ndlp is no long needed. Note that the |
| 6448 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 6449 | * callback function and an additional explicit ndlp reference decrementation |
| 6450 | * will trigger the actual release of the ndlp. |
| 6451 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6452 | static void |
| 6453 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6454 | struct lpfc_iocbq *rspiocb) |
| 6455 | { |
| 6456 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6457 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6458 | struct lpfc_nodelist *ndlp; |
| 6459 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6460 | |
| 6461 | irsp = &rspiocb->iocb; |
| 6462 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6463 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 6464 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6465 | |
| 6466 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6467 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6468 | |
| 6469 | /* Trigger the release of the ndlp after logo */ |
| 6470 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6471 | } |
| 6472 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6473 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6474 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6475 | * @vport: pointer to a virtual N_Port data structure. |
| 6476 | * @ndlp: pointer to a node-list data structure. |
| 6477 | * |
| 6478 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 6479 | * |
| 6480 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6481 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6482 | * will be stored into the context1 field of the IOCB for the completion |
| 6483 | * callback function to the LOGO ELS command. |
| 6484 | * |
| 6485 | * Return codes |
| 6486 | * 0 - Successfully issued logo off the @vport |
| 6487 | * 1 - Failed to issue logo off the @vport |
| 6488 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6489 | int |
| 6490 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 6491 | { |
| 6492 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6493 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6494 | IOCB_t *icmd; |
| 6495 | struct lpfc_iocbq *elsiocb; |
| 6496 | uint8_t *pcmd; |
| 6497 | uint16_t cmdsize; |
| 6498 | |
| 6499 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 6500 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 6501 | ELS_CMD_LOGO); |
| 6502 | if (!elsiocb) |
| 6503 | return 1; |
| 6504 | |
| 6505 | icmd = &elsiocb->iocb; |
| 6506 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6507 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 6508 | pcmd += sizeof(uint32_t); |
| 6509 | |
| 6510 | /* Fill in LOGO payload */ |
| 6511 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 6512 | pcmd += sizeof(uint32_t); |
| 6513 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 6514 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6515 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6516 | "Issue LOGO npiv did:x%x flg:x%x", |
| 6517 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 6518 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6519 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 6520 | spin_lock_irq(shost->host_lock); |
| 6521 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 6522 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6523 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 6524 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6525 | spin_lock_irq(shost->host_lock); |
| 6526 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 6527 | spin_unlock_irq(shost->host_lock); |
| 6528 | lpfc_els_free_iocb(phba, elsiocb); |
| 6529 | return 1; |
| 6530 | } |
| 6531 | return 0; |
| 6532 | } |
| 6533 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6534 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6535 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6536 | * @ptr: holder for the timer function associated data. |
| 6537 | * |
| 6538 | * This routine is invoked by the fabric iocb block timer after |
| 6539 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 6540 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 6541 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 6542 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 6543 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 6544 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6545 | void |
| 6546 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 6547 | { |
| 6548 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 6549 | unsigned long iflags; |
| 6550 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6551 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6552 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 6553 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 6554 | if (!tmo_posted) |
| 6555 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 6556 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 6557 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6558 | if (!tmo_posted) |
| 6559 | lpfc_worker_wake_up(phba); |
| 6560 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6561 | } |
| 6562 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6563 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6564 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6565 | * @phba: pointer to lpfc hba data structure. |
| 6566 | * |
| 6567 | * This routine issues one fabric iocb from the driver internal list to |
| 6568 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 6569 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 6570 | * remove one pending fabric iocb from the driver internal list and invokes |
| 6571 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 6572 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6573 | static void |
| 6574 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 6575 | { |
| 6576 | struct lpfc_iocbq *iocb; |
| 6577 | unsigned long iflags; |
| 6578 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6579 | IOCB_t *cmd; |
| 6580 | |
| 6581 | repeat: |
| 6582 | iocb = NULL; |
| 6583 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6584 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6585 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 6586 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 6587 | list); |
| 6588 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6589 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6590 | atomic_inc(&phba->fabric_iocb_count); |
| 6591 | } |
| 6592 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6593 | if (iocb) { |
| 6594 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6595 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6596 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6597 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6598 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6599 | "Fabric sched1: ste:x%x", |
| 6600 | iocb->vport->port_state, 0, 0); |
| 6601 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6602 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6603 | |
| 6604 | if (ret == IOCB_ERROR) { |
| 6605 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6606 | iocb->fabric_iocb_cmpl = NULL; |
| 6607 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6608 | cmd = &iocb->iocb; |
| 6609 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6610 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6611 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 6612 | |
| 6613 | atomic_dec(&phba->fabric_iocb_count); |
| 6614 | goto repeat; |
| 6615 | } |
| 6616 | } |
| 6617 | |
| 6618 | return; |
| 6619 | } |
| 6620 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6621 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6622 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6623 | * @phba: pointer to lpfc hba data structure. |
| 6624 | * |
| 6625 | * This routine unblocks the issuing fabric iocb command. The function |
| 6626 | * will clear the fabric iocb block bit and then invoke the routine |
| 6627 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 6628 | * from the driver internal fabric iocb list. |
| 6629 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6630 | void |
| 6631 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 6632 | { |
| 6633 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6634 | |
| 6635 | lpfc_resume_fabric_iocbs(phba); |
| 6636 | return; |
| 6637 | } |
| 6638 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6639 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6640 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6641 | * @phba: pointer to lpfc hba data structure. |
| 6642 | * |
| 6643 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 6644 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 6645 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 6646 | * fabric iocb will be issued out of the HBA. |
| 6647 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6648 | static void |
| 6649 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 6650 | { |
| 6651 | int blocked; |
| 6652 | |
| 6653 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6654 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6655 | if (!blocked) |
| 6656 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); |
| 6657 | |
| 6658 | return; |
| 6659 | } |
| 6660 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6661 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6662 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6663 | * @phba: pointer to lpfc hba data structure. |
| 6664 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6665 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6666 | * |
| 6667 | * This routine is the callback function that is put to the fabric iocb's |
| 6668 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 6669 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 6670 | * function first restores and invokes the original iocb's callback function |
| 6671 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 6672 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 6673 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6674 | static void |
| 6675 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6676 | struct lpfc_iocbq *rspiocb) |
| 6677 | { |
| 6678 | struct ls_rjt stat; |
| 6679 | |
| 6680 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 6681 | BUG(); |
| 6682 | |
| 6683 | switch (rspiocb->iocb.ulpStatus) { |
| 6684 | case IOSTAT_NPORT_RJT: |
| 6685 | case IOSTAT_FABRIC_RJT: |
| 6686 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 6687 | lpfc_block_fabric_iocbs(phba); |
| 6688 | } |
| 6689 | break; |
| 6690 | |
| 6691 | case IOSTAT_NPORT_BSY: |
| 6692 | case IOSTAT_FABRIC_BSY: |
| 6693 | lpfc_block_fabric_iocbs(phba); |
| 6694 | break; |
| 6695 | |
| 6696 | case IOSTAT_LS_RJT: |
| 6697 | stat.un.lsRjtError = |
| 6698 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 6699 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 6700 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 6701 | lpfc_block_fabric_iocbs(phba); |
| 6702 | break; |
| 6703 | } |
| 6704 | |
| 6705 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 6706 | BUG(); |
| 6707 | |
| 6708 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 6709 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 6710 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6711 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 6712 | |
| 6713 | atomic_dec(&phba->fabric_iocb_count); |
| 6714 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6715 | /* Post any pending iocbs to HBA */ |
| 6716 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6717 | } |
| 6718 | } |
| 6719 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6720 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6721 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6722 | * @phba: pointer to lpfc hba data structure. |
| 6723 | * @iocb: pointer to lpfc command iocb data structure. |
| 6724 | * |
| 6725 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 6726 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 6727 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 6728 | * any given time. As such, this function will first check to see whether there |
| 6729 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 6730 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 6731 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 6732 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 6733 | * |
| 6734 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 6735 | * order. The problem is caused by the construction of the "ready" boolen does |
| 6736 | * not include the condition that the internal fabric IOCB list is empty. As |
| 6737 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 6738 | * ahead of the fabric IOCBs in the internal list. |
| 6739 | * |
| 6740 | * Return code |
| 6741 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 6742 | * IOCB_ERROR - failed to issue fabric iocb |
| 6743 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6744 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6745 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 6746 | { |
| 6747 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6748 | int ready; |
| 6749 | int ret; |
| 6750 | |
| 6751 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 6752 | BUG(); |
| 6753 | |
| 6754 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6755 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 6756 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6757 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6758 | if (ready) |
| 6759 | /* Increment fabric iocb count to hold the position */ |
| 6760 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6761 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6762 | if (ready) { |
| 6763 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6764 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6765 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6766 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6767 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6768 | "Fabric sched2: ste:x%x", |
| 6769 | iocb->vport->port_state, 0, 0); |
| 6770 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6771 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6772 | |
| 6773 | if (ret == IOCB_ERROR) { |
| 6774 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6775 | iocb->fabric_iocb_cmpl = NULL; |
| 6776 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6777 | atomic_dec(&phba->fabric_iocb_count); |
| 6778 | } |
| 6779 | } else { |
| 6780 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6781 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 6782 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6783 | ret = IOCB_SUCCESS; |
| 6784 | } |
| 6785 | return ret; |
| 6786 | } |
| 6787 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6788 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6789 | * 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] | 6790 | * @vport: pointer to a virtual N_Port data structure. |
| 6791 | * |
| 6792 | * This routine aborts all the IOCBs associated with a @vport from the |
| 6793 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6794 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6795 | * list, removes each IOCB associated with the @vport off the list, set the |
| 6796 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6797 | * associated with the IOCB. |
| 6798 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6799 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6800 | { |
| 6801 | LIST_HEAD(completions); |
| 6802 | struct lpfc_hba *phba = vport->phba; |
| 6803 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6804 | |
| 6805 | spin_lock_irq(&phba->hbalock); |
| 6806 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6807 | list) { |
| 6808 | |
| 6809 | if (piocb->vport != vport) |
| 6810 | continue; |
| 6811 | |
| 6812 | list_move_tail(&piocb->list, &completions); |
| 6813 | } |
| 6814 | spin_unlock_irq(&phba->hbalock); |
| 6815 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6816 | /* Cancel all the IOCBs from the completions list */ |
| 6817 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6818 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6819 | } |
| 6820 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6821 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6822 | * 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] | 6823 | * @ndlp: pointer to a node-list data structure. |
| 6824 | * |
| 6825 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 6826 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6827 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6828 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 6829 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6830 | * associated with the IOCB. |
| 6831 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6832 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 6833 | { |
| 6834 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6835 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6836 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6837 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6838 | |
| 6839 | spin_lock_irq(&phba->hbalock); |
| 6840 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6841 | list) { |
| 6842 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 6843 | |
| 6844 | list_move_tail(&piocb->list, &completions); |
| 6845 | } |
| 6846 | } |
| 6847 | spin_unlock_irq(&phba->hbalock); |
| 6848 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6849 | /* Cancel all the IOCBs from the completions list */ |
| 6850 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6851 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6852 | } |
| 6853 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6854 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6855 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6856 | * @phba: pointer to lpfc hba data structure. |
| 6857 | * |
| 6858 | * This routine aborts all the IOCBs currently on the driver internal |
| 6859 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 6860 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 6861 | * list, removes IOCBs off the list, set the status feild to |
| 6862 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 6863 | * the IOCB. |
| 6864 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6865 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 6866 | { |
| 6867 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6868 | |
| 6869 | spin_lock_irq(&phba->hbalock); |
| 6870 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 6871 | spin_unlock_irq(&phba->hbalock); |
| 6872 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6873 | /* Cancel all the IOCBs from the completions list */ |
| 6874 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6875 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6876 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6877 | |
| 6878 | /** |
| 6879 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 6880 | * @phba: pointer to lpfc hba data structure. |
| 6881 | * @axri: pointer to the els xri abort wcqe structure. |
| 6882 | * |
| 6883 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 6884 | * ELS aborted xri. |
| 6885 | **/ |
| 6886 | void |
| 6887 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 6888 | struct sli4_wcqe_xri_aborted *axri) |
| 6889 | { |
| 6890 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
| 6891 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 6892 | unsigned long iflag = 0; |
| 6893 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 6894 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 6895 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6896 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 6897 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 6898 | if (sglq_entry->sli4_xritag == xri) { |
| 6899 | list_del(&sglq_entry->list); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6900 | list_add_tail(&sglq_entry->list, |
| 6901 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 6902 | sglq_entry->state = SGL_FREED; |
| 6903 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6904 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 6905 | return; |
| 6906 | } |
| 6907 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 6908 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 6909 | sglq_entry = __lpfc_get_active_sglq(phba, xri); |
| 6910 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { |
| 6911 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 6912 | return; |
| 6913 | } |
| 6914 | sglq_entry->state = SGL_XRI_ABORTED; |
| 6915 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 6916 | return; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6917 | } |