| 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 | c9f8735 | 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 | c9f8735 | 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; |
| 774 | int rc; |
| 775 | |
| 776 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 777 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 778 | /* One additional decrement on node reference count to |
| 779 | * trigger the release of the node |
| 780 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 781 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 782 | goto out; |
| 783 | } |
| 784 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 785 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 786 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 787 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 788 | vport->port_state); |
| 789 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 790 | if (irsp->ulpStatus) { |
| 791 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 792 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 793 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 794 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 795 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 796 | spin_lock_irq(shost->host_lock); |
| 797 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 798 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 799 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 800 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 801 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 802 | * alpa map would take too long otherwise. |
| 803 | */ |
| 804 | if (phba->alpa_map[0] == 0) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 805 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | /* FLOGI failure */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 809 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 810 | "0100 FLOGI failure Data: x%x x%x " |
| 811 | "x%x\n", |
| 812 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 813 | irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 814 | goto flogifail; |
| 815 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 816 | spin_lock_irq(shost->host_lock); |
| 817 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
| 818 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 819 | |
| 820 | /* |
| 821 | * The FLogI succeeded. Sync the data for the CPU before |
| 822 | * accessing it. |
| 823 | */ |
| 824 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 825 | |
| 826 | sp = prsp->virt + sizeof(uint32_t); |
| 827 | |
| 828 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 829 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 830 | "0101 FLOGI completes successfully " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 831 | "Data: x%x x%x x%x x%x\n", |
| 832 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
| 833 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 834 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 835 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 836 | /* |
| 837 | * If Common Service Parameters indicate Nport |
| 838 | * we are point to point, if Fport we are Fabric. |
| 839 | */ |
| 840 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 841 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 842 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 843 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 844 | |
| 845 | if (!rc) |
| 846 | goto out; |
| 847 | } |
| 848 | |
| 849 | flogifail: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 850 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 851 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 852 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 853 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 854 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 855 | |
| 856 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 857 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 858 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 859 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && |
| 860 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) && |
| 861 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 862 | /* If FLOGI failed enable link interrupt. */ |
| 863 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 864 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 865 | out: |
| 866 | lpfc_els_free_iocb(phba, cmdiocb); |
| 867 | } |
| 868 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 869 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 870 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 871 | * @vport: pointer to a host virtual N_Port data structure. |
| 872 | * @ndlp: pointer to a node-list data structure. |
| 873 | * @retry: number of retries to the command IOCB. |
| 874 | * |
| 875 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 876 | * for a @vport. The initiator service parameters are put into the payload |
| 877 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 878 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 879 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 880 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 881 | * |
| 882 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 883 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 884 | * will be stored into the context1 field of the IOCB for the completion |
| 885 | * callback function to the FLOGI ELS command. |
| 886 | * |
| 887 | * Return code |
| 888 | * 0 - successfully issued flogi iocb for @vport |
| 889 | * 1 - failed to issue flogi iocb for @vport |
| 890 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 891 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 892 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 893 | uint8_t retry) |
| 894 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 895 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 896 | struct serv_parm *sp; |
| 897 | IOCB_t *icmd; |
| 898 | struct lpfc_iocbq *elsiocb; |
| 899 | struct lpfc_sli_ring *pring; |
| 900 | uint8_t *pcmd; |
| 901 | uint16_t cmdsize; |
| 902 | uint32_t tmo; |
| 903 | int rc; |
| 904 | |
| 905 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 906 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 907 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 908 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 909 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 910 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 911 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 912 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 913 | |
| 914 | icmd = &elsiocb->iocb; |
| 915 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 916 | |
| 917 | /* For FLOGI request, remainder of payload is service parameters */ |
| 918 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 919 | pcmd += sizeof(uint32_t); |
| 920 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 921 | sp = (struct serv_parm *) pcmd; |
| 922 | |
| 923 | /* Setup CSPs accordingly for Fabric */ |
| 924 | sp->cmn.e_d_tov = 0; |
| 925 | sp->cmn.w2.r_a_tov = 0; |
| 926 | sp->cls1.classValid = 0; |
| 927 | sp->cls2.seqDelivery = 1; |
| 928 | sp->cls3.seqDelivery = 1; |
| 929 | if (sp->cmn.fcphLow < FC_PH3) |
| 930 | sp->cmn.fcphLow = FC_PH3; |
| 931 | if (sp->cmn.fcphHigh < FC_PH3) |
| 932 | sp->cmn.fcphHigh = FC_PH3; |
| 933 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 934 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 935 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 936 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 937 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 938 | /* Set the fcfi to the fcfi we registered with */ |
| 939 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 940 | } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 941 | sp->cmn.request_multiple_Nport = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 942 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 943 | icmd->ulpCt_h = 1; |
| 944 | icmd->ulpCt_l = 0; |
| 945 | } |
| 946 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 947 | if (phba->fc_topology != TOPOLOGY_LOOP) { |
| 948 | icmd->un.elsreq64.myID = 0; |
| 949 | icmd->un.elsreq64.fl = 1; |
| 950 | } |
| 951 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 952 | tmo = phba->fc_ratov; |
| 953 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 954 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 955 | phba->fc_ratov = tmo; |
| 956 | |
| 957 | phba->fc_stat.elsXmitFLOGI++; |
| 958 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 959 | |
| 960 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 961 | "Issue FLOGI: opt:x%x", |
| 962 | phba->sli3_options, 0, 0); |
| 963 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 964 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 965 | if (rc == IOCB_ERROR) { |
| 966 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 967 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 968 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 969 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 970 | } |
| 971 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 972 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 973 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 974 | * @phba: pointer to lpfc hba data structure. |
| 975 | * |
| 976 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 977 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 978 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 979 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 980 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 981 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 982 | * |
| 983 | * Return code |
| 984 | * 0 - Sucessfully issued abort iocb on all outstanding flogis (Always 0) |
| 985 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 986 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 987 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 988 | { |
| 989 | struct lpfc_sli_ring *pring; |
| 990 | struct lpfc_iocbq *iocb, *next_iocb; |
| 991 | struct lpfc_nodelist *ndlp; |
| 992 | IOCB_t *icmd; |
| 993 | |
| 994 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 995 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 996 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 997 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 998 | |
| 999 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 1000 | |
| 1001 | /* |
| 1002 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 1003 | * searching for. |
| 1004 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1005 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1006 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 1007 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1008 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR && |
| 1009 | icmd->un.elsreq64.bdl.ulpIoTag32) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1010 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1011 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 1012 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1013 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1014 | } |
| 1015 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1016 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1017 | |
| 1018 | return 0; |
| 1019 | } |
| 1020 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1021 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1022 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1023 | * @vport: pointer to a host virtual N_Port data structure. |
| 1024 | * |
| 1025 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 1026 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1027 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1028 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1029 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 1030 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 1031 | * @vport. |
| 1032 | * |
| 1033 | * Return code |
| 1034 | * 0 - failed to issue initial flogi for @vport |
| 1035 | * 1 - successfully issued initial flogi for @vport |
| 1036 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1037 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1038 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1039 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1040 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1041 | struct lpfc_nodelist *ndlp; |
| 1042 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1043 | vport->port_state = LPFC_FLOGI; |
| 1044 | lpfc_set_disctmo(vport); |
| 1045 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1046 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1047 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1048 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1049 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1050 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1051 | if (!ndlp) |
| 1052 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1053 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1054 | /* Set the node type */ |
| 1055 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1056 | /* Put ndlp onto node list */ |
| 1057 | lpfc_enqueue_node(vport, ndlp); |
| 1058 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1059 | /* re-setup ndlp without removing from node list */ |
| 1060 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1061 | if (!ndlp) |
| 1062 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1063 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1064 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1065 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1066 | /* This decrement of reference count to node shall kick off |
| 1067 | * the release of the node. |
| 1068 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1069 | lpfc_nlp_put(ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1070 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1071 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1072 | } |
| 1073 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1074 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1075 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1076 | * @vport: pointer to a host virtual N_Port data structure. |
| 1077 | * |
| 1078 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 1079 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1080 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1081 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1082 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 1083 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 1084 | * @vport. |
| 1085 | * |
| 1086 | * Return code |
| 1087 | * 0 - failed to issue initial fdisc for @vport |
| 1088 | * 1 - successfully issued initial fdisc for @vport |
| 1089 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1090 | int |
| 1091 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 1092 | { |
| 1093 | struct lpfc_hba *phba = vport->phba; |
| 1094 | struct lpfc_nodelist *ndlp; |
| 1095 | |
| 1096 | /* First look for the Fabric ndlp */ |
| 1097 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1098 | if (!ndlp) { |
| 1099 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 1100 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1101 | if (!ndlp) |
| 1102 | return 0; |
| 1103 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1104 | /* Put ndlp onto node list */ |
| 1105 | lpfc_enqueue_node(vport, ndlp); |
| 1106 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1107 | /* re-setup ndlp without removing from node list */ |
| 1108 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1109 | if (!ndlp) |
| 1110 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1111 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1112 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1113 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1114 | /* decrement node reference count to trigger the release of |
| 1115 | * the node. |
| 1116 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1117 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1118 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1119 | } |
| 1120 | return 1; |
| 1121 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1122 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1123 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1124 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1125 | * @vport: pointer to a host virtual N_Port data structure. |
| 1126 | * |
| 1127 | * This routine checks whether there are more remaining Port Logins |
| 1128 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1129 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1130 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1131 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1132 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1133 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1134 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1135 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1136 | { |
| 1137 | int sentplogi; |
| 1138 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1139 | if (vport->num_disc_nodes) |
| 1140 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1141 | |
| 1142 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1143 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1144 | "0232 Continue discovery with %d PLOGIs to go " |
| 1145 | "Data: x%x x%x x%x\n", |
| 1146 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1147 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1148 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1149 | if (vport->fc_flag & FC_NLP_MORE) |
| 1150 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 1151 | sentplogi = lpfc_els_disc_plogi(vport); |
| 1152 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1153 | return; |
| 1154 | } |
| 1155 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1156 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1157 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1158 | * @phba: pointer to lpfc hba data structure. |
| 1159 | * @prsp: pointer to response IOCB payload. |
| 1160 | * @ndlp: pointer to a node-list data structure. |
| 1161 | * |
| 1162 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1163 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1164 | * The following cases are considered N_Port confirmed: |
| 1165 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1166 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1167 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1168 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1169 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1170 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1171 | * on that node to release the RPI associated with the node; 2) if there is |
| 1172 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1173 | * into, a new node shall be allocated (or activated). In either case, the |
| 1174 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1175 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1176 | * its pointer returned as the confirmed node. |
| 1177 | * |
| 1178 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1179 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1180 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1181 | * into an inactive state on the vport node list and the vport node list |
| 1182 | * management algorithm does not allow two node with a same DID. |
| 1183 | * |
| 1184 | * Return code |
| 1185 | * pointer to the PLOGI N_Port @ndlp |
| 1186 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1187 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1188 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1189 | struct lpfc_nodelist *ndlp) |
| 1190 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1191 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1192 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1193 | struct lpfc_rport_data *rdata; |
| 1194 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1195 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1196 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1197 | uint32_t rc, keepDID = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1198 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1199 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1200 | * by WWPN. Just return the ndlp that was given to us. |
| 1201 | */ |
| 1202 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1203 | return ndlp; |
| 1204 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1205 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1206 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1207 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1208 | /* 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] | 1209 | * we have for that ndlp. If not, we have some work to do. |
| 1210 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1211 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1212 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1213 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1214 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1215 | |
| 1216 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1217 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1218 | sizeof(struct lpfc_name)); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1219 | if (!rc) |
| 1220 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1221 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
| 1222 | if (!new_ndlp) |
| 1223 | return ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1224 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1225 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1226 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1227 | sizeof(struct lpfc_name)); |
| 1228 | if (!rc) |
| 1229 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1230 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1231 | NLP_STE_UNUSED_NODE); |
| 1232 | if (!new_ndlp) |
| 1233 | return ndlp; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1234 | keepDID = new_ndlp->nlp_DID; |
| 1235 | } else |
| 1236 | keepDID = new_ndlp->nlp_DID; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1237 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1238 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1239 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1240 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1241 | |
| 1242 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) |
| 1243 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 1244 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 1245 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1246 | /* 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] | 1247 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1248 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1249 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1250 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1251 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1252 | * to put ndlp on UNUSED list and try to free it. |
| 1253 | */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1254 | |
| 1255 | /* Fix up the rport accordingly */ |
| 1256 | rport = ndlp->rport; |
| 1257 | if (rport) { |
| 1258 | rdata = rport->dd_data; |
| 1259 | if (rdata->pnode == ndlp) { |
| 1260 | lpfc_nlp_put(ndlp); |
| 1261 | ndlp->rport = NULL; |
| 1262 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1263 | new_ndlp->rport = rport; |
| 1264 | } |
| 1265 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1266 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1267 | /* We shall actually free the ndlp with both nlp_DID and |
| 1268 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1269 | * nodelist never to be used. |
| 1270 | */ |
| 1271 | if (ndlp->nlp_DID == 0) { |
| 1272 | spin_lock_irq(&phba->ndlp_lock); |
| 1273 | NLP_SET_FREE_REQ(ndlp); |
| 1274 | spin_unlock_irq(&phba->ndlp_lock); |
| 1275 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1276 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1277 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1278 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1279 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1280 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1281 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1282 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1283 | /* Two ndlps cannot have the same did */ |
| 1284 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1285 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1286 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1287 | return new_ndlp; |
| 1288 | } |
| 1289 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1290 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1291 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1292 | * @vport: pointer to a host virtual N_Port data structure. |
| 1293 | * |
| 1294 | * This routine checks whether more Registration State Change |
| 1295 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1296 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1297 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1298 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1299 | * handling the RSCNs. |
| 1300 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1301 | void |
| 1302 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1303 | { |
| 1304 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1305 | |
| 1306 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1307 | /* |
| 1308 | * Check to see if more RSCNs came in while we were |
| 1309 | * processing this one. |
| 1310 | */ |
| 1311 | if (vport->fc_rscn_id_cnt || |
| 1312 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1313 | lpfc_els_handle_rscn(vport); |
| 1314 | else { |
| 1315 | spin_lock_irq(shost->host_lock); |
| 1316 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1317 | spin_unlock_irq(shost->host_lock); |
| 1318 | } |
| 1319 | } |
| 1320 | } |
| 1321 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1322 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1323 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1324 | * @phba: pointer to lpfc hba data structure. |
| 1325 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1326 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1327 | * |
| 1328 | * This routine is the completion callback function for issuing the Port |
| 1329 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1330 | * ndlp on the vport node list that matches the remote node ID from the |
| 1331 | * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply |
| 1332 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1333 | * checked for error conditons. If there is error status reported, PLOGI |
| 1334 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1335 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1336 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1337 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1338 | * there are additional N_Port nodes with the vport that need to perform |
| 1339 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1340 | * PLOGIs. |
| 1341 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1342 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1343 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1344 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1345 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1346 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1347 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1348 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1349 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1350 | struct lpfc_dmabuf *prsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1351 | int disc, rc, did, type; |
| 1352 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1353 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1354 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1355 | |
| 1356 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1357 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1358 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1359 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1360 | irsp->un.elsreq64.remoteID); |
| 1361 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1362 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1363 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1364 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1365 | "0136 PLOGI completes to NPort x%x " |
| 1366 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1367 | irsp->un.elsreq64.remoteID, |
| 1368 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1369 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1370 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1371 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1372 | |
| 1373 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1374 | * is being used during discovery. |
| 1375 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1376 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1377 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1378 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1379 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1380 | rc = 0; |
| 1381 | |
| 1382 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1383 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1384 | "0102 PLOGI completes to NPort x%x " |
| 1385 | "Data: x%x x%x x%x x%x x%x\n", |
| 1386 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1387 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1388 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1389 | if (lpfc_els_chk_latt(vport)) { |
| 1390 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1391 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1392 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1393 | goto out; |
| 1394 | } |
| 1395 | |
| 1396 | /* ndlp could be freed in DSM, save these values now */ |
| 1397 | type = ndlp->nlp_type; |
| 1398 | did = ndlp->nlp_DID; |
| 1399 | |
| 1400 | if (irsp->ulpStatus) { |
| 1401 | /* Check for retry */ |
| 1402 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1403 | /* ELS command is being retried */ |
| 1404 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1405 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1406 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1407 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1408 | } |
| 1409 | goto out; |
| 1410 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1411 | /* PLOGI failed */ |
| 1412 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1413 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1414 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1415 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1416 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1417 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1418 | } else { |
| 1419 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1420 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1421 | cmdiocb->context2)->list.next, |
| 1422 | struct lpfc_dmabuf, list); |
| 1423 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1424 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1425 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1426 | } |
| 1427 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1428 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1429 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1430 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1431 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1432 | if (vport->num_disc_nodes == 0) { |
| 1433 | spin_lock_irq(shost->host_lock); |
| 1434 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1435 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1436 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1437 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1438 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1439 | } |
| 1440 | } |
| 1441 | |
| 1442 | out: |
| 1443 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1444 | return; |
| 1445 | } |
| 1446 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1447 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1448 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1449 | * @vport: pointer to a host virtual N_Port data structure. |
| 1450 | * @did: destination port identifier. |
| 1451 | * @retry: number of retries to the command IOCB. |
| 1452 | * |
| 1453 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1454 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1455 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1456 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1457 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1458 | * |
| 1459 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1460 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1461 | * will be stored into the context1 field of the IOCB for the completion |
| 1462 | * callback function to the PLOGI ELS command. |
| 1463 | * |
| 1464 | * Return code |
| 1465 | * 0 - Successfully issued a plogi for @vport |
| 1466 | * 1 - failed to issue a plogi for @vport |
| 1467 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1468 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1469 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1470 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1471 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1472 | struct serv_parm *sp; |
| 1473 | IOCB_t *icmd; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1474 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1475 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1476 | struct lpfc_sli *psli; |
| 1477 | uint8_t *pcmd; |
| 1478 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1479 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1480 | |
| 1481 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1482 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1483 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1484 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1485 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1486 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1487 | /* 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] | 1488 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1489 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1490 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1491 | if (!elsiocb) |
| 1492 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1493 | |
| 1494 | icmd = &elsiocb->iocb; |
| 1495 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1496 | |
| 1497 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1498 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1499 | pcmd += sizeof(uint32_t); |
| 1500 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1501 | sp = (struct serv_parm *) pcmd; |
| 1502 | |
| 1503 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1504 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1505 | |
| 1506 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1507 | sp->cmn.fcphHigh = FC_PH3; |
| 1508 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1509 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1510 | "Issue PLOGI: did:x%x", |
| 1511 | did, 0, 0); |
| 1512 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1513 | phba->fc_stat.elsXmitPLOGI++; |
| 1514 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1515 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1516 | |
| 1517 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1518 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1519 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1520 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1521 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1522 | } |
| 1523 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1524 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1525 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1526 | * @phba: pointer to lpfc hba data structure. |
| 1527 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1528 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1529 | * |
| 1530 | * This routine is the completion callback function for a Process Login |
| 1531 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 1532 | * status. If there is error status reported, PRLI retry shall be attempted |
| 1533 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 1534 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 1535 | * ndlp to mark the PRLI completion. |
| 1536 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1537 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1538 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1539 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1540 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1541 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1542 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1543 | IOCB_t *irsp; |
| 1544 | struct lpfc_sli *psli; |
| 1545 | struct lpfc_nodelist *ndlp; |
| 1546 | |
| 1547 | psli = &phba->sli; |
| 1548 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1549 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1550 | |
| 1551 | irsp = &(rspiocb->iocb); |
| 1552 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1553 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1554 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1555 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1556 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1557 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1558 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 1559 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1560 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1561 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1562 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1563 | "0103 PRLI completes to NPort x%x " |
| 1564 | "Data: x%x x%x x%x x%x\n", |
| 1565 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1566 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1567 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1568 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1569 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1570 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1571 | goto out; |
| 1572 | |
| 1573 | if (irsp->ulpStatus) { |
| 1574 | /* Check for retry */ |
| 1575 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1576 | /* ELS command is being retried */ |
| 1577 | goto out; |
| 1578 | } |
| 1579 | /* PRLI failed */ |
| 1580 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1581 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1582 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1583 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1584 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1585 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1586 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1587 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1588 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1589 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1590 | out: |
| 1591 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1592 | return; |
| 1593 | } |
| 1594 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1595 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1596 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1597 | * @vport: pointer to a host virtual N_Port data structure. |
| 1598 | * @ndlp: pointer to a node-list data structure. |
| 1599 | * @retry: number of retries to the command IOCB. |
| 1600 | * |
| 1601 | * This routine issues a Process Login (PRLI) ELS command for the |
| 1602 | * @vport. The PRLI service parameters are set up in the payload of the |
| 1603 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 1604 | * is put to the IOCB completion callback func field before invoking the |
| 1605 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 1606 | * |
| 1607 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1608 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1609 | * will be stored into the context1 field of the IOCB for the completion |
| 1610 | * callback function to the PRLI ELS command. |
| 1611 | * |
| 1612 | * Return code |
| 1613 | * 0 - successfully issued prli iocb command for @vport |
| 1614 | * 1 - failed to issue prli iocb command for @vport |
| 1615 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1616 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1617 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1618 | uint8_t retry) |
| 1619 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1620 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1621 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1622 | PRLI *npr; |
| 1623 | IOCB_t *icmd; |
| 1624 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1625 | uint8_t *pcmd; |
| 1626 | uint16_t cmdsize; |
| 1627 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1628 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1629 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1630 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1631 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1632 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1633 | |
| 1634 | icmd = &elsiocb->iocb; |
| 1635 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1636 | |
| 1637 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1638 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1639 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1640 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1641 | |
| 1642 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 1643 | npr = (PRLI *) pcmd; |
| 1644 | /* |
| 1645 | * If our firmware version is 3.20 or later, |
| 1646 | * set the following bits for FC-TAPE support. |
| 1647 | */ |
| 1648 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 1649 | npr->ConfmComplAllowed = 1; |
| 1650 | npr->Retry = 1; |
| 1651 | npr->TaskRetryIdReq = 1; |
| 1652 | } |
| 1653 | npr->estabImagePair = 1; |
| 1654 | npr->readXferRdyDis = 1; |
| 1655 | |
| 1656 | /* For FCP support */ |
| 1657 | npr->prliType = PRLI_FCP_TYPE; |
| 1658 | npr->initiatorFunc = 1; |
| 1659 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1660 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1661 | "Issue PRLI: did:x%x", |
| 1662 | ndlp->nlp_DID, 0, 0); |
| 1663 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1664 | phba->fc_stat.elsXmitPRLI++; |
| 1665 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1666 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1667 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1668 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1669 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 1670 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1671 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1672 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1673 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1674 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1675 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1676 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1677 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1678 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1679 | } |
| 1680 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1681 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1682 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1683 | * @vport: pointer to a host virtual N_Port data structure. |
| 1684 | * |
| 1685 | * This routine performs Registration State Change Notification (RSCN) |
| 1686 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 1687 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 1688 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 1689 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 1690 | * invoked to check and handle possible more RSCN came in during the period |
| 1691 | * of processing the current ones. |
| 1692 | **/ |
| 1693 | static void |
| 1694 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 1695 | { |
| 1696 | lpfc_can_disctmo(vport); |
| 1697 | |
| 1698 | /* RSCN discovery */ |
| 1699 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 1700 | if (vport->fc_npr_cnt) |
| 1701 | if (lpfc_els_disc_plogi(vport)) |
| 1702 | return; |
| 1703 | |
| 1704 | lpfc_end_rscn(vport); |
| 1705 | } |
| 1706 | |
| 1707 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1708 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1709 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 1710 | * |
| 1711 | * This function is called when the final ADISC is completed during discovery. |
| 1712 | * This function handles clearing link attention or issuing reg_vpi depending |
| 1713 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 1714 | * discovery. |
| 1715 | * This function is called with no locks held. |
| 1716 | **/ |
| 1717 | static void |
| 1718 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 1719 | { |
| 1720 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1721 | struct lpfc_hba *phba = vport->phba; |
| 1722 | |
| 1723 | /* |
| 1724 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 1725 | * and continue discovery. |
| 1726 | */ |
| 1727 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1728 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 1729 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1730 | lpfc_issue_reg_vpi(phba, vport); |
| 1731 | return; |
| 1732 | } |
| 1733 | /* |
| 1734 | * For SLI2, we need to set port_state to READY |
| 1735 | * and continue discovery. |
| 1736 | */ |
| 1737 | if (vport->port_state < LPFC_VPORT_READY) { |
| 1738 | /* If we get here, there is nothing to ADISC */ |
| 1739 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1740 | lpfc_issue_clear_la(phba, vport); |
| 1741 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 1742 | vport->num_disc_nodes = 0; |
| 1743 | /* go thru NPR list, issue ELS PLOGIs */ |
| 1744 | if (vport->fc_npr_cnt) |
| 1745 | lpfc_els_disc_plogi(vport); |
| 1746 | if (!vport->num_disc_nodes) { |
| 1747 | spin_lock_irq(shost->host_lock); |
| 1748 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1749 | spin_unlock_irq(shost->host_lock); |
| 1750 | lpfc_can_disctmo(vport); |
| 1751 | lpfc_end_rscn(vport); |
| 1752 | } |
| 1753 | } |
| 1754 | vport->port_state = LPFC_VPORT_READY; |
| 1755 | } else |
| 1756 | lpfc_rscn_disc(vport); |
| 1757 | } |
| 1758 | |
| 1759 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1760 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1761 | * @vport: pointer to a host virtual N_Port data structure. |
| 1762 | * |
| 1763 | * This routine determines whether there are more ndlps on a @vport |
| 1764 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 1765 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 1766 | * remaining nodes which need to have ADISC sent. |
| 1767 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1768 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1769 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1770 | { |
| 1771 | int sentadisc; |
| 1772 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1773 | if (vport->num_disc_nodes) |
| 1774 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1775 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1776 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1777 | "0210 Continue discovery with %d ADISCs to go " |
| 1778 | "Data: x%x x%x x%x\n", |
| 1779 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 1780 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1781 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1782 | if (vport->fc_flag & FC_NLP_MORE) { |
| 1783 | lpfc_set_disctmo(vport); |
| 1784 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 1785 | sentadisc = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1786 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1787 | if (!vport->num_disc_nodes) |
| 1788 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1789 | return; |
| 1790 | } |
| 1791 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1792 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1793 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1794 | * @phba: pointer to lpfc hba data structure. |
| 1795 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1796 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1797 | * |
| 1798 | * This routine is the completion function for issuing the Address Discover |
| 1799 | * (ADISC) command. It first checks to see whether link went down during |
| 1800 | * the discovery process. If so, the node will be marked as node port |
| 1801 | * recovery for issuing discover IOCB by the link attention handler and |
| 1802 | * exit. Otherwise, the response status is checked. If error was reported |
| 1803 | * in the response status, the ADISC command shall be retried by invoking |
| 1804 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 1805 | * the response status, the state machine is invoked to set transition |
| 1806 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 1807 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1808 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1809 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1810 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1811 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1812 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1813 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1814 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1815 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1816 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1817 | |
| 1818 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1819 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1820 | |
| 1821 | irsp = &(rspiocb->iocb); |
| 1822 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1823 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1824 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1825 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 1826 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1827 | ndlp->nlp_DID); |
| 1828 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1829 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1830 | * is being used during discovery. |
| 1831 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1832 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1833 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1834 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1835 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1836 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1837 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1838 | "0104 ADISC completes to NPort x%x " |
| 1839 | "Data: x%x x%x x%x x%x x%x\n", |
| 1840 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1841 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1842 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1843 | if (lpfc_els_chk_latt(vport)) { |
| 1844 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1845 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1846 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1847 | goto out; |
| 1848 | } |
| 1849 | |
| 1850 | if (irsp->ulpStatus) { |
| 1851 | /* Check for retry */ |
| 1852 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1853 | /* ELS command is being retried */ |
| 1854 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1855 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1856 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1857 | spin_unlock_irq(shost->host_lock); |
| 1858 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1859 | } |
| 1860 | goto out; |
| 1861 | } |
| 1862 | /* ADISC failed */ |
| 1863 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1864 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1865 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1866 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1867 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1868 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1869 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1870 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1871 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1872 | /* Check to see if there are more ADISCs to be sent */ |
| 1873 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1874 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1875 | out: |
| 1876 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1877 | return; |
| 1878 | } |
| 1879 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1880 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1881 | * 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] | 1882 | * @vport: pointer to a virtual N_Port data structure. |
| 1883 | * @ndlp: pointer to a node-list data structure. |
| 1884 | * @retry: number of retries to the command IOCB. |
| 1885 | * |
| 1886 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 1887 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 1888 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 1889 | * to issue the ADISC ELS command. |
| 1890 | * |
| 1891 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1892 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1893 | * will be stored into the context1 field of the IOCB for the completion |
| 1894 | * callback function to the ADISC ELS command. |
| 1895 | * |
| 1896 | * Return code |
| 1897 | * 0 - successfully issued adisc |
| 1898 | * 1 - failed to issue adisc |
| 1899 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1900 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1901 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1902 | uint8_t retry) |
| 1903 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1904 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1905 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1906 | ADISC *ap; |
| 1907 | IOCB_t *icmd; |
| 1908 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1909 | uint8_t *pcmd; |
| 1910 | uint16_t cmdsize; |
| 1911 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1912 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1913 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1914 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1915 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1916 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1917 | |
| 1918 | icmd = &elsiocb->iocb; |
| 1919 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1920 | |
| 1921 | /* For ADISC request, remainder of payload is service parameters */ |
| 1922 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1923 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1924 | |
| 1925 | /* Fill in ADISC payload */ |
| 1926 | ap = (ADISC *) pcmd; |
| 1927 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1928 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 1929 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1930 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1931 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1932 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1933 | "Issue ADISC: did:x%x", |
| 1934 | ndlp->nlp_DID, 0, 0); |
| 1935 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1936 | phba->fc_stat.elsXmitADISC++; |
| 1937 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1938 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1939 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1940 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1941 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 1942 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1943 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1944 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1945 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1946 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1947 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1948 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1949 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1950 | } |
| 1951 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1952 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1953 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1954 | * @phba: pointer to lpfc hba data structure. |
| 1955 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1956 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1957 | * |
| 1958 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 1959 | * command. If no error status was reported from the LOGO response, the |
| 1960 | * state machine of the associated ndlp shall be invoked for transition with |
| 1961 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 1962 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 1963 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1964 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1965 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1966 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1967 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1968 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 1969 | struct lpfc_vport *vport = ndlp->vport; |
| 1970 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1971 | IOCB_t *irsp; |
| 1972 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1973 | |
| 1974 | psli = &phba->sli; |
| 1975 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1976 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1977 | |
| 1978 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1979 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1980 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1981 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1982 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1983 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1984 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 1985 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1986 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1987 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1988 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1989 | "0105 LOGO completes to NPort x%x " |
| 1990 | "Data: x%x x%x x%x x%x\n", |
| 1991 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1992 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1993 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1994 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1995 | goto out; |
| 1996 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1997 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 1998 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 1999 | * which should abort all outstanding IOs. |
| 2000 | */ |
| 2001 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 2002 | NLP_EVT_DEVICE_RM); |
| 2003 | goto out; |
| 2004 | } |
| 2005 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2006 | if (irsp->ulpStatus) { |
| 2007 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2008 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2009 | /* ELS command is being retried */ |
| 2010 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2011 | /* LOGO failed */ |
| 2012 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2013 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2014 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2015 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2016 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2017 | NLP_EVT_CMPL_LOGO); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2018 | } else |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2019 | /* Good status, call state machine. |
| 2020 | * This will unregister the rpi if needed. |
| 2021 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2022 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2023 | NLP_EVT_CMPL_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2024 | out: |
| 2025 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2026 | return; |
| 2027 | } |
| 2028 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2029 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2030 | * 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] | 2031 | * @vport: pointer to a virtual N_Port data structure. |
| 2032 | * @ndlp: pointer to a node-list data structure. |
| 2033 | * @retry: number of retries to the command IOCB. |
| 2034 | * |
| 2035 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2036 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2037 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2038 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2039 | * |
| 2040 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2041 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2042 | * will be stored into the context1 field of the IOCB for the completion |
| 2043 | * callback function to the LOGO ELS command. |
| 2044 | * |
| 2045 | * Return code |
| 2046 | * 0 - successfully issued logo |
| 2047 | * 1 - failed to issue logo |
| 2048 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2049 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2050 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2051 | uint8_t retry) |
| 2052 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2053 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2054 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2055 | IOCB_t *icmd; |
| 2056 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2057 | uint8_t *pcmd; |
| 2058 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2059 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2060 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2061 | spin_lock_irq(shost->host_lock); |
| 2062 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2063 | spin_unlock_irq(shost->host_lock); |
| 2064 | return 0; |
| 2065 | } |
| 2066 | spin_unlock_irq(shost->host_lock); |
| 2067 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2068 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2069 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2070 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2071 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2072 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2073 | |
| 2074 | icmd = &elsiocb->iocb; |
| 2075 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2076 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2077 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2078 | |
| 2079 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2080 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2081 | pcmd += sizeof(uint32_t); |
| 2082 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2083 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2084 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2085 | "Issue LOGO: did:x%x", |
| 2086 | ndlp->nlp_DID, 0, 0); |
| 2087 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2088 | phba->fc_stat.elsXmitLOGO++; |
| 2089 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2090 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2091 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2092 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2093 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2094 | |
| 2095 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2096 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2097 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2098 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2099 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2100 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2101 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2102 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2103 | } |
| 2104 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2105 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2106 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2107 | * @phba: pointer to lpfc hba data structure. |
| 2108 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2109 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2110 | * |
| 2111 | * This routine is a generic completion callback function for ELS commands. |
| 2112 | * Specifically, it is the callback function which does not need to perform |
| 2113 | * any command specific operations. It is currently used by the ELS command |
| 2114 | * issuing routines for the ELS State Change Request (SCR), |
| 2115 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 2116 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2117 | * certain debug loggings, this callback function simply invokes the |
| 2118 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2119 | * discovery process. |
| 2120 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2121 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2122 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2123 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2124 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2125 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2126 | IOCB_t *irsp; |
| 2127 | |
| 2128 | irsp = &rspiocb->iocb; |
| 2129 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2130 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2131 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2132 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2133 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2134 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2135 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2136 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2137 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2138 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2139 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2140 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2141 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2142 | return; |
| 2143 | } |
| 2144 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2145 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2146 | * lpfc_issue_els_scr - Issue a scr to an node on a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2147 | * @vport: pointer to a host virtual N_Port data structure. |
| 2148 | * @nportid: N_Port identifier to the remote node. |
| 2149 | * @retry: number of retries to the command IOCB. |
| 2150 | * |
| 2151 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2152 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2153 | * first search the @vport node list to find the matching ndlp. If no such |
| 2154 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2155 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2156 | * routine is invoked to send the SCR IOCB. |
| 2157 | * |
| 2158 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2159 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2160 | * will be stored into the context1 field of the IOCB for the completion |
| 2161 | * callback function to the SCR ELS command. |
| 2162 | * |
| 2163 | * Return code |
| 2164 | * 0 - Successfully issued scr command |
| 2165 | * 1 - Failed to issue scr command |
| 2166 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2167 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2168 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2169 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2170 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2171 | IOCB_t *icmd; |
| 2172 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2173 | struct lpfc_sli *psli; |
| 2174 | uint8_t *pcmd; |
| 2175 | uint16_t cmdsize; |
| 2176 | struct lpfc_nodelist *ndlp; |
| 2177 | |
| 2178 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2179 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2180 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2181 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2182 | if (!ndlp) { |
| 2183 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2184 | if (!ndlp) |
| 2185 | return 1; |
| 2186 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2187 | lpfc_enqueue_node(vport, ndlp); |
| 2188 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2189 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2190 | if (!ndlp) |
| 2191 | return 1; |
| 2192 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2193 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2194 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2195 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2196 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2197 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2198 | /* This will trigger the release of the node just |
| 2199 | * allocated |
| 2200 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2201 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2202 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2203 | } |
| 2204 | |
| 2205 | icmd = &elsiocb->iocb; |
| 2206 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2207 | |
| 2208 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2209 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2210 | |
| 2211 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2212 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2213 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2214 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2215 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2216 | "Issue SCR: did:x%x", |
| 2217 | ndlp->nlp_DID, 0, 0); |
| 2218 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2219 | phba->fc_stat.elsXmitSCR++; |
| 2220 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2221 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2222 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2223 | /* The additional lpfc_nlp_put will cause the following |
| 2224 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2225 | * the node. |
| 2226 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2227 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2228 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2229 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2230 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2231 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2232 | * trigger the release of node. |
| 2233 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2234 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2235 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2236 | } |
| 2237 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2238 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2239 | * 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] | 2240 | * @vport: pointer to a host virtual N_Port data structure. |
| 2241 | * @nportid: N_Port identifier to the remote node. |
| 2242 | * @retry: number of retries to the command IOCB. |
| 2243 | * |
| 2244 | * This routine issues a Fibre Channel Address Resolution Response |
| 2245 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2246 | * is passed into the function. It first search the @vport node list to find |
| 2247 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2248 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2249 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2250 | * |
| 2251 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2252 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2253 | * will be stored into the context1 field of the IOCB for the completion |
| 2254 | * callback function to the PARPR ELS command. |
| 2255 | * |
| 2256 | * Return code |
| 2257 | * 0 - Successfully issued farpr command |
| 2258 | * 1 - Failed to issue farpr command |
| 2259 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2260 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2261 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2262 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2263 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2264 | IOCB_t *icmd; |
| 2265 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2266 | struct lpfc_sli *psli; |
| 2267 | FARP *fp; |
| 2268 | uint8_t *pcmd; |
| 2269 | uint32_t *lp; |
| 2270 | uint16_t cmdsize; |
| 2271 | struct lpfc_nodelist *ondlp; |
| 2272 | struct lpfc_nodelist *ndlp; |
| 2273 | |
| 2274 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2275 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2276 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2277 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2278 | if (!ndlp) { |
| 2279 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2280 | if (!ndlp) |
| 2281 | return 1; |
| 2282 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2283 | lpfc_enqueue_node(vport, ndlp); |
| 2284 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2285 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2286 | if (!ndlp) |
| 2287 | return 1; |
| 2288 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2289 | |
| 2290 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2291 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2292 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2293 | /* This will trigger the release of the node just |
| 2294 | * allocated |
| 2295 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2296 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2297 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2298 | } |
| 2299 | |
| 2300 | icmd = &elsiocb->iocb; |
| 2301 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2302 | |
| 2303 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2304 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2305 | |
| 2306 | /* Fill in FARPR payload */ |
| 2307 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2308 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2309 | lp = (uint32_t *) pcmd; |
| 2310 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2311 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2312 | fp->Rflags = 0; |
| 2313 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2314 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2315 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2316 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2317 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2318 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2319 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2320 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2321 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2322 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2323 | } |
| 2324 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2325 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2326 | "Issue FARPR: did:x%x", |
| 2327 | ndlp->nlp_DID, 0, 0); |
| 2328 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2329 | phba->fc_stat.elsXmitFARPR++; |
| 2330 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2331 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2332 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2333 | /* The additional lpfc_nlp_put will cause the following |
| 2334 | * lpfc_els_free_iocb routine to trigger the release of |
| 2335 | * the node. |
| 2336 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2337 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2338 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2339 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2340 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2341 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2342 | * trigger the release of the node. |
| 2343 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2344 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2345 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2346 | } |
| 2347 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2348 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2349 | * 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] | 2350 | * @vport: pointer to a host virtual N_Port data structure. |
| 2351 | * @nlp: pointer to a node-list data structure. |
| 2352 | * |
| 2353 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2354 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2355 | * removes the ELS retry event if it presents. In addition, if the |
| 2356 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2357 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2358 | * ADISC. |
| 2359 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2360 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2361 | 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] | 2362 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2363 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2364 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2365 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2366 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2367 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2368 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2369 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2370 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2371 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2372 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2373 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2374 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2375 | /* Decrement nlp reference count held for the delayed retry */ |
| 2376 | evtp = &nlp->els_retry_evt; |
| 2377 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2378 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2379 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2380 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2381 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2382 | spin_unlock_irq(shost->host_lock); |
| 2383 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2384 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2385 | /* Check if there are more ADISCs to be sent */ |
| 2386 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2387 | } else { |
| 2388 | /* Check if there are more PLOGIs to be sent */ |
| 2389 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2390 | if (vport->num_disc_nodes == 0) { |
| 2391 | spin_lock_irq(shost->host_lock); |
| 2392 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2393 | spin_unlock_irq(shost->host_lock); |
| 2394 | lpfc_can_disctmo(vport); |
| 2395 | lpfc_end_rscn(vport); |
| 2396 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2397 | } |
| 2398 | } |
| 2399 | } |
| 2400 | return; |
| 2401 | } |
| 2402 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2403 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2404 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2405 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2406 | * |
| 2407 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2408 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2409 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2410 | * adds the delayed events to the HBA work list and invokes the |
| 2411 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2412 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2413 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2414 | * reference to ndlp will still be available when the worker thread gets |
| 2415 | * to the event associated with the ndlp. |
| 2416 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2417 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2418 | lpfc_els_retry_delay(unsigned long ptr) |
| 2419 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2420 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2421 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2422 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2423 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2424 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2425 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2426 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2427 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2428 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2429 | return; |
| 2430 | } |
| 2431 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2432 | /* We need to hold the node by incrementing the reference |
| 2433 | * count until the queued work is done |
| 2434 | */ |
| 2435 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2436 | if (evtp->evt_arg1) { |
| 2437 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2438 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2439 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2440 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2441 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2442 | return; |
| 2443 | } |
| 2444 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2445 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2446 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2447 | * @ndlp: pointer to a node-list data structure. |
| 2448 | * |
| 2449 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 2450 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 2451 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 2452 | * function according to the delayed ELS command to retry the command. |
| 2453 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2454 | void |
| 2455 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 2456 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2457 | struct lpfc_vport *vport = ndlp->vport; |
| 2458 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2459 | uint32_t cmd, did, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2460 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2461 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2462 | did = ndlp->nlp_DID; |
| 2463 | cmd = ndlp->nlp_last_elscmd; |
| 2464 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2465 | |
| 2466 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2467 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2468 | return; |
| 2469 | } |
| 2470 | |
| 2471 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2472 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 2473 | /* |
| 2474 | * If a discovery event readded nlp_delayfunc after timer |
| 2475 | * firing and before processing the timer, cancel the |
| 2476 | * nlp_delayfunc. |
| 2477 | */ |
| 2478 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2479 | retry = ndlp->nlp_retry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 2480 | ndlp->nlp_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2481 | |
| 2482 | switch (cmd) { |
| 2483 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2484 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2485 | break; |
| 2486 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2487 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2488 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2489 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2490 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2491 | break; |
| 2492 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2493 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2494 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2495 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2496 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2497 | break; |
| 2498 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2499 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2500 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2501 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2502 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2503 | break; |
| 2504 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2505 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2506 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2507 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2508 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2509 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2510 | case ELS_CMD_FDISC: |
| 2511 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
| 2512 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2513 | } |
| 2514 | return; |
| 2515 | } |
| 2516 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2517 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2518 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2519 | * @phba: pointer to lpfc hba data structure. |
| 2520 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2521 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2522 | * |
| 2523 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 2524 | * failed. The following ELS IOCBs use this function for retrying the command |
| 2525 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 2526 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 2527 | * returned error status, it makes the decision whether a retry shall be |
| 2528 | * issued for the command, and whether a retry shall be made immediately or |
| 2529 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 2530 | * is called to retry the command. In the later case, the ELS command shall |
| 2531 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 2532 | * ndlp for the delayed command issusing. |
| 2533 | * |
| 2534 | * Return code |
| 2535 | * 0 - No retry of els command is made |
| 2536 | * 1 - Immediate or delayed retry of els command is made |
| 2537 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2538 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2539 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2540 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2541 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2542 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2543 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2544 | IOCB_t *irsp = &rspiocb->iocb; |
| 2545 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2546 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2547 | uint32_t *elscmd; |
| 2548 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2549 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2550 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2551 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2552 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2553 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2554 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2555 | /* Note: context2 may be 0 for internal driver abort |
| 2556 | * of delays ELS command. |
| 2557 | */ |
| 2558 | |
| 2559 | if (pcmd && pcmd->virt) { |
| 2560 | elscmd = (uint32_t *) (pcmd->virt); |
| 2561 | cmd = *elscmd++; |
| 2562 | } |
| 2563 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2564 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2565 | did = ndlp->nlp_DID; |
| 2566 | else { |
| 2567 | /* We should only hit this case for retrying PLOGI */ |
| 2568 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2569 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2570 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 2571 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2572 | return 1; |
| 2573 | } |
| 2574 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2575 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2576 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 2577 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 2578 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2579 | switch (irsp->ulpStatus) { |
| 2580 | case IOSTAT_FCP_RSP_ERROR: |
| 2581 | case IOSTAT_REMOTE_STOP: |
| 2582 | break; |
| 2583 | |
| 2584 | case IOSTAT_LOCAL_REJECT: |
| 2585 | switch ((irsp->un.ulpWord[4] & 0xff)) { |
| 2586 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2587 | if (cmd == ELS_CMD_FLOGI) { |
| 2588 | if (PCI_DEVICE_ID_HORNET == |
| 2589 | phba->pcidev->device) { |
| 2590 | phba->fc_topology = TOPOLOGY_LOOP; |
| 2591 | phba->pport->fc_myDID = 0; |
| 2592 | phba->alpa_map[0] = 0; |
| 2593 | phba->alpa_map[1] = 0; |
| 2594 | } |
| 2595 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2596 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2597 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2598 | retry = 1; |
| 2599 | break; |
| 2600 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2601 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2602 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2603 | "0124 Retry illegal cmd x%x " |
| 2604 | "retry:x%x delay:x%x\n", |
| 2605 | cmd, cmdiocb->retry, delay); |
| 2606 | retry = 1; |
| 2607 | /* All command's retry policy */ |
| 2608 | maxretry = 8; |
| 2609 | if (cmdiocb->retry > 2) |
| 2610 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2611 | break; |
| 2612 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2613 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2614 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2615 | retry = 1; |
| 2616 | if (cmdiocb->retry > 100) |
| 2617 | delay = 100; |
| 2618 | maxretry = 250; |
| 2619 | break; |
| 2620 | |
| 2621 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2622 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2623 | retry = 1; |
| 2624 | break; |
| 2625 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2626 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2627 | case IOERR_INVALID_RPI: |
| 2628 | retry = 1; |
| 2629 | break; |
| 2630 | } |
| 2631 | break; |
| 2632 | |
| 2633 | case IOSTAT_NPORT_RJT: |
| 2634 | case IOSTAT_FABRIC_RJT: |
| 2635 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 2636 | retry = 1; |
| 2637 | break; |
| 2638 | } |
| 2639 | break; |
| 2640 | |
| 2641 | case IOSTAT_NPORT_BSY: |
| 2642 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2643 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2644 | retry = 1; |
| 2645 | break; |
| 2646 | |
| 2647 | case IOSTAT_LS_RJT: |
| 2648 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 2649 | /* Added for Vendor specifc support |
| 2650 | * Just keep retrying for these Rsn / Exp codes |
| 2651 | */ |
| 2652 | switch (stat.un.b.lsRjtRsnCode) { |
| 2653 | case LSRJT_UNABLE_TPC: |
| 2654 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2655 | LSEXP_CMD_IN_PROGRESS) { |
| 2656 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2657 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2658 | maxretry = 48; |
| 2659 | } |
| 2660 | retry = 1; |
| 2661 | break; |
| 2662 | } |
| 2663 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2664 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2665 | maxretry = lpfc_max_els_tries + 1; |
| 2666 | retry = 1; |
| 2667 | break; |
| 2668 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2669 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2670 | (cmd == ELS_CMD_FDISC) && |
| 2671 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2672 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2673 | "0125 FDISC Failed (x%x). " |
| 2674 | "Fabric out of resources\n", |
| 2675 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2676 | lpfc_vport_set_state(vport, |
| 2677 | FC_VPORT_NO_FABRIC_RSCS); |
| 2678 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2679 | break; |
| 2680 | |
| 2681 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2682 | if ((cmd == ELS_CMD_PLOGI) || |
| 2683 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2684 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2685 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2686 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2687 | /* FDISC retry policy */ |
| 2688 | maxretry = 48; |
| 2689 | if (cmdiocb->retry >= 32) |
| 2690 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2691 | } |
| 2692 | retry = 1; |
| 2693 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2694 | |
| 2695 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2696 | /* There are some cases where switches return this |
| 2697 | * error when they are not ready and should be returning |
| 2698 | * Logical Busy. We should delay every time. |
| 2699 | */ |
| 2700 | if (cmd == ELS_CMD_FDISC && |
| 2701 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 2702 | maxretry = 3; |
| 2703 | delay = 1000; |
| 2704 | retry = 1; |
| 2705 | break; |
| 2706 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2707 | case LSRJT_PROTOCOL_ERR: |
| 2708 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2709 | (cmd == ELS_CMD_FDISC) && |
| 2710 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 2711 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 2712 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2713 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2714 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2715 | "Fabric Detected Bad WWN\n", |
| 2716 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2717 | lpfc_vport_set_state(vport, |
| 2718 | FC_VPORT_FABRIC_REJ_WWN); |
| 2719 | } |
| 2720 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2721 | } |
| 2722 | break; |
| 2723 | |
| 2724 | case IOSTAT_INTERMED_RSP: |
| 2725 | case IOSTAT_BA_RJT: |
| 2726 | break; |
| 2727 | |
| 2728 | default: |
| 2729 | break; |
| 2730 | } |
| 2731 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2732 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2733 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2734 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2735 | if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 2736 | (phba->fc_topology != TOPOLOGY_LOOP) && |
| 2737 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2738 | /* FLOGI retry policy */ |
| 2739 | retry = 1; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2740 | /* retry forever */ |
| 2741 | maxretry = 0; |
| 2742 | if (cmdiocb->retry >= 100) |
| 2743 | delay = 5000; |
| 2744 | else if (cmdiocb->retry >= 32) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2745 | delay = 1000; |
| 2746 | } |
| 2747 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2748 | cmdiocb->retry++; |
| 2749 | if (maxretry && (cmdiocb->retry >= maxretry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2750 | phba->fc_stat.elsRetryExceeded++; |
| 2751 | retry = 0; |
| 2752 | } |
| 2753 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2754 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 2755 | retry = 0; |
| 2756 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2757 | if (retry) { |
| 2758 | |
| 2759 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2760 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2761 | "0107 Retry ELS command x%x to remote " |
| 2762 | "NPORT x%x Data: x%x x%x\n", |
| 2763 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2764 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2765 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 2766 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 2767 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { |
| 2768 | /* Don't reset timer for no resources */ |
| 2769 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2770 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2771 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2772 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2773 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2774 | } |
| 2775 | |
| 2776 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2777 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2778 | phba->fc_stat.elsDelayRetry++; |
| 2779 | ndlp->nlp_retry = cmdiocb->retry; |
| 2780 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2781 | /* delay is specified in milliseconds */ |
| 2782 | mod_timer(&ndlp->nlp_delayfunc, |
| 2783 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2784 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2785 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2786 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2787 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2788 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2789 | if (cmd == ELS_CMD_PRLI) |
| 2790 | lpfc_nlp_set_state(vport, ndlp, |
| 2791 | NLP_STE_REG_LOGIN_ISSUE); |
| 2792 | else |
| 2793 | lpfc_nlp_set_state(vport, ndlp, |
| 2794 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2795 | ndlp->nlp_last_elscmd = cmd; |
| 2796 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2797 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2798 | } |
| 2799 | switch (cmd) { |
| 2800 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2801 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2802 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2803 | case ELS_CMD_FDISC: |
| 2804 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 2805 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2806 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2807 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2808 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2809 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2810 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2811 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2812 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2813 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2814 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2815 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2816 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 2817 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2818 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2819 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2820 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2821 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 2822 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2823 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2824 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2825 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2826 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 2827 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2828 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2829 | } |
| 2830 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2831 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2832 | if (logerr) { |
| 2833 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2834 | "0137 No retry ELS command x%x to remote " |
| 2835 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 2836 | cmd, did, irsp->ulpStatus, |
| 2837 | irsp->un.ulpWord[4]); |
| 2838 | } |
| 2839 | else { |
| 2840 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2841 | "0108 No retry ELS command x%x to remote " |
| 2842 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 2843 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 2844 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2845 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2846 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2847 | } |
| 2848 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2849 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2850 | * 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] | 2851 | * @phba: pointer to lpfc hba data structure. |
| 2852 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 2853 | * |
| 2854 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 2855 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 2856 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 2857 | * response of the command IOCB. If so, it will be released before releasing |
| 2858 | * the lpfc DMA buffer associated with the IOCB itself. |
| 2859 | * |
| 2860 | * Return code |
| 2861 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2862 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2863 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2864 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 2865 | { |
| 2866 | struct lpfc_dmabuf *buf_ptr; |
| 2867 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2868 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2869 | if (!list_empty(&buf_ptr1->list)) { |
| 2870 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 2871 | struct lpfc_dmabuf, |
| 2872 | list); |
| 2873 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2874 | kfree(buf_ptr); |
| 2875 | } |
| 2876 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 2877 | kfree(buf_ptr1); |
| 2878 | return 0; |
| 2879 | } |
| 2880 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2881 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2882 | * 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] | 2883 | * @phba: pointer to lpfc hba data structure. |
| 2884 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 2885 | * |
| 2886 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 2887 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 2888 | * pool. |
| 2889 | * |
| 2890 | * Return code |
| 2891 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2892 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2893 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2894 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 2895 | { |
| 2896 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2897 | kfree(buf_ptr); |
| 2898 | return 0; |
| 2899 | } |
| 2900 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2901 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2902 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2903 | * @phba: pointer to lpfc hba data structure. |
| 2904 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 2905 | * |
| 2906 | * This routine frees a command IOCB and its associated resources. The |
| 2907 | * command IOCB data structure contains the reference to various associated |
| 2908 | * resources, these fields must be set to NULL if the associated reference |
| 2909 | * not present: |
| 2910 | * context1 - reference to ndlp |
| 2911 | * context2 - reference to cmd |
| 2912 | * context2->next - reference to rsp |
| 2913 | * context3 - reference to bpl |
| 2914 | * |
| 2915 | * It first properly decrements the reference count held on ndlp for the |
| 2916 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 2917 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 2918 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 2919 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 2920 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 2921 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 2922 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 2923 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 2924 | * |
| 2925 | * Return code |
| 2926 | * 0 - Success (currently, always return 0) |
| 2927 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2928 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2929 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2930 | { |
| 2931 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2932 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2933 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2934 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 2935 | if (ndlp) { |
| 2936 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 2937 | lpfc_nlp_put(ndlp); |
| 2938 | |
| 2939 | /* If the ndlp is not being used by another discovery |
| 2940 | * thread, free it. |
| 2941 | */ |
| 2942 | if (!lpfc_nlp_not_used(ndlp)) { |
| 2943 | /* If ndlp is being used by another discovery |
| 2944 | * thread, just clear NLP_DEFER_RM |
| 2945 | */ |
| 2946 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 2947 | } |
| 2948 | } |
| 2949 | else |
| 2950 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2951 | elsiocb->context1 = NULL; |
| 2952 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2953 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 2954 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2955 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 2956 | /* Firmware could still be in progress of DMAing |
| 2957 | * payload, so don't free data buffer till after |
| 2958 | * a hbeat. |
| 2959 | */ |
| 2960 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 2961 | buf_ptr = elsiocb->context2; |
| 2962 | elsiocb->context2 = NULL; |
| 2963 | if (buf_ptr) { |
| 2964 | buf_ptr1 = NULL; |
| 2965 | spin_lock_irq(&phba->hbalock); |
| 2966 | if (!list_empty(&buf_ptr->list)) { |
| 2967 | list_remove_head(&buf_ptr->list, |
| 2968 | buf_ptr1, struct lpfc_dmabuf, |
| 2969 | list); |
| 2970 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 2971 | list_add_tail(&buf_ptr1->list, |
| 2972 | &phba->elsbuf); |
| 2973 | phba->elsbuf_cnt++; |
| 2974 | } |
| 2975 | INIT_LIST_HEAD(&buf_ptr->list); |
| 2976 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 2977 | phba->elsbuf_cnt++; |
| 2978 | spin_unlock_irq(&phba->hbalock); |
| 2979 | } |
| 2980 | } else { |
| 2981 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 2982 | lpfc_els_free_data(phba, buf_ptr1); |
| 2983 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2984 | } |
| 2985 | |
| 2986 | if (elsiocb->context3) { |
| 2987 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2988 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2989 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2990 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2991 | return 0; |
| 2992 | } |
| 2993 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2994 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2995 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2996 | * @phba: pointer to lpfc hba data structure. |
| 2997 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2998 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2999 | * |
| 3000 | * This routine is the completion callback function to the Logout (LOGO) |
| 3001 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 3002 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 3003 | * release the ndlp if it has the last reference remaining (reference count |
| 3004 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 3005 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 3006 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 3007 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 3008 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 3009 | * IOCB data structure. |
| 3010 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3011 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3012 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3013 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3014 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3015 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3016 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3017 | IOCB_t *irsp; |
| 3018 | |
| 3019 | irsp = &rspiocb->iocb; |
| 3020 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3021 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 3022 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3023 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3024 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3025 | "0109 ACC to LOGO completes to NPort x%x " |
| 3026 | "Data: x%x x%x x%x\n", |
| 3027 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3028 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3029 | |
| 3030 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 3031 | /* NPort Recovery mode or node is just allocated */ |
| 3032 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3033 | /* If the ndlp is being used by another discovery |
| 3034 | * thread, just unregister the RPI. |
| 3035 | */ |
| 3036 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3037 | } else { |
| 3038 | /* Indicate the node has already released, should |
| 3039 | * not reference to it from within lpfc_els_free_iocb. |
| 3040 | */ |
| 3041 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3042 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3043 | } |
| 3044 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3045 | return; |
| 3046 | } |
| 3047 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3048 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3049 | * 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] | 3050 | * @phba: pointer to lpfc hba data structure. |
| 3051 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 3052 | * |
| 3053 | * This routine is the completion callback function for unregister default |
| 3054 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 3055 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 3056 | * decrements the ndlp reference count held for this completion callback |
| 3057 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 3058 | * whether there is only one reference left on the ndlp. If so, it will |
| 3059 | * perform one more decrement and trigger the release of the ndlp. |
| 3060 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3061 | void |
| 3062 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3063 | { |
| 3064 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3065 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3066 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3067 | /* |
| 3068 | * This routine is used to register and unregister in previous SLI |
| 3069 | * modes. |
| 3070 | */ |
| 3071 | if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) && |
| 3072 | (phba->sli_rev == LPFC_SLI_REV4)) |
| 3073 | lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi); |
| 3074 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3075 | pmb->context1 = NULL; |
| 3076 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3077 | kfree(mp); |
| 3078 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3079 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3080 | lpfc_nlp_put(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3081 | /* This is the end of the default RPI cleanup logic for this |
| 3082 | * ndlp. If no other discovery threads are using this ndlp. |
| 3083 | * we should free all resources associated with it. |
| 3084 | */ |
| 3085 | lpfc_nlp_not_used(ndlp); |
| 3086 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3087 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3088 | return; |
| 3089 | } |
| 3090 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3091 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3092 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3093 | * @phba: pointer to lpfc hba data structure. |
| 3094 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3095 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3096 | * |
| 3097 | * This routine is the completion callback function for ELS Response IOCB |
| 3098 | * command. In normal case, this callback function just properly sets the |
| 3099 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 3100 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 3101 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 3102 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 3103 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 3104 | * routine shall be invoked trying to release the ndlp if no other threads |
| 3105 | * are currently referring it. |
| 3106 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3107 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3108 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3109 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3110 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3111 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3112 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 3113 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3114 | IOCB_t *irsp; |
| 3115 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3116 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3117 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3118 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3119 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3120 | irsp = &rspiocb->iocb; |
| 3121 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3122 | if (cmdiocb->context_un.mbox) |
| 3123 | mbox = cmdiocb->context_un.mbox; |
| 3124 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3125 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 3126 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 3127 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3128 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3129 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3130 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3131 | /* A LS_RJT associated with Default RPI cleanup has its own |
| 3132 | * seperate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3133 | */ |
| 3134 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 3135 | ls_rjt = 1; |
| 3136 | } |
| 3137 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3138 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3139 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3140 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3141 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3142 | if (mp) { |
| 3143 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3144 | kfree(mp); |
| 3145 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3146 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3147 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3148 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3149 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3150 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3151 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3152 | /* Indicate the node has already released, |
| 3153 | * should not reference to it from within |
| 3154 | * the routine lpfc_els_free_iocb. |
| 3155 | */ |
| 3156 | cmdiocb->context1 = NULL; |
| 3157 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3158 | goto out; |
| 3159 | } |
| 3160 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3161 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3162 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3163 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3164 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3165 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3166 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3167 | "0110 ELS response tag x%x completes " |
| 3168 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3169 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3170 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3171 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3172 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3173 | if (mbox) { |
| 3174 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3175 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3176 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3177 | /* Increment reference count to ndlp to hold the |
| 3178 | * reference to ndlp for the callback function. |
| 3179 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3180 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3181 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3182 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3183 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3184 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3185 | } |
| 3186 | else { |
| 3187 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3188 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3189 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3190 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3191 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3192 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3193 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3194 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3195 | else |
| 3196 | /* Decrement the ndlp reference count we |
| 3197 | * set for this failed mailbox command. |
| 3198 | */ |
| 3199 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3200 | |
| 3201 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3202 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3203 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3204 | "Data: x%x x%x x%x\n", |
| 3205 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3206 | ndlp->nlp_rpi); |
| 3207 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3208 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3209 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3210 | /* Indicate node has already been released, |
| 3211 | * should not reference to it from within |
| 3212 | * the routine lpfc_els_free_iocb. |
| 3213 | */ |
| 3214 | cmdiocb->context1 = NULL; |
| 3215 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3216 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3217 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3218 | if (!lpfc_error_lost_link(irsp) && |
| 3219 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3220 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3221 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3222 | /* Indicate node has already been |
| 3223 | * released, should not reference |
| 3224 | * to it from within the routine |
| 3225 | * lpfc_els_free_iocb. |
| 3226 | */ |
| 3227 | cmdiocb->context1 = NULL; |
| 3228 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3229 | } |
| 3230 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3231 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3232 | if (mp) { |
| 3233 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3234 | kfree(mp); |
| 3235 | } |
| 3236 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3237 | } |
| 3238 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3239 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3240 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3241 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3242 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3243 | |
| 3244 | /* If the node is not being used by another discovery thread, |
| 3245 | * and we are sending a reject, we are done with it. |
| 3246 | * Release driver reference count here and free associated |
| 3247 | * resources. |
| 3248 | */ |
| 3249 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3250 | if (lpfc_nlp_not_used(ndlp)) |
| 3251 | /* Indicate node has already been released, |
| 3252 | * should not reference to it from within |
| 3253 | * the routine lpfc_els_free_iocb. |
| 3254 | */ |
| 3255 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3256 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3257 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3258 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3259 | return; |
| 3260 | } |
| 3261 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3262 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3263 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3264 | * @vport: pointer to a host virtual N_Port data structure. |
| 3265 | * @flag: the els command code to be accepted. |
| 3266 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3267 | * @ndlp: pointer to a node-list data structure. |
| 3268 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3269 | * |
| 3270 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3271 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3272 | * specific ACC response command to be issued and invokes the |
| 3273 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3274 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3275 | * field of the IOCB for the completion callback function to issue the |
| 3276 | * mailbox command to the HBA later when callback is invoked. |
| 3277 | * |
| 3278 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3279 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3280 | * will be stored into the context1 field of the IOCB for the completion |
| 3281 | * callback function to the corresponding response ELS IOCB command. |
| 3282 | * |
| 3283 | * Return code |
| 3284 | * 0 - Successfully issued acc response |
| 3285 | * 1 - Failed to issue acc response |
| 3286 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3287 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3288 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3289 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3290 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3291 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3292 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3293 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3294 | IOCB_t *icmd; |
| 3295 | IOCB_t *oldcmd; |
| 3296 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3297 | struct lpfc_sli *psli; |
| 3298 | uint8_t *pcmd; |
| 3299 | uint16_t cmdsize; |
| 3300 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3301 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3302 | |
| 3303 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3304 | oldcmd = &oldiocb->iocb; |
| 3305 | |
| 3306 | switch (flag) { |
| 3307 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3308 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3309 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3310 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3311 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3312 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3313 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3314 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3315 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3316 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3317 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3318 | icmd = &elsiocb->iocb; |
| 3319 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3320 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3321 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3322 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3323 | |
| 3324 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3325 | "Issue ACC: did:x%x flg:x%x", |
| 3326 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3327 | break; |
| 3328 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3329 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3330 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3331 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3332 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3333 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3334 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3335 | icmd = &elsiocb->iocb; |
| 3336 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3337 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3338 | |
| 3339 | if (mbox) |
| 3340 | elsiocb->context_un.mbox = mbox; |
| 3341 | |
| 3342 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3343 | pcmd += sizeof(uint32_t); |
| 3344 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3345 | |
| 3346 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3347 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 3348 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3349 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3350 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3351 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3352 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3353 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3354 | if (!elsiocb) |
| 3355 | return 1; |
| 3356 | |
| 3357 | icmd = &elsiocb->iocb; |
| 3358 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3359 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3360 | |
| 3361 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3362 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3363 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 3364 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 3365 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3366 | |
| 3367 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3368 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 3369 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3370 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3371 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3372 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3373 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3374 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3375 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3376 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
| 3377 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", |
| 3378 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3379 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3380 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3381 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3382 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3383 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3384 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3385 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 3386 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3387 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3388 | } |
| 3389 | |
| 3390 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3391 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3392 | if (rc == IOCB_ERROR) { |
| 3393 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3394 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3395 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3396 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3397 | } |
| 3398 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3399 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3400 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3401 | * @vport: pointer to a virtual N_Port data structure. |
| 3402 | * @rejectError: |
| 3403 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3404 | * @ndlp: pointer to a node-list data structure. |
| 3405 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3406 | * |
| 3407 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 3408 | * command. If a @mbox pointer is passed in, it will be put into the |
| 3409 | * context_un.mbox field of the IOCB for the completion callback function |
| 3410 | * to issue to the HBA later. |
| 3411 | * |
| 3412 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3413 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3414 | * will be stored into the context1 field of the IOCB for the completion |
| 3415 | * callback function to the reject response ELS IOCB command. |
| 3416 | * |
| 3417 | * Return code |
| 3418 | * 0 - Successfully issued reject response |
| 3419 | * 1 - Failed to issue reject response |
| 3420 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3421 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3422 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3423 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 3424 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3425 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3426 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3427 | IOCB_t *icmd; |
| 3428 | IOCB_t *oldcmd; |
| 3429 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3430 | struct lpfc_sli *psli; |
| 3431 | uint8_t *pcmd; |
| 3432 | uint16_t cmdsize; |
| 3433 | int rc; |
| 3434 | |
| 3435 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3436 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3437 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3438 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3439 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3440 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3441 | |
| 3442 | icmd = &elsiocb->iocb; |
| 3443 | oldcmd = &oldiocb->iocb; |
| 3444 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3445 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3446 | |
| 3447 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3448 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3449 | *((uint32_t *) (pcmd)) = rejectError; |
| 3450 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3451 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3452 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3453 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3454 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3455 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3456 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 3457 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 3458 | "rpi x%x\n", |
| 3459 | rejectError, elsiocb->iotag, |
| 3460 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 3461 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3462 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3463 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 3464 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 3465 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3466 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3467 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3468 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3469 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3470 | if (rc == IOCB_ERROR) { |
| 3471 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3472 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3473 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3474 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3475 | } |
| 3476 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3477 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3478 | * 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] | 3479 | * @vport: pointer to a virtual N_Port data structure. |
| 3480 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3481 | * @ndlp: pointer to a node-list data structure. |
| 3482 | * |
| 3483 | * This routine prepares and issues an Accept (ACC) response to Address |
| 3484 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 3485 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3486 | * |
| 3487 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3488 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3489 | * will be stored into the context1 field of the IOCB for the completion |
| 3490 | * callback function to the ADISC Accept response ELS IOCB command. |
| 3491 | * |
| 3492 | * Return code |
| 3493 | * 0 - Successfully issued acc adisc response |
| 3494 | * 1 - Failed to issue adisc acc response |
| 3495 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3496 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3497 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 3498 | struct lpfc_nodelist *ndlp) |
| 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 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3502 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3503 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3504 | uint8_t *pcmd; |
| 3505 | uint16_t cmdsize; |
| 3506 | int rc; |
| 3507 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3508 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3509 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3510 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3511 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3512 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3513 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3514 | icmd = &elsiocb->iocb; |
| 3515 | oldcmd = &oldiocb->iocb; |
| 3516 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3517 | |
| 3518 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3519 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3520 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 3521 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 3522 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3523 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3524 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3525 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3526 | |
| 3527 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3528 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3529 | |
| 3530 | ap = (ADISC *) (pcmd); |
| 3531 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3532 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3533 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3534 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3535 | |
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 ACC ADISC: did:x%x flg:x%x", |
| 3538 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3539 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3540 | phba->fc_stat.elsXmitACC++; |
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); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3543 | if (rc == IOCB_ERROR) { |
| 3544 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3545 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3546 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3547 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3548 | } |
| 3549 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3550 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3551 | * 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] | 3552 | * @vport: pointer to a virtual N_Port data structure. |
| 3553 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3554 | * @ndlp: pointer to a node-list data structure. |
| 3555 | * |
| 3556 | * This routine prepares and issues an Accept (ACC) response to Process |
| 3557 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 3558 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3559 | * |
| 3560 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3561 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3562 | * will be stored into the context1 field of the IOCB for the completion |
| 3563 | * callback function to the PRLI Accept response ELS IOCB command. |
| 3564 | * |
| 3565 | * Return code |
| 3566 | * 0 - Successfully issued acc prli response |
| 3567 | * 1 - Failed to issue acc prli response |
| 3568 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3569 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3570 | 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] | 3571 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3572 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3573 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3574 | PRLI *npr; |
| 3575 | lpfc_vpd_t *vpd; |
| 3576 | IOCB_t *icmd; |
| 3577 | IOCB_t *oldcmd; |
| 3578 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3579 | struct lpfc_sli *psli; |
| 3580 | uint8_t *pcmd; |
| 3581 | uint16_t cmdsize; |
| 3582 | int rc; |
| 3583 | |
| 3584 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3585 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3586 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3587 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3588 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3589 | if (!elsiocb) |
| 3590 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3591 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3592 | icmd = &elsiocb->iocb; |
| 3593 | oldcmd = &oldiocb->iocb; |
| 3594 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3595 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3596 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3597 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 3598 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 3599 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3600 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3601 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3602 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3603 | |
| 3604 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3605 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3606 | |
| 3607 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3608 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3609 | |
| 3610 | npr = (PRLI *) pcmd; |
| 3611 | vpd = &phba->vpd; |
| 3612 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3613 | * If the remote port is a target and our firmware version is 3.20 or |
| 3614 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3615 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3616 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 3617 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3618 | npr->ConfmComplAllowed = 1; |
| 3619 | npr->Retry = 1; |
| 3620 | npr->TaskRetryIdReq = 1; |
| 3621 | } |
| 3622 | |
| 3623 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 3624 | npr->estabImagePair = 1; |
| 3625 | npr->readXferRdyDis = 1; |
| 3626 | npr->ConfmComplAllowed = 1; |
| 3627 | |
| 3628 | npr->prliType = PRLI_FCP_TYPE; |
| 3629 | npr->initiatorFunc = 1; |
| 3630 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3631 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3632 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 3633 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3634 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3635 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3636 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3637 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3638 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3639 | if (rc == IOCB_ERROR) { |
| 3640 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3641 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3642 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3643 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3644 | } |
| 3645 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3646 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3647 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3648 | * @vport: pointer to a virtual N_Port data structure. |
| 3649 | * @format: rnid command format. |
| 3650 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3651 | * @ndlp: pointer to a node-list data structure. |
| 3652 | * |
| 3653 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 3654 | * (ACC) response. It constructs the RNID ACC response command according to |
| 3655 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 3656 | * issue the response. Note that this command does not need to hold the ndlp |
| 3657 | * reference count for the callback. So, the ndlp reference count taken by |
| 3658 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 3659 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 3660 | * there is no ndlp reference available. |
| 3661 | * |
| 3662 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3663 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3664 | * will be stored into the context1 field of the IOCB for the completion |
| 3665 | * callback function. However, for the RNID Accept Response ELS command, |
| 3666 | * this is undone later by this routine after the IOCB is allocated. |
| 3667 | * |
| 3668 | * Return code |
| 3669 | * 0 - Successfully issued acc rnid response |
| 3670 | * 1 - Failed to issue acc rnid response |
| 3671 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3672 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3673 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3674 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3675 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3676 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3677 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3678 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3679 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3680 | struct lpfc_sli *psli; |
| 3681 | uint8_t *pcmd; |
| 3682 | uint16_t cmdsize; |
| 3683 | int rc; |
| 3684 | |
| 3685 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3686 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 3687 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3688 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3689 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3690 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3691 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3692 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3693 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3694 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3695 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3696 | icmd = &elsiocb->iocb; |
| 3697 | oldcmd = &oldiocb->iocb; |
| 3698 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3699 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3700 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3701 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 3702 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3703 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3704 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3705 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3706 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3707 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3708 | rn = (RNID *) (pcmd); |
| 3709 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3710 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 3711 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3712 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3713 | switch (format) { |
| 3714 | case 0: |
| 3715 | rn->SpecificLen = 0; |
| 3716 | break; |
| 3717 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3718 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3719 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3720 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3721 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 3722 | rn->un.topologyDisc.physPort = 0; |
| 3723 | rn->un.topologyDisc.attachedNodes = 0; |
| 3724 | break; |
| 3725 | default: |
| 3726 | rn->CommonLen = 0; |
| 3727 | rn->SpecificLen = 0; |
| 3728 | break; |
| 3729 | } |
| 3730 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3731 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3732 | "Issue ACC RNID: did:x%x flg:x%x", |
| 3733 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3734 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3735 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3736 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3737 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3738 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 3739 | * it could be freed */ |
| 3740 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3741 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3742 | if (rc == IOCB_ERROR) { |
| 3743 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3744 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3745 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3746 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3747 | } |
| 3748 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3749 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3750 | * 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] | 3751 | * @vport: pointer to a host virtual N_Port data structure. |
| 3752 | * |
| 3753 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 3754 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 3755 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 3756 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 3757 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 3758 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 3759 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 3760 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 3761 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 3762 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 3763 | * no more ADISC need to be sent. |
| 3764 | * |
| 3765 | * Return code |
| 3766 | * The number of N_Ports with adisc issued. |
| 3767 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3768 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3769 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3770 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3771 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3772 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3773 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3774 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3775 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3776 | 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] | 3777 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3778 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3779 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3780 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3781 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3782 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3783 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3784 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3785 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3786 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 3787 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3788 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3789 | vport->num_disc_nodes++; |
| 3790 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3791 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3792 | spin_lock_irq(shost->host_lock); |
| 3793 | vport->fc_flag |= FC_NLP_MORE; |
| 3794 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3795 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3796 | } |
| 3797 | } |
| 3798 | } |
| 3799 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3800 | spin_lock_irq(shost->host_lock); |
| 3801 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3802 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3803 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3804 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3805 | } |
| 3806 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3807 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3808 | * 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] | 3809 | * @vport: pointer to a host virtual N_Port data structure. |
| 3810 | * |
| 3811 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 3812 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 3813 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 3814 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 3815 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 3816 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 3817 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 3818 | * later pick up. On the other hand, after walking through all the ndlps with |
| 3819 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 3820 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 3821 | * PLOGI need to be sent. |
| 3822 | * |
| 3823 | * Return code |
| 3824 | * The number of N_Ports with plogi issued. |
| 3825 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3826 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3827 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3828 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3829 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3830 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3831 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3832 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3833 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 3834 | 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] | 3835 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3836 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3837 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3838 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3839 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 3840 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 3841 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3842 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 3843 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3844 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3845 | vport->num_disc_nodes++; |
| 3846 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3847 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3848 | spin_lock_irq(shost->host_lock); |
| 3849 | vport->fc_flag |= FC_NLP_MORE; |
| 3850 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3851 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3852 | } |
| 3853 | } |
| 3854 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3855 | if (sentplogi) { |
| 3856 | lpfc_set_disctmo(vport); |
| 3857 | } |
| 3858 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3859 | spin_lock_irq(shost->host_lock); |
| 3860 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3861 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3862 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3863 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3864 | } |
| 3865 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3866 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3867 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3868 | * @vport: pointer to a host virtual N_Port data structure. |
| 3869 | * |
| 3870 | * This routine cleans up any Registration State Change Notification |
| 3871 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 3872 | * @vport together with the host_lock is used to prevent multiple thread |
| 3873 | * trying to access the RSCN array on a same @vport at the same time. |
| 3874 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3875 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3876 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3877 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3878 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3879 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3880 | int i; |
| 3881 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3882 | spin_lock_irq(shost->host_lock); |
| 3883 | if (vport->fc_rscn_flush) { |
| 3884 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3885 | spin_unlock_irq(shost->host_lock); |
| 3886 | return; |
| 3887 | } |
| 3888 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 3889 | vport->fc_rscn_flush = 1; |
| 3890 | spin_unlock_irq(shost->host_lock); |
| 3891 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3892 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3893 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3894 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3895 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3896 | spin_lock_irq(shost->host_lock); |
| 3897 | vport->fc_rscn_id_cnt = 0; |
| 3898 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 3899 | spin_unlock_irq(shost->host_lock); |
| 3900 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3901 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 3902 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3903 | } |
| 3904 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3905 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3906 | * 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] | 3907 | * @vport: pointer to a host virtual N_Port data structure. |
| 3908 | * @did: remote destination port identifier. |
| 3909 | * |
| 3910 | * This routine checks whether there is any pending Registration State |
| 3911 | * Configuration Notification (RSCN) to a @did on @vport. |
| 3912 | * |
| 3913 | * Return code |
| 3914 | * None zero - The @did matched with a pending rscn |
| 3915 | * 0 - not able to match @did with a pending rscn |
| 3916 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3917 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3918 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3919 | { |
| 3920 | D_ID ns_did; |
| 3921 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3922 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3923 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3924 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3925 | |
| 3926 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3927 | |
| 3928 | /* Never match fabric nodes for RSCNs */ |
| 3929 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3930 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3931 | |
| 3932 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3933 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3934 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3935 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3936 | spin_lock_irq(shost->host_lock); |
| 3937 | if (vport->fc_rscn_flush) { |
| 3938 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3939 | spin_unlock_irq(shost->host_lock); |
| 3940 | return 0; |
| 3941 | } |
| 3942 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 3943 | vport->fc_rscn_flush = 1; |
| 3944 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3945 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3946 | lp = vport->fc_rscn_id_list[i]->virt; |
| 3947 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 3948 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3949 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3950 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 3951 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3952 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 3953 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3954 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 3955 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 3956 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3957 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3958 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3959 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3960 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 3961 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3962 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3963 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3964 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3965 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3966 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3967 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3968 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3969 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3970 | } |
| 3971 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3972 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3973 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 3974 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3975 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3976 | return_did_out: |
| 3977 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 3978 | vport->fc_rscn_flush = 0; |
| 3979 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3980 | } |
| 3981 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3982 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3983 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3984 | * @vport: pointer to a host virtual N_Port data structure. |
| 3985 | * |
| 3986 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 3987 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 3988 | * State Change Notification). |
| 3989 | * |
| 3990 | * Return code |
| 3991 | * 0 - Successful (currently alway return 0) |
| 3992 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3993 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3994 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3995 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3996 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3997 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3998 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3999 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4000 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4001 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 4002 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4003 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4004 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4005 | NLP_EVT_DEVICE_RECOVERY); |
| 4006 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4007 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4008 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4009 | } |
| 4010 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4011 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4012 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4013 | * @vport: pointer to a host virtual N_Port data structure. |
| 4014 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4015 | * |
| 4016 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 4017 | * applications. |
| 4018 | */ |
| 4019 | static void |
| 4020 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 4021 | struct lpfc_iocbq *cmdiocb) |
| 4022 | { |
| 4023 | struct lpfc_dmabuf *pcmd; |
| 4024 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4025 | uint32_t *payload_ptr; |
| 4026 | uint32_t payload_len; |
| 4027 | struct lpfc_rscn_event_header *rscn_event_data; |
| 4028 | |
| 4029 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4030 | payload_ptr = (uint32_t *) pcmd->virt; |
| 4031 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 4032 | |
| 4033 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 4034 | payload_len, GFP_KERNEL); |
| 4035 | if (!rscn_event_data) { |
| 4036 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4037 | "0147 Failed to allocate memory for RSCN event\n"); |
| 4038 | return; |
| 4039 | } |
| 4040 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 4041 | rscn_event_data->payload_length = payload_len; |
| 4042 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 4043 | payload_len); |
| 4044 | |
| 4045 | fc_host_post_vendor_event(shost, |
| 4046 | fc_get_event_number(), |
| 4047 | sizeof(struct lpfc_els_event_header) + payload_len, |
| 4048 | (char *)rscn_event_data, |
| 4049 | LPFC_NL_VENDOR_ID); |
| 4050 | |
| 4051 | kfree(rscn_event_data); |
| 4052 | } |
| 4053 | |
| 4054 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4055 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4056 | * @vport: pointer to a host virtual N_Port data structure. |
| 4057 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4058 | * @ndlp: pointer to a node-list data structure. |
| 4059 | * |
| 4060 | * This routine processes an unsolicited RSCN (Registration State Change |
| 4061 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 4062 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 4063 | * discover state machine is about to begin discovery, it just accepts the |
| 4064 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 4065 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 4066 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 4067 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 4068 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 4069 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 4070 | * routine is invoked to handle the RSCN event. |
| 4071 | * |
| 4072 | * Return code |
| 4073 | * 0 - Just sent the acc response |
| 4074 | * 1 - Sent the acc response and waited for name server completion |
| 4075 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4076 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4077 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4078 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4079 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4080 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4081 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4082 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4083 | uint32_t *lp, *datap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4084 | IOCB_t *icmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4085 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4086 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4087 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4088 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4089 | |
| 4090 | icmd = &cmdiocb->iocb; |
| 4091 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4092 | lp = (uint32_t *) pcmd->virt; |
| 4093 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4094 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4095 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4096 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4097 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4098 | "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] | 4099 | vport->fc_flag, payload_len, *lp, |
| 4100 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4101 | |
| 4102 | /* Send an RSCN event to the management application */ |
| 4103 | lpfc_send_rscn_event(vport, cmdiocb); |
| 4104 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4105 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4106 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4107 | FCH_EVT_RSCN, lp[i]); |
| 4108 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4109 | /* If we are about to begin discovery, just ACC the RSCN. |
| 4110 | * Discovery processing will satisfy it. |
| 4111 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4112 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4113 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4114 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 4115 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4116 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4117 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4118 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4119 | } |
| 4120 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4121 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 4122 | * just ACC and ignore it. |
| 4123 | */ |
| 4124 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4125 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4126 | i = payload_len; |
| 4127 | datap = lp; |
| 4128 | while (i > 0) { |
| 4129 | nportid = *datap++; |
| 4130 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 4131 | i -= sizeof(uint32_t); |
| 4132 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4133 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 4134 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4135 | } |
| 4136 | if (rscn_id == hba_id) { |
| 4137 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4138 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4139 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4140 | "Data: x%x x%x x%x x%x\n", |
| 4141 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4142 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4143 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4144 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 4145 | ndlp->nlp_DID, vport->port_state, |
| 4146 | ndlp->nlp_flag); |
| 4147 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4148 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4149 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4150 | return 0; |
| 4151 | } |
| 4152 | } |
| 4153 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4154 | spin_lock_irq(shost->host_lock); |
| 4155 | if (vport->fc_rscn_flush) { |
| 4156 | /* Another thread is walking fc_rscn_id_list on this vport */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4157 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 4158 | spin_unlock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4159 | /* Send back ACC */ |
| 4160 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4161 | return 0; |
| 4162 | } |
| 4163 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4164 | vport->fc_rscn_flush = 1; |
| 4165 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4166 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4167 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4168 | /* If we are already processing an RSCN, save the received |
| 4169 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 4170 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4171 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4172 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4173 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 4174 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4175 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4176 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4177 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 4178 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4179 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4180 | vport->fc_flag |= FC_RSCN_MODE; |
| 4181 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4182 | if (rscn_cnt) { |
| 4183 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 4184 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 4185 | } |
| 4186 | if ((rscn_cnt) && |
| 4187 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 4188 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4189 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4190 | memcpy(((uint8_t *)cmd) + length, lp, |
| 4191 | payload_len); |
| 4192 | } else { |
| 4193 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 4194 | vport->fc_rscn_id_cnt++; |
| 4195 | /* If we zero, cmdiocb->context2, the calling |
| 4196 | * routine will not try to free it. |
| 4197 | */ |
| 4198 | cmdiocb->context2 = NULL; |
| 4199 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4200 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4201 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4202 | "0235 Deferred RSCN " |
| 4203 | "Data: x%x x%x x%x\n", |
| 4204 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4205 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4206 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4207 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 4208 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4209 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4210 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4211 | "0234 ReDiscovery RSCN " |
| 4212 | "Data: x%x x%x x%x\n", |
| 4213 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4214 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4215 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4216 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4217 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4218 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4219 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4220 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4221 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4222 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4223 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4224 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4225 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4226 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4227 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4228 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 4229 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4230 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4231 | spin_lock_irq(shost->host_lock); |
| 4232 | vport->fc_flag |= FC_RSCN_MODE; |
| 4233 | spin_unlock_irq(shost->host_lock); |
| 4234 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4235 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4236 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4237 | /* |
| 4238 | * If we zero, cmdiocb->context2, the calling routine will |
| 4239 | * not try to free it. |
| 4240 | */ |
| 4241 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4242 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4243 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4244 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4245 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4246 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4247 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4248 | } |
| 4249 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4250 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4251 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4252 | * @vport: pointer to a host virtual N_Port data structure. |
| 4253 | * |
| 4254 | * This routine handles the Registration State Configuration Notification |
| 4255 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 4256 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 4257 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 4258 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 4259 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 4260 | * RSCN activities with the @vport. |
| 4261 | * |
| 4262 | * Return code |
| 4263 | * 0 - Cleaned up rscn on the @vport |
| 4264 | * 1 - Wait for plogi to name server before proceed |
| 4265 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4266 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4267 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4268 | { |
| 4269 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4270 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4271 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4272 | /* Ignore RSCN if the port is being torn down. */ |
| 4273 | if (vport->load_flag & FC_UNLOADING) { |
| 4274 | lpfc_els_flush_rscn(vport); |
| 4275 | return 0; |
| 4276 | } |
| 4277 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4278 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4279 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4280 | |
| 4281 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4282 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4283 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 4284 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 4285 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4286 | |
| 4287 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4288 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4289 | vport->num_disc_nodes = 0; |
| 4290 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4291 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4292 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 4293 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4294 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4295 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4296 | /* Wait for NameServer query cmpl before we can |
| 4297 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4298 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4299 | } else { |
| 4300 | /* If login to NameServer does not exist, issue one */ |
| 4301 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4302 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4303 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4304 | /* Wait for NameServer login cmpl before we can |
| 4305 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4306 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4307 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4308 | if (ndlp) { |
| 4309 | ndlp = lpfc_enable_node(vport, ndlp, |
| 4310 | NLP_STE_PLOGI_ISSUE); |
| 4311 | if (!ndlp) { |
| 4312 | lpfc_els_flush_rscn(vport); |
| 4313 | return 0; |
| 4314 | } |
| 4315 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4316 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4317 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4318 | if (!ndlp) { |
| 4319 | lpfc_els_flush_rscn(vport); |
| 4320 | return 0; |
| 4321 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4322 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4323 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4324 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4325 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4326 | ndlp->nlp_type |= NLP_FABRIC; |
| 4327 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 4328 | /* Wait for NameServer login cmpl before we can |
| 4329 | * continue |
| 4330 | */ |
| 4331 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4332 | } |
| 4333 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4334 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4335 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4336 | } |
| 4337 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4338 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4339 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4340 | * @vport: pointer to a host virtual N_Port data structure. |
| 4341 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4342 | * @ndlp: pointer to a node-list data structure. |
| 4343 | * |
| 4344 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 4345 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 4346 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 4347 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 4348 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 4349 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 4350 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 4351 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 4352 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 4353 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 4354 | * higher priority (as the winning port) and will initiate PLOGI and |
| 4355 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 4356 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 4357 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 4358 | * |
| 4359 | * Return code |
| 4360 | * 0 - Successfully processed the unsolicited flogi |
| 4361 | * 1 - Failed to process the unsolicited flogi |
| 4362 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4363 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4364 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4365 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4366 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4367 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4368 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4369 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4370 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 4371 | IOCB_t *icmd = &cmdiocb->iocb; |
| 4372 | struct serv_parm *sp; |
| 4373 | LPFC_MBOXQ_t *mbox; |
| 4374 | struct ls_rjt stat; |
| 4375 | uint32_t cmd, did; |
| 4376 | int rc; |
| 4377 | |
| 4378 | cmd = *lp++; |
| 4379 | sp = (struct serv_parm *) lp; |
| 4380 | |
| 4381 | /* FLOGI received */ |
| 4382 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4383 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4384 | |
| 4385 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 4386 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 4387 | did = icmd->un.elsreq64.remoteID; |
| 4388 | |
| 4389 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 4390 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4391 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4392 | "0113 An FLOGI ELS command x%x was " |
| 4393 | "received from DID x%x in Loop Mode\n", |
| 4394 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4395 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4396 | } |
| 4397 | |
| 4398 | did = Fabric_DID; |
| 4399 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 4400 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4401 | /* For a FLOGI we accept, then if our portname is greater |
| 4402 | * then the remote portname we initiate Nport login. |
| 4403 | */ |
| 4404 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4405 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4406 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4407 | |
| 4408 | if (!rc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4409 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4410 | if (!mbox) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4411 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4412 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4413 | lpfc_linkdown(phba); |
| 4414 | lpfc_init_link(phba, mbox, |
| 4415 | phba->cfg_topology, |
| 4416 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4417 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4418 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4419 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4420 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4421 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4422 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4423 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4424 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4425 | return 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4426 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4427 | spin_lock_irq(shost->host_lock); |
| 4428 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 4429 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4430 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4431 | spin_lock_irq(shost->host_lock); |
| 4432 | vport->fc_flag |= FC_PT2PT; |
| 4433 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 4434 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4435 | } else { |
| 4436 | /* Reject this request because invalid parameters */ |
| 4437 | stat.un.b.lsRjtRsvd0 = 0; |
| 4438 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4439 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 4440 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4441 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4442 | NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4443 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4444 | } |
| 4445 | |
| 4446 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4447 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4448 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4449 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4450 | } |
| 4451 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4452 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4453 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4454 | * @vport: pointer to a host virtual N_Port data structure. |
| 4455 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4456 | * @ndlp: pointer to a node-list data structure. |
| 4457 | * |
| 4458 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 4459 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 4460 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 4461 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 4462 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 4463 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 4464 | * |
| 4465 | * Return code |
| 4466 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 4467 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4468 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4469 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4470 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4471 | { |
| 4472 | struct lpfc_dmabuf *pcmd; |
| 4473 | uint32_t *lp; |
| 4474 | IOCB_t *icmd; |
| 4475 | RNID *rn; |
| 4476 | struct ls_rjt stat; |
| 4477 | uint32_t cmd, did; |
| 4478 | |
| 4479 | icmd = &cmdiocb->iocb; |
| 4480 | did = icmd->un.elsreq64.remoteID; |
| 4481 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4482 | lp = (uint32_t *) pcmd->virt; |
| 4483 | |
| 4484 | cmd = *lp++; |
| 4485 | rn = (RNID *) lp; |
| 4486 | |
| 4487 | /* RNID received */ |
| 4488 | |
| 4489 | switch (rn->Format) { |
| 4490 | case 0: |
| 4491 | case RNID_TOPOLOGY_DISC: |
| 4492 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4493 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4494 | break; |
| 4495 | default: |
| 4496 | /* Reject this request because format not supported */ |
| 4497 | stat.un.b.lsRjtRsvd0 = 0; |
| 4498 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4499 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4500 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4501 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4502 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4503 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4504 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4505 | } |
| 4506 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4507 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4508 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4509 | * @vport: pointer to a host virtual N_Port data structure. |
| 4510 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4511 | * @ndlp: pointer to a node-list data structure. |
| 4512 | * |
| 4513 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 4514 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 4515 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 4516 | * |
| 4517 | * Return code |
| 4518 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 4519 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4520 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4521 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4522 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4523 | { |
| 4524 | struct ls_rjt stat; |
| 4525 | |
| 4526 | /* For now, unconditionally reject this command */ |
| 4527 | stat.un.b.lsRjtRsvd0 = 0; |
| 4528 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4529 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4530 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4531 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4532 | return 0; |
| 4533 | } |
| 4534 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4535 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4536 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb |
| 4537 | * @vport: pointer to a host virtual N_Port data structure. |
| 4538 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4539 | * @ndlp: pointer to a node-list data structure. |
| 4540 | * |
| 4541 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB |
| 4542 | * received as an ELS unsolicited event. A request to RRQ shall only |
| 4543 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder |
| 4544 | * Nx_Port N_Port_ID of the target Exchange is the same as the |
| 4545 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is |
| 4546 | * not accepted, an LS_RJT with reason code "Unable to perform |
| 4547 | * command request" and reason code explanation "Invalid Originator |
| 4548 | * S_ID" shall be returned. For now, we just unconditionally accept |
| 4549 | * RRQ from the target. |
| 4550 | **/ |
| 4551 | static void |
| 4552 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4553 | struct lpfc_nodelist *ndlp) |
| 4554 | { |
| 4555 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| 4556 | } |
| 4557 | |
| 4558 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4559 | * 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] | 4560 | * @phba: pointer to lpfc hba data structure. |
| 4561 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4562 | * |
| 4563 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 4564 | * mailbox command. This callback function is to actually send the Accept |
| 4565 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 4566 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 4567 | * mailbox command, constructs the RPS response with the link statistics |
| 4568 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 4569 | * response to the RPS. |
| 4570 | * |
| 4571 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4572 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4573 | * will be stored into the context1 field of the IOCB for the completion |
| 4574 | * callback function to the RPS Accept Response ELS IOCB command. |
| 4575 | * |
| 4576 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4577 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4578 | 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] | 4579 | { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4580 | MAILBOX_t *mb; |
| 4581 | IOCB_t *icmd; |
| 4582 | RPS_RSP *rps_rsp; |
| 4583 | uint8_t *pcmd; |
| 4584 | struct lpfc_iocbq *elsiocb; |
| 4585 | struct lpfc_nodelist *ndlp; |
| 4586 | uint16_t xri, status; |
| 4587 | uint32_t cmdsize; |
| 4588 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4589 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4590 | |
| 4591 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4592 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 4593 | pmb->context1 = NULL; |
| 4594 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4595 | |
| 4596 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4597 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4598 | return; |
| 4599 | } |
| 4600 | |
| 4601 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4602 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4603 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 4604 | lpfc_max_els_tries, ndlp, |
| 4605 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4606 | |
| 4607 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4608 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4609 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4610 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4611 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4612 | |
| 4613 | icmd = &elsiocb->iocb; |
| 4614 | icmd->ulpContext = xri; |
| 4615 | |
| 4616 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4617 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4618 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4619 | rps_rsp = (RPS_RSP *)pcmd; |
| 4620 | |
| 4621 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| 4622 | status = 0x10; |
| 4623 | else |
| 4624 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4625 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4626 | status |= 0x4; |
| 4627 | |
| 4628 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4629 | rps_rsp->portStatus = cpu_to_be16(status); |
| 4630 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 4631 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 4632 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 4633 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 4634 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 4635 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4636 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4637 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 4638 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 4639 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4640 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4641 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4642 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4643 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4644 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4645 | 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] | 4646 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4647 | return; |
| 4648 | } |
| 4649 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4650 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4651 | * lpfc_els_rcv_rps - Process an unsolicited rps iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4652 | * @vport: pointer to a host virtual N_Port data structure. |
| 4653 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4654 | * @ndlp: pointer to a node-list data structure. |
| 4655 | * |
| 4656 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 4657 | * ELS unsolicited event. It first checks the remote port state. If the |
| 4658 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 4659 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 4660 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 4661 | * for reading the HBA link statistics. It is for the callback function, |
| 4662 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 4663 | * to actually sending out RPS Accept (ACC) response. |
| 4664 | * |
| 4665 | * Return codes |
| 4666 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 4667 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4668 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4669 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4670 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4671 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4672 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4673 | uint32_t *lp; |
| 4674 | uint8_t flag; |
| 4675 | LPFC_MBOXQ_t *mbox; |
| 4676 | struct lpfc_dmabuf *pcmd; |
| 4677 | RPS *rps; |
| 4678 | struct ls_rjt stat; |
| 4679 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4680 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4681 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 4682 | /* reject the unsolicited RPS request and done with it */ |
| 4683 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4684 | |
| 4685 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4686 | lp = (uint32_t *) pcmd->virt; |
| 4687 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 4688 | rps = (RPS *) lp; |
| 4689 | |
| 4690 | if ((flag == 0) || |
| 4691 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4692 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4693 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4694 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4695 | printk("Fix me....\n"); |
| 4696 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4697 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 4698 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4699 | lpfc_read_lnk_stat(phba, mbox); |
| 4700 | mbox->context1 = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4701 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4702 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4703 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4704 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4705 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4706 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4707 | /* Mbox completion will send ELS Response */ |
| 4708 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4709 | /* Decrement reference count used for the failed mbox |
| 4710 | * command. |
| 4711 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4712 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4713 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4714 | } |
| 4715 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4716 | |
| 4717 | reject_out: |
| 4718 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4719 | stat.un.b.lsRjtRsvd0 = 0; |
| 4720 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4721 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4722 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4723 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4724 | return 0; |
| 4725 | } |
| 4726 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4727 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4728 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4729 | * @vport: pointer to a host virtual N_Port data structure. |
| 4730 | * @cmdsize: size of the ELS command. |
| 4731 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4732 | * @ndlp: pointer to a node-list data structure. |
| 4733 | * |
| 4734 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 4735 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 4736 | * |
| 4737 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4738 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4739 | * will be stored into the context1 field of the IOCB for the completion |
| 4740 | * callback function to the RPL Accept Response ELS command. |
| 4741 | * |
| 4742 | * Return code |
| 4743 | * 0 - Successfully issued ACC RPL ELS command |
| 4744 | * 1 - Failed to issue ACC RPL ELS command |
| 4745 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4746 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4747 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 4748 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4749 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4750 | struct lpfc_hba *phba = vport->phba; |
| 4751 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4752 | RPL_RSP rpl_rsp; |
| 4753 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4754 | uint8_t *pcmd; |
| 4755 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4756 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4757 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4758 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4759 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4760 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4761 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4762 | icmd = &elsiocb->iocb; |
| 4763 | oldcmd = &oldiocb->iocb; |
| 4764 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 4765 | |
| 4766 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4767 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4768 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4769 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 4770 | pcmd += sizeof(uint16_t); |
| 4771 | |
| 4772 | /* Setup the RPL ACC payload */ |
| 4773 | rpl_rsp.listLen = be32_to_cpu(1); |
| 4774 | rpl_rsp.index = 0; |
| 4775 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4776 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 4777 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4778 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4779 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4780 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4781 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4782 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 4783 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 4784 | "rpi x%x\n", |
| 4785 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4786 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4787 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4788 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4789 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4790 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 4791 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4792 | lpfc_els_free_iocb(phba, elsiocb); |
| 4793 | return 1; |
| 4794 | } |
| 4795 | return 0; |
| 4796 | } |
| 4797 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4798 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4799 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4800 | * @vport: pointer to a host virtual N_Port data structure. |
| 4801 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4802 | * @ndlp: pointer to a node-list data structure. |
| 4803 | * |
| 4804 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 4805 | * unsolicited event. It first checks the remote port state. If the remote |
| 4806 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 4807 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 4808 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 4809 | * to accept the RPL. |
| 4810 | * |
| 4811 | * Return code |
| 4812 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 4813 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4814 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4815 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4816 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4817 | { |
| 4818 | struct lpfc_dmabuf *pcmd; |
| 4819 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4820 | uint32_t maxsize; |
| 4821 | uint16_t cmdsize; |
| 4822 | RPL *rpl; |
| 4823 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4824 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4825 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 4826 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4827 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4828 | stat.un.b.lsRjtRsvd0 = 0; |
| 4829 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4830 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4831 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4832 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4833 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4834 | /* rejected the unsolicited RPL request and done with it */ |
| 4835 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4836 | } |
| 4837 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4838 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4839 | lp = (uint32_t *) pcmd->virt; |
| 4840 | rpl = (RPL *) (lp + 1); |
| 4841 | |
| 4842 | maxsize = be32_to_cpu(rpl->maxsize); |
| 4843 | |
| 4844 | /* We support only one port */ |
| 4845 | if ((rpl->index == 0) && |
| 4846 | ((maxsize == 0) || |
| 4847 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 4848 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4849 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4850 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 4851 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4852 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4853 | |
| 4854 | return 0; |
| 4855 | } |
| 4856 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4857 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4858 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4859 | * @vport: pointer to a virtual N_Port data structure. |
| 4860 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4861 | * @ndlp: pointer to a node-list data structure. |
| 4862 | * |
| 4863 | * This routine processes Fibre Channel Address Resolution Protocol |
| 4864 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 4865 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 4866 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 4867 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 4868 | * remote PortName is compared against the FC PortName stored in the @vport |
| 4869 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 4870 | * compared against the FC NodeName stored in the @vport data structure. |
| 4871 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 4872 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 4873 | * invoked to send out FARP Response to the remote node. Before sending the |
| 4874 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 4875 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 4876 | * routine is invoked to log into the remote port first. |
| 4877 | * |
| 4878 | * Return code |
| 4879 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 4880 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4881 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4882 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4883 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4884 | { |
| 4885 | struct lpfc_dmabuf *pcmd; |
| 4886 | uint32_t *lp; |
| 4887 | IOCB_t *icmd; |
| 4888 | FARP *fp; |
| 4889 | uint32_t cmd, cnt, did; |
| 4890 | |
| 4891 | icmd = &cmdiocb->iocb; |
| 4892 | did = icmd->un.elsreq64.remoteID; |
| 4893 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4894 | lp = (uint32_t *) pcmd->virt; |
| 4895 | |
| 4896 | cmd = *lp++; |
| 4897 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4898 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4899 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4900 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4901 | /* We will only support match on WWPN or WWNN */ |
| 4902 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4903 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4904 | } |
| 4905 | |
| 4906 | cnt = 0; |
| 4907 | /* If this FARP command is searching for my portname */ |
| 4908 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4909 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4910 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4911 | cnt = 1; |
| 4912 | } |
| 4913 | |
| 4914 | /* If this FARP command is searching for my nodename */ |
| 4915 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4916 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4917 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4918 | cnt = 1; |
| 4919 | } |
| 4920 | |
| 4921 | if (cnt) { |
| 4922 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 4923 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 4924 | /* Log back into the node before sending the FARP. */ |
| 4925 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4926 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4927 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4928 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4929 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4930 | } |
| 4931 | |
| 4932 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4933 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 4934 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4935 | } |
| 4936 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4937 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4938 | } |
| 4939 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4940 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4941 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4942 | * @vport: pointer to a host virtual N_Port data structure. |
| 4943 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4944 | * @ndlp: pointer to a node-list data structure. |
| 4945 | * |
| 4946 | * This routine processes Fibre Channel Address Resolution Protocol |
| 4947 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 4948 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 4949 | * the FARP response request. |
| 4950 | * |
| 4951 | * Return code |
| 4952 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 4953 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4954 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4955 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4956 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4957 | { |
| 4958 | struct lpfc_dmabuf *pcmd; |
| 4959 | uint32_t *lp; |
| 4960 | IOCB_t *icmd; |
| 4961 | uint32_t cmd, did; |
| 4962 | |
| 4963 | icmd = &cmdiocb->iocb; |
| 4964 | did = icmd->un.elsreq64.remoteID; |
| 4965 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4966 | lp = (uint32_t *) pcmd->virt; |
| 4967 | |
| 4968 | cmd = *lp++; |
| 4969 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4970 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4971 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4972 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4973 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4974 | |
| 4975 | return 0; |
| 4976 | } |
| 4977 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4978 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4979 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4980 | * @vport: pointer to a host virtual N_Port data structure. |
| 4981 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4982 | * @fan_ndlp: pointer to a node-list data structure. |
| 4983 | * |
| 4984 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 4985 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 4986 | * only be processed on a physical port (i.e., the @vport represents the |
| 4987 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 4988 | * compared against those in the phba data structure. If any of those is |
| 4989 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 4990 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 4991 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 4992 | * is invoked to register login to the fabric. |
| 4993 | * |
| 4994 | * Return code |
| 4995 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 4996 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4997 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4998 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4999 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5000 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5001 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5002 | uint32_t *lp; |
| 5003 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5004 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5005 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 5006 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 5007 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5008 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5009 | if ((vport == phba->pport) && |
| 5010 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5011 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5012 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5013 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5014 | sizeof(struct lpfc_name)))) { |
| 5015 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5016 | lpfc_initial_flogi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5017 | } else { |
| 5018 | /* FAN verified - skip FLOGI */ |
| 5019 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5020 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5021 | lpfc_issue_fabric_reglogin(vport); |
| 5022 | else |
| 5023 | lpfc_issue_reg_vfi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5024 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5025 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5026 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5027 | } |
| 5028 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5029 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5030 | * lpfc_els_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5031 | * @ptr: holder for the timer function associated data. |
| 5032 | * |
| 5033 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 5034 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 5035 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 5036 | * up the worker thread. It is for the worker thread to invoke the routine |
| 5037 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 5038 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5039 | void |
| 5040 | lpfc_els_timeout(unsigned long ptr) |
| 5041 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5042 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 5043 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5044 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5045 | unsigned long iflag; |
| 5046 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5047 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5048 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
| 5049 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5050 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5051 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5052 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5053 | if (!tmo_posted) |
| 5054 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5055 | return; |
| 5056 | } |
| 5057 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5058 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5059 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5060 | * @vport: pointer to a virtual N_Port data structure. |
| 5061 | * |
| 5062 | * This routine is the actual handler function that processes an ELS timeout |
| 5063 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 5064 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 5065 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5066 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5067 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5068 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5069 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5070 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5071 | struct lpfc_sli_ring *pring; |
| 5072 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5073 | IOCB_t *cmd = NULL; |
| 5074 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5075 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5076 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5077 | uint32_t remote_ID = 0xffffffff; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5078 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5079 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5080 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 5081 | |
| 5082 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5083 | |
| 5084 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5085 | cmd = &piocb->iocb; |
| 5086 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5087 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 5088 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 5089 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5090 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5091 | |
| 5092 | if (piocb->vport != vport) |
| 5093 | continue; |
| 5094 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5095 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5096 | if (pcmd) |
| 5097 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5098 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5099 | if (els_command == ELS_CMD_FARP || |
| 5100 | els_command == ELS_CMD_FARPR || |
| 5101 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5102 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5103 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5104 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5105 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5106 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5107 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5108 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5109 | continue; |
| 5110 | } |
| 5111 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5112 | remote_ID = 0xffffffff; |
| 5113 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5114 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5115 | else { |
| 5116 | struct lpfc_nodelist *ndlp; |
| 5117 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5118 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5119 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5120 | } |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5121 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5122 | "0127 ELS timeout Data: x%x x%x x%x " |
| 5123 | "x%x\n", els_command, |
| 5124 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5125 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5126 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5127 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 5128 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5129 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
| 5130 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5131 | } |
| 5132 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5133 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5134 | * 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] | 5135 | * @vport: pointer to a host virtual N_Port data structure. |
| 5136 | * |
| 5137 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5138 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 5139 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5140 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5141 | * the IOCBs with a non-NULL completion callback function, the callback |
| 5142 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5143 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 5144 | * callback function, the IOCB will simply be released. Finally, it walks |
| 5145 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 5146 | * completion queue IOCB that is associated with the @vport and is not |
| 5147 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 5148 | * part of the discovery state machine) out to HBA by invoking the |
| 5149 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 5150 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 5151 | * the IOCBs are aborted when this function returns. |
| 5152 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5153 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5154 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5155 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5156 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5157 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5158 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5159 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5160 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5161 | |
| 5162 | lpfc_fabric_abort_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5163 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5164 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5165 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5166 | cmd = &piocb->iocb; |
| 5167 | |
| 5168 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5169 | continue; |
| 5170 | } |
| 5171 | |
| 5172 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5173 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5174 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5175 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5176 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5177 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5178 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5179 | if (piocb->vport != vport) |
| 5180 | continue; |
| 5181 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5182 | list_move_tail(&piocb->list, &completions); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5183 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5184 | } |
| 5185 | |
| 5186 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5187 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5188 | continue; |
| 5189 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5190 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5191 | if (piocb->vport != vport) |
| 5192 | continue; |
| 5193 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5194 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5195 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5196 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5197 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5198 | /* Cancell all the IOCBs from the completions list */ |
| 5199 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5200 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5201 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5202 | return; |
| 5203 | } |
| 5204 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5205 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5206 | * 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] | 5207 | * @phba: pointer to lpfc hba data structure. |
| 5208 | * |
| 5209 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5210 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 5211 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5212 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5213 | * the IOCBs with the completion callback function associated, the callback |
| 5214 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5215 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 5216 | * callback function associated, the IOCB will simply be released. Finally, |
| 5217 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 5218 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 5219 | * management plane IOCBs that are not part of the discovery state machine) |
| 5220 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5221 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5222 | void |
| 5223 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 5224 | { |
| 5225 | LIST_HEAD(completions); |
| 5226 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 5227 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5228 | IOCB_t *cmd = NULL; |
| 5229 | |
| 5230 | lpfc_fabric_abort_hba(phba); |
| 5231 | spin_lock_irq(&phba->hbalock); |
| 5232 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5233 | cmd = &piocb->iocb; |
| 5234 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5235 | continue; |
| 5236 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
| 5237 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5238 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5239 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5240 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| 5241 | continue; |
| 5242 | list_move_tail(&piocb->list, &completions); |
| 5243 | pring->txq_cnt--; |
| 5244 | } |
| 5245 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5246 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5247 | continue; |
| 5248 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5249 | } |
| 5250 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5251 | |
| 5252 | /* Cancel all the IOCBs from the completions list */ |
| 5253 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5254 | IOERR_SLI_ABORTED); |
| 5255 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5256 | return; |
| 5257 | } |
| 5258 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5259 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5260 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5261 | * @phba: Pointer to hba context object. |
| 5262 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 5263 | * @rspiocbp: Pointer to response iocb which reported error. |
| 5264 | * |
| 5265 | * This function sends an event when there is an ELS command |
| 5266 | * failure. |
| 5267 | **/ |
| 5268 | void |
| 5269 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 5270 | struct lpfc_iocbq *cmdiocbp, |
| 5271 | struct lpfc_iocbq *rspiocbp) |
| 5272 | { |
| 5273 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 5274 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5275 | struct lpfc_lsrjt_event lsrjt_event; |
| 5276 | struct lpfc_fabric_event_header fabric_event; |
| 5277 | struct ls_rjt stat; |
| 5278 | struct lpfc_nodelist *ndlp; |
| 5279 | uint32_t *pcmd; |
| 5280 | |
| 5281 | ndlp = cmdiocbp->context1; |
| 5282 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 5283 | return; |
| 5284 | |
| 5285 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 5286 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 5287 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 5288 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 5289 | sizeof(struct lpfc_name)); |
| 5290 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 5291 | sizeof(struct lpfc_name)); |
| 5292 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 5293 | cmdiocbp->context2)->virt); |
| 5294 | lsrjt_event.command = *pcmd; |
| 5295 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 5296 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 5297 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 5298 | fc_host_post_vendor_event(shost, |
| 5299 | fc_get_event_number(), |
| 5300 | sizeof(lsrjt_event), |
| 5301 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5302 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5303 | return; |
| 5304 | } |
| 5305 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 5306 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 5307 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 5308 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 5309 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 5310 | else |
| 5311 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 5312 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 5313 | sizeof(struct lpfc_name)); |
| 5314 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 5315 | sizeof(struct lpfc_name)); |
| 5316 | fc_host_post_vendor_event(shost, |
| 5317 | fc_get_event_number(), |
| 5318 | sizeof(fabric_event), |
| 5319 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5320 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5321 | return; |
| 5322 | } |
| 5323 | |
| 5324 | } |
| 5325 | |
| 5326 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5327 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5328 | * @vport: Pointer to vport object. |
| 5329 | * @ndlp: Pointer FC node object. |
| 5330 | * @cmd: ELS command code. |
| 5331 | * |
| 5332 | * This function posts an event when there is an incoming |
| 5333 | * unsolicited ELS command. |
| 5334 | **/ |
| 5335 | static void |
| 5336 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 5337 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5338 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5339 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5340 | struct lpfc_els_event_header *els_data = NULL; |
| 5341 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5342 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5343 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5344 | if (*payload == ELS_CMD_LOGO) { |
| 5345 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 5346 | if (!logo_data) { |
| 5347 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5348 | "0148 Failed to allocate memory " |
| 5349 | "for LOGO event\n"); |
| 5350 | return; |
| 5351 | } |
| 5352 | els_data = &logo_data->header; |
| 5353 | } else { |
| 5354 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 5355 | GFP_KERNEL); |
| 5356 | if (!els_data) { |
| 5357 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5358 | "0149 Failed to allocate memory " |
| 5359 | "for ELS event\n"); |
| 5360 | return; |
| 5361 | } |
| 5362 | } |
| 5363 | els_data->event_type = FC_REG_ELS_EVENT; |
| 5364 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5365 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5366 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5367 | break; |
| 5368 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5369 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5370 | break; |
| 5371 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5372 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 5373 | break; |
| 5374 | case ELS_CMD_LOGO: |
| 5375 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 5376 | /* Copy the WWPN in the LOGO payload */ |
| 5377 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 5378 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5379 | break; |
| 5380 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 5381 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5382 | return; |
| 5383 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5384 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 5385 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 5386 | if (*payload == ELS_CMD_LOGO) { |
| 5387 | fc_host_post_vendor_event(shost, |
| 5388 | fc_get_event_number(), |
| 5389 | sizeof(struct lpfc_logo_event), |
| 5390 | (char *)logo_data, |
| 5391 | LPFC_NL_VENDOR_ID); |
| 5392 | kfree(logo_data); |
| 5393 | } else { |
| 5394 | fc_host_post_vendor_event(shost, |
| 5395 | fc_get_event_number(), |
| 5396 | sizeof(struct lpfc_els_event_header), |
| 5397 | (char *)els_data, |
| 5398 | LPFC_NL_VENDOR_ID); |
| 5399 | kfree(els_data); |
| 5400 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5401 | |
| 5402 | return; |
| 5403 | } |
| 5404 | |
| 5405 | |
| 5406 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5407 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5408 | * @phba: pointer to lpfc hba data structure. |
| 5409 | * @pring: pointer to a SLI ring. |
| 5410 | * @vport: pointer to a host virtual N_Port data structure. |
| 5411 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 5412 | * |
| 5413 | * This routine is used for processing the IOCB associated with a unsolicited |
| 5414 | * event. It first determines whether there is an existing ndlp that matches |
| 5415 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 5416 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 5417 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 5418 | * of the discovery state machine. |
| 5419 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5420 | static void |
| 5421 | 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] | 5422 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5423 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5424 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5425 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5426 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5427 | uint32_t *payload; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5428 | uint32_t cmd, did, newnode, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5429 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5430 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5431 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5432 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5433 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5434 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5435 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 5436 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5437 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5438 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5439 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5440 | did = icmd->un.rcvels.remoteID; |
| 5441 | if (icmd->ulpStatus) { |
| 5442 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5443 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 5444 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5445 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5446 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5447 | |
| 5448 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5449 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5450 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5451 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 5452 | /* Ignore traffic received during vport shutdown. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5453 | if (vport->load_flag & FC_UNLOADING) |
| 5454 | goto dropit; |
| 5455 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5456 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5457 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5458 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5459 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5460 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5461 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5462 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5463 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5464 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5465 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5466 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5467 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5468 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5469 | ndlp = lpfc_enable_node(vport, ndlp, |
| 5470 | NLP_STE_UNUSED_NODE); |
| 5471 | if (!ndlp) |
| 5472 | goto dropit; |
| 5473 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5474 | newnode = 1; |
| 5475 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 5476 | ndlp->nlp_type |= NLP_FABRIC; |
| 5477 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 5478 | /* This is similar to the new node path */ |
| 5479 | ndlp = lpfc_nlp_get(ndlp); |
| 5480 | if (!ndlp) |
| 5481 | goto dropit; |
| 5482 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5483 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5484 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5485 | |
| 5486 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5487 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5488 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5489 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5490 | |
| 5491 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 5492 | cmd &= ELS_CMD_MASK; |
| 5493 | } |
| 5494 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5495 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5496 | "0112 ELS command x%x received from NPORT x%x " |
| 5497 | "Data: x%x\n", cmd, did, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5498 | switch (cmd) { |
| 5499 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5500 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5501 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 5502 | did, vport->port_state, ndlp->nlp_flag); |
| 5503 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5504 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5505 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
| 5506 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5507 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5508 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5509 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 5510 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 5511 | rjt_err = LSRJT_UNABLE_TPC; |
| 5512 | break; |
| 5513 | } |
| 5514 | /* We get here, and drop thru, if we are PT2PT with |
| 5515 | * another NPort and the other side has initiated |
| 5516 | * the PLOGI before responding to our FLOGI. |
| 5517 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5518 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5519 | |
| 5520 | shost = lpfc_shost_from_vport(vport); |
| 5521 | spin_lock_irq(shost->host_lock); |
| 5522 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 5523 | spin_unlock_irq(shost->host_lock); |
| 5524 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5525 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5526 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5527 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5528 | break; |
| 5529 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5530 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5531 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 5532 | did, vport->port_state, ndlp->nlp_flag); |
| 5533 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5534 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5535 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5536 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5537 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5538 | break; |
| 5539 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5540 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5541 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 5542 | did, vport->port_state, ndlp->nlp_flag); |
| 5543 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5544 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5545 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5546 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5547 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5548 | break; |
| 5549 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5550 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5551 | break; |
| 5552 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5553 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5554 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 5555 | did, vport->port_state, ndlp->nlp_flag); |
| 5556 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5557 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5558 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5559 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5560 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5561 | break; |
| 5562 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5563 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5564 | break; |
| 5565 | case ELS_CMD_RSCN: |
| 5566 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5567 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5568 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5569 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5570 | break; |
| 5571 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5572 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5573 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 5574 | did, vport->port_state, ndlp->nlp_flag); |
| 5575 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5576 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5577 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5578 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5579 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5580 | break; |
| 5581 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5582 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5583 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5584 | break; |
| 5585 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5586 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5587 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 5588 | did, vport->port_state, ndlp->nlp_flag); |
| 5589 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5590 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5591 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5592 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5593 | break; |
| 5594 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5595 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5596 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5597 | break; |
| 5598 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5599 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5600 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 5601 | did, vport->port_state, ndlp->nlp_flag); |
| 5602 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5603 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5604 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5605 | break; |
| 5606 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5607 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5608 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 5609 | did, vport->port_state, ndlp->nlp_flag); |
| 5610 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5611 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5612 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5613 | break; |
| 5614 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5615 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5616 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 5617 | did, vport->port_state, ndlp->nlp_flag); |
| 5618 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5619 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5620 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5621 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5622 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5623 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5624 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 5625 | did, vport->port_state, ndlp->nlp_flag); |
| 5626 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5627 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5628 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5629 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5630 | break; |
| 5631 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5632 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5633 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5634 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5635 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5636 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 5637 | did, vport->port_state, ndlp->nlp_flag); |
| 5638 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5639 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5640 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5641 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5642 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5643 | break; |
| 5644 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5645 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5646 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 5647 | did, vport->port_state, ndlp->nlp_flag); |
| 5648 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5649 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5650 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5651 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5652 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5653 | break; |
| 5654 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5655 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5656 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 5657 | did, vport->port_state, ndlp->nlp_flag); |
| 5658 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5659 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5660 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5661 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5662 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5663 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5664 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5665 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5666 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 5667 | did, vport->port_state, ndlp->nlp_flag); |
| 5668 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5669 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5670 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5671 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5672 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5673 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 5674 | case ELS_CMD_RRQ: |
| 5675 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5676 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", |
| 5677 | did, vport->port_state, ndlp->nlp_flag); |
| 5678 | |
| 5679 | phba->fc_stat.elsRcvRRQ++; |
| 5680 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); |
| 5681 | if (newnode) |
| 5682 | lpfc_nlp_put(ndlp); |
| 5683 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5684 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5685 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5686 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 5687 | cmd, did, vport->port_state); |
| 5688 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5689 | /* Unsupported ELS command, reject */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5690 | rjt_err = LSRJT_INVALID_CMD; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5691 | |
| 5692 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5693 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5694 | "0115 Unknown ELS command x%x " |
| 5695 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5696 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5697 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5698 | break; |
| 5699 | } |
| 5700 | |
| 5701 | /* check if need to LS_RJT received ELS cmd */ |
| 5702 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5703 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5704 | stat.un.b.lsRjtRsnCode = rjt_err; |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 5705 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5706 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 5707 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5708 | } |
| 5709 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5710 | lpfc_nlp_put(elsiocb->context1); |
| 5711 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5712 | return; |
| 5713 | |
| 5714 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5715 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5716 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5717 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5718 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5719 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5720 | phba->fc_stat.elsRcvDrop++; |
| 5721 | } |
| 5722 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5723 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5724 | * 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] | 5725 | * @phba: pointer to lpfc hba data structure. |
| 5726 | * @vpi: host virtual N_Port identifier. |
| 5727 | * |
| 5728 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 5729 | * @vpi. The function walks the HBA's vport list and returns the address |
| 5730 | * of the vport with the matching @vpi. |
| 5731 | * |
| 5732 | * Return code |
| 5733 | * NULL - No vport with the matching @vpi found |
| 5734 | * Otherwise - Address to the vport with the matching @vpi. |
| 5735 | **/ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5736 | struct lpfc_vport * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5737 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 5738 | { |
| 5739 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5740 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5741 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5742 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5743 | list_for_each_entry(vport, &phba->port_list, listentry) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5744 | if (vport->vpi == vpi) { |
| 5745 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5746 | return vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5747 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5748 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5749 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5750 | return NULL; |
| 5751 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5752 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5753 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5754 | * 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] | 5755 | * @phba: pointer to lpfc hba data structure. |
| 5756 | * @pring: pointer to a SLI ring. |
| 5757 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 5758 | * |
| 5759 | * This routine is used to process an unsolicited event received from a SLI |
| 5760 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 5761 | * associated with the unsolicited event is done by invoking the routine |
| 5762 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 5763 | * SLI ring on which the unsolicited event was received. |
| 5764 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5765 | void |
| 5766 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 5767 | struct lpfc_iocbq *elsiocb) |
| 5768 | { |
| 5769 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5770 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5771 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5772 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 5773 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5774 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5775 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5776 | elsiocb->context2 = NULL; |
| 5777 | elsiocb->context3 = NULL; |
| 5778 | |
| 5779 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 5780 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 5781 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 5782 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5783 | phba->fc_stat.NoRcvBuf++; |
| 5784 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5785 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5786 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5787 | return; |
| 5788 | } |
| 5789 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5790 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 5791 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 5792 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 5793 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 5794 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5795 | else |
| 5796 | vport = lpfc_find_vport_by_vpid(phba, |
| 5797 | icmd->unsli3.rcvsli3.vpi - phba->vpi_base); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5798 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5799 | /* If there are no BDEs associated |
| 5800 | * with this IOCB, there is nothing to do. |
| 5801 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5802 | if (icmd->ulpBdeCount == 0) |
| 5803 | return; |
| 5804 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5805 | /* type of ELS cmd is first 32bit word |
| 5806 | * in packet |
| 5807 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5808 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5809 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5810 | } else { |
| 5811 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 5812 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5813 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 5814 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5815 | } |
| 5816 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5817 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 5818 | /* |
| 5819 | * The different unsolicited event handlers would tell us |
| 5820 | * if they are done with "mp" by setting context2 to NULL. |
| 5821 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5822 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5823 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 5824 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5825 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5826 | |
| 5827 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5828 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5829 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5830 | elsiocb->context2 = bdeBuf2; |
| 5831 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5832 | /* free mp if we are done with it */ |
| 5833 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5834 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 5835 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5836 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5837 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5838 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5839 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5840 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5841 | * 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] | 5842 | * @phba: pointer to lpfc hba data structure. |
| 5843 | * @vport: pointer to a virtual N_Port data structure. |
| 5844 | * |
| 5845 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 5846 | * State Change Request (SCR) for a @vport. This routine will create an |
| 5847 | * ndlp for the Name Server associated to the @vport if such node does |
| 5848 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 5849 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 5850 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 5851 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 5852 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5853 | void |
| 5854 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 5855 | { |
| 5856 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
| 5857 | |
| 5858 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 5859 | if (!ndlp) { |
| 5860 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 5861 | if (!ndlp) { |
| 5862 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5863 | lpfc_disc_start(vport); |
| 5864 | return; |
| 5865 | } |
| 5866 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5867 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5868 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5869 | return; |
| 5870 | } |
| 5871 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5872 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5873 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 5874 | if (!ndlp) { |
| 5875 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5876 | lpfc_disc_start(vport); |
| 5877 | return; |
| 5878 | } |
| 5879 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5880 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5881 | "0348 NameServer login: node freed\n"); |
| 5882 | return; |
| 5883 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5884 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5885 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5886 | |
| 5887 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 5888 | |
| 5889 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 5890 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5891 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5892 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5893 | return; |
| 5894 | } |
| 5895 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5896 | if (vport->cfg_fdmi_on) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5897 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 5898 | GFP_KERNEL); |
| 5899 | if (ndlp_fdmi) { |
| 5900 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 5901 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5902 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
| 5903 | NLP_STE_PLOGI_ISSUE); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5904 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, |
| 5905 | 0); |
| 5906 | } |
| 5907 | } |
| 5908 | return; |
| 5909 | } |
| 5910 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5911 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5912 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5913 | * @phba: pointer to lpfc hba data structure. |
| 5914 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 5915 | * |
| 5916 | * This routine is the completion callback function to register new vport |
| 5917 | * mailbox command. If the new vport mailbox command completes successfully, |
| 5918 | * the fabric registration login shall be performed on physical port (the |
| 5919 | * new vport created is actually a physical port, with VPI 0) or the port |
| 5920 | * login to Name Server for State Change Request (SCR) will be performed |
| 5921 | * on virtual port (real virtual port, with VPI greater than 0). |
| 5922 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5923 | static void |
| 5924 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 5925 | { |
| 5926 | struct lpfc_vport *vport = pmb->vport; |
| 5927 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5928 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5929 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5930 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5931 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5932 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5933 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5934 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5935 | |
| 5936 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5937 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 5938 | "0915 Register VPI failed: 0x%x\n", |
| 5939 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5940 | |
| 5941 | switch (mb->mbxStatus) { |
| 5942 | case 0x11: /* unsupported feature */ |
| 5943 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5944 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5945 | /* giving up on vport registration */ |
| 5946 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5947 | spin_lock_irq(shost->host_lock); |
| 5948 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 5949 | spin_unlock_irq(shost->host_lock); |
| 5950 | lpfc_can_disctmo(vport); |
| 5951 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5952 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
| 5953 | case 0x20: |
| 5954 | spin_lock_irq(shost->host_lock); |
| 5955 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 5956 | spin_unlock_irq(shost->host_lock); |
| 5957 | lpfc_init_vpi(phba, pmb, vport->vpi); |
| 5958 | pmb->vport = vport; |
| 5959 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; |
| 5960 | rc = lpfc_sli_issue_mbox(phba, pmb, |
| 5961 | MBX_NOWAIT); |
| 5962 | if (rc == MBX_NOT_FINISHED) { |
| 5963 | lpfc_printf_vlog(vport, |
| 5964 | KERN_ERR, LOG_MBOX, |
| 5965 | "2732 Failed to issue INIT_VPI" |
| 5966 | " mailbox command\n"); |
| 5967 | } else { |
| 5968 | lpfc_nlp_put(ndlp); |
| 5969 | return; |
| 5970 | } |
| 5971 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5972 | default: |
| 5973 | /* Try to recover from this error */ |
| 5974 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5975 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5976 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5977 | spin_unlock_irq(shost->host_lock); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5978 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 5979 | lpfc_initial_flogi(vport); |
| 5980 | else |
| 5981 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5982 | break; |
| 5983 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5984 | } else { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5985 | spin_lock_irq(shost->host_lock); |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 5986 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5987 | spin_unlock_irq(shost->host_lock); |
| 5988 | if (vport == phba->pport) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5989 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5990 | lpfc_issue_fabric_reglogin(vport); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5991 | else { |
| 5992 | lpfc_start_fdiscs(phba); |
| 5993 | lpfc_do_scr_ns_plogi(phba, vport); |
| 5994 | } |
| 5995 | } else |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5996 | lpfc_do_scr_ns_plogi(phba, vport); |
| 5997 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5998 | |
| 5999 | /* Now, we decrement the ndlp reference count held for this |
| 6000 | * callback function |
| 6001 | */ |
| 6002 | lpfc_nlp_put(ndlp); |
| 6003 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6004 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6005 | return; |
| 6006 | } |
| 6007 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6008 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6009 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6010 | * @phba: pointer to lpfc hba data structure. |
| 6011 | * @vport: pointer to a host virtual N_Port data structure. |
| 6012 | * @ndlp: pointer to a node-list data structure. |
| 6013 | * |
| 6014 | * This routine registers the @vport as a new virtual port with a HBA. |
| 6015 | * It is done through a registering vpi mailbox command. |
| 6016 | **/ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6017 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6018 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 6019 | struct lpfc_nodelist *ndlp) |
| 6020 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6021 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6022 | LPFC_MBOXQ_t *mbox; |
| 6023 | |
| 6024 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6025 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6026 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6027 | mbox->vport = vport; |
| 6028 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 6029 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 6030 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6031 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6032 | /* mailbox command not success, decrement ndlp |
| 6033 | * reference count for this command |
| 6034 | */ |
| 6035 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6036 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6037 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6038 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6039 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6040 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6041 | } |
| 6042 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6043 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6044 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6045 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6046 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6047 | return; |
| 6048 | |
| 6049 | mbox_err_exit: |
| 6050 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6051 | spin_lock_irq(shost->host_lock); |
| 6052 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 6053 | spin_unlock_irq(shost->host_lock); |
| 6054 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6055 | } |
| 6056 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6057 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6058 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. |
| 6059 | * @phba: pointer to lpfc hba data structure. |
| 6060 | * |
| 6061 | * This routine abort all pending discovery commands and |
| 6062 | * start a timer to retry FLOGI for the physical port |
| 6063 | * discovery. |
| 6064 | **/ |
| 6065 | void |
| 6066 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) |
| 6067 | { |
| 6068 | struct lpfc_vport **vports; |
| 6069 | struct lpfc_nodelist *ndlp; |
| 6070 | struct Scsi_Host *shost; |
| 6071 | int i; |
| 6072 | uint32_t link_state; |
| 6073 | |
| 6074 | /* Treat this failure as linkdown for all vports */ |
| 6075 | link_state = phba->link_state; |
| 6076 | lpfc_linkdown(phba); |
| 6077 | phba->link_state = link_state; |
| 6078 | |
| 6079 | vports = lpfc_create_vport_work_array(phba); |
| 6080 | |
| 6081 | if (vports) { |
| 6082 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 6083 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); |
| 6084 | if (ndlp) |
| 6085 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); |
| 6086 | lpfc_els_flush_cmd(vports[i]); |
| 6087 | } |
| 6088 | lpfc_destroy_vport_work_array(phba, vports); |
| 6089 | } |
| 6090 | |
| 6091 | /* If fabric require FLOGI, then re-instantiate physical login */ |
| 6092 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
| 6093 | if (!ndlp) |
| 6094 | return; |
| 6095 | |
| 6096 | |
| 6097 | shost = lpfc_shost_from_vport(phba->pport); |
| 6098 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); |
| 6099 | spin_lock_irq(shost->host_lock); |
| 6100 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 6101 | spin_unlock_irq(shost->host_lock); |
| 6102 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; |
| 6103 | phba->pport->port_state = LPFC_FLOGI; |
| 6104 | return; |
| 6105 | } |
| 6106 | |
| 6107 | /** |
| 6108 | * lpfc_fabric_login_reqd - Check if FLOGI required. |
| 6109 | * @phba: pointer to lpfc hba data structure. |
| 6110 | * @cmdiocb: pointer to FDISC command iocb. |
| 6111 | * @rspiocb: pointer to FDISC response iocb. |
| 6112 | * |
| 6113 | * This routine checks if a FLOGI is reguired for FDISC |
| 6114 | * to succeed. |
| 6115 | **/ |
| 6116 | static int |
| 6117 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, |
| 6118 | struct lpfc_iocbq *cmdiocb, |
| 6119 | struct lpfc_iocbq *rspiocb) |
| 6120 | { |
| 6121 | |
| 6122 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || |
| 6123 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) |
| 6124 | return 0; |
| 6125 | else |
| 6126 | return 1; |
| 6127 | } |
| 6128 | |
| 6129 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6130 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6131 | * @phba: pointer to lpfc hba data structure. |
| 6132 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6133 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6134 | * |
| 6135 | * This routine is the completion callback function to a Fabric Discover |
| 6136 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 6137 | * single threaded, each FDISC completion callback function will reset |
| 6138 | * the discovery timer for all vports such that the timers will not get |
| 6139 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 6140 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 6141 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 6142 | * assigned to the vport has been changed with the completion of the FDISC |
| 6143 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 6144 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 6145 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 6146 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 6147 | * Server for State Change Request (SCR). |
| 6148 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6149 | static void |
| 6150 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6151 | struct lpfc_iocbq *rspiocb) |
| 6152 | { |
| 6153 | struct lpfc_vport *vport = cmdiocb->vport; |
| 6154 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6155 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 6156 | struct lpfc_nodelist *np; |
| 6157 | struct lpfc_nodelist *next_np; |
| 6158 | IOCB_t *irsp = &rspiocb->iocb; |
| 6159 | struct lpfc_iocbq *piocb; |
| 6160 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6161 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6162 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 6163 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 6164 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6165 | /* Since all FDISCs are being single threaded, we |
| 6166 | * must reset the discovery timer for ALL vports |
| 6167 | * waiting to send FDISC when one completes. |
| 6168 | */ |
| 6169 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 6170 | lpfc_set_disctmo(piocb->vport); |
| 6171 | } |
| 6172 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6173 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6174 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 6175 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 6176 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6177 | if (irsp->ulpStatus) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6178 | |
| 6179 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { |
| 6180 | lpfc_retry_pport_discovery(phba); |
| 6181 | goto out; |
| 6182 | } |
| 6183 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6184 | /* Check for retry */ |
| 6185 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 6186 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6187 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6188 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6189 | "0126 FDISC failed. (%d/%d)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6190 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6191 | goto fdisc_failed; |
| 6192 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6193 | spin_lock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6194 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6195 | vport->fc_flag |= FC_FABRIC; |
| 6196 | if (vport->phba->fc_topology == TOPOLOGY_LOOP) |
| 6197 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 6198 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6199 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6200 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 6201 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
| 6202 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 6203 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 6204 | /* If our NportID changed, we need to ensure all |
| 6205 | * remaining NPORTs get unreg_login'ed so we can |
| 6206 | * issue unreg_vpi. |
| 6207 | */ |
| 6208 | list_for_each_entry_safe(np, next_np, |
| 6209 | &vport->fc_nodes, nlp_listp) { |
| 6210 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 6211 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 6212 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 6213 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6214 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6215 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6216 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6217 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6218 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6219 | lpfc_mbx_unreg_vpi(vport); |
| 6220 | spin_lock_irq(shost->host_lock); |
| 6221 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame^] | 6222 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6223 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6224 | } |
| 6225 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame^] | 6226 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
| 6227 | lpfc_issue_init_vpi(vport); |
| 6228 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6229 | lpfc_register_new_vport(phba, vport, ndlp); |
| 6230 | else |
| 6231 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6232 | goto out; |
| 6233 | fdisc_failed: |
| 6234 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6235 | /* Cancel discovery timer */ |
| 6236 | lpfc_can_disctmo(vport); |
| 6237 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6238 | out: |
| 6239 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6240 | } |
| 6241 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6242 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6243 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6244 | * @vport: pointer to a virtual N_Port data structure. |
| 6245 | * @ndlp: pointer to a node-list data structure. |
| 6246 | * @retry: number of retries to the command IOCB. |
| 6247 | * |
| 6248 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 6249 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 6250 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 6251 | * IOCB will be sent off HBA at any given time. |
| 6252 | * |
| 6253 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6254 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6255 | * will be stored into the context1 field of the IOCB for the completion |
| 6256 | * callback function to the FDISC ELS command. |
| 6257 | * |
| 6258 | * Return code |
| 6259 | * 0 - Successfully issued fdisc iocb command |
| 6260 | * 1 - Failed to issue fdisc iocb command |
| 6261 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6262 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6263 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 6264 | uint8_t retry) |
| 6265 | { |
| 6266 | struct lpfc_hba *phba = vport->phba; |
| 6267 | IOCB_t *icmd; |
| 6268 | struct lpfc_iocbq *elsiocb; |
| 6269 | struct serv_parm *sp; |
| 6270 | uint8_t *pcmd; |
| 6271 | uint16_t cmdsize; |
| 6272 | int did = ndlp->nlp_DID; |
| 6273 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6274 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6275 | vport->port_state = LPFC_FDISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6276 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 6277 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 6278 | ELS_CMD_FDISC); |
| 6279 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6280 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6281 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6282 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6283 | return 1; |
| 6284 | } |
| 6285 | |
| 6286 | icmd = &elsiocb->iocb; |
| 6287 | icmd->un.elsreq64.myID = 0; |
| 6288 | icmd->un.elsreq64.fl = 1; |
| 6289 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6290 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 6291 | /* FDISC needs to be 1 for WQE VPI */ |
| 6292 | elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1; |
| 6293 | elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ; |
| 6294 | /* Set the ulpContext to the vpi */ |
| 6295 | elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base; |
| 6296 | } else { |
| 6297 | /* For FDISC, Let FDISC rsp set the NPortID for this VPI */ |
| 6298 | icmd->ulpCt_h = 1; |
| 6299 | icmd->ulpCt_l = 0; |
| 6300 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6301 | |
| 6302 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6303 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 6304 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 6305 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 6306 | sp = (struct serv_parm *) pcmd; |
| 6307 | /* Setup CSPs accordingly for Fabric */ |
| 6308 | sp->cmn.e_d_tov = 0; |
| 6309 | sp->cmn.w2.r_a_tov = 0; |
| 6310 | sp->cls1.classValid = 0; |
| 6311 | sp->cls2.seqDelivery = 1; |
| 6312 | sp->cls3.seqDelivery = 1; |
| 6313 | |
| 6314 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 6315 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 6316 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 6317 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 6318 | memcpy(pcmd, &vport->fc_portname, 8); |
| 6319 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6320 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6321 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 6322 | |
| 6323 | lpfc_set_disctmo(vport); |
| 6324 | |
| 6325 | phba->fc_stat.elsXmitFDISC++; |
| 6326 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 6327 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6328 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6329 | "Issue FDISC: did:x%x", |
| 6330 | did, 0, 0); |
| 6331 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6332 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 6333 | if (rc == IOCB_ERROR) { |
| 6334 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6335 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6336 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6337 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6338 | return 1; |
| 6339 | } |
| 6340 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6341 | return 0; |
| 6342 | } |
| 6343 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6344 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6345 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6346 | * @phba: pointer to lpfc hba data structure. |
| 6347 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6348 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6349 | * |
| 6350 | * This routine is the completion callback function to the issuing of a LOGO |
| 6351 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 6352 | * reference count held on ndlp for this completion function, indicating that |
| 6353 | * the reference to the ndlp is no long needed. Note that the |
| 6354 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 6355 | * callback function and an additional explicit ndlp reference decrementation |
| 6356 | * will trigger the actual release of the ndlp. |
| 6357 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6358 | static void |
| 6359 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6360 | struct lpfc_iocbq *rspiocb) |
| 6361 | { |
| 6362 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6363 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6364 | struct lpfc_nodelist *ndlp; |
| 6365 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6366 | |
| 6367 | irsp = &rspiocb->iocb; |
| 6368 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6369 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 6370 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6371 | |
| 6372 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6373 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6374 | |
| 6375 | /* Trigger the release of the ndlp after logo */ |
| 6376 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6377 | } |
| 6378 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6379 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6380 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6381 | * @vport: pointer to a virtual N_Port data structure. |
| 6382 | * @ndlp: pointer to a node-list data structure. |
| 6383 | * |
| 6384 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 6385 | * |
| 6386 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6387 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6388 | * will be stored into the context1 field of the IOCB for the completion |
| 6389 | * callback function to the LOGO ELS command. |
| 6390 | * |
| 6391 | * Return codes |
| 6392 | * 0 - Successfully issued logo off the @vport |
| 6393 | * 1 - Failed to issue logo off the @vport |
| 6394 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6395 | int |
| 6396 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 6397 | { |
| 6398 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6399 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6400 | IOCB_t *icmd; |
| 6401 | struct lpfc_iocbq *elsiocb; |
| 6402 | uint8_t *pcmd; |
| 6403 | uint16_t cmdsize; |
| 6404 | |
| 6405 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 6406 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 6407 | ELS_CMD_LOGO); |
| 6408 | if (!elsiocb) |
| 6409 | return 1; |
| 6410 | |
| 6411 | icmd = &elsiocb->iocb; |
| 6412 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6413 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 6414 | pcmd += sizeof(uint32_t); |
| 6415 | |
| 6416 | /* Fill in LOGO payload */ |
| 6417 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 6418 | pcmd += sizeof(uint32_t); |
| 6419 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 6420 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6421 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6422 | "Issue LOGO npiv did:x%x flg:x%x", |
| 6423 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 6424 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6425 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 6426 | spin_lock_irq(shost->host_lock); |
| 6427 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 6428 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6429 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 6430 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6431 | spin_lock_irq(shost->host_lock); |
| 6432 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 6433 | spin_unlock_irq(shost->host_lock); |
| 6434 | lpfc_els_free_iocb(phba, elsiocb); |
| 6435 | return 1; |
| 6436 | } |
| 6437 | return 0; |
| 6438 | } |
| 6439 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6440 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6441 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6442 | * @ptr: holder for the timer function associated data. |
| 6443 | * |
| 6444 | * This routine is invoked by the fabric iocb block timer after |
| 6445 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 6446 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 6447 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 6448 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 6449 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 6450 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6451 | void |
| 6452 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 6453 | { |
| 6454 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 6455 | unsigned long iflags; |
| 6456 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6457 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6458 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 6459 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 6460 | if (!tmo_posted) |
| 6461 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 6462 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 6463 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6464 | if (!tmo_posted) |
| 6465 | lpfc_worker_wake_up(phba); |
| 6466 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6467 | } |
| 6468 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6469 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6470 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6471 | * @phba: pointer to lpfc hba data structure. |
| 6472 | * |
| 6473 | * This routine issues one fabric iocb from the driver internal list to |
| 6474 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 6475 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 6476 | * remove one pending fabric iocb from the driver internal list and invokes |
| 6477 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 6478 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6479 | static void |
| 6480 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 6481 | { |
| 6482 | struct lpfc_iocbq *iocb; |
| 6483 | unsigned long iflags; |
| 6484 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6485 | IOCB_t *cmd; |
| 6486 | |
| 6487 | repeat: |
| 6488 | iocb = NULL; |
| 6489 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6490 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6491 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 6492 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 6493 | list); |
| 6494 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6495 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6496 | atomic_inc(&phba->fabric_iocb_count); |
| 6497 | } |
| 6498 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6499 | if (iocb) { |
| 6500 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6501 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6502 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6503 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6504 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6505 | "Fabric sched1: ste:x%x", |
| 6506 | iocb->vport->port_state, 0, 0); |
| 6507 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6508 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6509 | |
| 6510 | if (ret == IOCB_ERROR) { |
| 6511 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6512 | iocb->fabric_iocb_cmpl = NULL; |
| 6513 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6514 | cmd = &iocb->iocb; |
| 6515 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6516 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6517 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 6518 | |
| 6519 | atomic_dec(&phba->fabric_iocb_count); |
| 6520 | goto repeat; |
| 6521 | } |
| 6522 | } |
| 6523 | |
| 6524 | return; |
| 6525 | } |
| 6526 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6527 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6528 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6529 | * @phba: pointer to lpfc hba data structure. |
| 6530 | * |
| 6531 | * This routine unblocks the issuing fabric iocb command. The function |
| 6532 | * will clear the fabric iocb block bit and then invoke the routine |
| 6533 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 6534 | * from the driver internal fabric iocb list. |
| 6535 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6536 | void |
| 6537 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 6538 | { |
| 6539 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6540 | |
| 6541 | lpfc_resume_fabric_iocbs(phba); |
| 6542 | return; |
| 6543 | } |
| 6544 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6545 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6546 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6547 | * @phba: pointer to lpfc hba data structure. |
| 6548 | * |
| 6549 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 6550 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 6551 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 6552 | * fabric iocb will be issued out of the HBA. |
| 6553 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6554 | static void |
| 6555 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 6556 | { |
| 6557 | int blocked; |
| 6558 | |
| 6559 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6560 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6561 | if (!blocked) |
| 6562 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); |
| 6563 | |
| 6564 | return; |
| 6565 | } |
| 6566 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6567 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6568 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6569 | * @phba: pointer to lpfc hba data structure. |
| 6570 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6571 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6572 | * |
| 6573 | * This routine is the callback function that is put to the fabric iocb's |
| 6574 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 6575 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 6576 | * function first restores and invokes the original iocb's callback function |
| 6577 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 6578 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 6579 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6580 | static void |
| 6581 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6582 | struct lpfc_iocbq *rspiocb) |
| 6583 | { |
| 6584 | struct ls_rjt stat; |
| 6585 | |
| 6586 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 6587 | BUG(); |
| 6588 | |
| 6589 | switch (rspiocb->iocb.ulpStatus) { |
| 6590 | case IOSTAT_NPORT_RJT: |
| 6591 | case IOSTAT_FABRIC_RJT: |
| 6592 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 6593 | lpfc_block_fabric_iocbs(phba); |
| 6594 | } |
| 6595 | break; |
| 6596 | |
| 6597 | case IOSTAT_NPORT_BSY: |
| 6598 | case IOSTAT_FABRIC_BSY: |
| 6599 | lpfc_block_fabric_iocbs(phba); |
| 6600 | break; |
| 6601 | |
| 6602 | case IOSTAT_LS_RJT: |
| 6603 | stat.un.lsRjtError = |
| 6604 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 6605 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 6606 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 6607 | lpfc_block_fabric_iocbs(phba); |
| 6608 | break; |
| 6609 | } |
| 6610 | |
| 6611 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 6612 | BUG(); |
| 6613 | |
| 6614 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 6615 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 6616 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6617 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 6618 | |
| 6619 | atomic_dec(&phba->fabric_iocb_count); |
| 6620 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6621 | /* Post any pending iocbs to HBA */ |
| 6622 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6623 | } |
| 6624 | } |
| 6625 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6626 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6627 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6628 | * @phba: pointer to lpfc hba data structure. |
| 6629 | * @iocb: pointer to lpfc command iocb data structure. |
| 6630 | * |
| 6631 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 6632 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 6633 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 6634 | * any given time. As such, this function will first check to see whether there |
| 6635 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 6636 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 6637 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 6638 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 6639 | * |
| 6640 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 6641 | * order. The problem is caused by the construction of the "ready" boolen does |
| 6642 | * not include the condition that the internal fabric IOCB list is empty. As |
| 6643 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 6644 | * ahead of the fabric IOCBs in the internal list. |
| 6645 | * |
| 6646 | * Return code |
| 6647 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 6648 | * IOCB_ERROR - failed to issue fabric iocb |
| 6649 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6650 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6651 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 6652 | { |
| 6653 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6654 | int ready; |
| 6655 | int ret; |
| 6656 | |
| 6657 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 6658 | BUG(); |
| 6659 | |
| 6660 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6661 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 6662 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6663 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6664 | if (ready) |
| 6665 | /* Increment fabric iocb count to hold the position */ |
| 6666 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6667 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6668 | if (ready) { |
| 6669 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6670 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6671 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6672 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6673 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6674 | "Fabric sched2: ste:x%x", |
| 6675 | iocb->vport->port_state, 0, 0); |
| 6676 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6677 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6678 | |
| 6679 | if (ret == IOCB_ERROR) { |
| 6680 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6681 | iocb->fabric_iocb_cmpl = NULL; |
| 6682 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6683 | atomic_dec(&phba->fabric_iocb_count); |
| 6684 | } |
| 6685 | } else { |
| 6686 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6687 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 6688 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6689 | ret = IOCB_SUCCESS; |
| 6690 | } |
| 6691 | return ret; |
| 6692 | } |
| 6693 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6694 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6695 | * 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] | 6696 | * @vport: pointer to a virtual N_Port data structure. |
| 6697 | * |
| 6698 | * This routine aborts all the IOCBs associated with a @vport from the |
| 6699 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6700 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6701 | * list, removes each IOCB associated with the @vport off the list, set the |
| 6702 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6703 | * associated with the IOCB. |
| 6704 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6705 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6706 | { |
| 6707 | LIST_HEAD(completions); |
| 6708 | struct lpfc_hba *phba = vport->phba; |
| 6709 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6710 | |
| 6711 | spin_lock_irq(&phba->hbalock); |
| 6712 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6713 | list) { |
| 6714 | |
| 6715 | if (piocb->vport != vport) |
| 6716 | continue; |
| 6717 | |
| 6718 | list_move_tail(&piocb->list, &completions); |
| 6719 | } |
| 6720 | spin_unlock_irq(&phba->hbalock); |
| 6721 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6722 | /* Cancel all the IOCBs from the completions list */ |
| 6723 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6724 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6725 | } |
| 6726 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6727 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6728 | * 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] | 6729 | * @ndlp: pointer to a node-list data structure. |
| 6730 | * |
| 6731 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 6732 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6733 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6734 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 6735 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6736 | * associated with the IOCB. |
| 6737 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6738 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 6739 | { |
| 6740 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6741 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6742 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6743 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6744 | |
| 6745 | spin_lock_irq(&phba->hbalock); |
| 6746 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6747 | list) { |
| 6748 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 6749 | |
| 6750 | list_move_tail(&piocb->list, &completions); |
| 6751 | } |
| 6752 | } |
| 6753 | spin_unlock_irq(&phba->hbalock); |
| 6754 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6755 | /* Cancel all the IOCBs from the completions list */ |
| 6756 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6757 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6758 | } |
| 6759 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6760 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6761 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6762 | * @phba: pointer to lpfc hba data structure. |
| 6763 | * |
| 6764 | * This routine aborts all the IOCBs currently on the driver internal |
| 6765 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 6766 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 6767 | * list, removes IOCBs off the list, set the status feild to |
| 6768 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 6769 | * the IOCB. |
| 6770 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6771 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 6772 | { |
| 6773 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6774 | |
| 6775 | spin_lock_irq(&phba->hbalock); |
| 6776 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 6777 | spin_unlock_irq(&phba->hbalock); |
| 6778 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6779 | /* Cancel all the IOCBs from the completions list */ |
| 6780 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6781 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6782 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6783 | |
| 6784 | /** |
| 6785 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 6786 | * @phba: pointer to lpfc hba data structure. |
| 6787 | * @axri: pointer to the els xri abort wcqe structure. |
| 6788 | * |
| 6789 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 6790 | * ELS aborted xri. |
| 6791 | **/ |
| 6792 | void |
| 6793 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 6794 | struct sli4_wcqe_xri_aborted *axri) |
| 6795 | { |
| 6796 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
| 6797 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 6798 | unsigned long iflag = 0; |
| 6799 | |
| 6800 | spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, iflag); |
| 6801 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 6802 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 6803 | if (sglq_entry->sli4_xritag == xri) { |
| 6804 | list_del(&sglq_entry->list); |
| 6805 | spin_unlock_irqrestore( |
| 6806 | &phba->sli4_hba.abts_sgl_list_lock, |
| 6807 | iflag); |
| 6808 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 6809 | |
| 6810 | list_add_tail(&sglq_entry->list, |
| 6811 | &phba->sli4_hba.lpfc_sgl_list); |
| 6812 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 6813 | return; |
| 6814 | } |
| 6815 | } |
| 6816 | spin_unlock_irqrestore(&phba->sli4_hba.abts_sgl_list_lock, iflag); |
| 6817 | } |