| 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); |
| 53 | static void lpfc_register_new_vport(struct lpfc_hba *phba, |
| 54 | struct lpfc_vport *vport, |
| 55 | struct lpfc_nodelist *ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 56 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 57 | static int lpfc_max_els_tries = 3; |
| 58 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 59 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 60 | * lpfc_els_chk_latt - Check host link attention event for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 61 | * @vport: pointer to a host virtual N_Port data structure. |
| 62 | * |
| 63 | * This routine checks whether there is an outstanding host link |
| 64 | * attention event during the discovery process with the @vport. It is done |
| 65 | * by reading the HBA's Host Attention (HA) register. If there is any host |
| 66 | * link attention events during this @vport's discovery process, the @vport |
| 67 | * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall |
| 68 | * be issued if the link state is not already in host link cleared state, |
| 69 | * and a return code shall indicate whether the host link attention event |
| 70 | * had happened. |
| 71 | * |
| 72 | * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport |
| 73 | * state in LPFC_VPORT_READY, the request for checking host link attention |
| 74 | * event will be ignored and a return code shall indicate no host link |
| 75 | * attention event had happened. |
| 76 | * |
| 77 | * Return codes |
| 78 | * 0 - no host link attention event happened |
| 79 | * 1 - host link attention event happened |
| 80 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 81 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 82 | lpfc_els_chk_latt(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 83 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 84 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 85 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 86 | uint32_t ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 87 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 88 | if (vport->port_state >= LPFC_VPORT_READY || |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 89 | phba->link_state == LPFC_LINK_DOWN || |
| 90 | phba->sli_rev > LPFC_SLI_REV3) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 91 | return 0; |
| 92 | |
| 93 | /* Read the HBA Host Attention Register */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 94 | ha_copy = readl(phba->HAregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 95 | |
| 96 | if (!(ha_copy & HA_LATT)) |
| 97 | return 0; |
| 98 | |
| 99 | /* Pending Link Event during Discovery */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 100 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 101 | "0237 Pending Link Event during " |
| 102 | "Discovery: State x%x\n", |
| 103 | phba->pport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 104 | |
| 105 | /* CLEAR_LA should re-enable link attention events and |
| 106 | * we should then imediately take a LATT event. The |
| 107 | * LATT processing should call lpfc_linkdown() which |
| 108 | * will cleanup any left over in-progress discovery |
| 109 | * events. |
| 110 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 111 | spin_lock_irq(shost->host_lock); |
| 112 | vport->fc_flag |= FC_ABORT_DISCOVERY; |
| 113 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 114 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 115 | if (phba->link_state != LPFC_CLEAR_LA) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 116 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 117 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 118 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 119 | } |
| 120 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 121 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 122 | * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 123 | * @vport: pointer to a host virtual N_Port data structure. |
| 124 | * @expectRsp: flag indicating whether response is expected. |
| 125 | * @cmdSize: size of the ELS command. |
| 126 | * @retry: number of retries to the command IOCB when it fails. |
| 127 | * @ndlp: pointer to a node-list data structure. |
| 128 | * @did: destination identifier. |
| 129 | * @elscmd: the ELS command code. |
| 130 | * |
| 131 | * This routine is used for allocating a lpfc-IOCB data structure from |
| 132 | * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters |
| 133 | * passed into the routine for discovery state machine to issue an Extended |
| 134 | * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation |
| 135 | * and preparation routine that is used by all the discovery state machine |
| 136 | * routines and the ELS command-specific fields will be later set up by |
| 137 | * the individual discovery machine routines after calling this routine |
| 138 | * allocating and preparing a generic IOCB data structure. It fills in the |
| 139 | * Buffer Descriptor Entries (BDEs), allocates buffers for both command |
| 140 | * payload and response payload (if expected). The reference count on the |
| 141 | * ndlp is incremented by 1 and the reference to the ndlp is put into |
| 142 | * context1 of the IOCB data structure for this IOCB to hold the ndlp |
| 143 | * reference for the command's callback function to access later. |
| 144 | * |
| 145 | * Return code |
| 146 | * Pointer to the newly allocated/prepared els iocb data structure |
| 147 | * NULL - when els iocb data structure allocation/preparation failed |
| 148 | **/ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 149 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 150 | lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, |
| 151 | uint16_t cmdSize, uint8_t retry, |
| 152 | struct lpfc_nodelist *ndlp, uint32_t did, |
| 153 | uint32_t elscmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 154 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 155 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 156 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 157 | struct lpfc_dmabuf *pcmd, *prsp, *pbuflist; |
| 158 | struct ulp_bde64 *bpl; |
| 159 | IOCB_t *icmd; |
| 160 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 161 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 162 | if (!lpfc_is_link_up(phba)) |
| 163 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 164 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 165 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 166 | elsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 167 | |
| 168 | if (elsiocb == NULL) |
| 169 | return NULL; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 170 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 171 | /* |
| 172 | * If this command is for fabric controller and HBA running |
| 173 | * in FIP mode send FLOGI, FDISC and LOGO as FIP frames. |
| 174 | */ |
| 175 | if ((did == Fabric_DID) && |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 176 | (phba->hba_flag & HBA_FIP_SUPPORT) && |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 177 | ((elscmd == ELS_CMD_FLOGI) || |
| 178 | (elscmd == ELS_CMD_FDISC) || |
| 179 | (elscmd == ELS_CMD_LOGO))) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 180 | switch (elscmd) { |
| 181 | case ELS_CMD_FLOGI: |
| 182 | elsiocb->iocb_flag |= ((ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT) |
| 183 | & LPFC_FIP_ELS_ID_MASK); |
| 184 | break; |
| 185 | case ELS_CMD_FDISC: |
| 186 | elsiocb->iocb_flag |= ((ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT) |
| 187 | & LPFC_FIP_ELS_ID_MASK); |
| 188 | break; |
| 189 | case ELS_CMD_LOGO: |
| 190 | elsiocb->iocb_flag |= ((ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT) |
| 191 | & LPFC_FIP_ELS_ID_MASK); |
| 192 | break; |
| 193 | } |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 194 | else |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 195 | elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 196 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 197 | icmd = &elsiocb->iocb; |
| 198 | |
| 199 | /* fill in BDEs for command */ |
| 200 | /* Allocate buffer for command payload */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 201 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 202 | if (pcmd) |
| 203 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 204 | if (!pcmd || !pcmd->virt) |
| 205 | goto els_iocb_free_pcmb_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 206 | |
| 207 | INIT_LIST_HEAD(&pcmd->list); |
| 208 | |
| 209 | /* Allocate buffer for response payload */ |
| 210 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 211 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 212 | if (prsp) |
| 213 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 214 | &prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 215 | if (!prsp || !prsp->virt) |
| 216 | goto els_iocb_free_prsp_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 217 | INIT_LIST_HEAD(&prsp->list); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 218 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 219 | prsp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 220 | |
| 221 | /* Allocate buffer for Buffer ptr list */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 222 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 223 | if (pbuflist) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 224 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 225 | &pbuflist->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 226 | if (!pbuflist || !pbuflist->virt) |
| 227 | goto els_iocb_free_pbuf_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 228 | |
| 229 | INIT_LIST_HEAD(&pbuflist->list); |
| 230 | |
| 231 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 232 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 233 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 234 | icmd->un.elsreq64.remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 235 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 236 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 237 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 238 | icmd->ulpTimeout = phba->fc_ratov * 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 239 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 240 | icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 241 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; |
| 242 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 243 | icmd->ulpBdeCount = 1; |
| 244 | icmd->ulpLe = 1; |
| 245 | icmd->ulpClass = CLASS3; |
| 246 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 247 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 248 | icmd->un.elsreq64.myID = vport->fc_myDID; |
| 249 | |
| 250 | /* For ELS_REQUEST64_CR, use the VPI by default */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 251 | icmd->ulpContext = vport->vpi + phba->vpi_base; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 252 | icmd->ulpCt_h = 0; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 253 | /* The CT field must be 0=INVALID_RPI for the ECHO cmd */ |
| 254 | if (elscmd == ELS_CMD_ECHO) |
| 255 | icmd->ulpCt_l = 0; /* context = invalid RPI */ |
| 256 | else |
| 257 | icmd->ulpCt_l = 1; /* context = VPI */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 258 | } |
| 259 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 260 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
| 261 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); |
| 262 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); |
| 263 | bpl->tus.f.bdeSize = cmdSize; |
| 264 | bpl->tus.f.bdeFlags = 0; |
| 265 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 266 | |
| 267 | if (expectRsp) { |
| 268 | bpl++; |
| 269 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); |
| 270 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); |
| 271 | bpl->tus.f.bdeSize = FCELSSIZE; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 272 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 273 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 274 | } |
| 275 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 276 | /* prevent preparing iocb with NULL ndlp reference */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 277 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 278 | if (!elsiocb->context1) |
| 279 | goto els_iocb_free_pbuf_exit; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 280 | elsiocb->context2 = pcmd; |
| 281 | elsiocb->context3 = pbuflist; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 282 | elsiocb->retry = retry; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 283 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 284 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
| 285 | |
| 286 | if (prsp) { |
| 287 | list_add(&prsp->list, &pcmd->list); |
| 288 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 289 | if (expectRsp) { |
| 290 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 291 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 292 | "0116 Xmit ELS command x%x to remote " |
| 293 | "NPORT x%x I/O tag: x%x, port state: x%x\n", |
| 294 | elscmd, did, elsiocb->iotag, |
| 295 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 296 | } else { |
| 297 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 298 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 299 | "0117 Xmit ELS response x%x to remote " |
| 300 | "NPORT x%x I/O tag: x%x, size: x%x\n", |
| 301 | elscmd, ndlp->nlp_DID, elsiocb->iotag, |
| 302 | cmdSize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 303 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 304 | return elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 305 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 306 | els_iocb_free_pbuf_exit: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 307 | if (expectRsp) |
| 308 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 309 | kfree(pbuflist); |
| 310 | |
| 311 | els_iocb_free_prsp_exit: |
| 312 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 313 | kfree(prsp); |
| 314 | |
| 315 | els_iocb_free_pcmb_exit: |
| 316 | kfree(pcmd); |
| 317 | lpfc_sli_release_iocbq(phba, elsiocb); |
| 318 | return NULL; |
| 319 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 320 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 321 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 322 | * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 323 | * @vport: pointer to a host virtual N_Port data structure. |
| 324 | * |
| 325 | * This routine issues a fabric registration login for a @vport. An |
| 326 | * active ndlp node with Fabric_DID must already exist for this @vport. |
| 327 | * The routine invokes two mailbox commands to carry out fabric registration |
| 328 | * login through the HBA firmware: the first mailbox command requests the |
| 329 | * HBA to perform link configuration for the @vport; and the second mailbox |
| 330 | * command requests the HBA to perform the actual fabric registration login |
| 331 | * with the @vport. |
| 332 | * |
| 333 | * Return code |
| 334 | * 0 - successfully issued fabric registration login for @vport |
| 335 | * -ENXIO -- failed to issue fabric registration login for @vport |
| 336 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 337 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 338 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
| 339 | { |
| 340 | struct lpfc_hba *phba = vport->phba; |
| 341 | LPFC_MBOXQ_t *mbox; |
| 342 | struct lpfc_dmabuf *mp; |
| 343 | struct lpfc_nodelist *ndlp; |
| 344 | struct serv_parm *sp; |
| 345 | int rc; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 346 | int err = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 347 | |
| 348 | sp = &phba->fc_fabparam; |
| 349 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 350 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 351 | err = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 352 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 353 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 354 | |
| 355 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 356 | if (!mbox) { |
| 357 | err = 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 358 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 359 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 360 | |
| 361 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 362 | lpfc_config_link(phba, mbox); |
| 363 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 364 | mbox->vport = vport; |
| 365 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 366 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 367 | if (rc == MBX_NOT_FINISHED) { |
| 368 | err = 3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 369 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 370 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 371 | |
| 372 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 373 | if (!mbox) { |
| 374 | err = 4; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 375 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 376 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 377 | 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] | 378 | if (rc) { |
| 379 | err = 5; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 380 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 381 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 382 | |
| 383 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; |
| 384 | mbox->vport = vport; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 385 | /* increment the reference count on ndlp to hold reference |
| 386 | * for the callback routine. |
| 387 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 388 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 389 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 390 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 391 | if (rc == MBX_NOT_FINISHED) { |
| 392 | err = 6; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 393 | goto fail_issue_reg_login; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 394 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 395 | |
| 396 | return 0; |
| 397 | |
| 398 | fail_issue_reg_login: |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 399 | /* decrement the reference count on ndlp just incremented |
| 400 | * for the failed mbox command. |
| 401 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 402 | lpfc_nlp_put(ndlp); |
| 403 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 404 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 405 | kfree(mp); |
| 406 | fail_free_mbox: |
| 407 | mempool_free(mbox, phba->mbox_mem_pool); |
| 408 | |
| 409 | fail: |
| 410 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 411 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 412 | "0249 Cannot issue Register Fabric login: Err %d\n", err); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 413 | return -ENXIO; |
| 414 | } |
| 415 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 416 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 417 | * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login |
| 418 | * @vport: pointer to a host virtual N_Port data structure. |
| 419 | * |
| 420 | * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for |
| 421 | * the @vport. This mailbox command is necessary for FCoE only. |
| 422 | * |
| 423 | * Return code |
| 424 | * 0 - successfully issued REG_VFI for @vport |
| 425 | * A failure code otherwise. |
| 426 | **/ |
| 427 | static int |
| 428 | lpfc_issue_reg_vfi(struct lpfc_vport *vport) |
| 429 | { |
| 430 | struct lpfc_hba *phba = vport->phba; |
| 431 | LPFC_MBOXQ_t *mboxq; |
| 432 | struct lpfc_nodelist *ndlp; |
| 433 | struct serv_parm *sp; |
| 434 | struct lpfc_dmabuf *dmabuf; |
| 435 | int rc = 0; |
| 436 | |
| 437 | sp = &phba->fc_fabparam; |
| 438 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 439 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
| 440 | rc = -ENODEV; |
| 441 | goto fail; |
| 442 | } |
| 443 | |
| 444 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 445 | if (!dmabuf) { |
| 446 | rc = -ENOMEM; |
| 447 | goto fail; |
| 448 | } |
| 449 | dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys); |
| 450 | if (!dmabuf->virt) { |
| 451 | rc = -ENOMEM; |
| 452 | goto fail_free_dmabuf; |
| 453 | } |
| 454 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 455 | if (!mboxq) { |
| 456 | rc = -ENOMEM; |
| 457 | goto fail_free_coherent; |
| 458 | } |
| 459 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 460 | memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam)); |
| 461 | lpfc_reg_vfi(mboxq, vport, dmabuf->phys); |
| 462 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi; |
| 463 | mboxq->vport = vport; |
| 464 | mboxq->context1 = dmabuf; |
| 465 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 466 | if (rc == MBX_NOT_FINISHED) { |
| 467 | rc = -ENXIO; |
| 468 | goto fail_free_mbox; |
| 469 | } |
| 470 | return 0; |
| 471 | |
| 472 | fail_free_mbox: |
| 473 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 474 | fail_free_coherent: |
| 475 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 476 | fail_free_dmabuf: |
| 477 | kfree(dmabuf); |
| 478 | fail: |
| 479 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 480 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 481 | "0289 Issue Register VFI failed: Err %d\n", rc); |
| 482 | return rc; |
| 483 | } |
| 484 | |
| 485 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 486 | * 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] | 487 | * @vport: pointer to a host virtual N_Port data structure. |
| 488 | * @ndlp: pointer to a node-list data structure. |
| 489 | * @sp: pointer to service parameter data structure. |
| 490 | * @irsp: pointer to the IOCB within the lpfc response IOCB. |
| 491 | * |
| 492 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 493 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric |
| 494 | * port in a fabric topology. It properly sets up the parameters to the @ndlp |
| 495 | * from the IOCB response. It also check the newly assigned N_Port ID to the |
| 496 | * @vport against the previously assigned N_Port ID. If it is different from |
| 497 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine |
| 498 | * is invoked on all the remaining nodes with the @vport to unregister the |
| 499 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() |
| 500 | * is invoked to register login to the fabric. |
| 501 | * |
| 502 | * Return code |
| 503 | * 0 - Success (currently, always return 0) |
| 504 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 505 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 506 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 507 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 508 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 509 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 510 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 511 | struct lpfc_nodelist *np; |
| 512 | struct lpfc_nodelist *next_np; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 513 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 514 | spin_lock_irq(shost->host_lock); |
| 515 | vport->fc_flag |= FC_FABRIC; |
| 516 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 517 | |
| 518 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 519 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 520 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 521 | |
| 522 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 523 | |
| 524 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 525 | spin_lock_irq(shost->host_lock); |
| 526 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 527 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 528 | } else { |
| 529 | /* |
| 530 | * If we are a N-port connected to a Fabric, fixup sparam's so |
| 531 | * logins to devices on remote loops work. |
| 532 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 533 | vport->fc_sparam.cmn.altBbCredit = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 534 | } |
| 535 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 536 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 537 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 538 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 539 | ndlp->nlp_class_sup = 0; |
| 540 | if (sp->cls1.classValid) |
| 541 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 542 | if (sp->cls2.classValid) |
| 543 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 544 | if (sp->cls3.classValid) |
| 545 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 546 | if (sp->cls4.classValid) |
| 547 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 548 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 549 | sp->cmn.bbRcvSizeLsb; |
| 550 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 551 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 552 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 553 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 554 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 555 | LOG_ELS | LOG_VPORT, |
| 556 | "1816 FLOGI NPIV supported, " |
| 557 | "response data 0x%x\n", |
| 558 | sp->cmn.response_multiple_NPort); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 559 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 560 | } else { |
| 561 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 562 | to call reg_vnpid atleast for the physcial host */ |
| 563 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 564 | LOG_ELS | LOG_VPORT, |
| 565 | "1817 Fabric does not support NPIV " |
| 566 | "- configuring single port mode.\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 567 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 572 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 573 | |
| 574 | /* If our NportID changed, we need to ensure all |
| 575 | * remaining NPORTs get unreg_login'ed. |
| 576 | */ |
| 577 | list_for_each_entry_safe(np, next_np, |
| 578 | &vport->fc_nodes, nlp_listp) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 579 | if (!NLP_CHK_NODE_ACT(np)) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 580 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 581 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 582 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 583 | continue; |
| 584 | spin_lock_irq(shost->host_lock); |
| 585 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 586 | spin_unlock_irq(shost->host_lock); |
| 587 | lpfc_unreg_rpi(vport, np); |
| 588 | } |
| 589 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 590 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 591 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 592 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 593 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 594 | } |
| 595 | } |
| 596 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 597 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 598 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
| 599 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 600 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 601 | lpfc_register_new_vport(phba, vport, ndlp); |
| 602 | else |
| 603 | lpfc_issue_fabric_reglogin(vport); |
| 604 | } else { |
| 605 | ndlp->nlp_type |= NLP_FABRIC; |
| 606 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 607 | if (vport->vpi_state & LPFC_VPI_REGISTERED) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 608 | lpfc_start_fdiscs(phba); |
| 609 | lpfc_do_scr_ns_plogi(phba, vport); |
| 610 | } else |
| 611 | lpfc_issue_reg_vfi(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 612 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 613 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 614 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 615 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 616 | * 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] | 617 | * @vport: pointer to a host virtual N_Port data structure. |
| 618 | * @ndlp: pointer to a node-list data structure. |
| 619 | * @sp: pointer to service parameter data structure. |
| 620 | * |
| 621 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 622 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 623 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 624 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 625 | * the received N_Port Name lexicographically, this node shall assign local |
| 626 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 627 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 628 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 629 | * N_Port IDs. |
| 630 | * |
| 631 | * Return code |
| 632 | * 0 - Success |
| 633 | * -ENXIO - Fail |
| 634 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 635 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 636 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 637 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 638 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 639 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 640 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 641 | LPFC_MBOXQ_t *mbox; |
| 642 | int rc; |
| 643 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 644 | spin_lock_irq(shost->host_lock); |
| 645 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 646 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 647 | |
| 648 | phba->fc_edtov = FF_DEF_EDTOV; |
| 649 | phba->fc_ratov = FF_DEF_RATOV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 650 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 651 | sizeof(vport->fc_portname)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 652 | if (rc >= 0) { |
| 653 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 654 | spin_lock_irq(shost->host_lock); |
| 655 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 656 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 657 | |
| 658 | /* |
| 659 | * N_Port ID cannot be 0, set our to LocalID the other |
| 660 | * side will be RemoteID. |
| 661 | */ |
| 662 | |
| 663 | /* not equal */ |
| 664 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 665 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 666 | |
| 667 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 668 | if (!mbox) |
| 669 | goto fail; |
| 670 | |
| 671 | lpfc_config_link(phba, mbox); |
| 672 | |
| 673 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 674 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 675 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 676 | if (rc == MBX_NOT_FINISHED) { |
| 677 | mempool_free(mbox, phba->mbox_mem_pool); |
| 678 | goto fail; |
| 679 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 680 | /* Decrement ndlp reference count indicating that ndlp can be |
| 681 | * safely released when other references to it are done. |
| 682 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 683 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 684 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 685 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 686 | if (!ndlp) { |
| 687 | /* |
| 688 | * Cannot find existing Fabric ndlp, so allocate a |
| 689 | * new one |
| 690 | */ |
| 691 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 692 | if (!ndlp) |
| 693 | goto fail; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 694 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 695 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 696 | ndlp = lpfc_enable_node(vport, ndlp, |
| 697 | NLP_STE_UNUSED_NODE); |
| 698 | if(!ndlp) |
| 699 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 703 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 704 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 705 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 706 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 707 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 708 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 709 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 710 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 711 | } else |
| 712 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 713 | * count indicating that ndlp can be released when other |
| 714 | * references to it are done. |
| 715 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 716 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 717 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 718 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 719 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 720 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 721 | spin_lock_irq(shost->host_lock); |
| 722 | vport->fc_flag |= FC_PT2PT; |
| 723 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 724 | |
| 725 | /* Start discovery - this should just do CLEAR_LA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 726 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 727 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 728 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 729 | return -ENXIO; |
| 730 | } |
| 731 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 732 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 733 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 734 | * @phba: pointer to lpfc hba data structure. |
| 735 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 736 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 737 | * |
| 738 | * This routine is the top-level completion callback function for issuing |
| 739 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 740 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 741 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 742 | * returning 1), the command IOCB will be released and function returned. |
| 743 | * If the retry attempt has been given up (possibly reach the maximum |
| 744 | * number of retries), one additional decrement of ndlp reference shall be |
| 745 | * invoked before going out after releasing the command IOCB. This will |
| 746 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 747 | * invoke one decrement of ndlp reference count). If no error reported in |
| 748 | * the IOCB status, the command Port ID field is used to determine whether |
| 749 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 750 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 751 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 752 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 753 | * specific topology completion conditions. |
| 754 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 755 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 756 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 757 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 758 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 759 | struct lpfc_vport *vport = cmdiocb->vport; |
| 760 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 761 | IOCB_t *irsp = &rspiocb->iocb; |
| 762 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 763 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 764 | struct serv_parm *sp; |
| 765 | int rc; |
| 766 | |
| 767 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 768 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 769 | /* One additional decrement on node reference count to |
| 770 | * trigger the release of the node |
| 771 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 772 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 773 | goto out; |
| 774 | } |
| 775 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 776 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 777 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 778 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 779 | vport->port_state); |
| 780 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 781 | if (irsp->ulpStatus) { |
| 782 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 783 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 784 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 785 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 786 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 787 | spin_lock_irq(shost->host_lock); |
| 788 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 789 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 790 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 791 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 792 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 793 | * alpa map would take too long otherwise. |
| 794 | */ |
| 795 | if (phba->alpa_map[0] == 0) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 796 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | /* FLOGI failure */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 800 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 801 | "0100 FLOGI failure Data: x%x x%x " |
| 802 | "x%x\n", |
| 803 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 804 | irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 805 | goto flogifail; |
| 806 | } |
| 807 | |
| 808 | /* |
| 809 | * The FLogI succeeded. Sync the data for the CPU before |
| 810 | * accessing it. |
| 811 | */ |
| 812 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 813 | |
| 814 | sp = prsp->virt + sizeof(uint32_t); |
| 815 | |
| 816 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 817 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 818 | "0101 FLOGI completes successfully " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 819 | "Data: x%x x%x x%x x%x\n", |
| 820 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
| 821 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 822 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 823 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 824 | /* |
| 825 | * If Common Service Parameters indicate Nport |
| 826 | * we are point to point, if Fport we are Fabric. |
| 827 | */ |
| 828 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 829 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 830 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 831 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 832 | |
| 833 | if (!rc) |
| 834 | goto out; |
| 835 | } |
| 836 | |
| 837 | flogifail: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 838 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 839 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 840 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 841 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 842 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 843 | |
| 844 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 845 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 846 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 847 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && |
| 848 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) && |
| 849 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 850 | /* If FLOGI failed enable link interrupt. */ |
| 851 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 852 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 853 | out: |
| 854 | lpfc_els_free_iocb(phba, cmdiocb); |
| 855 | } |
| 856 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 857 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 858 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 859 | * @vport: pointer to a host virtual N_Port data structure. |
| 860 | * @ndlp: pointer to a node-list data structure. |
| 861 | * @retry: number of retries to the command IOCB. |
| 862 | * |
| 863 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 864 | * for a @vport. The initiator service parameters are put into the payload |
| 865 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 866 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 867 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 868 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 869 | * |
| 870 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 871 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 872 | * will be stored into the context1 field of the IOCB for the completion |
| 873 | * callback function to the FLOGI ELS command. |
| 874 | * |
| 875 | * Return code |
| 876 | * 0 - successfully issued flogi iocb for @vport |
| 877 | * 1 - failed to issue flogi iocb for @vport |
| 878 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 879 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 880 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 881 | uint8_t retry) |
| 882 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 883 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 884 | struct serv_parm *sp; |
| 885 | IOCB_t *icmd; |
| 886 | struct lpfc_iocbq *elsiocb; |
| 887 | struct lpfc_sli_ring *pring; |
| 888 | uint8_t *pcmd; |
| 889 | uint16_t cmdsize; |
| 890 | uint32_t tmo; |
| 891 | int rc; |
| 892 | |
| 893 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 894 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 895 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 896 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 897 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 898 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 899 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 900 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 901 | |
| 902 | icmd = &elsiocb->iocb; |
| 903 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 904 | |
| 905 | /* For FLOGI request, remainder of payload is service parameters */ |
| 906 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 907 | pcmd += sizeof(uint32_t); |
| 908 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 909 | sp = (struct serv_parm *) pcmd; |
| 910 | |
| 911 | /* Setup CSPs accordingly for Fabric */ |
| 912 | sp->cmn.e_d_tov = 0; |
| 913 | sp->cmn.w2.r_a_tov = 0; |
| 914 | sp->cls1.classValid = 0; |
| 915 | sp->cls2.seqDelivery = 1; |
| 916 | sp->cls3.seqDelivery = 1; |
| 917 | if (sp->cmn.fcphLow < FC_PH3) |
| 918 | sp->cmn.fcphLow = FC_PH3; |
| 919 | if (sp->cmn.fcphHigh < FC_PH3) |
| 920 | sp->cmn.fcphHigh = FC_PH3; |
| 921 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 922 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 923 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 924 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 925 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 926 | /* Set the fcfi to the fcfi we registered with */ |
| 927 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 928 | } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 929 | sp->cmn.request_multiple_Nport = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 930 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 931 | icmd->ulpCt_h = 1; |
| 932 | icmd->ulpCt_l = 0; |
| 933 | } |
| 934 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 935 | if (phba->fc_topology != TOPOLOGY_LOOP) { |
| 936 | icmd->un.elsreq64.myID = 0; |
| 937 | icmd->un.elsreq64.fl = 1; |
| 938 | } |
| 939 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 940 | tmo = phba->fc_ratov; |
| 941 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 942 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 943 | phba->fc_ratov = tmo; |
| 944 | |
| 945 | phba->fc_stat.elsXmitFLOGI++; |
| 946 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 947 | |
| 948 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 949 | "Issue FLOGI: opt:x%x", |
| 950 | phba->sli3_options, 0, 0); |
| 951 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 952 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 953 | if (rc == IOCB_ERROR) { |
| 954 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 955 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 956 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 957 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 958 | } |
| 959 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 960 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 961 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 962 | * @phba: pointer to lpfc hba data structure. |
| 963 | * |
| 964 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 965 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 966 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 967 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 968 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 969 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 970 | * |
| 971 | * Return code |
| 972 | * 0 - Sucessfully issued abort iocb on all outstanding flogis (Always 0) |
| 973 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 974 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 975 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 976 | { |
| 977 | struct lpfc_sli_ring *pring; |
| 978 | struct lpfc_iocbq *iocb, *next_iocb; |
| 979 | struct lpfc_nodelist *ndlp; |
| 980 | IOCB_t *icmd; |
| 981 | |
| 982 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 983 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 984 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 985 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 986 | |
| 987 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 988 | |
| 989 | /* |
| 990 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 991 | * searching for. |
| 992 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 993 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 994 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 995 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 996 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR && |
| 997 | icmd->un.elsreq64.bdl.ulpIoTag32) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 998 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 999 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 1000 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1001 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1002 | } |
| 1003 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1004 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1005 | |
| 1006 | return 0; |
| 1007 | } |
| 1008 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1009 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1010 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1011 | * @vport: pointer to a host virtual N_Port data structure. |
| 1012 | * |
| 1013 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 1014 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1015 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1016 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1017 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 1018 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 1019 | * @vport. |
| 1020 | * |
| 1021 | * Return code |
| 1022 | * 0 - failed to issue initial flogi for @vport |
| 1023 | * 1 - successfully issued initial flogi for @vport |
| 1024 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1025 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1026 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1027 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1028 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1029 | struct lpfc_nodelist *ndlp; |
| 1030 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1031 | vport->port_state = LPFC_FLOGI; |
| 1032 | lpfc_set_disctmo(vport); |
| 1033 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1034 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1035 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1036 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1037 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1038 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1039 | if (!ndlp) |
| 1040 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1041 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1042 | /* Set the node type */ |
| 1043 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1044 | /* Put ndlp onto node list */ |
| 1045 | lpfc_enqueue_node(vport, ndlp); |
| 1046 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1047 | /* re-setup ndlp without removing from node list */ |
| 1048 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1049 | if (!ndlp) |
| 1050 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1051 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1052 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1053 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1054 | /* This decrement of reference count to node shall kick off |
| 1055 | * the release of the node. |
| 1056 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1057 | lpfc_nlp_put(ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1058 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1059 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1060 | } |
| 1061 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1062 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1063 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1064 | * @vport: pointer to a host virtual N_Port data structure. |
| 1065 | * |
| 1066 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 1067 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1068 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1069 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1070 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 1071 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 1072 | * @vport. |
| 1073 | * |
| 1074 | * Return code |
| 1075 | * 0 - failed to issue initial fdisc for @vport |
| 1076 | * 1 - successfully issued initial fdisc for @vport |
| 1077 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1078 | int |
| 1079 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 1080 | { |
| 1081 | struct lpfc_hba *phba = vport->phba; |
| 1082 | struct lpfc_nodelist *ndlp; |
| 1083 | |
| 1084 | /* First look for the Fabric ndlp */ |
| 1085 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1086 | if (!ndlp) { |
| 1087 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 1088 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1089 | if (!ndlp) |
| 1090 | return 0; |
| 1091 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1092 | /* Put ndlp onto node list */ |
| 1093 | lpfc_enqueue_node(vport, ndlp); |
| 1094 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1095 | /* re-setup ndlp without removing from node list */ |
| 1096 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1097 | if (!ndlp) |
| 1098 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1099 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1100 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1101 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1102 | /* decrement node reference count to trigger the release of |
| 1103 | * the node. |
| 1104 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1105 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1106 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1107 | } |
| 1108 | return 1; |
| 1109 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1110 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1111 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1112 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1113 | * @vport: pointer to a host virtual N_Port data structure. |
| 1114 | * |
| 1115 | * This routine checks whether there are more remaining Port Logins |
| 1116 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1117 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1118 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1119 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1120 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1121 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1122 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1123 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1124 | { |
| 1125 | int sentplogi; |
| 1126 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1127 | if (vport->num_disc_nodes) |
| 1128 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1129 | |
| 1130 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1131 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1132 | "0232 Continue discovery with %d PLOGIs to go " |
| 1133 | "Data: x%x x%x x%x\n", |
| 1134 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1135 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1136 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1137 | if (vport->fc_flag & FC_NLP_MORE) |
| 1138 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 1139 | sentplogi = lpfc_els_disc_plogi(vport); |
| 1140 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1141 | return; |
| 1142 | } |
| 1143 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1144 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1145 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1146 | * @phba: pointer to lpfc hba data structure. |
| 1147 | * @prsp: pointer to response IOCB payload. |
| 1148 | * @ndlp: pointer to a node-list data structure. |
| 1149 | * |
| 1150 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1151 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1152 | * The following cases are considered N_Port confirmed: |
| 1153 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1154 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1155 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1156 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1157 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1158 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1159 | * on that node to release the RPI associated with the node; 2) if there is |
| 1160 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1161 | * into, a new node shall be allocated (or activated). In either case, the |
| 1162 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1163 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1164 | * its pointer returned as the confirmed node. |
| 1165 | * |
| 1166 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1167 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1168 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1169 | * into an inactive state on the vport node list and the vport node list |
| 1170 | * management algorithm does not allow two node with a same DID. |
| 1171 | * |
| 1172 | * Return code |
| 1173 | * pointer to the PLOGI N_Port @ndlp |
| 1174 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1175 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1176 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1177 | struct lpfc_nodelist *ndlp) |
| 1178 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1179 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1180 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1181 | struct lpfc_rport_data *rdata; |
| 1182 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1183 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1184 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1185 | uint32_t rc, keepDID = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1186 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1187 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1188 | * by WWPN. Just return the ndlp that was given to us. |
| 1189 | */ |
| 1190 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1191 | return ndlp; |
| 1192 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1193 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1194 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1195 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1196 | /* 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] | 1197 | * we have for that ndlp. If not, we have some work to do. |
| 1198 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1199 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1200 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1201 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1202 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1203 | |
| 1204 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1205 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1206 | sizeof(struct lpfc_name)); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1207 | if (!rc) |
| 1208 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1209 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
| 1210 | if (!new_ndlp) |
| 1211 | return ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1212 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1213 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1214 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1215 | sizeof(struct lpfc_name)); |
| 1216 | if (!rc) |
| 1217 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1218 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1219 | NLP_STE_UNUSED_NODE); |
| 1220 | if (!new_ndlp) |
| 1221 | return ndlp; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1222 | keepDID = new_ndlp->nlp_DID; |
| 1223 | } else |
| 1224 | keepDID = new_ndlp->nlp_DID; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1225 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1226 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1227 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1228 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1229 | |
| 1230 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) |
| 1231 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 1232 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 1233 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1234 | /* 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] | 1235 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1236 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1237 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1238 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1239 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1240 | * to put ndlp on UNUSED list and try to free it. |
| 1241 | */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1242 | |
| 1243 | /* Fix up the rport accordingly */ |
| 1244 | rport = ndlp->rport; |
| 1245 | if (rport) { |
| 1246 | rdata = rport->dd_data; |
| 1247 | if (rdata->pnode == ndlp) { |
| 1248 | lpfc_nlp_put(ndlp); |
| 1249 | ndlp->rport = NULL; |
| 1250 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1251 | new_ndlp->rport = rport; |
| 1252 | } |
| 1253 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1254 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1255 | /* We shall actually free the ndlp with both nlp_DID and |
| 1256 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1257 | * nodelist never to be used. |
| 1258 | */ |
| 1259 | if (ndlp->nlp_DID == 0) { |
| 1260 | spin_lock_irq(&phba->ndlp_lock); |
| 1261 | NLP_SET_FREE_REQ(ndlp); |
| 1262 | spin_unlock_irq(&phba->ndlp_lock); |
| 1263 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1264 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1265 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1266 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1267 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1268 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1269 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1270 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1271 | /* Two ndlps cannot have the same did */ |
| 1272 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1273 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1274 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1275 | return new_ndlp; |
| 1276 | } |
| 1277 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1278 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1279 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1280 | * @vport: pointer to a host virtual N_Port data structure. |
| 1281 | * |
| 1282 | * This routine checks whether more Registration State Change |
| 1283 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1284 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1285 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1286 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1287 | * handling the RSCNs. |
| 1288 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1289 | void |
| 1290 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1291 | { |
| 1292 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1293 | |
| 1294 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1295 | /* |
| 1296 | * Check to see if more RSCNs came in while we were |
| 1297 | * processing this one. |
| 1298 | */ |
| 1299 | if (vport->fc_rscn_id_cnt || |
| 1300 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1301 | lpfc_els_handle_rscn(vport); |
| 1302 | else { |
| 1303 | spin_lock_irq(shost->host_lock); |
| 1304 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1305 | spin_unlock_irq(shost->host_lock); |
| 1306 | } |
| 1307 | } |
| 1308 | } |
| 1309 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1310 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1311 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1312 | * @phba: pointer to lpfc hba data structure. |
| 1313 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1314 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1315 | * |
| 1316 | * This routine is the completion callback function for issuing the Port |
| 1317 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1318 | * ndlp on the vport node list that matches the remote node ID from the |
| 1319 | * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply |
| 1320 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1321 | * checked for error conditons. If there is error status reported, PLOGI |
| 1322 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1323 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1324 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1325 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1326 | * there are additional N_Port nodes with the vport that need to perform |
| 1327 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1328 | * PLOGIs. |
| 1329 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1330 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1331 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1332 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1333 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1334 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1335 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1336 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1337 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1338 | struct lpfc_dmabuf *prsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1339 | int disc, rc, did, type; |
| 1340 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1341 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1342 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1343 | |
| 1344 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1345 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1346 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1347 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1348 | irsp->un.elsreq64.remoteID); |
| 1349 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1350 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1351 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1352 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1353 | "0136 PLOGI completes to NPort x%x " |
| 1354 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1355 | irsp->un.elsreq64.remoteID, |
| 1356 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1357 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1358 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1359 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1360 | |
| 1361 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1362 | * is being used during discovery. |
| 1363 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1364 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1365 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1366 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1367 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1368 | rc = 0; |
| 1369 | |
| 1370 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1371 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1372 | "0102 PLOGI completes to NPort x%x " |
| 1373 | "Data: x%x x%x x%x x%x x%x\n", |
| 1374 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1375 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1376 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1377 | if (lpfc_els_chk_latt(vport)) { |
| 1378 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1379 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1380 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1381 | goto out; |
| 1382 | } |
| 1383 | |
| 1384 | /* ndlp could be freed in DSM, save these values now */ |
| 1385 | type = ndlp->nlp_type; |
| 1386 | did = ndlp->nlp_DID; |
| 1387 | |
| 1388 | if (irsp->ulpStatus) { |
| 1389 | /* Check for retry */ |
| 1390 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1391 | /* ELS command is being retried */ |
| 1392 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1393 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1394 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1395 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1396 | } |
| 1397 | goto out; |
| 1398 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1399 | /* PLOGI failed */ |
| 1400 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1401 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1402 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1403 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1404 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1405 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1406 | } else { |
| 1407 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1408 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1409 | cmdiocb->context2)->list.next, |
| 1410 | struct lpfc_dmabuf, list); |
| 1411 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1412 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1413 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1414 | } |
| 1415 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1416 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1417 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1418 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1419 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1420 | if (vport->num_disc_nodes == 0) { |
| 1421 | spin_lock_irq(shost->host_lock); |
| 1422 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1423 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1424 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1425 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1426 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | out: |
| 1431 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1432 | return; |
| 1433 | } |
| 1434 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1435 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1436 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1437 | * @vport: pointer to a host virtual N_Port data structure. |
| 1438 | * @did: destination port identifier. |
| 1439 | * @retry: number of retries to the command IOCB. |
| 1440 | * |
| 1441 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1442 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1443 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1444 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1445 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1446 | * |
| 1447 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1448 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1449 | * will be stored into the context1 field of the IOCB for the completion |
| 1450 | * callback function to the PLOGI ELS command. |
| 1451 | * |
| 1452 | * Return code |
| 1453 | * 0 - Successfully issued a plogi for @vport |
| 1454 | * 1 - failed to issue a plogi for @vport |
| 1455 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1456 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1457 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1458 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1459 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1460 | struct serv_parm *sp; |
| 1461 | IOCB_t *icmd; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1462 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1463 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1464 | struct lpfc_sli *psli; |
| 1465 | uint8_t *pcmd; |
| 1466 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1467 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1468 | |
| 1469 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1470 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1471 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1472 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1473 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1474 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1475 | /* 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] | 1476 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1477 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1478 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1479 | if (!elsiocb) |
| 1480 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1481 | |
| 1482 | icmd = &elsiocb->iocb; |
| 1483 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1484 | |
| 1485 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1486 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1487 | pcmd += sizeof(uint32_t); |
| 1488 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1489 | sp = (struct serv_parm *) pcmd; |
| 1490 | |
| 1491 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1492 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1493 | |
| 1494 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1495 | sp->cmn.fcphHigh = FC_PH3; |
| 1496 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1497 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1498 | "Issue PLOGI: did:x%x", |
| 1499 | did, 0, 0); |
| 1500 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1501 | phba->fc_stat.elsXmitPLOGI++; |
| 1502 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1503 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1504 | |
| 1505 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1506 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1507 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1508 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1509 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1510 | } |
| 1511 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1512 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1513 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1514 | * @phba: pointer to lpfc hba data structure. |
| 1515 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1516 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1517 | * |
| 1518 | * This routine is the completion callback function for a Process Login |
| 1519 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 1520 | * status. If there is error status reported, PRLI retry shall be attempted |
| 1521 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 1522 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 1523 | * ndlp to mark the PRLI completion. |
| 1524 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1525 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1526 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1527 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1528 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1529 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1530 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1531 | IOCB_t *irsp; |
| 1532 | struct lpfc_sli *psli; |
| 1533 | struct lpfc_nodelist *ndlp; |
| 1534 | |
| 1535 | psli = &phba->sli; |
| 1536 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1537 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1538 | |
| 1539 | irsp = &(rspiocb->iocb); |
| 1540 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1541 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1542 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1543 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1544 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1545 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1546 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 1547 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1548 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1549 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1550 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1551 | "0103 PRLI completes to NPort x%x " |
| 1552 | "Data: x%x x%x x%x x%x\n", |
| 1553 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1554 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1555 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1556 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1557 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1558 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1559 | goto out; |
| 1560 | |
| 1561 | if (irsp->ulpStatus) { |
| 1562 | /* Check for retry */ |
| 1563 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1564 | /* ELS command is being retried */ |
| 1565 | goto out; |
| 1566 | } |
| 1567 | /* PRLI failed */ |
| 1568 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1569 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1570 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1571 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1572 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1573 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1574 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1575 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1576 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1577 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1578 | out: |
| 1579 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1580 | return; |
| 1581 | } |
| 1582 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1583 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1584 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1585 | * @vport: pointer to a host virtual N_Port data structure. |
| 1586 | * @ndlp: pointer to a node-list data structure. |
| 1587 | * @retry: number of retries to the command IOCB. |
| 1588 | * |
| 1589 | * This routine issues a Process Login (PRLI) ELS command for the |
| 1590 | * @vport. The PRLI service parameters are set up in the payload of the |
| 1591 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 1592 | * is put to the IOCB completion callback func field before invoking the |
| 1593 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 1594 | * |
| 1595 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1596 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1597 | * will be stored into the context1 field of the IOCB for the completion |
| 1598 | * callback function to the PRLI ELS command. |
| 1599 | * |
| 1600 | * Return code |
| 1601 | * 0 - successfully issued prli iocb command for @vport |
| 1602 | * 1 - failed to issue prli iocb command for @vport |
| 1603 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1604 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1605 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1606 | uint8_t retry) |
| 1607 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1608 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1609 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1610 | PRLI *npr; |
| 1611 | IOCB_t *icmd; |
| 1612 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1613 | uint8_t *pcmd; |
| 1614 | uint16_t cmdsize; |
| 1615 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1616 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1617 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1618 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1619 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1620 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1621 | |
| 1622 | icmd = &elsiocb->iocb; |
| 1623 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1624 | |
| 1625 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1626 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1627 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1628 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1629 | |
| 1630 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 1631 | npr = (PRLI *) pcmd; |
| 1632 | /* |
| 1633 | * If our firmware version is 3.20 or later, |
| 1634 | * set the following bits for FC-TAPE support. |
| 1635 | */ |
| 1636 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 1637 | npr->ConfmComplAllowed = 1; |
| 1638 | npr->Retry = 1; |
| 1639 | npr->TaskRetryIdReq = 1; |
| 1640 | } |
| 1641 | npr->estabImagePair = 1; |
| 1642 | npr->readXferRdyDis = 1; |
| 1643 | |
| 1644 | /* For FCP support */ |
| 1645 | npr->prliType = PRLI_FCP_TYPE; |
| 1646 | npr->initiatorFunc = 1; |
| 1647 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1648 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1649 | "Issue PRLI: did:x%x", |
| 1650 | ndlp->nlp_DID, 0, 0); |
| 1651 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1652 | phba->fc_stat.elsXmitPRLI++; |
| 1653 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1654 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1655 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1656 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1657 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 1658 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1659 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1660 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1661 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1662 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1663 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1664 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1665 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1666 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1667 | } |
| 1668 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1669 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1670 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1671 | * @vport: pointer to a host virtual N_Port data structure. |
| 1672 | * |
| 1673 | * This routine performs Registration State Change Notification (RSCN) |
| 1674 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 1675 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 1676 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 1677 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 1678 | * invoked to check and handle possible more RSCN came in during the period |
| 1679 | * of processing the current ones. |
| 1680 | **/ |
| 1681 | static void |
| 1682 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 1683 | { |
| 1684 | lpfc_can_disctmo(vport); |
| 1685 | |
| 1686 | /* RSCN discovery */ |
| 1687 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 1688 | if (vport->fc_npr_cnt) |
| 1689 | if (lpfc_els_disc_plogi(vport)) |
| 1690 | return; |
| 1691 | |
| 1692 | lpfc_end_rscn(vport); |
| 1693 | } |
| 1694 | |
| 1695 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1696 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1697 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 1698 | * |
| 1699 | * This function is called when the final ADISC is completed during discovery. |
| 1700 | * This function handles clearing link attention or issuing reg_vpi depending |
| 1701 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 1702 | * discovery. |
| 1703 | * This function is called with no locks held. |
| 1704 | **/ |
| 1705 | static void |
| 1706 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 1707 | { |
| 1708 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1709 | struct lpfc_hba *phba = vport->phba; |
| 1710 | |
| 1711 | /* |
| 1712 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 1713 | * and continue discovery. |
| 1714 | */ |
| 1715 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1716 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 1717 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1718 | lpfc_issue_reg_vpi(phba, vport); |
| 1719 | return; |
| 1720 | } |
| 1721 | /* |
| 1722 | * For SLI2, we need to set port_state to READY |
| 1723 | * and continue discovery. |
| 1724 | */ |
| 1725 | if (vport->port_state < LPFC_VPORT_READY) { |
| 1726 | /* If we get here, there is nothing to ADISC */ |
| 1727 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1728 | lpfc_issue_clear_la(phba, vport); |
| 1729 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 1730 | vport->num_disc_nodes = 0; |
| 1731 | /* go thru NPR list, issue ELS PLOGIs */ |
| 1732 | if (vport->fc_npr_cnt) |
| 1733 | lpfc_els_disc_plogi(vport); |
| 1734 | if (!vport->num_disc_nodes) { |
| 1735 | spin_lock_irq(shost->host_lock); |
| 1736 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1737 | spin_unlock_irq(shost->host_lock); |
| 1738 | lpfc_can_disctmo(vport); |
| 1739 | lpfc_end_rscn(vport); |
| 1740 | } |
| 1741 | } |
| 1742 | vport->port_state = LPFC_VPORT_READY; |
| 1743 | } else |
| 1744 | lpfc_rscn_disc(vport); |
| 1745 | } |
| 1746 | |
| 1747 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1748 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1749 | * @vport: pointer to a host virtual N_Port data structure. |
| 1750 | * |
| 1751 | * This routine determines whether there are more ndlps on a @vport |
| 1752 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 1753 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 1754 | * remaining nodes which need to have ADISC sent. |
| 1755 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1756 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1757 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1758 | { |
| 1759 | int sentadisc; |
| 1760 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1761 | if (vport->num_disc_nodes) |
| 1762 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1763 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1764 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1765 | "0210 Continue discovery with %d ADISCs to go " |
| 1766 | "Data: x%x x%x x%x\n", |
| 1767 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 1768 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1769 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1770 | if (vport->fc_flag & FC_NLP_MORE) { |
| 1771 | lpfc_set_disctmo(vport); |
| 1772 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 1773 | sentadisc = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1774 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1775 | if (!vport->num_disc_nodes) |
| 1776 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1777 | return; |
| 1778 | } |
| 1779 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1780 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1781 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1782 | * @phba: pointer to lpfc hba data structure. |
| 1783 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1784 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1785 | * |
| 1786 | * This routine is the completion function for issuing the Address Discover |
| 1787 | * (ADISC) command. It first checks to see whether link went down during |
| 1788 | * the discovery process. If so, the node will be marked as node port |
| 1789 | * recovery for issuing discover IOCB by the link attention handler and |
| 1790 | * exit. Otherwise, the response status is checked. If error was reported |
| 1791 | * in the response status, the ADISC command shall be retried by invoking |
| 1792 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 1793 | * the response status, the state machine is invoked to set transition |
| 1794 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 1795 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1796 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1797 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1798 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1799 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1800 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1801 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1802 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1803 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1804 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1805 | |
| 1806 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1807 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1808 | |
| 1809 | irsp = &(rspiocb->iocb); |
| 1810 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1811 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1812 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1813 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 1814 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1815 | ndlp->nlp_DID); |
| 1816 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1817 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1818 | * is being used during discovery. |
| 1819 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1820 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1821 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1822 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1823 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1824 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1825 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1826 | "0104 ADISC completes to NPort x%x " |
| 1827 | "Data: x%x x%x x%x x%x x%x\n", |
| 1828 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1829 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1830 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1831 | if (lpfc_els_chk_latt(vport)) { |
| 1832 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1833 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1834 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1835 | goto out; |
| 1836 | } |
| 1837 | |
| 1838 | if (irsp->ulpStatus) { |
| 1839 | /* Check for retry */ |
| 1840 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1841 | /* ELS command is being retried */ |
| 1842 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1843 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1844 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1845 | spin_unlock_irq(shost->host_lock); |
| 1846 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1847 | } |
| 1848 | goto out; |
| 1849 | } |
| 1850 | /* ADISC failed */ |
| 1851 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1852 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1853 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1854 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1855 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1856 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1857 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1858 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1859 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1860 | /* Check to see if there are more ADISCs to be sent */ |
| 1861 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1862 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1863 | out: |
| 1864 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1865 | return; |
| 1866 | } |
| 1867 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1868 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1869 | * 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] | 1870 | * @vport: pointer to a virtual N_Port data structure. |
| 1871 | * @ndlp: pointer to a node-list data structure. |
| 1872 | * @retry: number of retries to the command IOCB. |
| 1873 | * |
| 1874 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 1875 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 1876 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 1877 | * to issue the ADISC ELS command. |
| 1878 | * |
| 1879 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1880 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1881 | * will be stored into the context1 field of the IOCB for the completion |
| 1882 | * callback function to the ADISC ELS command. |
| 1883 | * |
| 1884 | * Return code |
| 1885 | * 0 - successfully issued adisc |
| 1886 | * 1 - failed to issue adisc |
| 1887 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1888 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1889 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1890 | uint8_t retry) |
| 1891 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1892 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1893 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1894 | ADISC *ap; |
| 1895 | IOCB_t *icmd; |
| 1896 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1897 | uint8_t *pcmd; |
| 1898 | uint16_t cmdsize; |
| 1899 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1900 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1901 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1902 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1903 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1904 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1905 | |
| 1906 | icmd = &elsiocb->iocb; |
| 1907 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1908 | |
| 1909 | /* For ADISC request, remainder of payload is service parameters */ |
| 1910 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1911 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1912 | |
| 1913 | /* Fill in ADISC payload */ |
| 1914 | ap = (ADISC *) pcmd; |
| 1915 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1916 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 1917 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1918 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1919 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1920 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1921 | "Issue ADISC: did:x%x", |
| 1922 | ndlp->nlp_DID, 0, 0); |
| 1923 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1924 | phba->fc_stat.elsXmitADISC++; |
| 1925 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1926 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1927 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1928 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1929 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 1930 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1931 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1932 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1933 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1934 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1935 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1936 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1937 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1938 | } |
| 1939 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1940 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1941 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1942 | * @phba: pointer to lpfc hba data structure. |
| 1943 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1944 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1945 | * |
| 1946 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 1947 | * command. If no error status was reported from the LOGO response, the |
| 1948 | * state machine of the associated ndlp shall be invoked for transition with |
| 1949 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 1950 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 1951 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1952 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1953 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1954 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1955 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1956 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 1957 | struct lpfc_vport *vport = ndlp->vport; |
| 1958 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1959 | IOCB_t *irsp; |
| 1960 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1961 | |
| 1962 | psli = &phba->sli; |
| 1963 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1964 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1965 | |
| 1966 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1967 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1968 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1969 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1970 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1971 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1972 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 1973 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1974 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1975 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1976 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1977 | "0105 LOGO completes to NPort x%x " |
| 1978 | "Data: x%x x%x x%x x%x\n", |
| 1979 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1980 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1981 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1982 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1983 | goto out; |
| 1984 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1985 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 1986 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 1987 | * which should abort all outstanding IOs. |
| 1988 | */ |
| 1989 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 1990 | NLP_EVT_DEVICE_RM); |
| 1991 | goto out; |
| 1992 | } |
| 1993 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1994 | if (irsp->ulpStatus) { |
| 1995 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1996 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1997 | /* ELS command is being retried */ |
| 1998 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1999 | /* LOGO failed */ |
| 2000 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2001 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2002 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2003 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2004 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2005 | NLP_EVT_CMPL_LOGO); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2006 | } else |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2007 | /* Good status, call state machine. |
| 2008 | * This will unregister the rpi if needed. |
| 2009 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2010 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2011 | NLP_EVT_CMPL_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2012 | out: |
| 2013 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2014 | return; |
| 2015 | } |
| 2016 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2017 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2018 | * 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] | 2019 | * @vport: pointer to a virtual N_Port data structure. |
| 2020 | * @ndlp: pointer to a node-list data structure. |
| 2021 | * @retry: number of retries to the command IOCB. |
| 2022 | * |
| 2023 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2024 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2025 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2026 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2027 | * |
| 2028 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2029 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2030 | * will be stored into the context1 field of the IOCB for the completion |
| 2031 | * callback function to the LOGO ELS command. |
| 2032 | * |
| 2033 | * Return code |
| 2034 | * 0 - successfully issued logo |
| 2035 | * 1 - failed to issue logo |
| 2036 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2037 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2038 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2039 | uint8_t retry) |
| 2040 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2041 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2042 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2043 | IOCB_t *icmd; |
| 2044 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2045 | uint8_t *pcmd; |
| 2046 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2047 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2048 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2049 | spin_lock_irq(shost->host_lock); |
| 2050 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2051 | spin_unlock_irq(shost->host_lock); |
| 2052 | return 0; |
| 2053 | } |
| 2054 | spin_unlock_irq(shost->host_lock); |
| 2055 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2056 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2057 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2058 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2059 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2060 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2061 | |
| 2062 | icmd = &elsiocb->iocb; |
| 2063 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2064 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2065 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2066 | |
| 2067 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2068 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2069 | pcmd += sizeof(uint32_t); |
| 2070 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2071 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2072 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2073 | "Issue LOGO: did:x%x", |
| 2074 | ndlp->nlp_DID, 0, 0); |
| 2075 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2076 | phba->fc_stat.elsXmitLOGO++; |
| 2077 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2078 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2079 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2080 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2081 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2082 | |
| 2083 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2084 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2085 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2086 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2087 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2088 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2089 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2090 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2091 | } |
| 2092 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2093 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2094 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2095 | * @phba: pointer to lpfc hba data structure. |
| 2096 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2097 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2098 | * |
| 2099 | * This routine is a generic completion callback function for ELS commands. |
| 2100 | * Specifically, it is the callback function which does not need to perform |
| 2101 | * any command specific operations. It is currently used by the ELS command |
| 2102 | * issuing routines for the ELS State Change Request (SCR), |
| 2103 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 2104 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2105 | * certain debug loggings, this callback function simply invokes the |
| 2106 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2107 | * discovery process. |
| 2108 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2109 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2110 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2111 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2112 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2113 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2114 | IOCB_t *irsp; |
| 2115 | |
| 2116 | irsp = &rspiocb->iocb; |
| 2117 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2118 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2119 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2120 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2121 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2122 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2123 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2124 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2125 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2126 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2127 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2128 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2129 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2130 | return; |
| 2131 | } |
| 2132 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2133 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2134 | * 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] | 2135 | * @vport: pointer to a host virtual N_Port data structure. |
| 2136 | * @nportid: N_Port identifier to the remote node. |
| 2137 | * @retry: number of retries to the command IOCB. |
| 2138 | * |
| 2139 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2140 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2141 | * first search the @vport node list to find the matching ndlp. If no such |
| 2142 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2143 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2144 | * routine is invoked to send the SCR IOCB. |
| 2145 | * |
| 2146 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2147 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2148 | * will be stored into the context1 field of the IOCB for the completion |
| 2149 | * callback function to the SCR ELS command. |
| 2150 | * |
| 2151 | * Return code |
| 2152 | * 0 - Successfully issued scr command |
| 2153 | * 1 - Failed to issue scr command |
| 2154 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2155 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2156 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2157 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2158 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2159 | IOCB_t *icmd; |
| 2160 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2161 | struct lpfc_sli *psli; |
| 2162 | uint8_t *pcmd; |
| 2163 | uint16_t cmdsize; |
| 2164 | struct lpfc_nodelist *ndlp; |
| 2165 | |
| 2166 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2167 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2168 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2169 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2170 | if (!ndlp) { |
| 2171 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2172 | if (!ndlp) |
| 2173 | return 1; |
| 2174 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2175 | lpfc_enqueue_node(vport, ndlp); |
| 2176 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2177 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2178 | if (!ndlp) |
| 2179 | return 1; |
| 2180 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2181 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2182 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2183 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2184 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2185 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2186 | /* This will trigger the release of the node just |
| 2187 | * allocated |
| 2188 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2189 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2190 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2191 | } |
| 2192 | |
| 2193 | icmd = &elsiocb->iocb; |
| 2194 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2195 | |
| 2196 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2197 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2198 | |
| 2199 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2200 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2201 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2202 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2203 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2204 | "Issue SCR: did:x%x", |
| 2205 | ndlp->nlp_DID, 0, 0); |
| 2206 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2207 | phba->fc_stat.elsXmitSCR++; |
| 2208 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2209 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2210 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2211 | /* The additional lpfc_nlp_put will cause the following |
| 2212 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2213 | * the node. |
| 2214 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2215 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2216 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2217 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2218 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2219 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2220 | * trigger the release of node. |
| 2221 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2222 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2223 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2224 | } |
| 2225 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2226 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2227 | * 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] | 2228 | * @vport: pointer to a host virtual N_Port data structure. |
| 2229 | * @nportid: N_Port identifier to the remote node. |
| 2230 | * @retry: number of retries to the command IOCB. |
| 2231 | * |
| 2232 | * This routine issues a Fibre Channel Address Resolution Response |
| 2233 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2234 | * is passed into the function. It first search the @vport node list to find |
| 2235 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2236 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2237 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2238 | * |
| 2239 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2240 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2241 | * will be stored into the context1 field of the IOCB for the completion |
| 2242 | * callback function to the PARPR ELS command. |
| 2243 | * |
| 2244 | * Return code |
| 2245 | * 0 - Successfully issued farpr command |
| 2246 | * 1 - Failed to issue farpr command |
| 2247 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2248 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2249 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2250 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2251 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2252 | IOCB_t *icmd; |
| 2253 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2254 | struct lpfc_sli *psli; |
| 2255 | FARP *fp; |
| 2256 | uint8_t *pcmd; |
| 2257 | uint32_t *lp; |
| 2258 | uint16_t cmdsize; |
| 2259 | struct lpfc_nodelist *ondlp; |
| 2260 | struct lpfc_nodelist *ndlp; |
| 2261 | |
| 2262 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2263 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2264 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2265 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2266 | if (!ndlp) { |
| 2267 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2268 | if (!ndlp) |
| 2269 | return 1; |
| 2270 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2271 | lpfc_enqueue_node(vport, ndlp); |
| 2272 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2273 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2274 | if (!ndlp) |
| 2275 | return 1; |
| 2276 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2277 | |
| 2278 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2279 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2280 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2281 | /* This will trigger the release of the node just |
| 2282 | * allocated |
| 2283 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2284 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2285 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2286 | } |
| 2287 | |
| 2288 | icmd = &elsiocb->iocb; |
| 2289 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2290 | |
| 2291 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2292 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2293 | |
| 2294 | /* Fill in FARPR payload */ |
| 2295 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2296 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2297 | lp = (uint32_t *) pcmd; |
| 2298 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2299 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2300 | fp->Rflags = 0; |
| 2301 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2302 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2303 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2304 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2305 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2306 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2307 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2308 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2309 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2310 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2311 | } |
| 2312 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2313 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2314 | "Issue FARPR: did:x%x", |
| 2315 | ndlp->nlp_DID, 0, 0); |
| 2316 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2317 | phba->fc_stat.elsXmitFARPR++; |
| 2318 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2319 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2320 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2321 | /* The additional lpfc_nlp_put will cause the following |
| 2322 | * lpfc_els_free_iocb routine to trigger the release of |
| 2323 | * the node. |
| 2324 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2325 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2326 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2327 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2328 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2329 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2330 | * trigger the release of the node. |
| 2331 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2332 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2333 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2334 | } |
| 2335 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2336 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2337 | * 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] | 2338 | * @vport: pointer to a host virtual N_Port data structure. |
| 2339 | * @nlp: pointer to a node-list data structure. |
| 2340 | * |
| 2341 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2342 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2343 | * removes the ELS retry event if it presents. In addition, if the |
| 2344 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2345 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2346 | * ADISC. |
| 2347 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2348 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2349 | 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] | 2350 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2351 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2352 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2353 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2354 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2355 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2356 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2357 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2358 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2359 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2360 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2361 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2362 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2363 | /* Decrement nlp reference count held for the delayed retry */ |
| 2364 | evtp = &nlp->els_retry_evt; |
| 2365 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2366 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2367 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
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_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2370 | spin_unlock_irq(shost->host_lock); |
| 2371 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2372 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2373 | /* Check if there are more ADISCs to be sent */ |
| 2374 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2375 | } else { |
| 2376 | /* Check if there are more PLOGIs to be sent */ |
| 2377 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2378 | if (vport->num_disc_nodes == 0) { |
| 2379 | spin_lock_irq(shost->host_lock); |
| 2380 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2381 | spin_unlock_irq(shost->host_lock); |
| 2382 | lpfc_can_disctmo(vport); |
| 2383 | lpfc_end_rscn(vport); |
| 2384 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2385 | } |
| 2386 | } |
| 2387 | } |
| 2388 | return; |
| 2389 | } |
| 2390 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2391 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2392 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2393 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2394 | * |
| 2395 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2396 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2397 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2398 | * adds the delayed events to the HBA work list and invokes the |
| 2399 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2400 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2401 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2402 | * reference to ndlp will still be available when the worker thread gets |
| 2403 | * to the event associated with the ndlp. |
| 2404 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2405 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2406 | lpfc_els_retry_delay(unsigned long ptr) |
| 2407 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2408 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2409 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2410 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2411 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2412 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2413 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2414 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2415 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2416 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2417 | return; |
| 2418 | } |
| 2419 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2420 | /* We need to hold the node by incrementing the reference |
| 2421 | * count until the queued work is done |
| 2422 | */ |
| 2423 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2424 | if (evtp->evt_arg1) { |
| 2425 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2426 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2427 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2428 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2429 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2430 | return; |
| 2431 | } |
| 2432 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2433 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2434 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2435 | * @ndlp: pointer to a node-list data structure. |
| 2436 | * |
| 2437 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 2438 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 2439 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 2440 | * function according to the delayed ELS command to retry the command. |
| 2441 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2442 | void |
| 2443 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 2444 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2445 | struct lpfc_vport *vport = ndlp->vport; |
| 2446 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2447 | uint32_t cmd, did, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2448 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2449 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2450 | did = ndlp->nlp_DID; |
| 2451 | cmd = ndlp->nlp_last_elscmd; |
| 2452 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2453 | |
| 2454 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2455 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2456 | return; |
| 2457 | } |
| 2458 | |
| 2459 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2460 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 2461 | /* |
| 2462 | * If a discovery event readded nlp_delayfunc after timer |
| 2463 | * firing and before processing the timer, cancel the |
| 2464 | * nlp_delayfunc. |
| 2465 | */ |
| 2466 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2467 | retry = ndlp->nlp_retry; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 2468 | ndlp->nlp_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2469 | |
| 2470 | switch (cmd) { |
| 2471 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2472 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2473 | break; |
| 2474 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2475 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2476 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2477 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2478 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2479 | break; |
| 2480 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2481 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2482 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2483 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2484 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2485 | break; |
| 2486 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2487 | if (!lpfc_issue_els_prli(vport, ndlp, 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_PRLI_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_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2493 | if (!lpfc_issue_els_logo(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_NPR_NODE); |
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; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2498 | case ELS_CMD_FDISC: |
| 2499 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
| 2500 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2501 | } |
| 2502 | return; |
| 2503 | } |
| 2504 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2505 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2506 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2507 | * @phba: pointer to lpfc hba data structure. |
| 2508 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2509 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2510 | * |
| 2511 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 2512 | * failed. The following ELS IOCBs use this function for retrying the command |
| 2513 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 2514 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 2515 | * returned error status, it makes the decision whether a retry shall be |
| 2516 | * issued for the command, and whether a retry shall be made immediately or |
| 2517 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 2518 | * is called to retry the command. In the later case, the ELS command shall |
| 2519 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 2520 | * ndlp for the delayed command issusing. |
| 2521 | * |
| 2522 | * Return code |
| 2523 | * 0 - No retry of els command is made |
| 2524 | * 1 - Immediate or delayed retry of els command is made |
| 2525 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2526 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2527 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2528 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2529 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2530 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2531 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2532 | IOCB_t *irsp = &rspiocb->iocb; |
| 2533 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2534 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2535 | uint32_t *elscmd; |
| 2536 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2537 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2538 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2539 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2540 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2541 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2542 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2543 | /* Note: context2 may be 0 for internal driver abort |
| 2544 | * of delays ELS command. |
| 2545 | */ |
| 2546 | |
| 2547 | if (pcmd && pcmd->virt) { |
| 2548 | elscmd = (uint32_t *) (pcmd->virt); |
| 2549 | cmd = *elscmd++; |
| 2550 | } |
| 2551 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2552 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2553 | did = ndlp->nlp_DID; |
| 2554 | else { |
| 2555 | /* We should only hit this case for retrying PLOGI */ |
| 2556 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2557 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2558 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 2559 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2560 | return 1; |
| 2561 | } |
| 2562 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2563 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2564 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 2565 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 2566 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2567 | switch (irsp->ulpStatus) { |
| 2568 | case IOSTAT_FCP_RSP_ERROR: |
| 2569 | case IOSTAT_REMOTE_STOP: |
| 2570 | break; |
| 2571 | |
| 2572 | case IOSTAT_LOCAL_REJECT: |
| 2573 | switch ((irsp->un.ulpWord[4] & 0xff)) { |
| 2574 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2575 | if (cmd == ELS_CMD_FLOGI) { |
| 2576 | if (PCI_DEVICE_ID_HORNET == |
| 2577 | phba->pcidev->device) { |
| 2578 | phba->fc_topology = TOPOLOGY_LOOP; |
| 2579 | phba->pport->fc_myDID = 0; |
| 2580 | phba->alpa_map[0] = 0; |
| 2581 | phba->alpa_map[1] = 0; |
| 2582 | } |
| 2583 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2584 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2585 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2586 | retry = 1; |
| 2587 | break; |
| 2588 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2589 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2590 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2591 | "0124 Retry illegal cmd x%x " |
| 2592 | "retry:x%x delay:x%x\n", |
| 2593 | cmd, cmdiocb->retry, delay); |
| 2594 | retry = 1; |
| 2595 | /* All command's retry policy */ |
| 2596 | maxretry = 8; |
| 2597 | if (cmdiocb->retry > 2) |
| 2598 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2599 | break; |
| 2600 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2601 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2602 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2603 | retry = 1; |
| 2604 | if (cmdiocb->retry > 100) |
| 2605 | delay = 100; |
| 2606 | maxretry = 250; |
| 2607 | break; |
| 2608 | |
| 2609 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2610 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2611 | retry = 1; |
| 2612 | break; |
| 2613 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2614 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2615 | case IOERR_INVALID_RPI: |
| 2616 | retry = 1; |
| 2617 | break; |
| 2618 | } |
| 2619 | break; |
| 2620 | |
| 2621 | case IOSTAT_NPORT_RJT: |
| 2622 | case IOSTAT_FABRIC_RJT: |
| 2623 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 2624 | retry = 1; |
| 2625 | break; |
| 2626 | } |
| 2627 | break; |
| 2628 | |
| 2629 | case IOSTAT_NPORT_BSY: |
| 2630 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2631 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2632 | retry = 1; |
| 2633 | break; |
| 2634 | |
| 2635 | case IOSTAT_LS_RJT: |
| 2636 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 2637 | /* Added for Vendor specifc support |
| 2638 | * Just keep retrying for these Rsn / Exp codes |
| 2639 | */ |
| 2640 | switch (stat.un.b.lsRjtRsnCode) { |
| 2641 | case LSRJT_UNABLE_TPC: |
| 2642 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2643 | LSEXP_CMD_IN_PROGRESS) { |
| 2644 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2645 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2646 | maxretry = 48; |
| 2647 | } |
| 2648 | retry = 1; |
| 2649 | break; |
| 2650 | } |
| 2651 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2652 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2653 | maxretry = lpfc_max_els_tries + 1; |
| 2654 | retry = 1; |
| 2655 | break; |
| 2656 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2657 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2658 | (cmd == ELS_CMD_FDISC) && |
| 2659 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2660 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2661 | "0125 FDISC Failed (x%x). " |
| 2662 | "Fabric out of resources\n", |
| 2663 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2664 | lpfc_vport_set_state(vport, |
| 2665 | FC_VPORT_NO_FABRIC_RSCS); |
| 2666 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2667 | break; |
| 2668 | |
| 2669 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2670 | if ((cmd == ELS_CMD_PLOGI) || |
| 2671 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2672 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2673 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2674 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2675 | /* FDISC retry policy */ |
| 2676 | maxretry = 48; |
| 2677 | if (cmdiocb->retry >= 32) |
| 2678 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2679 | } |
| 2680 | retry = 1; |
| 2681 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2682 | |
| 2683 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2684 | /* There are some cases where switches return this |
| 2685 | * error when they are not ready and should be returning |
| 2686 | * Logical Busy. We should delay every time. |
| 2687 | */ |
| 2688 | if (cmd == ELS_CMD_FDISC && |
| 2689 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 2690 | maxretry = 3; |
| 2691 | delay = 1000; |
| 2692 | retry = 1; |
| 2693 | break; |
| 2694 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2695 | case LSRJT_PROTOCOL_ERR: |
| 2696 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2697 | (cmd == ELS_CMD_FDISC) && |
| 2698 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 2699 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 2700 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2701 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2702 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2703 | "Fabric Detected Bad WWN\n", |
| 2704 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2705 | lpfc_vport_set_state(vport, |
| 2706 | FC_VPORT_FABRIC_REJ_WWN); |
| 2707 | } |
| 2708 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2709 | } |
| 2710 | break; |
| 2711 | |
| 2712 | case IOSTAT_INTERMED_RSP: |
| 2713 | case IOSTAT_BA_RJT: |
| 2714 | break; |
| 2715 | |
| 2716 | default: |
| 2717 | break; |
| 2718 | } |
| 2719 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2720 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2721 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2722 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2723 | if ((cmd == ELS_CMD_FLOGI) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 2724 | (phba->fc_topology != TOPOLOGY_LOOP) && |
| 2725 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2726 | /* FLOGI retry policy */ |
| 2727 | retry = 1; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2728 | /* retry forever */ |
| 2729 | maxretry = 0; |
| 2730 | if (cmdiocb->retry >= 100) |
| 2731 | delay = 5000; |
| 2732 | else if (cmdiocb->retry >= 32) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2733 | delay = 1000; |
| 2734 | } |
| 2735 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2736 | cmdiocb->retry++; |
| 2737 | if (maxretry && (cmdiocb->retry >= maxretry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2738 | phba->fc_stat.elsRetryExceeded++; |
| 2739 | retry = 0; |
| 2740 | } |
| 2741 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2742 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 2743 | retry = 0; |
| 2744 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2745 | if (retry) { |
| 2746 | |
| 2747 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2748 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2749 | "0107 Retry ELS command x%x to remote " |
| 2750 | "NPORT x%x Data: x%x x%x\n", |
| 2751 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2752 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2753 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 2754 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 2755 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { |
| 2756 | /* Don't reset timer for no resources */ |
| 2757 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2758 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2759 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2760 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2761 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2762 | } |
| 2763 | |
| 2764 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2765 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2766 | phba->fc_stat.elsDelayRetry++; |
| 2767 | ndlp->nlp_retry = cmdiocb->retry; |
| 2768 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2769 | /* delay is specified in milliseconds */ |
| 2770 | mod_timer(&ndlp->nlp_delayfunc, |
| 2771 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2772 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2773 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2774 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2775 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2776 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2777 | if (cmd == ELS_CMD_PRLI) |
| 2778 | lpfc_nlp_set_state(vport, ndlp, |
| 2779 | NLP_STE_REG_LOGIN_ISSUE); |
| 2780 | else |
| 2781 | lpfc_nlp_set_state(vport, ndlp, |
| 2782 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2783 | ndlp->nlp_last_elscmd = cmd; |
| 2784 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2785 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2786 | } |
| 2787 | switch (cmd) { |
| 2788 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2789 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2790 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2791 | case ELS_CMD_FDISC: |
| 2792 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 2793 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2794 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2795 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2796 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2797 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2798 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2799 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2800 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2801 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2802 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2803 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2804 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 2805 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2806 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2807 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -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, NLP_STE_PRLI_ISSUE); |
| 2810 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2811 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2812 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2813 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2814 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 2815 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2816 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2817 | } |
| 2818 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2819 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2820 | if (logerr) { |
| 2821 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2822 | "0137 No retry ELS command x%x to remote " |
| 2823 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 2824 | cmd, did, irsp->ulpStatus, |
| 2825 | irsp->un.ulpWord[4]); |
| 2826 | } |
| 2827 | else { |
| 2828 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2829 | "0108 No retry ELS command x%x to remote " |
| 2830 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 2831 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 2832 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2833 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2834 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2835 | } |
| 2836 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2837 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2838 | * 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] | 2839 | * @phba: pointer to lpfc hba data structure. |
| 2840 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 2841 | * |
| 2842 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 2843 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 2844 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 2845 | * response of the command IOCB. If so, it will be released before releasing |
| 2846 | * the lpfc DMA buffer associated with the IOCB itself. |
| 2847 | * |
| 2848 | * Return code |
| 2849 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2850 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2851 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2852 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 2853 | { |
| 2854 | struct lpfc_dmabuf *buf_ptr; |
| 2855 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2856 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2857 | if (!list_empty(&buf_ptr1->list)) { |
| 2858 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 2859 | struct lpfc_dmabuf, |
| 2860 | list); |
| 2861 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2862 | kfree(buf_ptr); |
| 2863 | } |
| 2864 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 2865 | kfree(buf_ptr1); |
| 2866 | return 0; |
| 2867 | } |
| 2868 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2869 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2870 | * 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] | 2871 | * @phba: pointer to lpfc hba data structure. |
| 2872 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 2873 | * |
| 2874 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 2875 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 2876 | * pool. |
| 2877 | * |
| 2878 | * Return code |
| 2879 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2880 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2881 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2882 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 2883 | { |
| 2884 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2885 | kfree(buf_ptr); |
| 2886 | return 0; |
| 2887 | } |
| 2888 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2889 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2890 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2891 | * @phba: pointer to lpfc hba data structure. |
| 2892 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 2893 | * |
| 2894 | * This routine frees a command IOCB and its associated resources. The |
| 2895 | * command IOCB data structure contains the reference to various associated |
| 2896 | * resources, these fields must be set to NULL if the associated reference |
| 2897 | * not present: |
| 2898 | * context1 - reference to ndlp |
| 2899 | * context2 - reference to cmd |
| 2900 | * context2->next - reference to rsp |
| 2901 | * context3 - reference to bpl |
| 2902 | * |
| 2903 | * It first properly decrements the reference count held on ndlp for the |
| 2904 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 2905 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 2906 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 2907 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 2908 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 2909 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 2910 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 2911 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 2912 | * |
| 2913 | * Return code |
| 2914 | * 0 - Success (currently, always return 0) |
| 2915 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2916 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2917 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2918 | { |
| 2919 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2920 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2921 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2922 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 2923 | if (ndlp) { |
| 2924 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 2925 | lpfc_nlp_put(ndlp); |
| 2926 | |
| 2927 | /* If the ndlp is not being used by another discovery |
| 2928 | * thread, free it. |
| 2929 | */ |
| 2930 | if (!lpfc_nlp_not_used(ndlp)) { |
| 2931 | /* If ndlp is being used by another discovery |
| 2932 | * thread, just clear NLP_DEFER_RM |
| 2933 | */ |
| 2934 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 2935 | } |
| 2936 | } |
| 2937 | else |
| 2938 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2939 | elsiocb->context1 = NULL; |
| 2940 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2941 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 2942 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2943 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 2944 | /* Firmware could still be in progress of DMAing |
| 2945 | * payload, so don't free data buffer till after |
| 2946 | * a hbeat. |
| 2947 | */ |
| 2948 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 2949 | buf_ptr = elsiocb->context2; |
| 2950 | elsiocb->context2 = NULL; |
| 2951 | if (buf_ptr) { |
| 2952 | buf_ptr1 = NULL; |
| 2953 | spin_lock_irq(&phba->hbalock); |
| 2954 | if (!list_empty(&buf_ptr->list)) { |
| 2955 | list_remove_head(&buf_ptr->list, |
| 2956 | buf_ptr1, struct lpfc_dmabuf, |
| 2957 | list); |
| 2958 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 2959 | list_add_tail(&buf_ptr1->list, |
| 2960 | &phba->elsbuf); |
| 2961 | phba->elsbuf_cnt++; |
| 2962 | } |
| 2963 | INIT_LIST_HEAD(&buf_ptr->list); |
| 2964 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 2965 | phba->elsbuf_cnt++; |
| 2966 | spin_unlock_irq(&phba->hbalock); |
| 2967 | } |
| 2968 | } else { |
| 2969 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 2970 | lpfc_els_free_data(phba, buf_ptr1); |
| 2971 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2972 | } |
| 2973 | |
| 2974 | if (elsiocb->context3) { |
| 2975 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2976 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2977 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2978 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2979 | return 0; |
| 2980 | } |
| 2981 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2982 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2983 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2984 | * @phba: pointer to lpfc hba data structure. |
| 2985 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2986 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2987 | * |
| 2988 | * This routine is the completion callback function to the Logout (LOGO) |
| 2989 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 2990 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 2991 | * release the ndlp if it has the last reference remaining (reference count |
| 2992 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 2993 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 2994 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 2995 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 2996 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 2997 | * IOCB data structure. |
| 2998 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2999 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3000 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 3001 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3002 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3003 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3004 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3005 | IOCB_t *irsp; |
| 3006 | |
| 3007 | irsp = &rspiocb->iocb; |
| 3008 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3009 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 3010 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3011 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3012 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3013 | "0109 ACC to LOGO completes to NPort x%x " |
| 3014 | "Data: x%x x%x x%x\n", |
| 3015 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3016 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3017 | |
| 3018 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 3019 | /* NPort Recovery mode or node is just allocated */ |
| 3020 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3021 | /* If the ndlp is being used by another discovery |
| 3022 | * thread, just unregister the RPI. |
| 3023 | */ |
| 3024 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3025 | } else { |
| 3026 | /* Indicate the node has already released, should |
| 3027 | * not reference to it from within lpfc_els_free_iocb. |
| 3028 | */ |
| 3029 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3030 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3031 | } |
| 3032 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3033 | return; |
| 3034 | } |
| 3035 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3036 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3037 | * lpfc_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] | 3038 | * @phba: pointer to lpfc hba data structure. |
| 3039 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 3040 | * |
| 3041 | * This routine is the completion callback function for unregister default |
| 3042 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 3043 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 3044 | * decrements the ndlp reference count held for this completion callback |
| 3045 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 3046 | * whether there is only one reference left on the ndlp. If so, it will |
| 3047 | * perform one more decrement and trigger the release of the ndlp. |
| 3048 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3049 | void |
| 3050 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3051 | { |
| 3052 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3053 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3054 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3055 | /* |
| 3056 | * This routine is used to register and unregister in previous SLI |
| 3057 | * modes. |
| 3058 | */ |
| 3059 | if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) && |
| 3060 | (phba->sli_rev == LPFC_SLI_REV4)) |
| 3061 | lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi); |
| 3062 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3063 | pmb->context1 = NULL; |
| 3064 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3065 | kfree(mp); |
| 3066 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3067 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3068 | lpfc_nlp_put(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3069 | /* This is the end of the default RPI cleanup logic for this |
| 3070 | * ndlp. If no other discovery threads are using this ndlp. |
| 3071 | * we should free all resources associated with it. |
| 3072 | */ |
| 3073 | lpfc_nlp_not_used(ndlp); |
| 3074 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3075 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3076 | return; |
| 3077 | } |
| 3078 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3079 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3080 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3081 | * @phba: pointer to lpfc hba data structure. |
| 3082 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3083 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3084 | * |
| 3085 | * This routine is the completion callback function for ELS Response IOCB |
| 3086 | * command. In normal case, this callback function just properly sets the |
| 3087 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 3088 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 3089 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 3090 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 3091 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 3092 | * routine shall be invoked trying to release the ndlp if no other threads |
| 3093 | * are currently referring it. |
| 3094 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3095 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3096 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3097 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3098 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3099 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3100 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 3101 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3102 | IOCB_t *irsp; |
| 3103 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3104 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3105 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3106 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3107 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3108 | irsp = &rspiocb->iocb; |
| 3109 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3110 | if (cmdiocb->context_un.mbox) |
| 3111 | mbox = cmdiocb->context_un.mbox; |
| 3112 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3113 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 3114 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 3115 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3116 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3117 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3118 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3119 | /* A LS_RJT associated with Default RPI cleanup has its own |
| 3120 | * seperate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3121 | */ |
| 3122 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 3123 | ls_rjt = 1; |
| 3124 | } |
| 3125 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3126 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3127 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3128 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3129 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3130 | if (mp) { |
| 3131 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3132 | kfree(mp); |
| 3133 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3134 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3135 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3136 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3137 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3138 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3139 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3140 | /* Indicate the node has already released, |
| 3141 | * should not reference to it from within |
| 3142 | * the routine lpfc_els_free_iocb. |
| 3143 | */ |
| 3144 | cmdiocb->context1 = NULL; |
| 3145 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3146 | goto out; |
| 3147 | } |
| 3148 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3149 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3150 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3151 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3152 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3153 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3154 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3155 | "0110 ELS response tag x%x completes " |
| 3156 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3157 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3158 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3159 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3160 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3161 | if (mbox) { |
| 3162 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3163 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3164 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3165 | /* Increment reference count to ndlp to hold the |
| 3166 | * reference to ndlp for the callback function. |
| 3167 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3168 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3169 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3170 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3171 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3172 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3173 | } |
| 3174 | else { |
| 3175 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3176 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3177 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3178 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3179 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3180 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3181 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3182 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3183 | else |
| 3184 | /* Decrement the ndlp reference count we |
| 3185 | * set for this failed mailbox command. |
| 3186 | */ |
| 3187 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3188 | |
| 3189 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3190 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3191 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3192 | "Data: x%x x%x x%x\n", |
| 3193 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3194 | ndlp->nlp_rpi); |
| 3195 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3196 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3197 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3198 | /* Indicate node has already been released, |
| 3199 | * should not reference to it from within |
| 3200 | * the routine lpfc_els_free_iocb. |
| 3201 | */ |
| 3202 | cmdiocb->context1 = NULL; |
| 3203 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3204 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3205 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3206 | if (!lpfc_error_lost_link(irsp) && |
| 3207 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
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 |
| 3211 | * released, should not reference |
| 3212 | * to it from within the routine |
| 3213 | * lpfc_els_free_iocb. |
| 3214 | */ |
| 3215 | cmdiocb->context1 = NULL; |
| 3216 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3217 | } |
| 3218 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3219 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3220 | if (mp) { |
| 3221 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3222 | kfree(mp); |
| 3223 | } |
| 3224 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3225 | } |
| 3226 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3227 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3228 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3229 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3230 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3231 | |
| 3232 | /* If the node is not being used by another discovery thread, |
| 3233 | * and we are sending a reject, we are done with it. |
| 3234 | * Release driver reference count here and free associated |
| 3235 | * resources. |
| 3236 | */ |
| 3237 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3238 | if (lpfc_nlp_not_used(ndlp)) |
| 3239 | /* Indicate node has already been released, |
| 3240 | * should not reference to it from within |
| 3241 | * the routine lpfc_els_free_iocb. |
| 3242 | */ |
| 3243 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3244 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3245 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3246 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3247 | return; |
| 3248 | } |
| 3249 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3250 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3251 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3252 | * @vport: pointer to a host virtual N_Port data structure. |
| 3253 | * @flag: the els command code to be accepted. |
| 3254 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3255 | * @ndlp: pointer to a node-list data structure. |
| 3256 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3257 | * |
| 3258 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3259 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3260 | * specific ACC response command to be issued and invokes the |
| 3261 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3262 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3263 | * field of the IOCB for the completion callback function to issue the |
| 3264 | * mailbox command to the HBA later when callback is invoked. |
| 3265 | * |
| 3266 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3267 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3268 | * will be stored into the context1 field of the IOCB for the completion |
| 3269 | * callback function to the corresponding response ELS IOCB command. |
| 3270 | * |
| 3271 | * Return code |
| 3272 | * 0 - Successfully issued acc response |
| 3273 | * 1 - Failed to issue acc response |
| 3274 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3275 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3276 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3277 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3278 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3279 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3280 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3281 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3282 | IOCB_t *icmd; |
| 3283 | IOCB_t *oldcmd; |
| 3284 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3285 | struct lpfc_sli *psli; |
| 3286 | uint8_t *pcmd; |
| 3287 | uint16_t cmdsize; |
| 3288 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3289 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3290 | |
| 3291 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3292 | oldcmd = &oldiocb->iocb; |
| 3293 | |
| 3294 | switch (flag) { |
| 3295 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3296 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3297 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3298 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3299 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3300 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3301 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3302 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3303 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3304 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3305 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3306 | icmd = &elsiocb->iocb; |
| 3307 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3308 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3309 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3310 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3311 | |
| 3312 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3313 | "Issue ACC: did:x%x flg:x%x", |
| 3314 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3315 | break; |
| 3316 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3317 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3318 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3319 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3320 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3321 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3322 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3323 | icmd = &elsiocb->iocb; |
| 3324 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3325 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3326 | |
| 3327 | if (mbox) |
| 3328 | elsiocb->context_un.mbox = mbox; |
| 3329 | |
| 3330 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3331 | pcmd += sizeof(uint32_t); |
| 3332 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3333 | |
| 3334 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3335 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 3336 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3337 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3338 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3339 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3340 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3341 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3342 | if (!elsiocb) |
| 3343 | return 1; |
| 3344 | |
| 3345 | icmd = &elsiocb->iocb; |
| 3346 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3347 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3348 | |
| 3349 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3350 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3351 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 3352 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 3353 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3354 | |
| 3355 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3356 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 3357 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3358 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3359 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3360 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3361 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3362 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3363 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3364 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
| 3365 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", |
| 3366 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3367 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3368 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3369 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3370 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3371 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3372 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3373 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 3374 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3375 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3376 | } |
| 3377 | |
| 3378 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3379 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3380 | if (rc == IOCB_ERROR) { |
| 3381 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3382 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3383 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3384 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3385 | } |
| 3386 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3387 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3388 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3389 | * @vport: pointer to a virtual N_Port data structure. |
| 3390 | * @rejectError: |
| 3391 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3392 | * @ndlp: pointer to a node-list data structure. |
| 3393 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3394 | * |
| 3395 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 3396 | * command. If a @mbox pointer is passed in, it will be put into the |
| 3397 | * context_un.mbox field of the IOCB for the completion callback function |
| 3398 | * to issue to the HBA later. |
| 3399 | * |
| 3400 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3401 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3402 | * will be stored into the context1 field of the IOCB for the completion |
| 3403 | * callback function to the reject response ELS IOCB command. |
| 3404 | * |
| 3405 | * Return code |
| 3406 | * 0 - Successfully issued reject response |
| 3407 | * 1 - Failed to issue reject response |
| 3408 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3409 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3410 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3411 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 3412 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3413 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3414 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3415 | IOCB_t *icmd; |
| 3416 | IOCB_t *oldcmd; |
| 3417 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3418 | struct lpfc_sli *psli; |
| 3419 | uint8_t *pcmd; |
| 3420 | uint16_t cmdsize; |
| 3421 | int rc; |
| 3422 | |
| 3423 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3424 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3425 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3426 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3427 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3428 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3429 | |
| 3430 | icmd = &elsiocb->iocb; |
| 3431 | oldcmd = &oldiocb->iocb; |
| 3432 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3433 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3434 | |
| 3435 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3436 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3437 | *((uint32_t *) (pcmd)) = rejectError; |
| 3438 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3439 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3440 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3441 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3442 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3443 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3444 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 3445 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 3446 | "rpi x%x\n", |
| 3447 | rejectError, elsiocb->iotag, |
| 3448 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 3449 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3450 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3451 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 3452 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 3453 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3454 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3455 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3456 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3457 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3458 | if (rc == IOCB_ERROR) { |
| 3459 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3460 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3461 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3462 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3463 | } |
| 3464 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3465 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3466 | * 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] | 3467 | * @vport: pointer to a virtual N_Port data structure. |
| 3468 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3469 | * @ndlp: pointer to a node-list data structure. |
| 3470 | * |
| 3471 | * This routine prepares and issues an Accept (ACC) response to Address |
| 3472 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 3473 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3474 | * |
| 3475 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3476 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3477 | * will be stored into the context1 field of the IOCB for the completion |
| 3478 | * callback function to the ADISC Accept response ELS IOCB command. |
| 3479 | * |
| 3480 | * Return code |
| 3481 | * 0 - Successfully issued acc adisc response |
| 3482 | * 1 - Failed to issue adisc acc response |
| 3483 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3484 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3485 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 3486 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3487 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3488 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3489 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3490 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3491 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3492 | uint8_t *pcmd; |
| 3493 | uint16_t cmdsize; |
| 3494 | int rc; |
| 3495 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3496 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3497 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3498 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3499 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3500 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3501 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3502 | icmd = &elsiocb->iocb; |
| 3503 | oldcmd = &oldiocb->iocb; |
| 3504 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3505 | |
| 3506 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3507 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3508 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 3509 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 3510 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3511 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3512 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3513 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3514 | |
| 3515 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3516 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3517 | |
| 3518 | ap = (ADISC *) (pcmd); |
| 3519 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3520 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3521 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3522 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3523 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3524 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3525 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 3526 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3527 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3528 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3529 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3530 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3531 | if (rc == IOCB_ERROR) { |
| 3532 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3533 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3534 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3535 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3536 | } |
| 3537 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3538 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3539 | * 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] | 3540 | * @vport: pointer to a virtual N_Port data structure. |
| 3541 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3542 | * @ndlp: pointer to a node-list data structure. |
| 3543 | * |
| 3544 | * This routine prepares and issues an Accept (ACC) response to Process |
| 3545 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 3546 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3547 | * |
| 3548 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3549 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3550 | * will be stored into the context1 field of the IOCB for the completion |
| 3551 | * callback function to the PRLI Accept response ELS IOCB command. |
| 3552 | * |
| 3553 | * Return code |
| 3554 | * 0 - Successfully issued acc prli response |
| 3555 | * 1 - Failed to issue acc prli response |
| 3556 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3557 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3558 | 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] | 3559 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3560 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3561 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3562 | PRLI *npr; |
| 3563 | lpfc_vpd_t *vpd; |
| 3564 | IOCB_t *icmd; |
| 3565 | IOCB_t *oldcmd; |
| 3566 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3567 | struct lpfc_sli *psli; |
| 3568 | uint8_t *pcmd; |
| 3569 | uint16_t cmdsize; |
| 3570 | int rc; |
| 3571 | |
| 3572 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3573 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3574 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3575 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3576 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3577 | if (!elsiocb) |
| 3578 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3579 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3580 | icmd = &elsiocb->iocb; |
| 3581 | oldcmd = &oldiocb->iocb; |
| 3582 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3583 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3584 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3585 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 3586 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 3587 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3588 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3589 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3590 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3591 | |
| 3592 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3593 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3594 | |
| 3595 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3596 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3597 | |
| 3598 | npr = (PRLI *) pcmd; |
| 3599 | vpd = &phba->vpd; |
| 3600 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3601 | * If the remote port is a target and our firmware version is 3.20 or |
| 3602 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3603 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3604 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 3605 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3606 | npr->ConfmComplAllowed = 1; |
| 3607 | npr->Retry = 1; |
| 3608 | npr->TaskRetryIdReq = 1; |
| 3609 | } |
| 3610 | |
| 3611 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 3612 | npr->estabImagePair = 1; |
| 3613 | npr->readXferRdyDis = 1; |
| 3614 | npr->ConfmComplAllowed = 1; |
| 3615 | |
| 3616 | npr->prliType = PRLI_FCP_TYPE; |
| 3617 | npr->initiatorFunc = 1; |
| 3618 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3619 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3620 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 3621 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3622 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3623 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3624 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3625 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3626 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3627 | if (rc == IOCB_ERROR) { |
| 3628 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3629 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3630 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3631 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3632 | } |
| 3633 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3634 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3635 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3636 | * @vport: pointer to a virtual N_Port data structure. |
| 3637 | * @format: rnid command format. |
| 3638 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3639 | * @ndlp: pointer to a node-list data structure. |
| 3640 | * |
| 3641 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 3642 | * (ACC) response. It constructs the RNID ACC response command according to |
| 3643 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 3644 | * issue the response. Note that this command does not need to hold the ndlp |
| 3645 | * reference count for the callback. So, the ndlp reference count taken by |
| 3646 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 3647 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 3648 | * there is no ndlp reference available. |
| 3649 | * |
| 3650 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3651 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3652 | * will be stored into the context1 field of the IOCB for the completion |
| 3653 | * callback function. However, for the RNID Accept Response ELS command, |
| 3654 | * this is undone later by this routine after the IOCB is allocated. |
| 3655 | * |
| 3656 | * Return code |
| 3657 | * 0 - Successfully issued acc rnid response |
| 3658 | * 1 - Failed to issue acc rnid response |
| 3659 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3660 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3661 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3662 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3663 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3664 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3665 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3666 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3667 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3668 | struct lpfc_sli *psli; |
| 3669 | uint8_t *pcmd; |
| 3670 | uint16_t cmdsize; |
| 3671 | int rc; |
| 3672 | |
| 3673 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3674 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 3675 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3676 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3677 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3678 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3679 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3680 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3681 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3682 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3683 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3684 | icmd = &elsiocb->iocb; |
| 3685 | oldcmd = &oldiocb->iocb; |
| 3686 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3687 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3688 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3689 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 3690 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3691 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3692 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3693 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3694 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3695 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3696 | rn = (RNID *) (pcmd); |
| 3697 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3698 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 3699 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3700 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3701 | switch (format) { |
| 3702 | case 0: |
| 3703 | rn->SpecificLen = 0; |
| 3704 | break; |
| 3705 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3706 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3707 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3708 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3709 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 3710 | rn->un.topologyDisc.physPort = 0; |
| 3711 | rn->un.topologyDisc.attachedNodes = 0; |
| 3712 | break; |
| 3713 | default: |
| 3714 | rn->CommonLen = 0; |
| 3715 | rn->SpecificLen = 0; |
| 3716 | break; |
| 3717 | } |
| 3718 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3719 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3720 | "Issue ACC RNID: did:x%x flg:x%x", |
| 3721 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3722 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3723 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3724 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3725 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3726 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 3727 | * it could be freed */ |
| 3728 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3729 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3730 | if (rc == IOCB_ERROR) { |
| 3731 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3732 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3733 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3734 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3735 | } |
| 3736 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3737 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3738 | * 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] | 3739 | * @vport: pointer to a host virtual N_Port data structure. |
| 3740 | * |
| 3741 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 3742 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 3743 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 3744 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 3745 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 3746 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 3747 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 3748 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 3749 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 3750 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 3751 | * no more ADISC need to be sent. |
| 3752 | * |
| 3753 | * Return code |
| 3754 | * The number of N_Ports with adisc issued. |
| 3755 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3756 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3757 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3758 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3759 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3760 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3761 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3762 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3763 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3764 | 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] | 3765 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3766 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3767 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3768 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3769 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3770 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3771 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3772 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3773 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3774 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 3775 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3776 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3777 | vport->num_disc_nodes++; |
| 3778 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3779 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3780 | spin_lock_irq(shost->host_lock); |
| 3781 | vport->fc_flag |= FC_NLP_MORE; |
| 3782 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3783 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3784 | } |
| 3785 | } |
| 3786 | } |
| 3787 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3788 | spin_lock_irq(shost->host_lock); |
| 3789 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3790 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3791 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3792 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3793 | } |
| 3794 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3795 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3796 | * 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] | 3797 | * @vport: pointer to a host virtual N_Port data structure. |
| 3798 | * |
| 3799 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 3800 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 3801 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 3802 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 3803 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 3804 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 3805 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 3806 | * later pick up. On the other hand, after walking through all the ndlps with |
| 3807 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 3808 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 3809 | * PLOGI need to be sent. |
| 3810 | * |
| 3811 | * Return code |
| 3812 | * The number of N_Ports with plogi issued. |
| 3813 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3814 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3815 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3816 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3817 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3818 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3819 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3820 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3821 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 3822 | 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] | 3823 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3824 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3825 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3826 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3827 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 3828 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 3829 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3830 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 3831 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3832 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3833 | vport->num_disc_nodes++; |
| 3834 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3835 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3836 | spin_lock_irq(shost->host_lock); |
| 3837 | vport->fc_flag |= FC_NLP_MORE; |
| 3838 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3839 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3840 | } |
| 3841 | } |
| 3842 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3843 | if (sentplogi) { |
| 3844 | lpfc_set_disctmo(vport); |
| 3845 | } |
| 3846 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3847 | spin_lock_irq(shost->host_lock); |
| 3848 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3849 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3850 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3851 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3852 | } |
| 3853 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3854 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3855 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3856 | * @vport: pointer to a host virtual N_Port data structure. |
| 3857 | * |
| 3858 | * This routine cleans up any Registration State Change Notification |
| 3859 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 3860 | * @vport together with the host_lock is used to prevent multiple thread |
| 3861 | * trying to access the RSCN array on a same @vport at the same time. |
| 3862 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3863 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3864 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3865 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3866 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3867 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3868 | int i; |
| 3869 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3870 | spin_lock_irq(shost->host_lock); |
| 3871 | if (vport->fc_rscn_flush) { |
| 3872 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3873 | spin_unlock_irq(shost->host_lock); |
| 3874 | return; |
| 3875 | } |
| 3876 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 3877 | vport->fc_rscn_flush = 1; |
| 3878 | spin_unlock_irq(shost->host_lock); |
| 3879 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3880 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3881 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3882 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3883 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3884 | spin_lock_irq(shost->host_lock); |
| 3885 | vport->fc_rscn_id_cnt = 0; |
| 3886 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 3887 | spin_unlock_irq(shost->host_lock); |
| 3888 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3889 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 3890 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3891 | } |
| 3892 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3893 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3894 | * 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] | 3895 | * @vport: pointer to a host virtual N_Port data structure. |
| 3896 | * @did: remote destination port identifier. |
| 3897 | * |
| 3898 | * This routine checks whether there is any pending Registration State |
| 3899 | * Configuration Notification (RSCN) to a @did on @vport. |
| 3900 | * |
| 3901 | * Return code |
| 3902 | * None zero - The @did matched with a pending rscn |
| 3903 | * 0 - not able to match @did with a pending rscn |
| 3904 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3905 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3906 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3907 | { |
| 3908 | D_ID ns_did; |
| 3909 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3910 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3911 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3912 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3913 | |
| 3914 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3915 | |
| 3916 | /* Never match fabric nodes for RSCNs */ |
| 3917 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3918 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3919 | |
| 3920 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3921 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3922 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3923 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3924 | spin_lock_irq(shost->host_lock); |
| 3925 | if (vport->fc_rscn_flush) { |
| 3926 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3927 | spin_unlock_irq(shost->host_lock); |
| 3928 | return 0; |
| 3929 | } |
| 3930 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 3931 | vport->fc_rscn_flush = 1; |
| 3932 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3933 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3934 | lp = vport->fc_rscn_id_list[i]->virt; |
| 3935 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 3936 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3937 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3938 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 3939 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3940 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 3941 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3942 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 3943 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 3944 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3945 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3946 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3947 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3948 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 3949 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3950 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3951 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3952 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3953 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3954 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3955 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3956 | case RSCN_ADDRESS_FORMAT_FABRIC: |
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 | } |
| 3959 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3960 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3961 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 3962 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3963 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3964 | return_did_out: |
| 3965 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 3966 | vport->fc_rscn_flush = 0; |
| 3967 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3968 | } |
| 3969 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3970 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3971 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3972 | * @vport: pointer to a host virtual N_Port data structure. |
| 3973 | * |
| 3974 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 3975 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 3976 | * State Change Notification). |
| 3977 | * |
| 3978 | * Return code |
| 3979 | * 0 - Successful (currently alway return 0) |
| 3980 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3981 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3982 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3983 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3984 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3985 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3986 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3987 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3988 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3989 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 3990 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3991 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3992 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3993 | NLP_EVT_DEVICE_RECOVERY); |
| 3994 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3995 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3996 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3997 | } |
| 3998 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3999 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4000 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4001 | * @vport: pointer to a host virtual N_Port data structure. |
| 4002 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4003 | * |
| 4004 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 4005 | * applications. |
| 4006 | */ |
| 4007 | static void |
| 4008 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 4009 | struct lpfc_iocbq *cmdiocb) |
| 4010 | { |
| 4011 | struct lpfc_dmabuf *pcmd; |
| 4012 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4013 | uint32_t *payload_ptr; |
| 4014 | uint32_t payload_len; |
| 4015 | struct lpfc_rscn_event_header *rscn_event_data; |
| 4016 | |
| 4017 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4018 | payload_ptr = (uint32_t *) pcmd->virt; |
| 4019 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 4020 | |
| 4021 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 4022 | payload_len, GFP_KERNEL); |
| 4023 | if (!rscn_event_data) { |
| 4024 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4025 | "0147 Failed to allocate memory for RSCN event\n"); |
| 4026 | return; |
| 4027 | } |
| 4028 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 4029 | rscn_event_data->payload_length = payload_len; |
| 4030 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 4031 | payload_len); |
| 4032 | |
| 4033 | fc_host_post_vendor_event(shost, |
| 4034 | fc_get_event_number(), |
| 4035 | sizeof(struct lpfc_els_event_header) + payload_len, |
| 4036 | (char *)rscn_event_data, |
| 4037 | LPFC_NL_VENDOR_ID); |
| 4038 | |
| 4039 | kfree(rscn_event_data); |
| 4040 | } |
| 4041 | |
| 4042 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4043 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4044 | * @vport: pointer to a host virtual N_Port data structure. |
| 4045 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4046 | * @ndlp: pointer to a node-list data structure. |
| 4047 | * |
| 4048 | * This routine processes an unsolicited RSCN (Registration State Change |
| 4049 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 4050 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 4051 | * discover state machine is about to begin discovery, it just accepts the |
| 4052 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 4053 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 4054 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 4055 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 4056 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 4057 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 4058 | * routine is invoked to handle the RSCN event. |
| 4059 | * |
| 4060 | * Return code |
| 4061 | * 0 - Just sent the acc response |
| 4062 | * 1 - Sent the acc response and waited for name server completion |
| 4063 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4064 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4065 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4066 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4067 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4068 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4069 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4070 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4071 | uint32_t *lp, *datap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4072 | IOCB_t *icmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4073 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4074 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4075 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4076 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4077 | |
| 4078 | icmd = &cmdiocb->iocb; |
| 4079 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4080 | lp = (uint32_t *) pcmd->virt; |
| 4081 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4082 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4083 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4084 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4085 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4086 | "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] | 4087 | vport->fc_flag, payload_len, *lp, |
| 4088 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4089 | |
| 4090 | /* Send an RSCN event to the management application */ |
| 4091 | lpfc_send_rscn_event(vport, cmdiocb); |
| 4092 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4093 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4094 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4095 | FCH_EVT_RSCN, lp[i]); |
| 4096 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4097 | /* If we are about to begin discovery, just ACC the RSCN. |
| 4098 | * Discovery processing will satisfy it. |
| 4099 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4100 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4101 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4102 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 4103 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4104 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4105 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4106 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4107 | } |
| 4108 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4109 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 4110 | * just ACC and ignore it. |
| 4111 | */ |
| 4112 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4113 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4114 | i = payload_len; |
| 4115 | datap = lp; |
| 4116 | while (i > 0) { |
| 4117 | nportid = *datap++; |
| 4118 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 4119 | i -= sizeof(uint32_t); |
| 4120 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4121 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 4122 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4123 | } |
| 4124 | if (rscn_id == hba_id) { |
| 4125 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4126 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4127 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4128 | "Data: x%x x%x x%x x%x\n", |
| 4129 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4130 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4131 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4132 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 4133 | ndlp->nlp_DID, vport->port_state, |
| 4134 | ndlp->nlp_flag); |
| 4135 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4136 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4137 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4138 | return 0; |
| 4139 | } |
| 4140 | } |
| 4141 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4142 | spin_lock_irq(shost->host_lock); |
| 4143 | if (vport->fc_rscn_flush) { |
| 4144 | /* Another thread is walking fc_rscn_id_list on this vport */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4145 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 4146 | spin_unlock_irq(shost->host_lock); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4147 | /* Send back ACC */ |
| 4148 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4149 | return 0; |
| 4150 | } |
| 4151 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4152 | vport->fc_rscn_flush = 1; |
| 4153 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4154 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4155 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4156 | /* If we are already processing an RSCN, save the received |
| 4157 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 4158 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4159 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4160 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4161 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 4162 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4163 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4164 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4165 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 4166 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4167 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4168 | vport->fc_flag |= FC_RSCN_MODE; |
| 4169 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4170 | if (rscn_cnt) { |
| 4171 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 4172 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 4173 | } |
| 4174 | if ((rscn_cnt) && |
| 4175 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 4176 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4177 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4178 | memcpy(((uint8_t *)cmd) + length, lp, |
| 4179 | payload_len); |
| 4180 | } else { |
| 4181 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 4182 | vport->fc_rscn_id_cnt++; |
| 4183 | /* If we zero, cmdiocb->context2, the calling |
| 4184 | * routine will not try to free it. |
| 4185 | */ |
| 4186 | cmdiocb->context2 = NULL; |
| 4187 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4188 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4189 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4190 | "0235 Deferred RSCN " |
| 4191 | "Data: x%x x%x x%x\n", |
| 4192 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4193 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4194 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4195 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 4196 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4197 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4198 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4199 | "0234 ReDiscovery RSCN " |
| 4200 | "Data: x%x x%x x%x\n", |
| 4201 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4202 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4203 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4204 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4205 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4206 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4207 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4208 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4209 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4210 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4211 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4212 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4213 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4214 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4215 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4216 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 4217 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4218 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4219 | spin_lock_irq(shost->host_lock); |
| 4220 | vport->fc_flag |= FC_RSCN_MODE; |
| 4221 | spin_unlock_irq(shost->host_lock); |
| 4222 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4223 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4224 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4225 | /* |
| 4226 | * If we zero, cmdiocb->context2, the calling routine will |
| 4227 | * not try to free it. |
| 4228 | */ |
| 4229 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4230 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4231 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4232 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4233 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4234 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4235 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4236 | } |
| 4237 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4238 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4239 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4240 | * @vport: pointer to a host virtual N_Port data structure. |
| 4241 | * |
| 4242 | * This routine handles the Registration State Configuration Notification |
| 4243 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 4244 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 4245 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 4246 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 4247 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 4248 | * RSCN activities with the @vport. |
| 4249 | * |
| 4250 | * Return code |
| 4251 | * 0 - Cleaned up rscn on the @vport |
| 4252 | * 1 - Wait for plogi to name server before proceed |
| 4253 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4254 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4255 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4256 | { |
| 4257 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4258 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4259 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4260 | /* Ignore RSCN if the port is being torn down. */ |
| 4261 | if (vport->load_flag & FC_UNLOADING) { |
| 4262 | lpfc_els_flush_rscn(vport); |
| 4263 | return 0; |
| 4264 | } |
| 4265 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4266 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4267 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4268 | |
| 4269 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4270 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4271 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 4272 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 4273 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4274 | |
| 4275 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4276 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4277 | vport->num_disc_nodes = 0; |
| 4278 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4279 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4280 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 4281 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4282 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4283 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4284 | /* Wait for NameServer query cmpl before we can |
| 4285 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4286 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4287 | } else { |
| 4288 | /* If login to NameServer does not exist, issue one */ |
| 4289 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4290 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4291 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4292 | /* Wait for NameServer login cmpl before we can |
| 4293 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4294 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4295 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4296 | if (ndlp) { |
| 4297 | ndlp = lpfc_enable_node(vport, ndlp, |
| 4298 | NLP_STE_PLOGI_ISSUE); |
| 4299 | if (!ndlp) { |
| 4300 | lpfc_els_flush_rscn(vport); |
| 4301 | return 0; |
| 4302 | } |
| 4303 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4304 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4305 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4306 | if (!ndlp) { |
| 4307 | lpfc_els_flush_rscn(vport); |
| 4308 | return 0; |
| 4309 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4310 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4311 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4312 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4313 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4314 | ndlp->nlp_type |= NLP_FABRIC; |
| 4315 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 4316 | /* Wait for NameServer login cmpl before we can |
| 4317 | * continue |
| 4318 | */ |
| 4319 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4320 | } |
| 4321 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4322 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4323 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4324 | } |
| 4325 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4326 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4327 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4328 | * @vport: pointer to a host virtual N_Port data structure. |
| 4329 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4330 | * @ndlp: pointer to a node-list data structure. |
| 4331 | * |
| 4332 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 4333 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 4334 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 4335 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 4336 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 4337 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 4338 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 4339 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 4340 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 4341 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 4342 | * higher priority (as the winning port) and will initiate PLOGI and |
| 4343 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 4344 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 4345 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 4346 | * |
| 4347 | * Return code |
| 4348 | * 0 - Successfully processed the unsolicited flogi |
| 4349 | * 1 - Failed to process the unsolicited flogi |
| 4350 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4351 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4352 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4353 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4354 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4355 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4356 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4357 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4358 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 4359 | IOCB_t *icmd = &cmdiocb->iocb; |
| 4360 | struct serv_parm *sp; |
| 4361 | LPFC_MBOXQ_t *mbox; |
| 4362 | struct ls_rjt stat; |
| 4363 | uint32_t cmd, did; |
| 4364 | int rc; |
| 4365 | |
| 4366 | cmd = *lp++; |
| 4367 | sp = (struct serv_parm *) lp; |
| 4368 | |
| 4369 | /* FLOGI received */ |
| 4370 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4371 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4372 | |
| 4373 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 4374 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 4375 | did = icmd->un.elsreq64.remoteID; |
| 4376 | |
| 4377 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 4378 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4379 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4380 | "0113 An FLOGI ELS command x%x was " |
| 4381 | "received from DID x%x in Loop Mode\n", |
| 4382 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4383 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4384 | } |
| 4385 | |
| 4386 | did = Fabric_DID; |
| 4387 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4388 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4389 | /* For a FLOGI we accept, then if our portname is greater |
| 4390 | * then the remote portname we initiate Nport login. |
| 4391 | */ |
| 4392 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4393 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4394 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4395 | |
| 4396 | if (!rc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4397 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4398 | if (!mbox) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4399 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4400 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4401 | lpfc_linkdown(phba); |
| 4402 | lpfc_init_link(phba, mbox, |
| 4403 | phba->cfg_topology, |
| 4404 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4405 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4406 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4407 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4408 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4409 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4410 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4411 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4412 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4413 | return 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4414 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4415 | spin_lock_irq(shost->host_lock); |
| 4416 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 4417 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4418 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4419 | spin_lock_irq(shost->host_lock); |
| 4420 | vport->fc_flag |= FC_PT2PT; |
| 4421 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 4422 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4423 | } else { |
| 4424 | /* Reject this request because invalid parameters */ |
| 4425 | stat.un.b.lsRjtRsvd0 = 0; |
| 4426 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4427 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 4428 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4429 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4430 | NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4431 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4432 | } |
| 4433 | |
| 4434 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4435 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4436 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4437 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4438 | } |
| 4439 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4440 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4441 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4442 | * @vport: pointer to a host virtual N_Port data structure. |
| 4443 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4444 | * @ndlp: pointer to a node-list data structure. |
| 4445 | * |
| 4446 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 4447 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 4448 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 4449 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 4450 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 4451 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 4452 | * |
| 4453 | * Return code |
| 4454 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 4455 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4456 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4457 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4458 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4459 | { |
| 4460 | struct lpfc_dmabuf *pcmd; |
| 4461 | uint32_t *lp; |
| 4462 | IOCB_t *icmd; |
| 4463 | RNID *rn; |
| 4464 | struct ls_rjt stat; |
| 4465 | uint32_t cmd, did; |
| 4466 | |
| 4467 | icmd = &cmdiocb->iocb; |
| 4468 | did = icmd->un.elsreq64.remoteID; |
| 4469 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4470 | lp = (uint32_t *) pcmd->virt; |
| 4471 | |
| 4472 | cmd = *lp++; |
| 4473 | rn = (RNID *) lp; |
| 4474 | |
| 4475 | /* RNID received */ |
| 4476 | |
| 4477 | switch (rn->Format) { |
| 4478 | case 0: |
| 4479 | case RNID_TOPOLOGY_DISC: |
| 4480 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4481 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4482 | break; |
| 4483 | default: |
| 4484 | /* Reject this request because format not supported */ |
| 4485 | stat.un.b.lsRjtRsvd0 = 0; |
| 4486 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4487 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4488 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4489 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4490 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4491 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4492 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4493 | } |
| 4494 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4495 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4496 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4497 | * @vport: pointer to a host virtual N_Port data structure. |
| 4498 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4499 | * @ndlp: pointer to a node-list data structure. |
| 4500 | * |
| 4501 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 4502 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 4503 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 4504 | * |
| 4505 | * Return code |
| 4506 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 4507 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4508 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4509 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4510 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4511 | { |
| 4512 | struct ls_rjt stat; |
| 4513 | |
| 4514 | /* For now, unconditionally reject this command */ |
| 4515 | stat.un.b.lsRjtRsvd0 = 0; |
| 4516 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4517 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4518 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4519 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4520 | return 0; |
| 4521 | } |
| 4522 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4523 | /** |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 4524 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb |
| 4525 | * @vport: pointer to a host virtual N_Port data structure. |
| 4526 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4527 | * @ndlp: pointer to a node-list data structure. |
| 4528 | * |
| 4529 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB |
| 4530 | * received as an ELS unsolicited event. A request to RRQ shall only |
| 4531 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder |
| 4532 | * Nx_Port N_Port_ID of the target Exchange is the same as the |
| 4533 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is |
| 4534 | * not accepted, an LS_RJT with reason code "Unable to perform |
| 4535 | * command request" and reason code explanation "Invalid Originator |
| 4536 | * S_ID" shall be returned. For now, we just unconditionally accept |
| 4537 | * RRQ from the target. |
| 4538 | **/ |
| 4539 | static void |
| 4540 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4541 | struct lpfc_nodelist *ndlp) |
| 4542 | { |
| 4543 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| 4544 | } |
| 4545 | |
| 4546 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4547 | * 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] | 4548 | * @phba: pointer to lpfc hba data structure. |
| 4549 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4550 | * |
| 4551 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 4552 | * mailbox command. This callback function is to actually send the Accept |
| 4553 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 4554 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 4555 | * mailbox command, constructs the RPS response with the link statistics |
| 4556 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 4557 | * response to the RPS. |
| 4558 | * |
| 4559 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4560 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4561 | * will be stored into the context1 field of the IOCB for the completion |
| 4562 | * callback function to the RPS Accept Response ELS IOCB command. |
| 4563 | * |
| 4564 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4565 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4566 | 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] | 4567 | { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4568 | MAILBOX_t *mb; |
| 4569 | IOCB_t *icmd; |
| 4570 | RPS_RSP *rps_rsp; |
| 4571 | uint8_t *pcmd; |
| 4572 | struct lpfc_iocbq *elsiocb; |
| 4573 | struct lpfc_nodelist *ndlp; |
| 4574 | uint16_t xri, status; |
| 4575 | uint32_t cmdsize; |
| 4576 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4577 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4578 | |
| 4579 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4580 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 4581 | pmb->context1 = NULL; |
| 4582 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4583 | |
| 4584 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4585 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4586 | return; |
| 4587 | } |
| 4588 | |
| 4589 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4590 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4591 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 4592 | lpfc_max_els_tries, ndlp, |
| 4593 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4594 | |
| 4595 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4596 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4597 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4598 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4599 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4600 | |
| 4601 | icmd = &elsiocb->iocb; |
| 4602 | icmd->ulpContext = xri; |
| 4603 | |
| 4604 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4605 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4606 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4607 | rps_rsp = (RPS_RSP *)pcmd; |
| 4608 | |
| 4609 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| 4610 | status = 0x10; |
| 4611 | else |
| 4612 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4613 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4614 | status |= 0x4; |
| 4615 | |
| 4616 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4617 | rps_rsp->portStatus = cpu_to_be16(status); |
| 4618 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 4619 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 4620 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 4621 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 4622 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 4623 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4624 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4625 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 4626 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 4627 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4628 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4629 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4630 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4631 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4632 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4633 | 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] | 4634 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4635 | return; |
| 4636 | } |
| 4637 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4638 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4639 | * lpfc_els_rcv_rps - Process an unsolicited rps iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4640 | * @vport: pointer to a host virtual N_Port data structure. |
| 4641 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4642 | * @ndlp: pointer to a node-list data structure. |
| 4643 | * |
| 4644 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 4645 | * ELS unsolicited event. It first checks the remote port state. If the |
| 4646 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 4647 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 4648 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 4649 | * for reading the HBA link statistics. It is for the callback function, |
| 4650 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 4651 | * to actually sending out RPS Accept (ACC) response. |
| 4652 | * |
| 4653 | * Return codes |
| 4654 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 4655 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4656 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4657 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4658 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4659 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4660 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4661 | uint32_t *lp; |
| 4662 | uint8_t flag; |
| 4663 | LPFC_MBOXQ_t *mbox; |
| 4664 | struct lpfc_dmabuf *pcmd; |
| 4665 | RPS *rps; |
| 4666 | struct ls_rjt stat; |
| 4667 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4668 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4669 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 4670 | /* reject the unsolicited RPS request and done with it */ |
| 4671 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4672 | |
| 4673 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4674 | lp = (uint32_t *) pcmd->virt; |
| 4675 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 4676 | rps = (RPS *) lp; |
| 4677 | |
| 4678 | if ((flag == 0) || |
| 4679 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4680 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4681 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4682 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4683 | printk("Fix me....\n"); |
| 4684 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4685 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 4686 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4687 | lpfc_read_lnk_stat(phba, mbox); |
| 4688 | mbox->context1 = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4689 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4690 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4691 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4692 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4693 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4694 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4695 | /* Mbox completion will send ELS Response */ |
| 4696 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4697 | /* Decrement reference count used for the failed mbox |
| 4698 | * command. |
| 4699 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4700 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4701 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4702 | } |
| 4703 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4704 | |
| 4705 | reject_out: |
| 4706 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4707 | stat.un.b.lsRjtRsvd0 = 0; |
| 4708 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4709 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4710 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4711 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4712 | return 0; |
| 4713 | } |
| 4714 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4715 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4716 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4717 | * @vport: pointer to a host virtual N_Port data structure. |
| 4718 | * @cmdsize: size of the ELS command. |
| 4719 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4720 | * @ndlp: pointer to a node-list data structure. |
| 4721 | * |
| 4722 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 4723 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 4724 | * |
| 4725 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4726 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4727 | * will be stored into the context1 field of the IOCB for the completion |
| 4728 | * callback function to the RPL Accept Response ELS command. |
| 4729 | * |
| 4730 | * Return code |
| 4731 | * 0 - Successfully issued ACC RPL ELS command |
| 4732 | * 1 - Failed to issue ACC RPL ELS command |
| 4733 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4734 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4735 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 4736 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4737 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4738 | struct lpfc_hba *phba = vport->phba; |
| 4739 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4740 | RPL_RSP rpl_rsp; |
| 4741 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4742 | uint8_t *pcmd; |
| 4743 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4744 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4745 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4746 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4747 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4748 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4749 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4750 | icmd = &elsiocb->iocb; |
| 4751 | oldcmd = &oldiocb->iocb; |
| 4752 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 4753 | |
| 4754 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4755 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4756 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4757 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 4758 | pcmd += sizeof(uint16_t); |
| 4759 | |
| 4760 | /* Setup the RPL ACC payload */ |
| 4761 | rpl_rsp.listLen = be32_to_cpu(1); |
| 4762 | rpl_rsp.index = 0; |
| 4763 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4764 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 4765 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4766 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4767 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4768 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4769 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4770 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 4771 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 4772 | "rpi x%x\n", |
| 4773 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4774 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4775 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4776 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4777 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4778 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 4779 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4780 | lpfc_els_free_iocb(phba, elsiocb); |
| 4781 | return 1; |
| 4782 | } |
| 4783 | return 0; |
| 4784 | } |
| 4785 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4786 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4787 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4788 | * @vport: pointer to a host virtual N_Port data structure. |
| 4789 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4790 | * @ndlp: pointer to a node-list data structure. |
| 4791 | * |
| 4792 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 4793 | * unsolicited event. It first checks the remote port state. If the remote |
| 4794 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 4795 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 4796 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 4797 | * to accept the RPL. |
| 4798 | * |
| 4799 | * Return code |
| 4800 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 4801 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4802 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4803 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4804 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4805 | { |
| 4806 | struct lpfc_dmabuf *pcmd; |
| 4807 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4808 | uint32_t maxsize; |
| 4809 | uint16_t cmdsize; |
| 4810 | RPL *rpl; |
| 4811 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4812 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4813 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 4814 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4815 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4816 | stat.un.b.lsRjtRsvd0 = 0; |
| 4817 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4818 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4819 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4820 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4821 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4822 | /* rejected the unsolicited RPL request and done with it */ |
| 4823 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4824 | } |
| 4825 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4826 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4827 | lp = (uint32_t *) pcmd->virt; |
| 4828 | rpl = (RPL *) (lp + 1); |
| 4829 | |
| 4830 | maxsize = be32_to_cpu(rpl->maxsize); |
| 4831 | |
| 4832 | /* We support only one port */ |
| 4833 | if ((rpl->index == 0) && |
| 4834 | ((maxsize == 0) || |
| 4835 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 4836 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4837 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4838 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 4839 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4840 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4841 | |
| 4842 | return 0; |
| 4843 | } |
| 4844 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4845 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4846 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4847 | * @vport: pointer to a virtual N_Port data structure. |
| 4848 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4849 | * @ndlp: pointer to a node-list data structure. |
| 4850 | * |
| 4851 | * This routine processes Fibre Channel Address Resolution Protocol |
| 4852 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 4853 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 4854 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 4855 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 4856 | * remote PortName is compared against the FC PortName stored in the @vport |
| 4857 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 4858 | * compared against the FC NodeName stored in the @vport data structure. |
| 4859 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 4860 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 4861 | * invoked to send out FARP Response to the remote node. Before sending the |
| 4862 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 4863 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 4864 | * routine is invoked to log into the remote port first. |
| 4865 | * |
| 4866 | * Return code |
| 4867 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 4868 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4869 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4870 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4871 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4872 | { |
| 4873 | struct lpfc_dmabuf *pcmd; |
| 4874 | uint32_t *lp; |
| 4875 | IOCB_t *icmd; |
| 4876 | FARP *fp; |
| 4877 | uint32_t cmd, cnt, did; |
| 4878 | |
| 4879 | icmd = &cmdiocb->iocb; |
| 4880 | did = icmd->un.elsreq64.remoteID; |
| 4881 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4882 | lp = (uint32_t *) pcmd->virt; |
| 4883 | |
| 4884 | cmd = *lp++; |
| 4885 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4886 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4887 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4888 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4889 | /* We will only support match on WWPN or WWNN */ |
| 4890 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4891 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4892 | } |
| 4893 | |
| 4894 | cnt = 0; |
| 4895 | /* If this FARP command is searching for my portname */ |
| 4896 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4897 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4898 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4899 | cnt = 1; |
| 4900 | } |
| 4901 | |
| 4902 | /* If this FARP command is searching for my nodename */ |
| 4903 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4904 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4905 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4906 | cnt = 1; |
| 4907 | } |
| 4908 | |
| 4909 | if (cnt) { |
| 4910 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 4911 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 4912 | /* Log back into the node before sending the FARP. */ |
| 4913 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4914 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4915 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4916 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4917 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4918 | } |
| 4919 | |
| 4920 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4921 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 4922 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4923 | } |
| 4924 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4925 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4926 | } |
| 4927 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4928 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4929 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4930 | * @vport: pointer to a host virtual N_Port data structure. |
| 4931 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4932 | * @ndlp: pointer to a node-list data structure. |
| 4933 | * |
| 4934 | * This routine processes Fibre Channel Address Resolution Protocol |
| 4935 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 4936 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 4937 | * the FARP response request. |
| 4938 | * |
| 4939 | * Return code |
| 4940 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 4941 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4942 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4943 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4944 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4945 | { |
| 4946 | struct lpfc_dmabuf *pcmd; |
| 4947 | uint32_t *lp; |
| 4948 | IOCB_t *icmd; |
| 4949 | uint32_t cmd, did; |
| 4950 | |
| 4951 | icmd = &cmdiocb->iocb; |
| 4952 | did = icmd->un.elsreq64.remoteID; |
| 4953 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4954 | lp = (uint32_t *) pcmd->virt; |
| 4955 | |
| 4956 | cmd = *lp++; |
| 4957 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4958 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4959 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4960 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4961 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4962 | |
| 4963 | return 0; |
| 4964 | } |
| 4965 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4966 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4967 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4968 | * @vport: pointer to a host virtual N_Port data structure. |
| 4969 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4970 | * @fan_ndlp: pointer to a node-list data structure. |
| 4971 | * |
| 4972 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 4973 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 4974 | * only be processed on a physical port (i.e., the @vport represents the |
| 4975 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 4976 | * compared against those in the phba data structure. If any of those is |
| 4977 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 4978 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 4979 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 4980 | * is invoked to register login to the fabric. |
| 4981 | * |
| 4982 | * Return code |
| 4983 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 4984 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4985 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4986 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4987 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4988 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4989 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4990 | uint32_t *lp; |
| 4991 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4992 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4993 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 4994 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 4995 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4996 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4997 | if ((vport == phba->pport) && |
| 4998 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4999 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5000 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5001 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5002 | sizeof(struct lpfc_name)))) { |
| 5003 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5004 | lpfc_initial_flogi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5005 | } else { |
| 5006 | /* FAN verified - skip FLOGI */ |
| 5007 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5008 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5009 | lpfc_issue_fabric_reglogin(vport); |
| 5010 | else |
| 5011 | lpfc_issue_reg_vfi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5012 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5013 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5014 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5015 | } |
| 5016 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5017 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5018 | * lpfc_els_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5019 | * @ptr: holder for the timer function associated data. |
| 5020 | * |
| 5021 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 5022 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 5023 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 5024 | * up the worker thread. It is for the worker thread to invoke the routine |
| 5025 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 5026 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5027 | void |
| 5028 | lpfc_els_timeout(unsigned long ptr) |
| 5029 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5030 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 5031 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5032 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5033 | unsigned long iflag; |
| 5034 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5035 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5036 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
| 5037 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5038 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5039 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5040 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5041 | if (!tmo_posted) |
| 5042 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5043 | return; |
| 5044 | } |
| 5045 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5046 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5047 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5048 | * @vport: pointer to a virtual N_Port data structure. |
| 5049 | * |
| 5050 | * This routine is the actual handler function that processes an ELS timeout |
| 5051 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 5052 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 5053 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5054 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5055 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5056 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5057 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5058 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5059 | struct lpfc_sli_ring *pring; |
| 5060 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5061 | IOCB_t *cmd = NULL; |
| 5062 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5063 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5064 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5065 | uint32_t remote_ID = 0xffffffff; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5066 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5067 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5068 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 5069 | |
| 5070 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5071 | |
| 5072 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5073 | cmd = &piocb->iocb; |
| 5074 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5075 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 5076 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 5077 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5078 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5079 | |
| 5080 | if (piocb->vport != vport) |
| 5081 | continue; |
| 5082 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5083 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5084 | if (pcmd) |
| 5085 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5086 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5087 | if (els_command == ELS_CMD_FARP || |
| 5088 | els_command == ELS_CMD_FARPR || |
| 5089 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5090 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5091 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5092 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5093 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5094 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5095 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5096 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5097 | continue; |
| 5098 | } |
| 5099 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5100 | remote_ID = 0xffffffff; |
| 5101 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5102 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5103 | else { |
| 5104 | struct lpfc_nodelist *ndlp; |
| 5105 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5106 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5107 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5108 | } |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5109 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5110 | "0127 ELS timeout Data: x%x x%x x%x " |
| 5111 | "x%x\n", els_command, |
| 5112 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5113 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5114 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5115 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 5116 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5117 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
| 5118 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5119 | } |
| 5120 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5121 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5122 | * 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] | 5123 | * @vport: pointer to a host virtual N_Port data structure. |
| 5124 | * |
| 5125 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5126 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 5127 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5128 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5129 | * the IOCBs with a non-NULL completion callback function, the callback |
| 5130 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5131 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 5132 | * callback function, the IOCB will simply be released. Finally, it walks |
| 5133 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 5134 | * completion queue IOCB that is associated with the @vport and is not |
| 5135 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 5136 | * part of the discovery state machine) out to HBA by invoking the |
| 5137 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 5138 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 5139 | * the IOCBs are aborted when this function returns. |
| 5140 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5141 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5142 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5143 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5144 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5145 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5146 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5147 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5148 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5149 | |
| 5150 | lpfc_fabric_abort_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5151 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5152 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5153 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5154 | cmd = &piocb->iocb; |
| 5155 | |
| 5156 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5157 | continue; |
| 5158 | } |
| 5159 | |
| 5160 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5161 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5162 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5163 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5164 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5165 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5166 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5167 | if (piocb->vport != vport) |
| 5168 | continue; |
| 5169 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5170 | list_move_tail(&piocb->list, &completions); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5171 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5172 | } |
| 5173 | |
| 5174 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5175 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5176 | continue; |
| 5177 | } |
| 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 | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5182 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5183 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5184 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5185 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5186 | /* Cancell all the IOCBs from the completions list */ |
| 5187 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5188 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5189 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5190 | return; |
| 5191 | } |
| 5192 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5193 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5194 | * 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] | 5195 | * @phba: pointer to lpfc hba data structure. |
| 5196 | * |
| 5197 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5198 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 5199 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5200 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5201 | * the IOCBs with the completion callback function associated, the callback |
| 5202 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5203 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 5204 | * callback function associated, the IOCB will simply be released. Finally, |
| 5205 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 5206 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 5207 | * management plane IOCBs that are not part of the discovery state machine) |
| 5208 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5209 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5210 | void |
| 5211 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 5212 | { |
| 5213 | LIST_HEAD(completions); |
| 5214 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 5215 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5216 | IOCB_t *cmd = NULL; |
| 5217 | |
| 5218 | lpfc_fabric_abort_hba(phba); |
| 5219 | spin_lock_irq(&phba->hbalock); |
| 5220 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5221 | cmd = &piocb->iocb; |
| 5222 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5223 | continue; |
| 5224 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
| 5225 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5226 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5227 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5228 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| 5229 | continue; |
| 5230 | list_move_tail(&piocb->list, &completions); |
| 5231 | pring->txq_cnt--; |
| 5232 | } |
| 5233 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5234 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5235 | continue; |
| 5236 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5237 | } |
| 5238 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5239 | |
| 5240 | /* Cancel all the IOCBs from the completions list */ |
| 5241 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5242 | IOERR_SLI_ABORTED); |
| 5243 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5244 | return; |
| 5245 | } |
| 5246 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5247 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5248 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5249 | * @phba: Pointer to hba context object. |
| 5250 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 5251 | * @rspiocbp: Pointer to response iocb which reported error. |
| 5252 | * |
| 5253 | * This function sends an event when there is an ELS command |
| 5254 | * failure. |
| 5255 | **/ |
| 5256 | void |
| 5257 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 5258 | struct lpfc_iocbq *cmdiocbp, |
| 5259 | struct lpfc_iocbq *rspiocbp) |
| 5260 | { |
| 5261 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 5262 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5263 | struct lpfc_lsrjt_event lsrjt_event; |
| 5264 | struct lpfc_fabric_event_header fabric_event; |
| 5265 | struct ls_rjt stat; |
| 5266 | struct lpfc_nodelist *ndlp; |
| 5267 | uint32_t *pcmd; |
| 5268 | |
| 5269 | ndlp = cmdiocbp->context1; |
| 5270 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 5271 | return; |
| 5272 | |
| 5273 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 5274 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 5275 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 5276 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 5277 | sizeof(struct lpfc_name)); |
| 5278 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 5279 | sizeof(struct lpfc_name)); |
| 5280 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 5281 | cmdiocbp->context2)->virt); |
| 5282 | lsrjt_event.command = *pcmd; |
| 5283 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 5284 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 5285 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 5286 | fc_host_post_vendor_event(shost, |
| 5287 | fc_get_event_number(), |
| 5288 | sizeof(lsrjt_event), |
| 5289 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5290 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5291 | return; |
| 5292 | } |
| 5293 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 5294 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 5295 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 5296 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 5297 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 5298 | else |
| 5299 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 5300 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 5301 | sizeof(struct lpfc_name)); |
| 5302 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 5303 | sizeof(struct lpfc_name)); |
| 5304 | fc_host_post_vendor_event(shost, |
| 5305 | fc_get_event_number(), |
| 5306 | sizeof(fabric_event), |
| 5307 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5308 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5309 | return; |
| 5310 | } |
| 5311 | |
| 5312 | } |
| 5313 | |
| 5314 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5315 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5316 | * @vport: Pointer to vport object. |
| 5317 | * @ndlp: Pointer FC node object. |
| 5318 | * @cmd: ELS command code. |
| 5319 | * |
| 5320 | * This function posts an event when there is an incoming |
| 5321 | * unsolicited ELS command. |
| 5322 | **/ |
| 5323 | static void |
| 5324 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 5325 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5326 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5327 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5328 | struct lpfc_els_event_header *els_data = NULL; |
| 5329 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5330 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5331 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5332 | if (*payload == ELS_CMD_LOGO) { |
| 5333 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 5334 | if (!logo_data) { |
| 5335 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5336 | "0148 Failed to allocate memory " |
| 5337 | "for LOGO event\n"); |
| 5338 | return; |
| 5339 | } |
| 5340 | els_data = &logo_data->header; |
| 5341 | } else { |
| 5342 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 5343 | GFP_KERNEL); |
| 5344 | if (!els_data) { |
| 5345 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5346 | "0149 Failed to allocate memory " |
| 5347 | "for ELS event\n"); |
| 5348 | return; |
| 5349 | } |
| 5350 | } |
| 5351 | els_data->event_type = FC_REG_ELS_EVENT; |
| 5352 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5353 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5354 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5355 | break; |
| 5356 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5357 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5358 | break; |
| 5359 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5360 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 5361 | break; |
| 5362 | case ELS_CMD_LOGO: |
| 5363 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 5364 | /* Copy the WWPN in the LOGO payload */ |
| 5365 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 5366 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5367 | break; |
| 5368 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 5369 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5370 | return; |
| 5371 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5372 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 5373 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 5374 | if (*payload == ELS_CMD_LOGO) { |
| 5375 | fc_host_post_vendor_event(shost, |
| 5376 | fc_get_event_number(), |
| 5377 | sizeof(struct lpfc_logo_event), |
| 5378 | (char *)logo_data, |
| 5379 | LPFC_NL_VENDOR_ID); |
| 5380 | kfree(logo_data); |
| 5381 | } else { |
| 5382 | fc_host_post_vendor_event(shost, |
| 5383 | fc_get_event_number(), |
| 5384 | sizeof(struct lpfc_els_event_header), |
| 5385 | (char *)els_data, |
| 5386 | LPFC_NL_VENDOR_ID); |
| 5387 | kfree(els_data); |
| 5388 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5389 | |
| 5390 | return; |
| 5391 | } |
| 5392 | |
| 5393 | |
| 5394 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5395 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5396 | * @phba: pointer to lpfc hba data structure. |
| 5397 | * @pring: pointer to a SLI ring. |
| 5398 | * @vport: pointer to a host virtual N_Port data structure. |
| 5399 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 5400 | * |
| 5401 | * This routine is used for processing the IOCB associated with a unsolicited |
| 5402 | * event. It first determines whether there is an existing ndlp that matches |
| 5403 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 5404 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 5405 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 5406 | * of the discovery state machine. |
| 5407 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5408 | static void |
| 5409 | 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] | 5410 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5411 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5412 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5413 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5414 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5415 | uint32_t *payload; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5416 | uint32_t cmd, did, newnode, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5417 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5418 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5419 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5420 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5421 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5422 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5423 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 5424 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5425 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5426 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5427 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5428 | did = icmd->un.rcvels.remoteID; |
| 5429 | if (icmd->ulpStatus) { |
| 5430 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5431 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 5432 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5433 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5434 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5435 | |
| 5436 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5437 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5438 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5439 | |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 5440 | /* Ignore traffic received during vport shutdown. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5441 | if (vport->load_flag & FC_UNLOADING) |
| 5442 | goto dropit; |
| 5443 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5444 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5445 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5446 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5447 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5448 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5449 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5450 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5451 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5452 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5453 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5454 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5455 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5456 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5457 | ndlp = lpfc_enable_node(vport, ndlp, |
| 5458 | NLP_STE_UNUSED_NODE); |
| 5459 | if (!ndlp) |
| 5460 | goto dropit; |
| 5461 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5462 | newnode = 1; |
| 5463 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 5464 | ndlp->nlp_type |= NLP_FABRIC; |
| 5465 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 5466 | /* This is similar to the new node path */ |
| 5467 | ndlp = lpfc_nlp_get(ndlp); |
| 5468 | if (!ndlp) |
| 5469 | goto dropit; |
| 5470 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5471 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5472 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5473 | |
| 5474 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5475 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5476 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5477 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5478 | |
| 5479 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 5480 | cmd &= ELS_CMD_MASK; |
| 5481 | } |
| 5482 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5483 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5484 | "0112 ELS command x%x received from NPORT x%x " |
| 5485 | "Data: x%x\n", cmd, did, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5486 | switch (cmd) { |
| 5487 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5488 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5489 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 5490 | did, vport->port_state, ndlp->nlp_flag); |
| 5491 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5492 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5493 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
| 5494 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5495 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5496 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5497 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 5498 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 5499 | rjt_err = LSRJT_UNABLE_TPC; |
| 5500 | break; |
| 5501 | } |
| 5502 | /* We get here, and drop thru, if we are PT2PT with |
| 5503 | * another NPort and the other side has initiated |
| 5504 | * the PLOGI before responding to our FLOGI. |
| 5505 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5506 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5507 | |
| 5508 | shost = lpfc_shost_from_vport(vport); |
| 5509 | spin_lock_irq(shost->host_lock); |
| 5510 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 5511 | spin_unlock_irq(shost->host_lock); |
| 5512 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5513 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5514 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5515 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5516 | break; |
| 5517 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5518 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5519 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 5520 | did, vport->port_state, ndlp->nlp_flag); |
| 5521 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5522 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5523 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5524 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5525 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5526 | break; |
| 5527 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5528 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5529 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 5530 | did, vport->port_state, ndlp->nlp_flag); |
| 5531 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5532 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5533 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5534 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5535 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5536 | break; |
| 5537 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5538 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5539 | break; |
| 5540 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5541 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5542 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 5543 | did, vport->port_state, ndlp->nlp_flag); |
| 5544 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5545 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5546 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5547 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5548 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5549 | break; |
| 5550 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5551 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5552 | break; |
| 5553 | case ELS_CMD_RSCN: |
| 5554 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5555 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5556 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5557 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5558 | break; |
| 5559 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5560 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5561 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 5562 | did, vport->port_state, ndlp->nlp_flag); |
| 5563 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5564 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5565 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5566 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5567 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5568 | break; |
| 5569 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5570 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5571 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5572 | break; |
| 5573 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5574 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5575 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 5576 | did, vport->port_state, ndlp->nlp_flag); |
| 5577 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5578 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5579 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5580 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5581 | break; |
| 5582 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5583 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5584 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5585 | break; |
| 5586 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5587 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5588 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 5589 | did, vport->port_state, ndlp->nlp_flag); |
| 5590 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5591 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5592 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5593 | break; |
| 5594 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5595 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5596 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 5597 | did, vport->port_state, ndlp->nlp_flag); |
| 5598 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5599 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5600 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5601 | break; |
| 5602 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5603 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5604 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 5605 | did, vport->port_state, ndlp->nlp_flag); |
| 5606 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5607 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5608 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5609 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5610 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5611 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5612 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 5613 | did, vport->port_state, ndlp->nlp_flag); |
| 5614 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5615 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5616 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5617 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5618 | break; |
| 5619 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5620 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5621 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5622 | case ELS_CMD_LIRR: |
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 LIRR: did:x%x/ste:x%x flg:x%x", |
| 5625 | did, vport->port_state, ndlp->nlp_flag); |
| 5626 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5627 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5628 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5629 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5630 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5631 | break; |
| 5632 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5633 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5634 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 5635 | did, vport->port_state, ndlp->nlp_flag); |
| 5636 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5637 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5638 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5639 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5640 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5641 | break; |
| 5642 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5643 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5644 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 5645 | did, vport->port_state, ndlp->nlp_flag); |
| 5646 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5647 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5648 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5649 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5650 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5651 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5652 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5653 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5654 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 5655 | did, vport->port_state, ndlp->nlp_flag); |
| 5656 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5657 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5658 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5659 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5660 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5661 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 5662 | case ELS_CMD_RRQ: |
| 5663 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5664 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", |
| 5665 | did, vport->port_state, ndlp->nlp_flag); |
| 5666 | |
| 5667 | phba->fc_stat.elsRcvRRQ++; |
| 5668 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); |
| 5669 | if (newnode) |
| 5670 | lpfc_nlp_put(ndlp); |
| 5671 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5672 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5673 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5674 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 5675 | cmd, did, vport->port_state); |
| 5676 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5677 | /* Unsupported ELS command, reject */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5678 | rjt_err = LSRJT_INVALID_CMD; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5679 | |
| 5680 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5681 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5682 | "0115 Unknown ELS command x%x " |
| 5683 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5684 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5685 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5686 | break; |
| 5687 | } |
| 5688 | |
| 5689 | /* check if need to LS_RJT received ELS cmd */ |
| 5690 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5691 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5692 | stat.un.b.lsRjtRsnCode = rjt_err; |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 5693 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5694 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 5695 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5696 | } |
| 5697 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5698 | lpfc_nlp_put(elsiocb->context1); |
| 5699 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5700 | return; |
| 5701 | |
| 5702 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5703 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5704 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5705 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5706 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5707 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5708 | phba->fc_stat.elsRcvDrop++; |
| 5709 | } |
| 5710 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5711 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5712 | * 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] | 5713 | * @phba: pointer to lpfc hba data structure. |
| 5714 | * @vpi: host virtual N_Port identifier. |
| 5715 | * |
| 5716 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 5717 | * @vpi. The function walks the HBA's vport list and returns the address |
| 5718 | * of the vport with the matching @vpi. |
| 5719 | * |
| 5720 | * Return code |
| 5721 | * NULL - No vport with the matching @vpi found |
| 5722 | * Otherwise - Address to the vport with the matching @vpi. |
| 5723 | **/ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5724 | struct lpfc_vport * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5725 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 5726 | { |
| 5727 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5728 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5729 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5730 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5731 | list_for_each_entry(vport, &phba->port_list, listentry) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5732 | if (vport->vpi == vpi) { |
| 5733 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5734 | return vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5735 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5736 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5737 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5738 | return NULL; |
| 5739 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5740 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5741 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5742 | * 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] | 5743 | * @phba: pointer to lpfc hba data structure. |
| 5744 | * @pring: pointer to a SLI ring. |
| 5745 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 5746 | * |
| 5747 | * This routine is used to process an unsolicited event received from a SLI |
| 5748 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 5749 | * associated with the unsolicited event is done by invoking the routine |
| 5750 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 5751 | * SLI ring on which the unsolicited event was received. |
| 5752 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5753 | void |
| 5754 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 5755 | struct lpfc_iocbq *elsiocb) |
| 5756 | { |
| 5757 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5758 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5759 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5760 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 5761 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5762 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5763 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5764 | elsiocb->context2 = NULL; |
| 5765 | elsiocb->context3 = NULL; |
| 5766 | |
| 5767 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 5768 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 5769 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 5770 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5771 | phba->fc_stat.NoRcvBuf++; |
| 5772 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5773 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5774 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5775 | return; |
| 5776 | } |
| 5777 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5778 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 5779 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 5780 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 5781 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 5782 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5783 | else |
| 5784 | vport = lpfc_find_vport_by_vpid(phba, |
| 5785 | icmd->unsli3.rcvsli3.vpi - phba->vpi_base); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5786 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5787 | /* If there are no BDEs associated |
| 5788 | * with this IOCB, there is nothing to do. |
| 5789 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5790 | if (icmd->ulpBdeCount == 0) |
| 5791 | return; |
| 5792 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5793 | /* type of ELS cmd is first 32bit word |
| 5794 | * in packet |
| 5795 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5796 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5797 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5798 | } else { |
| 5799 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 5800 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5801 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 5802 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5803 | } |
| 5804 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5805 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 5806 | /* |
| 5807 | * The different unsolicited event handlers would tell us |
| 5808 | * if they are done with "mp" by setting context2 to NULL. |
| 5809 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5810 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5811 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 5812 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5813 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5814 | |
| 5815 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5816 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5817 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5818 | elsiocb->context2 = bdeBuf2; |
| 5819 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5820 | /* free mp if we are done with it */ |
| 5821 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5822 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 5823 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5824 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5825 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5826 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5827 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5828 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5829 | * 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] | 5830 | * @phba: pointer to lpfc hba data structure. |
| 5831 | * @vport: pointer to a virtual N_Port data structure. |
| 5832 | * |
| 5833 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 5834 | * State Change Request (SCR) for a @vport. This routine will create an |
| 5835 | * ndlp for the Name Server associated to the @vport if such node does |
| 5836 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 5837 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 5838 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 5839 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 5840 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5841 | void |
| 5842 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 5843 | { |
| 5844 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
| 5845 | |
| 5846 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 5847 | if (!ndlp) { |
| 5848 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 5849 | if (!ndlp) { |
| 5850 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5851 | lpfc_disc_start(vport); |
| 5852 | return; |
| 5853 | } |
| 5854 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5855 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5856 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5857 | return; |
| 5858 | } |
| 5859 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5860 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5861 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 5862 | if (!ndlp) { |
| 5863 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5864 | lpfc_disc_start(vport); |
| 5865 | return; |
| 5866 | } |
| 5867 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5868 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5869 | "0348 NameServer login: node freed\n"); |
| 5870 | return; |
| 5871 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5872 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5873 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5874 | |
| 5875 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 5876 | |
| 5877 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 5878 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5879 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5880 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5881 | return; |
| 5882 | } |
| 5883 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5884 | if (vport->cfg_fdmi_on) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5885 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 5886 | GFP_KERNEL); |
| 5887 | if (ndlp_fdmi) { |
| 5888 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 5889 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5890 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
| 5891 | NLP_STE_PLOGI_ISSUE); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5892 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, |
| 5893 | 0); |
| 5894 | } |
| 5895 | } |
| 5896 | return; |
| 5897 | } |
| 5898 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5899 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5900 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5901 | * @phba: pointer to lpfc hba data structure. |
| 5902 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 5903 | * |
| 5904 | * This routine is the completion callback function to register new vport |
| 5905 | * mailbox command. If the new vport mailbox command completes successfully, |
| 5906 | * the fabric registration login shall be performed on physical port (the |
| 5907 | * new vport created is actually a physical port, with VPI 0) or the port |
| 5908 | * login to Name Server for State Change Request (SCR) will be performed |
| 5909 | * on virtual port (real virtual port, with VPI greater than 0). |
| 5910 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5911 | static void |
| 5912 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 5913 | { |
| 5914 | struct lpfc_vport *vport = pmb->vport; |
| 5915 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5916 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5917 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5918 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5919 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5920 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5921 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5922 | |
| 5923 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5924 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 5925 | "0915 Register VPI failed: 0x%x\n", |
| 5926 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5927 | |
| 5928 | switch (mb->mbxStatus) { |
| 5929 | case 0x11: /* unsupported feature */ |
| 5930 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5931 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5932 | /* giving up on vport registration */ |
| 5933 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5934 | spin_lock_irq(shost->host_lock); |
| 5935 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 5936 | spin_unlock_irq(shost->host_lock); |
| 5937 | lpfc_can_disctmo(vport); |
| 5938 | break; |
| 5939 | default: |
| 5940 | /* Try to recover from this error */ |
| 5941 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5942 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5943 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5944 | spin_unlock_irq(shost->host_lock); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5945 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 5946 | lpfc_initial_flogi(vport); |
| 5947 | else |
| 5948 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5949 | break; |
| 5950 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5951 | } else { |
James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 5952 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5953 | if (vport == phba->pport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5954 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5955 | lpfc_issue_fabric_reglogin(vport); |
| 5956 | else |
| 5957 | lpfc_issue_reg_vfi(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5958 | else |
| 5959 | lpfc_do_scr_ns_plogi(phba, vport); |
| 5960 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5961 | |
| 5962 | /* Now, we decrement the ndlp reference count held for this |
| 5963 | * callback function |
| 5964 | */ |
| 5965 | lpfc_nlp_put(ndlp); |
| 5966 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5967 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5968 | return; |
| 5969 | } |
| 5970 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5971 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5972 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5973 | * @phba: pointer to lpfc hba data structure. |
| 5974 | * @vport: pointer to a host virtual N_Port data structure. |
| 5975 | * @ndlp: pointer to a node-list data structure. |
| 5976 | * |
| 5977 | * This routine registers the @vport as a new virtual port with a HBA. |
| 5978 | * It is done through a registering vpi mailbox command. |
| 5979 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5980 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5981 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 5982 | struct lpfc_nodelist *ndlp) |
| 5983 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5984 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5985 | LPFC_MBOXQ_t *mbox; |
| 5986 | |
| 5987 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5988 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5989 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5990 | mbox->vport = vport; |
| 5991 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 5992 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5993 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5994 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5995 | /* mailbox command not success, decrement ndlp |
| 5996 | * reference count for this command |
| 5997 | */ |
| 5998 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5999 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6000 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6001 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6002 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6003 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6004 | } |
| 6005 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6006 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 6007 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6008 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6009 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6010 | return; |
| 6011 | |
| 6012 | mbox_err_exit: |
| 6013 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6014 | spin_lock_irq(shost->host_lock); |
| 6015 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 6016 | spin_unlock_irq(shost->host_lock); |
| 6017 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6018 | } |
| 6019 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6020 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6021 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6022 | * @phba: pointer to lpfc hba data structure. |
| 6023 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6024 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6025 | * |
| 6026 | * This routine is the completion callback function to a Fabric Discover |
| 6027 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 6028 | * single threaded, each FDISC completion callback function will reset |
| 6029 | * the discovery timer for all vports such that the timers will not get |
| 6030 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 6031 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 6032 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 6033 | * assigned to the vport has been changed with the completion of the FDISC |
| 6034 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 6035 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 6036 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 6037 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 6038 | * Server for State Change Request (SCR). |
| 6039 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6040 | static void |
| 6041 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6042 | struct lpfc_iocbq *rspiocb) |
| 6043 | { |
| 6044 | struct lpfc_vport *vport = cmdiocb->vport; |
| 6045 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6046 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 6047 | struct lpfc_nodelist *np; |
| 6048 | struct lpfc_nodelist *next_np; |
| 6049 | IOCB_t *irsp = &rspiocb->iocb; |
| 6050 | struct lpfc_iocbq *piocb; |
| 6051 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6052 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6053 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 6054 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 6055 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6056 | /* Since all FDISCs are being single threaded, we |
| 6057 | * must reset the discovery timer for ALL vports |
| 6058 | * waiting to send FDISC when one completes. |
| 6059 | */ |
| 6060 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 6061 | lpfc_set_disctmo(piocb->vport); |
| 6062 | } |
| 6063 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6064 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6065 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 6066 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 6067 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6068 | if (irsp->ulpStatus) { |
| 6069 | /* Check for retry */ |
| 6070 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 6071 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6072 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6073 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6074 | "0126 FDISC failed. (%d/%d)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6075 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6076 | goto fdisc_failed; |
| 6077 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6078 | spin_lock_irq(shost->host_lock); |
| 6079 | vport->fc_flag |= FC_FABRIC; |
| 6080 | if (vport->phba->fc_topology == TOPOLOGY_LOOP) |
| 6081 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 6082 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6083 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6084 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 6085 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
| 6086 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 6087 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 6088 | /* If our NportID changed, we need to ensure all |
| 6089 | * remaining NPORTs get unreg_login'ed so we can |
| 6090 | * issue unreg_vpi. |
| 6091 | */ |
| 6092 | list_for_each_entry_safe(np, next_np, |
| 6093 | &vport->fc_nodes, nlp_listp) { |
| 6094 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 6095 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 6096 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 6097 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6098 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6099 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6100 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6101 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6102 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6103 | lpfc_mbx_unreg_vpi(vport); |
| 6104 | spin_lock_irq(shost->host_lock); |
| 6105 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 6106 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6107 | } |
| 6108 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6109 | if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 6110 | lpfc_register_new_vport(phba, vport, ndlp); |
| 6111 | else |
| 6112 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6113 | goto out; |
| 6114 | fdisc_failed: |
| 6115 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6116 | /* Cancel discovery timer */ |
| 6117 | lpfc_can_disctmo(vport); |
| 6118 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6119 | out: |
| 6120 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6121 | } |
| 6122 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6123 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6124 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6125 | * @vport: pointer to a virtual N_Port data structure. |
| 6126 | * @ndlp: pointer to a node-list data structure. |
| 6127 | * @retry: number of retries to the command IOCB. |
| 6128 | * |
| 6129 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 6130 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 6131 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 6132 | * IOCB will be sent off HBA at any given time. |
| 6133 | * |
| 6134 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6135 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6136 | * will be stored into the context1 field of the IOCB for the completion |
| 6137 | * callback function to the FDISC ELS command. |
| 6138 | * |
| 6139 | * Return code |
| 6140 | * 0 - Successfully issued fdisc iocb command |
| 6141 | * 1 - Failed to issue fdisc iocb command |
| 6142 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6143 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6144 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 6145 | uint8_t retry) |
| 6146 | { |
| 6147 | struct lpfc_hba *phba = vport->phba; |
| 6148 | IOCB_t *icmd; |
| 6149 | struct lpfc_iocbq *elsiocb; |
| 6150 | struct serv_parm *sp; |
| 6151 | uint8_t *pcmd; |
| 6152 | uint16_t cmdsize; |
| 6153 | int did = ndlp->nlp_DID; |
| 6154 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6155 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6156 | vport->port_state = LPFC_FDISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6157 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 6158 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 6159 | ELS_CMD_FDISC); |
| 6160 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6161 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6162 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6163 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6164 | return 1; |
| 6165 | } |
| 6166 | |
| 6167 | icmd = &elsiocb->iocb; |
| 6168 | icmd->un.elsreq64.myID = 0; |
| 6169 | icmd->un.elsreq64.fl = 1; |
| 6170 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6171 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 6172 | /* FDISC needs to be 1 for WQE VPI */ |
| 6173 | elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1; |
| 6174 | elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ; |
| 6175 | /* Set the ulpContext to the vpi */ |
| 6176 | elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base; |
| 6177 | } else { |
| 6178 | /* For FDISC, Let FDISC rsp set the NPortID for this VPI */ |
| 6179 | icmd->ulpCt_h = 1; |
| 6180 | icmd->ulpCt_l = 0; |
| 6181 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6182 | |
| 6183 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6184 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 6185 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 6186 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 6187 | sp = (struct serv_parm *) pcmd; |
| 6188 | /* Setup CSPs accordingly for Fabric */ |
| 6189 | sp->cmn.e_d_tov = 0; |
| 6190 | sp->cmn.w2.r_a_tov = 0; |
| 6191 | sp->cls1.classValid = 0; |
| 6192 | sp->cls2.seqDelivery = 1; |
| 6193 | sp->cls3.seqDelivery = 1; |
| 6194 | |
| 6195 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 6196 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 6197 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 6198 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 6199 | memcpy(pcmd, &vport->fc_portname, 8); |
| 6200 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6201 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6202 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 6203 | |
| 6204 | lpfc_set_disctmo(vport); |
| 6205 | |
| 6206 | phba->fc_stat.elsXmitFDISC++; |
| 6207 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 6208 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6209 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6210 | "Issue FDISC: did:x%x", |
| 6211 | did, 0, 0); |
| 6212 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6213 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 6214 | if (rc == IOCB_ERROR) { |
| 6215 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6216 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6217 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6218 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6219 | return 1; |
| 6220 | } |
| 6221 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6222 | return 0; |
| 6223 | } |
| 6224 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6225 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6226 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6227 | * @phba: pointer to lpfc hba data structure. |
| 6228 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6229 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6230 | * |
| 6231 | * This routine is the completion callback function to the issuing of a LOGO |
| 6232 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 6233 | * reference count held on ndlp for this completion function, indicating that |
| 6234 | * the reference to the ndlp is no long needed. Note that the |
| 6235 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 6236 | * callback function and an additional explicit ndlp reference decrementation |
| 6237 | * will trigger the actual release of the ndlp. |
| 6238 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6239 | static void |
| 6240 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6241 | struct lpfc_iocbq *rspiocb) |
| 6242 | { |
| 6243 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6244 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6245 | struct lpfc_nodelist *ndlp; |
| 6246 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6247 | |
| 6248 | irsp = &rspiocb->iocb; |
| 6249 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6250 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 6251 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6252 | |
| 6253 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6254 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6255 | |
| 6256 | /* Trigger the release of the ndlp after logo */ |
| 6257 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6258 | } |
| 6259 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6260 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6261 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6262 | * @vport: pointer to a virtual N_Port data structure. |
| 6263 | * @ndlp: pointer to a node-list data structure. |
| 6264 | * |
| 6265 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 6266 | * |
| 6267 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6268 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6269 | * will be stored into the context1 field of the IOCB for the completion |
| 6270 | * callback function to the LOGO ELS command. |
| 6271 | * |
| 6272 | * Return codes |
| 6273 | * 0 - Successfully issued logo off the @vport |
| 6274 | * 1 - Failed to issue logo off the @vport |
| 6275 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6276 | int |
| 6277 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 6278 | { |
| 6279 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6280 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6281 | IOCB_t *icmd; |
| 6282 | struct lpfc_iocbq *elsiocb; |
| 6283 | uint8_t *pcmd; |
| 6284 | uint16_t cmdsize; |
| 6285 | |
| 6286 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 6287 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 6288 | ELS_CMD_LOGO); |
| 6289 | if (!elsiocb) |
| 6290 | return 1; |
| 6291 | |
| 6292 | icmd = &elsiocb->iocb; |
| 6293 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6294 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 6295 | pcmd += sizeof(uint32_t); |
| 6296 | |
| 6297 | /* Fill in LOGO payload */ |
| 6298 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 6299 | pcmd += sizeof(uint32_t); |
| 6300 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 6301 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6302 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6303 | "Issue LOGO npiv did:x%x flg:x%x", |
| 6304 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 6305 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6306 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 6307 | spin_lock_irq(shost->host_lock); |
| 6308 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 6309 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6310 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 6311 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6312 | spin_lock_irq(shost->host_lock); |
| 6313 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 6314 | spin_unlock_irq(shost->host_lock); |
| 6315 | lpfc_els_free_iocb(phba, elsiocb); |
| 6316 | return 1; |
| 6317 | } |
| 6318 | return 0; |
| 6319 | } |
| 6320 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6321 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6322 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6323 | * @ptr: holder for the timer function associated data. |
| 6324 | * |
| 6325 | * This routine is invoked by the fabric iocb block timer after |
| 6326 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 6327 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 6328 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 6329 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 6330 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 6331 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6332 | void |
| 6333 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 6334 | { |
| 6335 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 6336 | unsigned long iflags; |
| 6337 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6338 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6339 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 6340 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 6341 | if (!tmo_posted) |
| 6342 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 6343 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 6344 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6345 | if (!tmo_posted) |
| 6346 | lpfc_worker_wake_up(phba); |
| 6347 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6348 | } |
| 6349 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6350 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6351 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6352 | * @phba: pointer to lpfc hba data structure. |
| 6353 | * |
| 6354 | * This routine issues one fabric iocb from the driver internal list to |
| 6355 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 6356 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 6357 | * remove one pending fabric iocb from the driver internal list and invokes |
| 6358 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 6359 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6360 | static void |
| 6361 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 6362 | { |
| 6363 | struct lpfc_iocbq *iocb; |
| 6364 | unsigned long iflags; |
| 6365 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6366 | IOCB_t *cmd; |
| 6367 | |
| 6368 | repeat: |
| 6369 | iocb = NULL; |
| 6370 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6371 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6372 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 6373 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 6374 | list); |
| 6375 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6376 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6377 | atomic_inc(&phba->fabric_iocb_count); |
| 6378 | } |
| 6379 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6380 | if (iocb) { |
| 6381 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6382 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6383 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6384 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6385 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6386 | "Fabric sched1: ste:x%x", |
| 6387 | iocb->vport->port_state, 0, 0); |
| 6388 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6389 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6390 | |
| 6391 | if (ret == IOCB_ERROR) { |
| 6392 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6393 | iocb->fabric_iocb_cmpl = NULL; |
| 6394 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6395 | cmd = &iocb->iocb; |
| 6396 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6397 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6398 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 6399 | |
| 6400 | atomic_dec(&phba->fabric_iocb_count); |
| 6401 | goto repeat; |
| 6402 | } |
| 6403 | } |
| 6404 | |
| 6405 | return; |
| 6406 | } |
| 6407 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6408 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6409 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6410 | * @phba: pointer to lpfc hba data structure. |
| 6411 | * |
| 6412 | * This routine unblocks the issuing fabric iocb command. The function |
| 6413 | * will clear the fabric iocb block bit and then invoke the routine |
| 6414 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 6415 | * from the driver internal fabric iocb list. |
| 6416 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6417 | void |
| 6418 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 6419 | { |
| 6420 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6421 | |
| 6422 | lpfc_resume_fabric_iocbs(phba); |
| 6423 | return; |
| 6424 | } |
| 6425 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6426 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6427 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6428 | * @phba: pointer to lpfc hba data structure. |
| 6429 | * |
| 6430 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 6431 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 6432 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 6433 | * fabric iocb will be issued out of the HBA. |
| 6434 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6435 | static void |
| 6436 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 6437 | { |
| 6438 | int blocked; |
| 6439 | |
| 6440 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6441 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6442 | if (!blocked) |
| 6443 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); |
| 6444 | |
| 6445 | return; |
| 6446 | } |
| 6447 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6448 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6449 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6450 | * @phba: pointer to lpfc hba data structure. |
| 6451 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6452 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6453 | * |
| 6454 | * This routine is the callback function that is put to the fabric iocb's |
| 6455 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 6456 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 6457 | * function first restores and invokes the original iocb's callback function |
| 6458 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 6459 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 6460 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6461 | static void |
| 6462 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6463 | struct lpfc_iocbq *rspiocb) |
| 6464 | { |
| 6465 | struct ls_rjt stat; |
| 6466 | |
| 6467 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 6468 | BUG(); |
| 6469 | |
| 6470 | switch (rspiocb->iocb.ulpStatus) { |
| 6471 | case IOSTAT_NPORT_RJT: |
| 6472 | case IOSTAT_FABRIC_RJT: |
| 6473 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 6474 | lpfc_block_fabric_iocbs(phba); |
| 6475 | } |
| 6476 | break; |
| 6477 | |
| 6478 | case IOSTAT_NPORT_BSY: |
| 6479 | case IOSTAT_FABRIC_BSY: |
| 6480 | lpfc_block_fabric_iocbs(phba); |
| 6481 | break; |
| 6482 | |
| 6483 | case IOSTAT_LS_RJT: |
| 6484 | stat.un.lsRjtError = |
| 6485 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 6486 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 6487 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 6488 | lpfc_block_fabric_iocbs(phba); |
| 6489 | break; |
| 6490 | } |
| 6491 | |
| 6492 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 6493 | BUG(); |
| 6494 | |
| 6495 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 6496 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 6497 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6498 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 6499 | |
| 6500 | atomic_dec(&phba->fabric_iocb_count); |
| 6501 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6502 | /* Post any pending iocbs to HBA */ |
| 6503 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6504 | } |
| 6505 | } |
| 6506 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6507 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6508 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6509 | * @phba: pointer to lpfc hba data structure. |
| 6510 | * @iocb: pointer to lpfc command iocb data structure. |
| 6511 | * |
| 6512 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 6513 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 6514 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 6515 | * any given time. As such, this function will first check to see whether there |
| 6516 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 6517 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 6518 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 6519 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 6520 | * |
| 6521 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 6522 | * order. The problem is caused by the construction of the "ready" boolen does |
| 6523 | * not include the condition that the internal fabric IOCB list is empty. As |
| 6524 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 6525 | * ahead of the fabric IOCBs in the internal list. |
| 6526 | * |
| 6527 | * Return code |
| 6528 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 6529 | * IOCB_ERROR - failed to issue fabric iocb |
| 6530 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6531 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6532 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 6533 | { |
| 6534 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6535 | int ready; |
| 6536 | int ret; |
| 6537 | |
| 6538 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 6539 | BUG(); |
| 6540 | |
| 6541 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6542 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 6543 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6544 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6545 | if (ready) |
| 6546 | /* Increment fabric iocb count to hold the position */ |
| 6547 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6548 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6549 | if (ready) { |
| 6550 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6551 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6552 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6553 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6554 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6555 | "Fabric sched2: ste:x%x", |
| 6556 | iocb->vport->port_state, 0, 0); |
| 6557 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6558 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6559 | |
| 6560 | if (ret == IOCB_ERROR) { |
| 6561 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6562 | iocb->fabric_iocb_cmpl = NULL; |
| 6563 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6564 | atomic_dec(&phba->fabric_iocb_count); |
| 6565 | } |
| 6566 | } else { |
| 6567 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6568 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 6569 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6570 | ret = IOCB_SUCCESS; |
| 6571 | } |
| 6572 | return ret; |
| 6573 | } |
| 6574 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6575 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6576 | * 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] | 6577 | * @vport: pointer to a virtual N_Port data structure. |
| 6578 | * |
| 6579 | * This routine aborts all the IOCBs associated with a @vport from the |
| 6580 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6581 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6582 | * list, removes each IOCB associated with the @vport off the list, set the |
| 6583 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6584 | * associated with the IOCB. |
| 6585 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6586 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6587 | { |
| 6588 | LIST_HEAD(completions); |
| 6589 | struct lpfc_hba *phba = vport->phba; |
| 6590 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6591 | |
| 6592 | spin_lock_irq(&phba->hbalock); |
| 6593 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6594 | list) { |
| 6595 | |
| 6596 | if (piocb->vport != vport) |
| 6597 | continue; |
| 6598 | |
| 6599 | list_move_tail(&piocb->list, &completions); |
| 6600 | } |
| 6601 | spin_unlock_irq(&phba->hbalock); |
| 6602 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6603 | /* Cancel all the IOCBs from the completions list */ |
| 6604 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6605 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6606 | } |
| 6607 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6608 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6609 | * 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] | 6610 | * @ndlp: pointer to a node-list data structure. |
| 6611 | * |
| 6612 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 6613 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6614 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6615 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 6616 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6617 | * associated with the IOCB. |
| 6618 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6619 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 6620 | { |
| 6621 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6622 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6623 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6624 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6625 | |
| 6626 | spin_lock_irq(&phba->hbalock); |
| 6627 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6628 | list) { |
| 6629 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 6630 | |
| 6631 | list_move_tail(&piocb->list, &completions); |
| 6632 | } |
| 6633 | } |
| 6634 | spin_unlock_irq(&phba->hbalock); |
| 6635 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6636 | /* Cancel all the IOCBs from the completions list */ |
| 6637 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6638 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6639 | } |
| 6640 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6641 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6642 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6643 | * @phba: pointer to lpfc hba data structure. |
| 6644 | * |
| 6645 | * This routine aborts all the IOCBs currently on the driver internal |
| 6646 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 6647 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 6648 | * list, removes IOCBs off the list, set the status feild to |
| 6649 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 6650 | * the IOCB. |
| 6651 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6652 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 6653 | { |
| 6654 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6655 | |
| 6656 | spin_lock_irq(&phba->hbalock); |
| 6657 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 6658 | spin_unlock_irq(&phba->hbalock); |
| 6659 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6660 | /* Cancel all the IOCBs from the completions list */ |
| 6661 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6662 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6663 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6664 | |
| 6665 | /** |
| 6666 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 6667 | * @phba: pointer to lpfc hba data structure. |
| 6668 | * @axri: pointer to the els xri abort wcqe structure. |
| 6669 | * |
| 6670 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 6671 | * ELS aborted xri. |
| 6672 | **/ |
| 6673 | void |
| 6674 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 6675 | struct sli4_wcqe_xri_aborted *axri) |
| 6676 | { |
| 6677 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
| 6678 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 6679 | unsigned long iflag = 0; |
| 6680 | |
| 6681 | spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, iflag); |
| 6682 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 6683 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 6684 | if (sglq_entry->sli4_xritag == xri) { |
| 6685 | list_del(&sglq_entry->list); |
| 6686 | spin_unlock_irqrestore( |
| 6687 | &phba->sli4_hba.abts_sgl_list_lock, |
| 6688 | iflag); |
| 6689 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 6690 | |
| 6691 | list_add_tail(&sglq_entry->list, |
| 6692 | &phba->sli4_hba.lpfc_sgl_list); |
| 6693 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 6694 | return; |
| 6695 | } |
| 6696 | } |
| 6697 | spin_unlock_irqrestore(&phba->sli4_hba.abts_sgl_list_lock, iflag); |
| 6698 | } |