| 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) && |
| 176 | bf_get(lpfc_fip_flag, &phba->sli4_hba.sli4_flags) && |
| 177 | ((elscmd == ELS_CMD_FLOGI) || |
| 178 | (elscmd == ELS_CMD_FDISC) || |
| 179 | (elscmd == ELS_CMD_LOGO))) |
| 180 | elsiocb->iocb_flag |= LPFC_FIP_ELS; |
| 181 | else |
| 182 | elsiocb->iocb_flag &= ~LPFC_FIP_ELS; |
| 183 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 184 | icmd = &elsiocb->iocb; |
| 185 | |
| 186 | /* fill in BDEs for command */ |
| 187 | /* Allocate buffer for command payload */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 188 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 189 | if (pcmd) |
| 190 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 191 | if (!pcmd || !pcmd->virt) |
| 192 | goto els_iocb_free_pcmb_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 193 | |
| 194 | INIT_LIST_HEAD(&pcmd->list); |
| 195 | |
| 196 | /* Allocate buffer for response payload */ |
| 197 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 198 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 199 | if (prsp) |
| 200 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 201 | &prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 202 | if (!prsp || !prsp->virt) |
| 203 | goto els_iocb_free_prsp_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 204 | INIT_LIST_HEAD(&prsp->list); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 205 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 206 | prsp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 207 | |
| 208 | /* Allocate buffer for Buffer ptr list */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 209 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 210 | if (pbuflist) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 211 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 212 | &pbuflist->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 213 | if (!pbuflist || !pbuflist->virt) |
| 214 | goto els_iocb_free_pbuf_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 215 | |
| 216 | INIT_LIST_HEAD(&pbuflist->list); |
| 217 | |
| 218 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 219 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 220 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 221 | icmd->un.elsreq64.remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 222 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 223 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 224 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 225 | icmd->ulpTimeout = phba->fc_ratov * 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 226 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 227 | icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 228 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; |
| 229 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 230 | icmd->ulpBdeCount = 1; |
| 231 | icmd->ulpLe = 1; |
| 232 | icmd->ulpClass = CLASS3; |
| 233 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 234 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 235 | icmd->un.elsreq64.myID = vport->fc_myDID; |
| 236 | |
| 237 | /* For ELS_REQUEST64_CR, use the VPI by default */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 238 | icmd->ulpContext = vport->vpi + phba->vpi_base; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 239 | icmd->ulpCt_h = 0; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 240 | /* The CT field must be 0=INVALID_RPI for the ECHO cmd */ |
| 241 | if (elscmd == ELS_CMD_ECHO) |
| 242 | icmd->ulpCt_l = 0; /* context = invalid RPI */ |
| 243 | else |
| 244 | icmd->ulpCt_l = 1; /* context = VPI */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 245 | } |
| 246 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 247 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
| 248 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); |
| 249 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); |
| 250 | bpl->tus.f.bdeSize = cmdSize; |
| 251 | bpl->tus.f.bdeFlags = 0; |
| 252 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 253 | |
| 254 | if (expectRsp) { |
| 255 | bpl++; |
| 256 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); |
| 257 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); |
| 258 | bpl->tus.f.bdeSize = FCELSSIZE; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 259 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 260 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 261 | } |
| 262 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 263 | /* prevent preparing iocb with NULL ndlp reference */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 264 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 265 | if (!elsiocb->context1) |
| 266 | goto els_iocb_free_pbuf_exit; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 267 | elsiocb->context2 = pcmd; |
| 268 | elsiocb->context3 = pbuflist; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 269 | elsiocb->retry = retry; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 270 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 271 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
| 272 | |
| 273 | if (prsp) { |
| 274 | list_add(&prsp->list, &pcmd->list); |
| 275 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 276 | if (expectRsp) { |
| 277 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 278 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 279 | "0116 Xmit ELS command x%x to remote " |
| 280 | "NPORT x%x I/O tag: x%x, port state: x%x\n", |
| 281 | elscmd, did, elsiocb->iotag, |
| 282 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 283 | } else { |
| 284 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 285 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 286 | "0117 Xmit ELS response x%x to remote " |
| 287 | "NPORT x%x I/O tag: x%x, size: x%x\n", |
| 288 | elscmd, ndlp->nlp_DID, elsiocb->iotag, |
| 289 | cmdSize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 290 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 291 | return elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 292 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 293 | els_iocb_free_pbuf_exit: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 294 | if (expectRsp) |
| 295 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 296 | kfree(pbuflist); |
| 297 | |
| 298 | els_iocb_free_prsp_exit: |
| 299 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 300 | kfree(prsp); |
| 301 | |
| 302 | els_iocb_free_pcmb_exit: |
| 303 | kfree(pcmd); |
| 304 | lpfc_sli_release_iocbq(phba, elsiocb); |
| 305 | return NULL; |
| 306 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 307 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 308 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 309 | * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 310 | * @vport: pointer to a host virtual N_Port data structure. |
| 311 | * |
| 312 | * This routine issues a fabric registration login for a @vport. An |
| 313 | * active ndlp node with Fabric_DID must already exist for this @vport. |
| 314 | * The routine invokes two mailbox commands to carry out fabric registration |
| 315 | * login through the HBA firmware: the first mailbox command requests the |
| 316 | * HBA to perform link configuration for the @vport; and the second mailbox |
| 317 | * command requests the HBA to perform the actual fabric registration login |
| 318 | * with the @vport. |
| 319 | * |
| 320 | * Return code |
| 321 | * 0 - successfully issued fabric registration login for @vport |
| 322 | * -ENXIO -- failed to issue fabric registration login for @vport |
| 323 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 324 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 325 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
| 326 | { |
| 327 | struct lpfc_hba *phba = vport->phba; |
| 328 | LPFC_MBOXQ_t *mbox; |
| 329 | struct lpfc_dmabuf *mp; |
| 330 | struct lpfc_nodelist *ndlp; |
| 331 | struct serv_parm *sp; |
| 332 | int rc; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 333 | int err = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 334 | |
| 335 | sp = &phba->fc_fabparam; |
| 336 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 337 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 338 | err = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 339 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 340 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 341 | |
| 342 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 343 | if (!mbox) { |
| 344 | err = 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 345 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 346 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 347 | |
| 348 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 349 | lpfc_config_link(phba, mbox); |
| 350 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 351 | mbox->vport = vport; |
| 352 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 353 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 354 | if (rc == MBX_NOT_FINISHED) { |
| 355 | err = 3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 356 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 357 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 358 | |
| 359 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 360 | if (!mbox) { |
| 361 | err = 4; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 362 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 363 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 364 | 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] | 365 | if (rc) { |
| 366 | err = 5; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 367 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 368 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 369 | |
| 370 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; |
| 371 | mbox->vport = vport; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 372 | /* increment the reference count on ndlp to hold reference |
| 373 | * for the callback routine. |
| 374 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 375 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 376 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 377 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 378 | if (rc == MBX_NOT_FINISHED) { |
| 379 | err = 6; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 380 | goto fail_issue_reg_login; |
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 | return 0; |
| 384 | |
| 385 | fail_issue_reg_login: |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 386 | /* decrement the reference count on ndlp just incremented |
| 387 | * for the failed mbox command. |
| 388 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 389 | lpfc_nlp_put(ndlp); |
| 390 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 391 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 392 | kfree(mp); |
| 393 | fail_free_mbox: |
| 394 | mempool_free(mbox, phba->mbox_mem_pool); |
| 395 | |
| 396 | fail: |
| 397 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 398 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 399 | "0249 Cannot issue Register Fabric login: Err %d\n", err); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 400 | return -ENXIO; |
| 401 | } |
| 402 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 403 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 404 | * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login |
| 405 | * @vport: pointer to a host virtual N_Port data structure. |
| 406 | * |
| 407 | * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for |
| 408 | * the @vport. This mailbox command is necessary for FCoE only. |
| 409 | * |
| 410 | * Return code |
| 411 | * 0 - successfully issued REG_VFI for @vport |
| 412 | * A failure code otherwise. |
| 413 | **/ |
| 414 | static int |
| 415 | lpfc_issue_reg_vfi(struct lpfc_vport *vport) |
| 416 | { |
| 417 | struct lpfc_hba *phba = vport->phba; |
| 418 | LPFC_MBOXQ_t *mboxq; |
| 419 | struct lpfc_nodelist *ndlp; |
| 420 | struct serv_parm *sp; |
| 421 | struct lpfc_dmabuf *dmabuf; |
| 422 | int rc = 0; |
| 423 | |
| 424 | sp = &phba->fc_fabparam; |
| 425 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 426 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
| 427 | rc = -ENODEV; |
| 428 | goto fail; |
| 429 | } |
| 430 | |
| 431 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 432 | if (!dmabuf) { |
| 433 | rc = -ENOMEM; |
| 434 | goto fail; |
| 435 | } |
| 436 | dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys); |
| 437 | if (!dmabuf->virt) { |
| 438 | rc = -ENOMEM; |
| 439 | goto fail_free_dmabuf; |
| 440 | } |
| 441 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 442 | if (!mboxq) { |
| 443 | rc = -ENOMEM; |
| 444 | goto fail_free_coherent; |
| 445 | } |
| 446 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 447 | memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam)); |
| 448 | lpfc_reg_vfi(mboxq, vport, dmabuf->phys); |
| 449 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi; |
| 450 | mboxq->vport = vport; |
| 451 | mboxq->context1 = dmabuf; |
| 452 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 453 | if (rc == MBX_NOT_FINISHED) { |
| 454 | rc = -ENXIO; |
| 455 | goto fail_free_mbox; |
| 456 | } |
| 457 | return 0; |
| 458 | |
| 459 | fail_free_mbox: |
| 460 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 461 | fail_free_coherent: |
| 462 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 463 | fail_free_dmabuf: |
| 464 | kfree(dmabuf); |
| 465 | fail: |
| 466 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 467 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 468 | "0289 Issue Register VFI failed: Err %d\n", rc); |
| 469 | return rc; |
| 470 | } |
| 471 | |
| 472 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 473 | * 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] | 474 | * @vport: pointer to a host virtual N_Port data structure. |
| 475 | * @ndlp: pointer to a node-list data structure. |
| 476 | * @sp: pointer to service parameter data structure. |
| 477 | * @irsp: pointer to the IOCB within the lpfc response IOCB. |
| 478 | * |
| 479 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 480 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric |
| 481 | * port in a fabric topology. It properly sets up the parameters to the @ndlp |
| 482 | * from the IOCB response. It also check the newly assigned N_Port ID to the |
| 483 | * @vport against the previously assigned N_Port ID. If it is different from |
| 484 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine |
| 485 | * is invoked on all the remaining nodes with the @vport to unregister the |
| 486 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() |
| 487 | * is invoked to register login to the fabric. |
| 488 | * |
| 489 | * Return code |
| 490 | * 0 - Success (currently, always return 0) |
| 491 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 492 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 493 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 494 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 495 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 496 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 497 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 498 | struct lpfc_nodelist *np; |
| 499 | struct lpfc_nodelist *next_np; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 500 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 501 | spin_lock_irq(shost->host_lock); |
| 502 | vport->fc_flag |= FC_FABRIC; |
| 503 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 504 | |
| 505 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 506 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 507 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 508 | |
| 509 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 510 | |
| 511 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 512 | spin_lock_irq(shost->host_lock); |
| 513 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 514 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 515 | } else { |
| 516 | /* |
| 517 | * If we are a N-port connected to a Fabric, fixup sparam's so |
| 518 | * logins to devices on remote loops work. |
| 519 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 520 | vport->fc_sparam.cmn.altBbCredit = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 521 | } |
| 522 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 523 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 524 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 525 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 526 | ndlp->nlp_class_sup = 0; |
| 527 | if (sp->cls1.classValid) |
| 528 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 529 | if (sp->cls2.classValid) |
| 530 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 531 | if (sp->cls3.classValid) |
| 532 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 533 | if (sp->cls4.classValid) |
| 534 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 535 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 536 | sp->cmn.bbRcvSizeLsb; |
| 537 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 538 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 539 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 540 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 541 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 542 | LOG_ELS | LOG_VPORT, |
| 543 | "1816 FLOGI NPIV supported, " |
| 544 | "response data 0x%x\n", |
| 545 | sp->cmn.response_multiple_NPort); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 546 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 547 | } else { |
| 548 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 549 | to call reg_vnpid atleast for the physcial host */ |
| 550 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 551 | LOG_ELS | LOG_VPORT, |
| 552 | "1817 Fabric does not support NPIV " |
| 553 | "- configuring single port mode.\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 554 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 559 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 560 | |
| 561 | /* If our NportID changed, we need to ensure all |
| 562 | * remaining NPORTs get unreg_login'ed. |
| 563 | */ |
| 564 | list_for_each_entry_safe(np, next_np, |
| 565 | &vport->fc_nodes, nlp_listp) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 566 | if (!NLP_CHK_NODE_ACT(np)) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 567 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 568 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 569 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 570 | continue; |
| 571 | spin_lock_irq(shost->host_lock); |
| 572 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 573 | spin_unlock_irq(shost->host_lock); |
| 574 | lpfc_unreg_rpi(vport, np); |
| 575 | } |
| 576 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 577 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 578 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 579 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 580 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 581 | } |
| 582 | } |
| 583 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 584 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 585 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
| 586 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 587 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 588 | lpfc_register_new_vport(phba, vport, ndlp); |
| 589 | else |
| 590 | lpfc_issue_fabric_reglogin(vport); |
| 591 | } else { |
| 592 | ndlp->nlp_type |= NLP_FABRIC; |
| 593 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| 594 | if (vport->vfi_state & LPFC_VFI_REGISTERED) { |
| 595 | lpfc_start_fdiscs(phba); |
| 596 | lpfc_do_scr_ns_plogi(phba, vport); |
| 597 | } else |
| 598 | lpfc_issue_reg_vfi(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 599 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 600 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 601 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 602 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 603 | * 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] | 604 | * @vport: pointer to a host virtual N_Port data structure. |
| 605 | * @ndlp: pointer to a node-list data structure. |
| 606 | * @sp: pointer to service parameter data structure. |
| 607 | * |
| 608 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 609 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 610 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 611 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 612 | * the received N_Port Name lexicographically, this node shall assign local |
| 613 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 614 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 615 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 616 | * N_Port IDs. |
| 617 | * |
| 618 | * Return code |
| 619 | * 0 - Success |
| 620 | * -ENXIO - Fail |
| 621 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 622 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 623 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 624 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 625 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 626 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 627 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 628 | LPFC_MBOXQ_t *mbox; |
| 629 | int rc; |
| 630 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 631 | spin_lock_irq(shost->host_lock); |
| 632 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 633 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 634 | |
| 635 | phba->fc_edtov = FF_DEF_EDTOV; |
| 636 | phba->fc_ratov = FF_DEF_RATOV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 637 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 638 | sizeof(vport->fc_portname)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 639 | if (rc >= 0) { |
| 640 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 641 | spin_lock_irq(shost->host_lock); |
| 642 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 643 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 644 | |
| 645 | /* |
| 646 | * N_Port ID cannot be 0, set our to LocalID the other |
| 647 | * side will be RemoteID. |
| 648 | */ |
| 649 | |
| 650 | /* not equal */ |
| 651 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 652 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 653 | |
| 654 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 655 | if (!mbox) |
| 656 | goto fail; |
| 657 | |
| 658 | lpfc_config_link(phba, mbox); |
| 659 | |
| 660 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 661 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 662 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 663 | if (rc == MBX_NOT_FINISHED) { |
| 664 | mempool_free(mbox, phba->mbox_mem_pool); |
| 665 | goto fail; |
| 666 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 667 | /* Decrement ndlp reference count indicating that ndlp can be |
| 668 | * safely released when other references to it are done. |
| 669 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 670 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 671 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 672 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 673 | if (!ndlp) { |
| 674 | /* |
| 675 | * Cannot find existing Fabric ndlp, so allocate a |
| 676 | * new one |
| 677 | */ |
| 678 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 679 | if (!ndlp) |
| 680 | goto fail; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 681 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 682 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 683 | ndlp = lpfc_enable_node(vport, ndlp, |
| 684 | NLP_STE_UNUSED_NODE); |
| 685 | if(!ndlp) |
| 686 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 690 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 691 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 692 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 693 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 694 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 695 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 696 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 697 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 698 | } else |
| 699 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 700 | * count indicating that ndlp can be released when other |
| 701 | * references to it are done. |
| 702 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 703 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 704 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 705 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 706 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 707 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 708 | spin_lock_irq(shost->host_lock); |
| 709 | vport->fc_flag |= FC_PT2PT; |
| 710 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 711 | |
| 712 | /* Start discovery - this should just do CLEAR_LA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 713 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 714 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 715 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 716 | return -ENXIO; |
| 717 | } |
| 718 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 719 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 720 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 721 | * @phba: pointer to lpfc hba data structure. |
| 722 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 723 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 724 | * |
| 725 | * This routine is the top-level completion callback function for issuing |
| 726 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 727 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 728 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 729 | * returning 1), the command IOCB will be released and function returned. |
| 730 | * If the retry attempt has been given up (possibly reach the maximum |
| 731 | * number of retries), one additional decrement of ndlp reference shall be |
| 732 | * invoked before going out after releasing the command IOCB. This will |
| 733 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 734 | * invoke one decrement of ndlp reference count). If no error reported in |
| 735 | * the IOCB status, the command Port ID field is used to determine whether |
| 736 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 737 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 738 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 739 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 740 | * specific topology completion conditions. |
| 741 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 742 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 743 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 744 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 745 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 746 | struct lpfc_vport *vport = cmdiocb->vport; |
| 747 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 748 | IOCB_t *irsp = &rspiocb->iocb; |
| 749 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 750 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 751 | struct serv_parm *sp; |
| 752 | int rc; |
| 753 | |
| 754 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 755 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 756 | /* One additional decrement on node reference count to |
| 757 | * trigger the release of the node |
| 758 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 759 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 760 | goto out; |
| 761 | } |
| 762 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 763 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 764 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 765 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 766 | vport->port_state); |
| 767 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 768 | if (irsp->ulpStatus) { |
| 769 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 770 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 771 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 772 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 773 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 774 | spin_lock_irq(shost->host_lock); |
| 775 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 776 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 777 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 778 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 779 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 780 | * alpa map would take too long otherwise. |
| 781 | */ |
| 782 | if (phba->alpa_map[0] == 0) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 783 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | /* FLOGI failure */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 787 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 788 | "0100 FLOGI failure Data: x%x x%x " |
| 789 | "x%x\n", |
| 790 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 791 | irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 792 | goto flogifail; |
| 793 | } |
| 794 | |
| 795 | /* |
| 796 | * The FLogI succeeded. Sync the data for the CPU before |
| 797 | * accessing it. |
| 798 | */ |
| 799 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 800 | |
| 801 | sp = prsp->virt + sizeof(uint32_t); |
| 802 | |
| 803 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 804 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame^] | 805 | "0101 FLOGI completes successfully " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 806 | "Data: x%x x%x x%x x%x\n", |
| 807 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
| 808 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 809 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 810 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 811 | /* |
| 812 | * If Common Service Parameters indicate Nport |
| 813 | * we are point to point, if Fport we are Fabric. |
| 814 | */ |
| 815 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 816 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 817 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 818 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 819 | |
| 820 | if (!rc) |
| 821 | goto out; |
| 822 | } |
| 823 | |
| 824 | flogifail: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 825 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 826 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 827 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 828 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 829 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 830 | |
| 831 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 832 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 833 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 834 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && |
| 835 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) && |
| 836 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 837 | /* If FLOGI failed enable link interrupt. */ |
| 838 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 839 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 840 | out: |
| 841 | lpfc_els_free_iocb(phba, cmdiocb); |
| 842 | } |
| 843 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 844 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 845 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 846 | * @vport: pointer to a host virtual N_Port data structure. |
| 847 | * @ndlp: pointer to a node-list data structure. |
| 848 | * @retry: number of retries to the command IOCB. |
| 849 | * |
| 850 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 851 | * for a @vport. The initiator service parameters are put into the payload |
| 852 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 853 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 854 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 855 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 856 | * |
| 857 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 858 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 859 | * will be stored into the context1 field of the IOCB for the completion |
| 860 | * callback function to the FLOGI ELS command. |
| 861 | * |
| 862 | * Return code |
| 863 | * 0 - successfully issued flogi iocb for @vport |
| 864 | * 1 - failed to issue flogi iocb for @vport |
| 865 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 866 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 867 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 868 | uint8_t retry) |
| 869 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 870 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 871 | struct serv_parm *sp; |
| 872 | IOCB_t *icmd; |
| 873 | struct lpfc_iocbq *elsiocb; |
| 874 | struct lpfc_sli_ring *pring; |
| 875 | uint8_t *pcmd; |
| 876 | uint16_t cmdsize; |
| 877 | uint32_t tmo; |
| 878 | int rc; |
| 879 | |
| 880 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 881 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 882 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 883 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 884 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 885 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 886 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 887 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 888 | |
| 889 | icmd = &elsiocb->iocb; |
| 890 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 891 | |
| 892 | /* For FLOGI request, remainder of payload is service parameters */ |
| 893 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 894 | pcmd += sizeof(uint32_t); |
| 895 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 896 | sp = (struct serv_parm *) pcmd; |
| 897 | |
| 898 | /* Setup CSPs accordingly for Fabric */ |
| 899 | sp->cmn.e_d_tov = 0; |
| 900 | sp->cmn.w2.r_a_tov = 0; |
| 901 | sp->cls1.classValid = 0; |
| 902 | sp->cls2.seqDelivery = 1; |
| 903 | sp->cls3.seqDelivery = 1; |
| 904 | if (sp->cmn.fcphLow < FC_PH3) |
| 905 | sp->cmn.fcphLow = FC_PH3; |
| 906 | if (sp->cmn.fcphHigh < FC_PH3) |
| 907 | sp->cmn.fcphHigh = FC_PH3; |
| 908 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 909 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 910 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 911 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 912 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 913 | /* Set the fcfi to the fcfi we registered with */ |
| 914 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 915 | } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 916 | sp->cmn.request_multiple_Nport = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 917 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 918 | icmd->ulpCt_h = 1; |
| 919 | icmd->ulpCt_l = 0; |
| 920 | } |
| 921 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 922 | if (phba->fc_topology != TOPOLOGY_LOOP) { |
| 923 | icmd->un.elsreq64.myID = 0; |
| 924 | icmd->un.elsreq64.fl = 1; |
| 925 | } |
| 926 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 927 | tmo = phba->fc_ratov; |
| 928 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 929 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 930 | phba->fc_ratov = tmo; |
| 931 | |
| 932 | phba->fc_stat.elsXmitFLOGI++; |
| 933 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 934 | |
| 935 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 936 | "Issue FLOGI: opt:x%x", |
| 937 | phba->sli3_options, 0, 0); |
| 938 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 939 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 940 | if (rc == IOCB_ERROR) { |
| 941 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 942 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 943 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 944 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 945 | } |
| 946 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 947 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 948 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 949 | * @phba: pointer to lpfc hba data structure. |
| 950 | * |
| 951 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 952 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 953 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 954 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 955 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 956 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 957 | * |
| 958 | * Return code |
| 959 | * 0 - Sucessfully issued abort iocb on all outstanding flogis (Always 0) |
| 960 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 961 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 962 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 963 | { |
| 964 | struct lpfc_sli_ring *pring; |
| 965 | struct lpfc_iocbq *iocb, *next_iocb; |
| 966 | struct lpfc_nodelist *ndlp; |
| 967 | IOCB_t *icmd; |
| 968 | |
| 969 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 970 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 971 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 972 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 973 | |
| 974 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 975 | |
| 976 | /* |
| 977 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 978 | * searching for. |
| 979 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 980 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 981 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 982 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 983 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR && |
| 984 | icmd->un.elsreq64.bdl.ulpIoTag32) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 985 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 986 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 987 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 988 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 989 | } |
| 990 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 991 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 992 | |
| 993 | return 0; |
| 994 | } |
| 995 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 996 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 997 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 998 | * @vport: pointer to a host virtual N_Port data structure. |
| 999 | * |
| 1000 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 1001 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1002 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1003 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1004 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 1005 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 1006 | * @vport. |
| 1007 | * |
| 1008 | * Return code |
| 1009 | * 0 - failed to issue initial flogi for @vport |
| 1010 | * 1 - successfully issued initial flogi for @vport |
| 1011 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1012 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1013 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1014 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1015 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1016 | struct lpfc_nodelist *ndlp; |
| 1017 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1018 | vport->port_state = LPFC_FLOGI; |
| 1019 | lpfc_set_disctmo(vport); |
| 1020 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1021 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1022 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1023 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1024 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1025 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1026 | if (!ndlp) |
| 1027 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1028 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1029 | /* Set the node type */ |
| 1030 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1031 | /* Put ndlp onto node list */ |
| 1032 | lpfc_enqueue_node(vport, ndlp); |
| 1033 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1034 | /* re-setup ndlp without removing from node list */ |
| 1035 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1036 | if (!ndlp) |
| 1037 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1038 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1039 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1040 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1041 | /* This decrement of reference count to node shall kick off |
| 1042 | * the release of the node. |
| 1043 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1044 | lpfc_nlp_put(ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1045 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1046 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1047 | } |
| 1048 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1049 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1050 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1051 | * @vport: pointer to a host virtual N_Port data structure. |
| 1052 | * |
| 1053 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 1054 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1055 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1056 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1057 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 1058 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 1059 | * @vport. |
| 1060 | * |
| 1061 | * Return code |
| 1062 | * 0 - failed to issue initial fdisc for @vport |
| 1063 | * 1 - successfully issued initial fdisc for @vport |
| 1064 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1065 | int |
| 1066 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 1067 | { |
| 1068 | struct lpfc_hba *phba = vport->phba; |
| 1069 | struct lpfc_nodelist *ndlp; |
| 1070 | |
| 1071 | /* First look for the Fabric ndlp */ |
| 1072 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1073 | if (!ndlp) { |
| 1074 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 1075 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1076 | if (!ndlp) |
| 1077 | return 0; |
| 1078 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1079 | /* Put ndlp onto node list */ |
| 1080 | lpfc_enqueue_node(vport, ndlp); |
| 1081 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1082 | /* re-setup ndlp without removing from node list */ |
| 1083 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1084 | if (!ndlp) |
| 1085 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1086 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1087 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1088 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1089 | /* decrement node reference count to trigger the release of |
| 1090 | * the node. |
| 1091 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1092 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1093 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1094 | } |
| 1095 | return 1; |
| 1096 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1097 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1098 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1099 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1100 | * @vport: pointer to a host virtual N_Port data structure. |
| 1101 | * |
| 1102 | * This routine checks whether there are more remaining Port Logins |
| 1103 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1104 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1105 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1106 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1107 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1108 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1109 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1110 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1111 | { |
| 1112 | int sentplogi; |
| 1113 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1114 | if (vport->num_disc_nodes) |
| 1115 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1116 | |
| 1117 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1118 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1119 | "0232 Continue discovery with %d PLOGIs to go " |
| 1120 | "Data: x%x x%x x%x\n", |
| 1121 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1122 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1123 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1124 | if (vport->fc_flag & FC_NLP_MORE) |
| 1125 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 1126 | sentplogi = lpfc_els_disc_plogi(vport); |
| 1127 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1128 | return; |
| 1129 | } |
| 1130 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1131 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1132 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1133 | * @phba: pointer to lpfc hba data structure. |
| 1134 | * @prsp: pointer to response IOCB payload. |
| 1135 | * @ndlp: pointer to a node-list data structure. |
| 1136 | * |
| 1137 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1138 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1139 | * The following cases are considered N_Port confirmed: |
| 1140 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1141 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1142 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1143 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1144 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1145 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1146 | * on that node to release the RPI associated with the node; 2) if there is |
| 1147 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1148 | * into, a new node shall be allocated (or activated). In either case, the |
| 1149 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1150 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1151 | * its pointer returned as the confirmed node. |
| 1152 | * |
| 1153 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1154 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1155 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1156 | * into an inactive state on the vport node list and the vport node list |
| 1157 | * management algorithm does not allow two node with a same DID. |
| 1158 | * |
| 1159 | * Return code |
| 1160 | * pointer to the PLOGI N_Port @ndlp |
| 1161 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1162 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1163 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1164 | struct lpfc_nodelist *ndlp) |
| 1165 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1166 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1167 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1168 | struct lpfc_rport_data *rdata; |
| 1169 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1170 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1171 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1172 | uint32_t rc, keepDID = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1173 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1174 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1175 | * by WWPN. Just return the ndlp that was given to us. |
| 1176 | */ |
| 1177 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1178 | return ndlp; |
| 1179 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1180 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1181 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1182 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1183 | /* 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] | 1184 | * we have for that ndlp. If not, we have some work to do. |
| 1185 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1186 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1187 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1188 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1189 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1190 | |
| 1191 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1192 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1193 | sizeof(struct lpfc_name)); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1194 | if (!rc) |
| 1195 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1196 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
| 1197 | if (!new_ndlp) |
| 1198 | return ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1199 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1200 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1201 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1202 | sizeof(struct lpfc_name)); |
| 1203 | if (!rc) |
| 1204 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1205 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1206 | NLP_STE_UNUSED_NODE); |
| 1207 | if (!new_ndlp) |
| 1208 | return ndlp; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1209 | keepDID = new_ndlp->nlp_DID; |
| 1210 | } else |
| 1211 | keepDID = new_ndlp->nlp_DID; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1212 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1213 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1214 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1215 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1216 | |
| 1217 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) |
| 1218 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 1219 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 1220 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1221 | /* 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] | 1222 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1223 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1224 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1225 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1226 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1227 | * to put ndlp on UNUSED list and try to free it. |
| 1228 | */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1229 | |
| 1230 | /* Fix up the rport accordingly */ |
| 1231 | rport = ndlp->rport; |
| 1232 | if (rport) { |
| 1233 | rdata = rport->dd_data; |
| 1234 | if (rdata->pnode == ndlp) { |
| 1235 | lpfc_nlp_put(ndlp); |
| 1236 | ndlp->rport = NULL; |
| 1237 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1238 | new_ndlp->rport = rport; |
| 1239 | } |
| 1240 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1241 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1242 | /* We shall actually free the ndlp with both nlp_DID and |
| 1243 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1244 | * nodelist never to be used. |
| 1245 | */ |
| 1246 | if (ndlp->nlp_DID == 0) { |
| 1247 | spin_lock_irq(&phba->ndlp_lock); |
| 1248 | NLP_SET_FREE_REQ(ndlp); |
| 1249 | spin_unlock_irq(&phba->ndlp_lock); |
| 1250 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1251 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1252 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1253 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1254 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1255 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1256 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1257 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1258 | /* Two ndlps cannot have the same did */ |
| 1259 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1260 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1261 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1262 | return new_ndlp; |
| 1263 | } |
| 1264 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1265 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1266 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1267 | * @vport: pointer to a host virtual N_Port data structure. |
| 1268 | * |
| 1269 | * This routine checks whether more Registration State Change |
| 1270 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1271 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1272 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1273 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1274 | * handling the RSCNs. |
| 1275 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1276 | void |
| 1277 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1278 | { |
| 1279 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1280 | |
| 1281 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1282 | /* |
| 1283 | * Check to see if more RSCNs came in while we were |
| 1284 | * processing this one. |
| 1285 | */ |
| 1286 | if (vport->fc_rscn_id_cnt || |
| 1287 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1288 | lpfc_els_handle_rscn(vport); |
| 1289 | else { |
| 1290 | spin_lock_irq(shost->host_lock); |
| 1291 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1292 | spin_unlock_irq(shost->host_lock); |
| 1293 | } |
| 1294 | } |
| 1295 | } |
| 1296 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1297 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1298 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1299 | * @phba: pointer to lpfc hba data structure. |
| 1300 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1301 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1302 | * |
| 1303 | * This routine is the completion callback function for issuing the Port |
| 1304 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1305 | * ndlp on the vport node list that matches the remote node ID from the |
| 1306 | * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply |
| 1307 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1308 | * checked for error conditons. If there is error status reported, PLOGI |
| 1309 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1310 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1311 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1312 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1313 | * there are additional N_Port nodes with the vport that need to perform |
| 1314 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1315 | * PLOGIs. |
| 1316 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1317 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1318 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1319 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1320 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1321 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1322 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1323 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1324 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1325 | struct lpfc_dmabuf *prsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1326 | int disc, rc, did, type; |
| 1327 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1328 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1329 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1330 | |
| 1331 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1332 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1333 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1334 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1335 | irsp->un.elsreq64.remoteID); |
| 1336 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1337 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1338 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1339 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1340 | "0136 PLOGI completes to NPort x%x " |
| 1341 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1342 | irsp->un.elsreq64.remoteID, |
| 1343 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1344 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1345 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1346 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1347 | |
| 1348 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1349 | * is being used during discovery. |
| 1350 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1351 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1352 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1353 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1354 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1355 | rc = 0; |
| 1356 | |
| 1357 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1358 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1359 | "0102 PLOGI completes to NPort x%x " |
| 1360 | "Data: x%x x%x x%x x%x x%x\n", |
| 1361 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1362 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1363 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1364 | if (lpfc_els_chk_latt(vport)) { |
| 1365 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -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 | goto out; |
| 1369 | } |
| 1370 | |
| 1371 | /* ndlp could be freed in DSM, save these values now */ |
| 1372 | type = ndlp->nlp_type; |
| 1373 | did = ndlp->nlp_DID; |
| 1374 | |
| 1375 | if (irsp->ulpStatus) { |
| 1376 | /* Check for retry */ |
| 1377 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1378 | /* ELS command is being retried */ |
| 1379 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1380 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1381 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1382 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1383 | } |
| 1384 | goto out; |
| 1385 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1386 | /* PLOGI failed */ |
| 1387 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1388 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1389 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1390 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1391 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1392 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1393 | } else { |
| 1394 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1395 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1396 | cmdiocb->context2)->list.next, |
| 1397 | struct lpfc_dmabuf, list); |
| 1398 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1399 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1400 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1401 | } |
| 1402 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1403 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1404 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1405 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1406 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1407 | if (vport->num_disc_nodes == 0) { |
| 1408 | spin_lock_irq(shost->host_lock); |
| 1409 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1410 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1411 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1412 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1413 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1414 | } |
| 1415 | } |
| 1416 | |
| 1417 | out: |
| 1418 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1419 | return; |
| 1420 | } |
| 1421 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1422 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1423 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1424 | * @vport: pointer to a host virtual N_Port data structure. |
| 1425 | * @did: destination port identifier. |
| 1426 | * @retry: number of retries to the command IOCB. |
| 1427 | * |
| 1428 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1429 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1430 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1431 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1432 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1433 | * |
| 1434 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1435 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1436 | * will be stored into the context1 field of the IOCB for the completion |
| 1437 | * callback function to the PLOGI ELS command. |
| 1438 | * |
| 1439 | * Return code |
| 1440 | * 0 - Successfully issued a plogi for @vport |
| 1441 | * 1 - failed to issue a plogi for @vport |
| 1442 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1443 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1444 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1445 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1446 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1447 | struct serv_parm *sp; |
| 1448 | IOCB_t *icmd; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1449 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1450 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1451 | struct lpfc_sli *psli; |
| 1452 | uint8_t *pcmd; |
| 1453 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1454 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1455 | |
| 1456 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1457 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1458 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1459 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1460 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1461 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1462 | /* 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] | 1463 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1464 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1465 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1466 | if (!elsiocb) |
| 1467 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1468 | |
| 1469 | icmd = &elsiocb->iocb; |
| 1470 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1471 | |
| 1472 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1473 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1474 | pcmd += sizeof(uint32_t); |
| 1475 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1476 | sp = (struct serv_parm *) pcmd; |
| 1477 | |
| 1478 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1479 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1480 | |
| 1481 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1482 | sp->cmn.fcphHigh = FC_PH3; |
| 1483 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1484 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1485 | "Issue PLOGI: did:x%x", |
| 1486 | did, 0, 0); |
| 1487 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1488 | phba->fc_stat.elsXmitPLOGI++; |
| 1489 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1490 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1491 | |
| 1492 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1493 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1494 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1495 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1496 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1497 | } |
| 1498 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1499 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1500 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1501 | * @phba: pointer to lpfc hba data structure. |
| 1502 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1503 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1504 | * |
| 1505 | * This routine is the completion callback function for a Process Login |
| 1506 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 1507 | * status. If there is error status reported, PRLI retry shall be attempted |
| 1508 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 1509 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 1510 | * ndlp to mark the PRLI completion. |
| 1511 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1512 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1513 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1514 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1515 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1516 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1517 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1518 | IOCB_t *irsp; |
| 1519 | struct lpfc_sli *psli; |
| 1520 | struct lpfc_nodelist *ndlp; |
| 1521 | |
| 1522 | psli = &phba->sli; |
| 1523 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1524 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1525 | |
| 1526 | irsp = &(rspiocb->iocb); |
| 1527 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1528 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1529 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1530 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1531 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1532 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1533 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 1534 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1535 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1536 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1537 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1538 | "0103 PRLI completes to NPort x%x " |
| 1539 | "Data: x%x x%x x%x x%x\n", |
| 1540 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1541 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1542 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1543 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1544 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1545 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1546 | goto out; |
| 1547 | |
| 1548 | if (irsp->ulpStatus) { |
| 1549 | /* Check for retry */ |
| 1550 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1551 | /* ELS command is being retried */ |
| 1552 | goto out; |
| 1553 | } |
| 1554 | /* PRLI failed */ |
| 1555 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1556 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1557 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1558 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1559 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1560 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1561 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1562 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1563 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1564 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1565 | out: |
| 1566 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1567 | return; |
| 1568 | } |
| 1569 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1570 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1571 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1572 | * @vport: pointer to a host virtual N_Port data structure. |
| 1573 | * @ndlp: pointer to a node-list data structure. |
| 1574 | * @retry: number of retries to the command IOCB. |
| 1575 | * |
| 1576 | * This routine issues a Process Login (PRLI) ELS command for the |
| 1577 | * @vport. The PRLI service parameters are set up in the payload of the |
| 1578 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 1579 | * is put to the IOCB completion callback func field before invoking the |
| 1580 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 1581 | * |
| 1582 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1583 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1584 | * will be stored into the context1 field of the IOCB for the completion |
| 1585 | * callback function to the PRLI ELS command. |
| 1586 | * |
| 1587 | * Return code |
| 1588 | * 0 - successfully issued prli iocb command for @vport |
| 1589 | * 1 - failed to issue prli iocb command for @vport |
| 1590 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1591 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1592 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1593 | uint8_t retry) |
| 1594 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1595 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1596 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1597 | PRLI *npr; |
| 1598 | IOCB_t *icmd; |
| 1599 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1600 | uint8_t *pcmd; |
| 1601 | uint16_t cmdsize; |
| 1602 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1603 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1604 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1605 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1606 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1607 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1608 | |
| 1609 | icmd = &elsiocb->iocb; |
| 1610 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1611 | |
| 1612 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1613 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1614 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1615 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1616 | |
| 1617 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 1618 | npr = (PRLI *) pcmd; |
| 1619 | /* |
| 1620 | * If our firmware version is 3.20 or later, |
| 1621 | * set the following bits for FC-TAPE support. |
| 1622 | */ |
| 1623 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 1624 | npr->ConfmComplAllowed = 1; |
| 1625 | npr->Retry = 1; |
| 1626 | npr->TaskRetryIdReq = 1; |
| 1627 | } |
| 1628 | npr->estabImagePair = 1; |
| 1629 | npr->readXferRdyDis = 1; |
| 1630 | |
| 1631 | /* For FCP support */ |
| 1632 | npr->prliType = PRLI_FCP_TYPE; |
| 1633 | npr->initiatorFunc = 1; |
| 1634 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1635 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1636 | "Issue PRLI: did:x%x", |
| 1637 | ndlp->nlp_DID, 0, 0); |
| 1638 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1639 | phba->fc_stat.elsXmitPRLI++; |
| 1640 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1641 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1642 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1643 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1644 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 1645 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1646 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1647 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1648 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1649 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1650 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1651 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1652 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1653 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1654 | } |
| 1655 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1656 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1657 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1658 | * @vport: pointer to a host virtual N_Port data structure. |
| 1659 | * |
| 1660 | * This routine performs Registration State Change Notification (RSCN) |
| 1661 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 1662 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 1663 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 1664 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 1665 | * invoked to check and handle possible more RSCN came in during the period |
| 1666 | * of processing the current ones. |
| 1667 | **/ |
| 1668 | static void |
| 1669 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 1670 | { |
| 1671 | lpfc_can_disctmo(vport); |
| 1672 | |
| 1673 | /* RSCN discovery */ |
| 1674 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 1675 | if (vport->fc_npr_cnt) |
| 1676 | if (lpfc_els_disc_plogi(vport)) |
| 1677 | return; |
| 1678 | |
| 1679 | lpfc_end_rscn(vport); |
| 1680 | } |
| 1681 | |
| 1682 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1683 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1684 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 1685 | * |
| 1686 | * This function is called when the final ADISC is completed during discovery. |
| 1687 | * This function handles clearing link attention or issuing reg_vpi depending |
| 1688 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 1689 | * discovery. |
| 1690 | * This function is called with no locks held. |
| 1691 | **/ |
| 1692 | static void |
| 1693 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 1694 | { |
| 1695 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1696 | struct lpfc_hba *phba = vport->phba; |
| 1697 | |
| 1698 | /* |
| 1699 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 1700 | * and continue discovery. |
| 1701 | */ |
| 1702 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1703 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 1704 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1705 | lpfc_issue_reg_vpi(phba, vport); |
| 1706 | return; |
| 1707 | } |
| 1708 | /* |
| 1709 | * For SLI2, we need to set port_state to READY |
| 1710 | * and continue discovery. |
| 1711 | */ |
| 1712 | if (vport->port_state < LPFC_VPORT_READY) { |
| 1713 | /* If we get here, there is nothing to ADISC */ |
| 1714 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1715 | lpfc_issue_clear_la(phba, vport); |
| 1716 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 1717 | vport->num_disc_nodes = 0; |
| 1718 | /* go thru NPR list, issue ELS PLOGIs */ |
| 1719 | if (vport->fc_npr_cnt) |
| 1720 | lpfc_els_disc_plogi(vport); |
| 1721 | if (!vport->num_disc_nodes) { |
| 1722 | spin_lock_irq(shost->host_lock); |
| 1723 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1724 | spin_unlock_irq(shost->host_lock); |
| 1725 | lpfc_can_disctmo(vport); |
| 1726 | lpfc_end_rscn(vport); |
| 1727 | } |
| 1728 | } |
| 1729 | vport->port_state = LPFC_VPORT_READY; |
| 1730 | } else |
| 1731 | lpfc_rscn_disc(vport); |
| 1732 | } |
| 1733 | |
| 1734 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1735 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1736 | * @vport: pointer to a host virtual N_Port data structure. |
| 1737 | * |
| 1738 | * This routine determines whether there are more ndlps on a @vport |
| 1739 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 1740 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 1741 | * remaining nodes which need to have ADISC sent. |
| 1742 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1743 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1744 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1745 | { |
| 1746 | int sentadisc; |
| 1747 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1748 | if (vport->num_disc_nodes) |
| 1749 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1750 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1751 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1752 | "0210 Continue discovery with %d ADISCs to go " |
| 1753 | "Data: x%x x%x x%x\n", |
| 1754 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 1755 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1756 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1757 | if (vport->fc_flag & FC_NLP_MORE) { |
| 1758 | lpfc_set_disctmo(vport); |
| 1759 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 1760 | sentadisc = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1761 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1762 | if (!vport->num_disc_nodes) |
| 1763 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1764 | return; |
| 1765 | } |
| 1766 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1767 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1768 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1769 | * @phba: pointer to lpfc hba data structure. |
| 1770 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1771 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1772 | * |
| 1773 | * This routine is the completion function for issuing the Address Discover |
| 1774 | * (ADISC) command. It first checks to see whether link went down during |
| 1775 | * the discovery process. If so, the node will be marked as node port |
| 1776 | * recovery for issuing discover IOCB by the link attention handler and |
| 1777 | * exit. Otherwise, the response status is checked. If error was reported |
| 1778 | * in the response status, the ADISC command shall be retried by invoking |
| 1779 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 1780 | * the response status, the state machine is invoked to set transition |
| 1781 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 1782 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1783 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1784 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1785 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1786 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1787 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1788 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1789 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1790 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1791 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1792 | |
| 1793 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1794 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1795 | |
| 1796 | irsp = &(rspiocb->iocb); |
| 1797 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1798 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1799 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1800 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 1801 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1802 | ndlp->nlp_DID); |
| 1803 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1804 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1805 | * is being used during discovery. |
| 1806 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1807 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1808 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1809 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1810 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1811 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1812 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1813 | "0104 ADISC completes to NPort x%x " |
| 1814 | "Data: x%x x%x x%x x%x x%x\n", |
| 1815 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1816 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1817 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1818 | if (lpfc_els_chk_latt(vport)) { |
| 1819 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1820 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1821 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1822 | goto out; |
| 1823 | } |
| 1824 | |
| 1825 | if (irsp->ulpStatus) { |
| 1826 | /* Check for retry */ |
| 1827 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1828 | /* ELS command is being retried */ |
| 1829 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1830 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1831 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1832 | spin_unlock_irq(shost->host_lock); |
| 1833 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1834 | } |
| 1835 | goto out; |
| 1836 | } |
| 1837 | /* ADISC failed */ |
| 1838 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1839 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1840 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1841 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1842 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1843 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1844 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1845 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1846 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1847 | /* Check to see if there are more ADISCs to be sent */ |
| 1848 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1849 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1850 | out: |
| 1851 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1852 | return; |
| 1853 | } |
| 1854 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1855 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1856 | * 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] | 1857 | * @vport: pointer to a virtual N_Port data structure. |
| 1858 | * @ndlp: pointer to a node-list data structure. |
| 1859 | * @retry: number of retries to the command IOCB. |
| 1860 | * |
| 1861 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 1862 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 1863 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 1864 | * to issue the ADISC ELS command. |
| 1865 | * |
| 1866 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1867 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1868 | * will be stored into the context1 field of the IOCB for the completion |
| 1869 | * callback function to the ADISC ELS command. |
| 1870 | * |
| 1871 | * Return code |
| 1872 | * 0 - successfully issued adisc |
| 1873 | * 1 - failed to issue adisc |
| 1874 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1875 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1876 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1877 | uint8_t retry) |
| 1878 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1879 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1880 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1881 | ADISC *ap; |
| 1882 | IOCB_t *icmd; |
| 1883 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1884 | uint8_t *pcmd; |
| 1885 | uint16_t cmdsize; |
| 1886 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1887 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1888 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1889 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1890 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1891 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1892 | |
| 1893 | icmd = &elsiocb->iocb; |
| 1894 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1895 | |
| 1896 | /* For ADISC request, remainder of payload is service parameters */ |
| 1897 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1898 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1899 | |
| 1900 | /* Fill in ADISC payload */ |
| 1901 | ap = (ADISC *) pcmd; |
| 1902 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1903 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 1904 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1905 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1906 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1907 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1908 | "Issue ADISC: did:x%x", |
| 1909 | ndlp->nlp_DID, 0, 0); |
| 1910 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1911 | phba->fc_stat.elsXmitADISC++; |
| 1912 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1913 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1914 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1915 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1916 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 1917 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1918 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1919 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1920 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1921 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1922 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1923 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1924 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1925 | } |
| 1926 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1927 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1928 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1929 | * @phba: pointer to lpfc hba data structure. |
| 1930 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1931 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1932 | * |
| 1933 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 1934 | * command. If no error status was reported from the LOGO response, the |
| 1935 | * state machine of the associated ndlp shall be invoked for transition with |
| 1936 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 1937 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 1938 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1939 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1940 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1941 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1942 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1943 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 1944 | struct lpfc_vport *vport = ndlp->vport; |
| 1945 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1946 | IOCB_t *irsp; |
| 1947 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1948 | |
| 1949 | psli = &phba->sli; |
| 1950 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1951 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1952 | |
| 1953 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1954 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1955 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1956 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1957 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1958 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1959 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 1960 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1961 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1962 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1963 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1964 | "0105 LOGO completes to NPort x%x " |
| 1965 | "Data: x%x x%x x%x x%x\n", |
| 1966 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1967 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1968 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1969 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1970 | goto out; |
| 1971 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1972 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 1973 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 1974 | * which should abort all outstanding IOs. |
| 1975 | */ |
| 1976 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 1977 | NLP_EVT_DEVICE_RM); |
| 1978 | goto out; |
| 1979 | } |
| 1980 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1981 | if (irsp->ulpStatus) { |
| 1982 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1983 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1984 | /* ELS command is being retried */ |
| 1985 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1986 | /* LOGO failed */ |
| 1987 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1988 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1989 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1990 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1991 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1992 | NLP_EVT_CMPL_LOGO); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1993 | } else |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1994 | /* Good status, call state machine. |
| 1995 | * This will unregister the rpi if needed. |
| 1996 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1997 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1998 | NLP_EVT_CMPL_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1999 | out: |
| 2000 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2001 | return; |
| 2002 | } |
| 2003 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2004 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2005 | * 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] | 2006 | * @vport: pointer to a virtual N_Port data structure. |
| 2007 | * @ndlp: pointer to a node-list data structure. |
| 2008 | * @retry: number of retries to the command IOCB. |
| 2009 | * |
| 2010 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 2011 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 2012 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2013 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2014 | * |
| 2015 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2016 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2017 | * will be stored into the context1 field of the IOCB for the completion |
| 2018 | * callback function to the LOGO ELS command. |
| 2019 | * |
| 2020 | * Return code |
| 2021 | * 0 - successfully issued logo |
| 2022 | * 1 - failed to issue logo |
| 2023 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2024 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2025 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2026 | uint8_t retry) |
| 2027 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2028 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2029 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2030 | IOCB_t *icmd; |
| 2031 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2032 | uint8_t *pcmd; |
| 2033 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2034 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2035 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2036 | spin_lock_irq(shost->host_lock); |
| 2037 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2038 | spin_unlock_irq(shost->host_lock); |
| 2039 | return 0; |
| 2040 | } |
| 2041 | spin_unlock_irq(shost->host_lock); |
| 2042 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2043 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2044 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2045 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2046 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2047 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2048 | |
| 2049 | icmd = &elsiocb->iocb; |
| 2050 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2051 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2052 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2053 | |
| 2054 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2055 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2056 | pcmd += sizeof(uint32_t); |
| 2057 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2058 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2059 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2060 | "Issue LOGO: did:x%x", |
| 2061 | ndlp->nlp_DID, 0, 0); |
| 2062 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2063 | phba->fc_stat.elsXmitLOGO++; |
| 2064 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2065 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2066 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2067 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2068 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2069 | |
| 2070 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2071 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2072 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2073 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2074 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2075 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2076 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2077 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2078 | } |
| 2079 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2080 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2081 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2082 | * @phba: pointer to lpfc hba data structure. |
| 2083 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2084 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2085 | * |
| 2086 | * This routine is a generic completion callback function for ELS commands. |
| 2087 | * Specifically, it is the callback function which does not need to perform |
| 2088 | * any command specific operations. It is currently used by the ELS command |
| 2089 | * issuing routines for the ELS State Change Request (SCR), |
| 2090 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 2091 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2092 | * certain debug loggings, this callback function simply invokes the |
| 2093 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2094 | * discovery process. |
| 2095 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2096 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2097 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2098 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2099 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2100 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2101 | IOCB_t *irsp; |
| 2102 | |
| 2103 | irsp = &rspiocb->iocb; |
| 2104 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2105 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2106 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2107 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2108 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2109 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2110 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2111 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2112 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2113 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2114 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2115 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2116 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2117 | return; |
| 2118 | } |
| 2119 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2120 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2121 | * 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] | 2122 | * @vport: pointer to a host virtual N_Port data structure. |
| 2123 | * @nportid: N_Port identifier to the remote node. |
| 2124 | * @retry: number of retries to the command IOCB. |
| 2125 | * |
| 2126 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2127 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2128 | * first search the @vport node list to find the matching ndlp. If no such |
| 2129 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2130 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2131 | * routine is invoked to send the SCR IOCB. |
| 2132 | * |
| 2133 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2134 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2135 | * will be stored into the context1 field of the IOCB for the completion |
| 2136 | * callback function to the SCR ELS command. |
| 2137 | * |
| 2138 | * Return code |
| 2139 | * 0 - Successfully issued scr command |
| 2140 | * 1 - Failed to issue scr command |
| 2141 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2142 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2143 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2144 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2145 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2146 | IOCB_t *icmd; |
| 2147 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2148 | struct lpfc_sli *psli; |
| 2149 | uint8_t *pcmd; |
| 2150 | uint16_t cmdsize; |
| 2151 | struct lpfc_nodelist *ndlp; |
| 2152 | |
| 2153 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2154 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2155 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2156 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2157 | if (!ndlp) { |
| 2158 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2159 | if (!ndlp) |
| 2160 | return 1; |
| 2161 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2162 | lpfc_enqueue_node(vport, ndlp); |
| 2163 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2164 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2165 | if (!ndlp) |
| 2166 | return 1; |
| 2167 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2168 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2169 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2170 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2171 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2172 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2173 | /* This will trigger the release of the node just |
| 2174 | * allocated |
| 2175 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2176 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2177 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2178 | } |
| 2179 | |
| 2180 | icmd = &elsiocb->iocb; |
| 2181 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2182 | |
| 2183 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2184 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2185 | |
| 2186 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2187 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2188 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2189 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2190 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2191 | "Issue SCR: did:x%x", |
| 2192 | ndlp->nlp_DID, 0, 0); |
| 2193 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2194 | phba->fc_stat.elsXmitSCR++; |
| 2195 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2196 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2197 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2198 | /* The additional lpfc_nlp_put will cause the following |
| 2199 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2200 | * the node. |
| 2201 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2202 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2203 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2204 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2205 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2206 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2207 | * trigger the release of node. |
| 2208 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2209 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2210 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2211 | } |
| 2212 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2213 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2214 | * 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] | 2215 | * @vport: pointer to a host virtual N_Port data structure. |
| 2216 | * @nportid: N_Port identifier to the remote node. |
| 2217 | * @retry: number of retries to the command IOCB. |
| 2218 | * |
| 2219 | * This routine issues a Fibre Channel Address Resolution Response |
| 2220 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2221 | * is passed into the function. It first search the @vport node list to find |
| 2222 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2223 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2224 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2225 | * |
| 2226 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2227 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2228 | * will be stored into the context1 field of the IOCB for the completion |
| 2229 | * callback function to the PARPR ELS command. |
| 2230 | * |
| 2231 | * Return code |
| 2232 | * 0 - Successfully issued farpr command |
| 2233 | * 1 - Failed to issue farpr command |
| 2234 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2235 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2236 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2237 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2238 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2239 | IOCB_t *icmd; |
| 2240 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2241 | struct lpfc_sli *psli; |
| 2242 | FARP *fp; |
| 2243 | uint8_t *pcmd; |
| 2244 | uint32_t *lp; |
| 2245 | uint16_t cmdsize; |
| 2246 | struct lpfc_nodelist *ondlp; |
| 2247 | struct lpfc_nodelist *ndlp; |
| 2248 | |
| 2249 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2250 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2251 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2252 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2253 | if (!ndlp) { |
| 2254 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2255 | if (!ndlp) |
| 2256 | return 1; |
| 2257 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2258 | lpfc_enqueue_node(vport, ndlp); |
| 2259 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2260 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2261 | if (!ndlp) |
| 2262 | return 1; |
| 2263 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2264 | |
| 2265 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2266 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2267 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2268 | /* This will trigger the release of the node just |
| 2269 | * allocated |
| 2270 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2271 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2272 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2273 | } |
| 2274 | |
| 2275 | icmd = &elsiocb->iocb; |
| 2276 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2277 | |
| 2278 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2279 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2280 | |
| 2281 | /* Fill in FARPR payload */ |
| 2282 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2283 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2284 | lp = (uint32_t *) pcmd; |
| 2285 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2286 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2287 | fp->Rflags = 0; |
| 2288 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2289 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2290 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2291 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2292 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2293 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2294 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2295 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2296 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2297 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2298 | } |
| 2299 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2300 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2301 | "Issue FARPR: did:x%x", |
| 2302 | ndlp->nlp_DID, 0, 0); |
| 2303 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2304 | phba->fc_stat.elsXmitFARPR++; |
| 2305 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2306 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2307 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2308 | /* The additional lpfc_nlp_put will cause the following |
| 2309 | * lpfc_els_free_iocb routine to trigger the release of |
| 2310 | * the node. |
| 2311 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2312 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2313 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2314 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2315 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2316 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2317 | * trigger the release of the node. |
| 2318 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2319 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2320 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2321 | } |
| 2322 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2323 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2324 | * 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] | 2325 | * @vport: pointer to a host virtual N_Port data structure. |
| 2326 | * @nlp: pointer to a node-list data structure. |
| 2327 | * |
| 2328 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2329 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2330 | * removes the ELS retry event if it presents. In addition, if the |
| 2331 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2332 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2333 | * ADISC. |
| 2334 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2335 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2336 | 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] | 2337 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2338 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2339 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2340 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2341 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2342 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2343 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2344 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2345 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2346 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2347 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2348 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2349 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2350 | /* Decrement nlp reference count held for the delayed retry */ |
| 2351 | evtp = &nlp->els_retry_evt; |
| 2352 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2353 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2354 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2355 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2356 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2357 | spin_unlock_irq(shost->host_lock); |
| 2358 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2359 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2360 | /* Check if there are more ADISCs to be sent */ |
| 2361 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2362 | } else { |
| 2363 | /* Check if there are more PLOGIs to be sent */ |
| 2364 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2365 | if (vport->num_disc_nodes == 0) { |
| 2366 | spin_lock_irq(shost->host_lock); |
| 2367 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2368 | spin_unlock_irq(shost->host_lock); |
| 2369 | lpfc_can_disctmo(vport); |
| 2370 | lpfc_end_rscn(vport); |
| 2371 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2372 | } |
| 2373 | } |
| 2374 | } |
| 2375 | return; |
| 2376 | } |
| 2377 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2378 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2379 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2380 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2381 | * |
| 2382 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2383 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2384 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2385 | * adds the delayed events to the HBA work list and invokes the |
| 2386 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2387 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2388 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2389 | * reference to ndlp will still be available when the worker thread gets |
| 2390 | * to the event associated with the ndlp. |
| 2391 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2392 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2393 | lpfc_els_retry_delay(unsigned long ptr) |
| 2394 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2395 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2396 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2397 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2398 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2399 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2400 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2401 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2402 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2403 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2404 | return; |
| 2405 | } |
| 2406 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2407 | /* We need to hold the node by incrementing the reference |
| 2408 | * count until the queued work is done |
| 2409 | */ |
| 2410 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2411 | if (evtp->evt_arg1) { |
| 2412 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2413 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2414 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2415 | } |
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 | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2420 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2421 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2422 | * @ndlp: pointer to a node-list data structure. |
| 2423 | * |
| 2424 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 2425 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 2426 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 2427 | * function according to the delayed ELS command to retry the command. |
| 2428 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2429 | void |
| 2430 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 2431 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2432 | struct lpfc_vport *vport = ndlp->vport; |
| 2433 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2434 | uint32_t cmd, did, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2435 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2436 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2437 | did = ndlp->nlp_DID; |
| 2438 | cmd = ndlp->nlp_last_elscmd; |
| 2439 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2440 | |
| 2441 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2442 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2443 | return; |
| 2444 | } |
| 2445 | |
| 2446 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2447 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 2448 | /* |
| 2449 | * If a discovery event readded nlp_delayfunc after timer |
| 2450 | * firing and before processing the timer, cancel the |
| 2451 | * nlp_delayfunc. |
| 2452 | */ |
| 2453 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2454 | retry = ndlp->nlp_retry; |
| 2455 | |
| 2456 | switch (cmd) { |
| 2457 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2458 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2459 | break; |
| 2460 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2461 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2462 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2463 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2464 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2465 | break; |
| 2466 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2467 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2468 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2469 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2470 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2471 | break; |
| 2472 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2473 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2474 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2475 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2476 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2477 | break; |
| 2478 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2479 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2480 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2481 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2482 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2483 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2484 | case ELS_CMD_FDISC: |
| 2485 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
| 2486 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2487 | } |
| 2488 | return; |
| 2489 | } |
| 2490 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2491 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2492 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2493 | * @phba: pointer to lpfc hba data structure. |
| 2494 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2495 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2496 | * |
| 2497 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 2498 | * failed. The following ELS IOCBs use this function for retrying the command |
| 2499 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 2500 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 2501 | * returned error status, it makes the decision whether a retry shall be |
| 2502 | * issued for the command, and whether a retry shall be made immediately or |
| 2503 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 2504 | * is called to retry the command. In the later case, the ELS command shall |
| 2505 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 2506 | * ndlp for the delayed command issusing. |
| 2507 | * |
| 2508 | * Return code |
| 2509 | * 0 - No retry of els command is made |
| 2510 | * 1 - Immediate or delayed retry of els command is made |
| 2511 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2512 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2513 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2514 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2515 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2516 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2517 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2518 | IOCB_t *irsp = &rspiocb->iocb; |
| 2519 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2520 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2521 | uint32_t *elscmd; |
| 2522 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2523 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2524 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2525 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2526 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2527 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2528 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2529 | /* Note: context2 may be 0 for internal driver abort |
| 2530 | * of delays ELS command. |
| 2531 | */ |
| 2532 | |
| 2533 | if (pcmd && pcmd->virt) { |
| 2534 | elscmd = (uint32_t *) (pcmd->virt); |
| 2535 | cmd = *elscmd++; |
| 2536 | } |
| 2537 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2538 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2539 | did = ndlp->nlp_DID; |
| 2540 | else { |
| 2541 | /* We should only hit this case for retrying PLOGI */ |
| 2542 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2543 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2544 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 2545 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2546 | return 1; |
| 2547 | } |
| 2548 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2549 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2550 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 2551 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 2552 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2553 | switch (irsp->ulpStatus) { |
| 2554 | case IOSTAT_FCP_RSP_ERROR: |
| 2555 | case IOSTAT_REMOTE_STOP: |
| 2556 | break; |
| 2557 | |
| 2558 | case IOSTAT_LOCAL_REJECT: |
| 2559 | switch ((irsp->un.ulpWord[4] & 0xff)) { |
| 2560 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2561 | if (cmd == ELS_CMD_FLOGI) { |
| 2562 | if (PCI_DEVICE_ID_HORNET == |
| 2563 | phba->pcidev->device) { |
| 2564 | phba->fc_topology = TOPOLOGY_LOOP; |
| 2565 | phba->pport->fc_myDID = 0; |
| 2566 | phba->alpa_map[0] = 0; |
| 2567 | phba->alpa_map[1] = 0; |
| 2568 | } |
| 2569 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2570 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2571 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2572 | retry = 1; |
| 2573 | break; |
| 2574 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2575 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2576 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2577 | "0124 Retry illegal cmd x%x " |
| 2578 | "retry:x%x delay:x%x\n", |
| 2579 | cmd, cmdiocb->retry, delay); |
| 2580 | retry = 1; |
| 2581 | /* All command's retry policy */ |
| 2582 | maxretry = 8; |
| 2583 | if (cmdiocb->retry > 2) |
| 2584 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2585 | break; |
| 2586 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2587 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2588 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2589 | retry = 1; |
| 2590 | if (cmdiocb->retry > 100) |
| 2591 | delay = 100; |
| 2592 | maxretry = 250; |
| 2593 | break; |
| 2594 | |
| 2595 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2596 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2597 | retry = 1; |
| 2598 | break; |
| 2599 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2600 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2601 | case IOERR_INVALID_RPI: |
| 2602 | retry = 1; |
| 2603 | break; |
| 2604 | } |
| 2605 | break; |
| 2606 | |
| 2607 | case IOSTAT_NPORT_RJT: |
| 2608 | case IOSTAT_FABRIC_RJT: |
| 2609 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 2610 | retry = 1; |
| 2611 | break; |
| 2612 | } |
| 2613 | break; |
| 2614 | |
| 2615 | case IOSTAT_NPORT_BSY: |
| 2616 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2617 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2618 | retry = 1; |
| 2619 | break; |
| 2620 | |
| 2621 | case IOSTAT_LS_RJT: |
| 2622 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 2623 | /* Added for Vendor specifc support |
| 2624 | * Just keep retrying for these Rsn / Exp codes |
| 2625 | */ |
| 2626 | switch (stat.un.b.lsRjtRsnCode) { |
| 2627 | case LSRJT_UNABLE_TPC: |
| 2628 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2629 | LSEXP_CMD_IN_PROGRESS) { |
| 2630 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2631 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2632 | maxretry = 48; |
| 2633 | } |
| 2634 | retry = 1; |
| 2635 | break; |
| 2636 | } |
| 2637 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2638 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2639 | maxretry = lpfc_max_els_tries + 1; |
| 2640 | retry = 1; |
| 2641 | break; |
| 2642 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2643 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2644 | (cmd == ELS_CMD_FDISC) && |
| 2645 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2646 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2647 | "0125 FDISC Failed (x%x). " |
| 2648 | "Fabric out of resources\n", |
| 2649 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2650 | lpfc_vport_set_state(vport, |
| 2651 | FC_VPORT_NO_FABRIC_RSCS); |
| 2652 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2653 | break; |
| 2654 | |
| 2655 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2656 | if ((cmd == ELS_CMD_PLOGI) || |
| 2657 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2658 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2659 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2660 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2661 | /* FDISC retry policy */ |
| 2662 | maxretry = 48; |
| 2663 | if (cmdiocb->retry >= 32) |
| 2664 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2665 | } |
| 2666 | retry = 1; |
| 2667 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2668 | |
| 2669 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2670 | /* There are some cases where switches return this |
| 2671 | * error when they are not ready and should be returning |
| 2672 | * Logical Busy. We should delay every time. |
| 2673 | */ |
| 2674 | if (cmd == ELS_CMD_FDISC && |
| 2675 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 2676 | maxretry = 3; |
| 2677 | delay = 1000; |
| 2678 | retry = 1; |
| 2679 | break; |
| 2680 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2681 | case LSRJT_PROTOCOL_ERR: |
| 2682 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2683 | (cmd == ELS_CMD_FDISC) && |
| 2684 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 2685 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 2686 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2687 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2688 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2689 | "Fabric Detected Bad WWN\n", |
| 2690 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2691 | lpfc_vport_set_state(vport, |
| 2692 | FC_VPORT_FABRIC_REJ_WWN); |
| 2693 | } |
| 2694 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2695 | } |
| 2696 | break; |
| 2697 | |
| 2698 | case IOSTAT_INTERMED_RSP: |
| 2699 | case IOSTAT_BA_RJT: |
| 2700 | break; |
| 2701 | |
| 2702 | default: |
| 2703 | break; |
| 2704 | } |
| 2705 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2706 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2707 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2708 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2709 | if ((cmd == ELS_CMD_FLOGI) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 2710 | (phba->fc_topology != TOPOLOGY_LOOP) && |
| 2711 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2712 | /* FLOGI retry policy */ |
| 2713 | retry = 1; |
| 2714 | maxretry = 48; |
| 2715 | if (cmdiocb->retry >= 32) |
| 2716 | delay = 1000; |
| 2717 | } |
| 2718 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2719 | if ((++cmdiocb->retry) >= maxretry) { |
| 2720 | phba->fc_stat.elsRetryExceeded++; |
| 2721 | retry = 0; |
| 2722 | } |
| 2723 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2724 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 2725 | retry = 0; |
| 2726 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2727 | if (retry) { |
| 2728 | |
| 2729 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2730 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2731 | "0107 Retry ELS command x%x to remote " |
| 2732 | "NPORT x%x Data: x%x x%x\n", |
| 2733 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2734 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2735 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 2736 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 2737 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { |
| 2738 | /* Don't reset timer for no resources */ |
| 2739 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2740 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2741 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2742 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2743 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2744 | } |
| 2745 | |
| 2746 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2747 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2748 | phba->fc_stat.elsDelayRetry++; |
| 2749 | ndlp->nlp_retry = cmdiocb->retry; |
| 2750 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2751 | /* delay is specified in milliseconds */ |
| 2752 | mod_timer(&ndlp->nlp_delayfunc, |
| 2753 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2754 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2755 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2756 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2757 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2758 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2759 | if (cmd == ELS_CMD_PRLI) |
| 2760 | lpfc_nlp_set_state(vport, ndlp, |
| 2761 | NLP_STE_REG_LOGIN_ISSUE); |
| 2762 | else |
| 2763 | lpfc_nlp_set_state(vport, ndlp, |
| 2764 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2765 | ndlp->nlp_last_elscmd = cmd; |
| 2766 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2767 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2768 | } |
| 2769 | switch (cmd) { |
| 2770 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2771 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2772 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2773 | case ELS_CMD_FDISC: |
| 2774 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 2775 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2776 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2777 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2778 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2779 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2780 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2781 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2782 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2783 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2784 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2785 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2786 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 2787 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2788 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2789 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2790 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2791 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 2792 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2793 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2794 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2795 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2796 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 2797 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2798 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2799 | } |
| 2800 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2801 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2802 | if (logerr) { |
| 2803 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2804 | "0137 No retry ELS command x%x to remote " |
| 2805 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 2806 | cmd, did, irsp->ulpStatus, |
| 2807 | irsp->un.ulpWord[4]); |
| 2808 | } |
| 2809 | else { |
| 2810 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2811 | "0108 No retry ELS command x%x to remote " |
| 2812 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 2813 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 2814 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2815 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2816 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2817 | } |
| 2818 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2819 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2820 | * 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] | 2821 | * @phba: pointer to lpfc hba data structure. |
| 2822 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 2823 | * |
| 2824 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 2825 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 2826 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 2827 | * response of the command IOCB. If so, it will be released before releasing |
| 2828 | * the lpfc DMA buffer associated with the IOCB itself. |
| 2829 | * |
| 2830 | * Return code |
| 2831 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2832 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2833 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2834 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 2835 | { |
| 2836 | struct lpfc_dmabuf *buf_ptr; |
| 2837 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2838 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2839 | if (!list_empty(&buf_ptr1->list)) { |
| 2840 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 2841 | struct lpfc_dmabuf, |
| 2842 | list); |
| 2843 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2844 | kfree(buf_ptr); |
| 2845 | } |
| 2846 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 2847 | kfree(buf_ptr1); |
| 2848 | return 0; |
| 2849 | } |
| 2850 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2851 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2852 | * 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] | 2853 | * @phba: pointer to lpfc hba data structure. |
| 2854 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 2855 | * |
| 2856 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 2857 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 2858 | * pool. |
| 2859 | * |
| 2860 | * Return code |
| 2861 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2862 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2863 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2864 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 2865 | { |
| 2866 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2867 | kfree(buf_ptr); |
| 2868 | return 0; |
| 2869 | } |
| 2870 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2871 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2872 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2873 | * @phba: pointer to lpfc hba data structure. |
| 2874 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 2875 | * |
| 2876 | * This routine frees a command IOCB and its associated resources. The |
| 2877 | * command IOCB data structure contains the reference to various associated |
| 2878 | * resources, these fields must be set to NULL if the associated reference |
| 2879 | * not present: |
| 2880 | * context1 - reference to ndlp |
| 2881 | * context2 - reference to cmd |
| 2882 | * context2->next - reference to rsp |
| 2883 | * context3 - reference to bpl |
| 2884 | * |
| 2885 | * It first properly decrements the reference count held on ndlp for the |
| 2886 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 2887 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 2888 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 2889 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 2890 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 2891 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 2892 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 2893 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 2894 | * |
| 2895 | * Return code |
| 2896 | * 0 - Success (currently, always return 0) |
| 2897 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2898 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2899 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2900 | { |
| 2901 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2902 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2903 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2904 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 2905 | if (ndlp) { |
| 2906 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 2907 | lpfc_nlp_put(ndlp); |
| 2908 | |
| 2909 | /* If the ndlp is not being used by another discovery |
| 2910 | * thread, free it. |
| 2911 | */ |
| 2912 | if (!lpfc_nlp_not_used(ndlp)) { |
| 2913 | /* If ndlp is being used by another discovery |
| 2914 | * thread, just clear NLP_DEFER_RM |
| 2915 | */ |
| 2916 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 2917 | } |
| 2918 | } |
| 2919 | else |
| 2920 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2921 | elsiocb->context1 = NULL; |
| 2922 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2923 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 2924 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2925 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 2926 | /* Firmware could still be in progress of DMAing |
| 2927 | * payload, so don't free data buffer till after |
| 2928 | * a hbeat. |
| 2929 | */ |
| 2930 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 2931 | buf_ptr = elsiocb->context2; |
| 2932 | elsiocb->context2 = NULL; |
| 2933 | if (buf_ptr) { |
| 2934 | buf_ptr1 = NULL; |
| 2935 | spin_lock_irq(&phba->hbalock); |
| 2936 | if (!list_empty(&buf_ptr->list)) { |
| 2937 | list_remove_head(&buf_ptr->list, |
| 2938 | buf_ptr1, struct lpfc_dmabuf, |
| 2939 | list); |
| 2940 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 2941 | list_add_tail(&buf_ptr1->list, |
| 2942 | &phba->elsbuf); |
| 2943 | phba->elsbuf_cnt++; |
| 2944 | } |
| 2945 | INIT_LIST_HEAD(&buf_ptr->list); |
| 2946 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 2947 | phba->elsbuf_cnt++; |
| 2948 | spin_unlock_irq(&phba->hbalock); |
| 2949 | } |
| 2950 | } else { |
| 2951 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 2952 | lpfc_els_free_data(phba, buf_ptr1); |
| 2953 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2954 | } |
| 2955 | |
| 2956 | if (elsiocb->context3) { |
| 2957 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2958 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2959 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2960 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2961 | return 0; |
| 2962 | } |
| 2963 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2964 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2965 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2966 | * @phba: pointer to lpfc hba data structure. |
| 2967 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2968 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2969 | * |
| 2970 | * This routine is the completion callback function to the Logout (LOGO) |
| 2971 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 2972 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 2973 | * release the ndlp if it has the last reference remaining (reference count |
| 2974 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 2975 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 2976 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 2977 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 2978 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 2979 | * IOCB data structure. |
| 2980 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2981 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2982 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2983 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2984 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2985 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2986 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2987 | IOCB_t *irsp; |
| 2988 | |
| 2989 | irsp = &rspiocb->iocb; |
| 2990 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 2991 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 2992 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2993 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2994 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2995 | "0109 ACC to LOGO completes to NPort x%x " |
| 2996 | "Data: x%x x%x x%x\n", |
| 2997 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 2998 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2999 | |
| 3000 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 3001 | /* NPort Recovery mode or node is just allocated */ |
| 3002 | if (!lpfc_nlp_not_used(ndlp)) { |
| 3003 | /* If the ndlp is being used by another discovery |
| 3004 | * thread, just unregister the RPI. |
| 3005 | */ |
| 3006 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3007 | } else { |
| 3008 | /* Indicate the node has already released, should |
| 3009 | * not reference to it from within lpfc_els_free_iocb. |
| 3010 | */ |
| 3011 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3012 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3013 | } |
| 3014 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3015 | return; |
| 3016 | } |
| 3017 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3018 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3019 | * 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] | 3020 | * @phba: pointer to lpfc hba data structure. |
| 3021 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 3022 | * |
| 3023 | * This routine is the completion callback function for unregister default |
| 3024 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 3025 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 3026 | * decrements the ndlp reference count held for this completion callback |
| 3027 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 3028 | * whether there is only one reference left on the ndlp. If so, it will |
| 3029 | * perform one more decrement and trigger the release of the ndlp. |
| 3030 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3031 | void |
| 3032 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3033 | { |
| 3034 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3035 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3036 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3037 | /* |
| 3038 | * This routine is used to register and unregister in previous SLI |
| 3039 | * modes. |
| 3040 | */ |
| 3041 | if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) && |
| 3042 | (phba->sli_rev == LPFC_SLI_REV4)) |
| 3043 | lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi); |
| 3044 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3045 | pmb->context1 = NULL; |
| 3046 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3047 | kfree(mp); |
| 3048 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3049 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3050 | lpfc_nlp_put(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3051 | /* This is the end of the default RPI cleanup logic for this |
| 3052 | * ndlp. If no other discovery threads are using this ndlp. |
| 3053 | * we should free all resources associated with it. |
| 3054 | */ |
| 3055 | lpfc_nlp_not_used(ndlp); |
| 3056 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3057 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3058 | return; |
| 3059 | } |
| 3060 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3061 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3062 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3063 | * @phba: pointer to lpfc hba data structure. |
| 3064 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3065 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3066 | * |
| 3067 | * This routine is the completion callback function for ELS Response IOCB |
| 3068 | * command. In normal case, this callback function just properly sets the |
| 3069 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 3070 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 3071 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 3072 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 3073 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 3074 | * routine shall be invoked trying to release the ndlp if no other threads |
| 3075 | * are currently referring it. |
| 3076 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3077 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3078 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3079 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3080 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3081 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3082 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 3083 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3084 | IOCB_t *irsp; |
| 3085 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3086 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3087 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3088 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3089 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3090 | irsp = &rspiocb->iocb; |
| 3091 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3092 | if (cmdiocb->context_un.mbox) |
| 3093 | mbox = cmdiocb->context_un.mbox; |
| 3094 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3095 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 3096 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 3097 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3098 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3099 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3100 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3101 | /* A LS_RJT associated with Default RPI cleanup has its own |
| 3102 | * seperate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3103 | */ |
| 3104 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 3105 | ls_rjt = 1; |
| 3106 | } |
| 3107 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3108 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3109 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3110 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3111 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3112 | if (mp) { |
| 3113 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3114 | kfree(mp); |
| 3115 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3116 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3117 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3118 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3119 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3120 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3121 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3122 | /* Indicate the node has already released, |
| 3123 | * should not reference to it from within |
| 3124 | * the routine lpfc_els_free_iocb. |
| 3125 | */ |
| 3126 | cmdiocb->context1 = NULL; |
| 3127 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3128 | goto out; |
| 3129 | } |
| 3130 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3131 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3132 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3133 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3134 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3135 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3136 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3137 | "0110 ELS response tag x%x completes " |
| 3138 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3139 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3140 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3141 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3142 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3143 | if (mbox) { |
| 3144 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3145 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3146 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3147 | /* Increment reference count to ndlp to hold the |
| 3148 | * reference to ndlp for the callback function. |
| 3149 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3150 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3151 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3152 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3153 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3154 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3155 | } |
| 3156 | else { |
| 3157 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3158 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3159 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3160 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3161 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3162 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3163 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3164 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3165 | else |
| 3166 | /* Decrement the ndlp reference count we |
| 3167 | * set for this failed mailbox command. |
| 3168 | */ |
| 3169 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3170 | |
| 3171 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3172 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3173 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3174 | "Data: x%x x%x x%x\n", |
| 3175 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3176 | ndlp->nlp_rpi); |
| 3177 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3178 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3179 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3180 | /* Indicate node has already been released, |
| 3181 | * should not reference to it from within |
| 3182 | * the routine lpfc_els_free_iocb. |
| 3183 | */ |
| 3184 | cmdiocb->context1 = NULL; |
| 3185 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3186 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3187 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3188 | if (!lpfc_error_lost_link(irsp) && |
| 3189 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3190 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3191 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3192 | /* Indicate node has already been |
| 3193 | * released, should not reference |
| 3194 | * to it from within the routine |
| 3195 | * lpfc_els_free_iocb. |
| 3196 | */ |
| 3197 | cmdiocb->context1 = NULL; |
| 3198 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3199 | } |
| 3200 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3201 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3202 | if (mp) { |
| 3203 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3204 | kfree(mp); |
| 3205 | } |
| 3206 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3207 | } |
| 3208 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3209 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3210 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3211 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3212 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3213 | |
| 3214 | /* If the node is not being used by another discovery thread, |
| 3215 | * and we are sending a reject, we are done with it. |
| 3216 | * Release driver reference count here and free associated |
| 3217 | * resources. |
| 3218 | */ |
| 3219 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3220 | if (lpfc_nlp_not_used(ndlp)) |
| 3221 | /* Indicate node has already been released, |
| 3222 | * should not reference to it from within |
| 3223 | * the routine lpfc_els_free_iocb. |
| 3224 | */ |
| 3225 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3226 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3227 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3228 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3229 | return; |
| 3230 | } |
| 3231 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3232 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3233 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3234 | * @vport: pointer to a host virtual N_Port data structure. |
| 3235 | * @flag: the els command code to be accepted. |
| 3236 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3237 | * @ndlp: pointer to a node-list data structure. |
| 3238 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3239 | * |
| 3240 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3241 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3242 | * specific ACC response command to be issued and invokes the |
| 3243 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3244 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3245 | * field of the IOCB for the completion callback function to issue the |
| 3246 | * mailbox command to the HBA later when callback is invoked. |
| 3247 | * |
| 3248 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3249 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3250 | * will be stored into the context1 field of the IOCB for the completion |
| 3251 | * callback function to the corresponding response ELS IOCB command. |
| 3252 | * |
| 3253 | * Return code |
| 3254 | * 0 - Successfully issued acc response |
| 3255 | * 1 - Failed to issue acc response |
| 3256 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3257 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3258 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3259 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3260 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3261 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3262 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3263 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3264 | IOCB_t *icmd; |
| 3265 | IOCB_t *oldcmd; |
| 3266 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3267 | struct lpfc_sli *psli; |
| 3268 | uint8_t *pcmd; |
| 3269 | uint16_t cmdsize; |
| 3270 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3271 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3272 | |
| 3273 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3274 | oldcmd = &oldiocb->iocb; |
| 3275 | |
| 3276 | switch (flag) { |
| 3277 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3278 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3279 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3280 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3281 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3282 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3283 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3284 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3285 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3286 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3287 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3288 | icmd = &elsiocb->iocb; |
| 3289 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3290 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3291 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3292 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3293 | |
| 3294 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3295 | "Issue ACC: did:x%x flg:x%x", |
| 3296 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3297 | break; |
| 3298 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3299 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3300 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3301 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3302 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3303 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3304 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3305 | icmd = &elsiocb->iocb; |
| 3306 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3307 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3308 | |
| 3309 | if (mbox) |
| 3310 | elsiocb->context_un.mbox = mbox; |
| 3311 | |
| 3312 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3313 | pcmd += sizeof(uint32_t); |
| 3314 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3315 | |
| 3316 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3317 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 3318 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3319 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3320 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3321 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3322 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3323 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3324 | if (!elsiocb) |
| 3325 | return 1; |
| 3326 | |
| 3327 | icmd = &elsiocb->iocb; |
| 3328 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3329 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3330 | |
| 3331 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3332 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3333 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 3334 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 3335 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3336 | |
| 3337 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3338 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 3339 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3340 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3341 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3342 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3343 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3344 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3345 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3346 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
| 3347 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", |
| 3348 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3349 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3350 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3351 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3352 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3353 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3354 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3355 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 3356 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3357 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3358 | } |
| 3359 | |
| 3360 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3361 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3362 | if (rc == IOCB_ERROR) { |
| 3363 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3364 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3365 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3366 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3367 | } |
| 3368 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3369 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3370 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3371 | * @vport: pointer to a virtual N_Port data structure. |
| 3372 | * @rejectError: |
| 3373 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3374 | * @ndlp: pointer to a node-list data structure. |
| 3375 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3376 | * |
| 3377 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 3378 | * command. If a @mbox pointer is passed in, it will be put into the |
| 3379 | * context_un.mbox field of the IOCB for the completion callback function |
| 3380 | * to issue to the HBA later. |
| 3381 | * |
| 3382 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3383 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3384 | * will be stored into the context1 field of the IOCB for the completion |
| 3385 | * callback function to the reject response ELS IOCB command. |
| 3386 | * |
| 3387 | * Return code |
| 3388 | * 0 - Successfully issued reject response |
| 3389 | * 1 - Failed to issue reject response |
| 3390 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3391 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3392 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3393 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 3394 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3395 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3396 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3397 | IOCB_t *icmd; |
| 3398 | IOCB_t *oldcmd; |
| 3399 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3400 | struct lpfc_sli *psli; |
| 3401 | uint8_t *pcmd; |
| 3402 | uint16_t cmdsize; |
| 3403 | int rc; |
| 3404 | |
| 3405 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3406 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3407 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3408 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3409 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3410 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3411 | |
| 3412 | icmd = &elsiocb->iocb; |
| 3413 | oldcmd = &oldiocb->iocb; |
| 3414 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3415 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3416 | |
| 3417 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3418 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3419 | *((uint32_t *) (pcmd)) = rejectError; |
| 3420 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3421 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3422 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3423 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3424 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3425 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3426 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 3427 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 3428 | "rpi x%x\n", |
| 3429 | rejectError, elsiocb->iotag, |
| 3430 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 3431 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3432 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3433 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 3434 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 3435 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3436 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3437 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3438 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3439 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3440 | if (rc == IOCB_ERROR) { |
| 3441 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3442 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3443 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3444 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3445 | } |
| 3446 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3447 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3448 | * 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] | 3449 | * @vport: pointer to a virtual N_Port data structure. |
| 3450 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3451 | * @ndlp: pointer to a node-list data structure. |
| 3452 | * |
| 3453 | * This routine prepares and issues an Accept (ACC) response to Address |
| 3454 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 3455 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3456 | * |
| 3457 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3458 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3459 | * will be stored into the context1 field of the IOCB for the completion |
| 3460 | * callback function to the ADISC Accept response ELS IOCB command. |
| 3461 | * |
| 3462 | * Return code |
| 3463 | * 0 - Successfully issued acc adisc response |
| 3464 | * 1 - Failed to issue adisc acc response |
| 3465 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3466 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3467 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 3468 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3469 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3470 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3471 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3472 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3473 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3474 | uint8_t *pcmd; |
| 3475 | uint16_t cmdsize; |
| 3476 | int rc; |
| 3477 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3478 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3479 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3480 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3481 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3482 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3483 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3484 | icmd = &elsiocb->iocb; |
| 3485 | oldcmd = &oldiocb->iocb; |
| 3486 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3487 | |
| 3488 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3489 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3490 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 3491 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 3492 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3493 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3494 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3495 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3496 | |
| 3497 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3498 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3499 | |
| 3500 | ap = (ADISC *) (pcmd); |
| 3501 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3502 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3503 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3504 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3505 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3506 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3507 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 3508 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3509 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3510 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3511 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3512 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3513 | if (rc == IOCB_ERROR) { |
| 3514 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3515 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3516 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3517 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3518 | } |
| 3519 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3520 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3521 | * 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] | 3522 | * @vport: pointer to a virtual N_Port data structure. |
| 3523 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3524 | * @ndlp: pointer to a node-list data structure. |
| 3525 | * |
| 3526 | * This routine prepares and issues an Accept (ACC) response to Process |
| 3527 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 3528 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3529 | * |
| 3530 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3531 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3532 | * will be stored into the context1 field of the IOCB for the completion |
| 3533 | * callback function to the PRLI Accept response ELS IOCB command. |
| 3534 | * |
| 3535 | * Return code |
| 3536 | * 0 - Successfully issued acc prli response |
| 3537 | * 1 - Failed to issue acc prli response |
| 3538 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3539 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3540 | 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] | 3541 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3542 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3543 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3544 | PRLI *npr; |
| 3545 | lpfc_vpd_t *vpd; |
| 3546 | IOCB_t *icmd; |
| 3547 | IOCB_t *oldcmd; |
| 3548 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3549 | struct lpfc_sli *psli; |
| 3550 | uint8_t *pcmd; |
| 3551 | uint16_t cmdsize; |
| 3552 | int rc; |
| 3553 | |
| 3554 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3555 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3556 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3557 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3558 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3559 | if (!elsiocb) |
| 3560 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3561 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3562 | icmd = &elsiocb->iocb; |
| 3563 | oldcmd = &oldiocb->iocb; |
| 3564 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3565 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3566 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3567 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 3568 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 3569 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3570 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3571 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3572 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3573 | |
| 3574 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3575 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3576 | |
| 3577 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3578 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3579 | |
| 3580 | npr = (PRLI *) pcmd; |
| 3581 | vpd = &phba->vpd; |
| 3582 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3583 | * If the remote port is a target and our firmware version is 3.20 or |
| 3584 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3585 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3586 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 3587 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3588 | npr->ConfmComplAllowed = 1; |
| 3589 | npr->Retry = 1; |
| 3590 | npr->TaskRetryIdReq = 1; |
| 3591 | } |
| 3592 | |
| 3593 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 3594 | npr->estabImagePair = 1; |
| 3595 | npr->readXferRdyDis = 1; |
| 3596 | npr->ConfmComplAllowed = 1; |
| 3597 | |
| 3598 | npr->prliType = PRLI_FCP_TYPE; |
| 3599 | npr->initiatorFunc = 1; |
| 3600 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3601 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3602 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 3603 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3604 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3605 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3606 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3607 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3608 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3609 | if (rc == IOCB_ERROR) { |
| 3610 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3611 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3612 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3613 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3614 | } |
| 3615 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3616 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3617 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3618 | * @vport: pointer to a virtual N_Port data structure. |
| 3619 | * @format: rnid command format. |
| 3620 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3621 | * @ndlp: pointer to a node-list data structure. |
| 3622 | * |
| 3623 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 3624 | * (ACC) response. It constructs the RNID ACC response command according to |
| 3625 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 3626 | * issue the response. Note that this command does not need to hold the ndlp |
| 3627 | * reference count for the callback. So, the ndlp reference count taken by |
| 3628 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 3629 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 3630 | * there is no ndlp reference available. |
| 3631 | * |
| 3632 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3633 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3634 | * will be stored into the context1 field of the IOCB for the completion |
| 3635 | * callback function. However, for the RNID Accept Response ELS command, |
| 3636 | * this is undone later by this routine after the IOCB is allocated. |
| 3637 | * |
| 3638 | * Return code |
| 3639 | * 0 - Successfully issued acc rnid response |
| 3640 | * 1 - Failed to issue acc rnid response |
| 3641 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3642 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3643 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3644 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3645 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3646 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3647 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3648 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3649 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3650 | struct lpfc_sli *psli; |
| 3651 | uint8_t *pcmd; |
| 3652 | uint16_t cmdsize; |
| 3653 | int rc; |
| 3654 | |
| 3655 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3656 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 3657 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3658 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3659 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3660 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3661 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3662 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3663 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3664 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3665 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3666 | icmd = &elsiocb->iocb; |
| 3667 | oldcmd = &oldiocb->iocb; |
| 3668 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3669 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3670 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3671 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 3672 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3673 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3674 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3675 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3676 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3677 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3678 | rn = (RNID *) (pcmd); |
| 3679 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3680 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 3681 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3682 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3683 | switch (format) { |
| 3684 | case 0: |
| 3685 | rn->SpecificLen = 0; |
| 3686 | break; |
| 3687 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3688 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3689 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3690 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3691 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 3692 | rn->un.topologyDisc.physPort = 0; |
| 3693 | rn->un.topologyDisc.attachedNodes = 0; |
| 3694 | break; |
| 3695 | default: |
| 3696 | rn->CommonLen = 0; |
| 3697 | rn->SpecificLen = 0; |
| 3698 | break; |
| 3699 | } |
| 3700 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3701 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3702 | "Issue ACC RNID: did:x%x flg:x%x", |
| 3703 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3704 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3705 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3706 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3707 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3708 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 3709 | * it could be freed */ |
| 3710 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3711 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3712 | if (rc == IOCB_ERROR) { |
| 3713 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3714 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3715 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3716 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3717 | } |
| 3718 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3719 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3720 | * 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] | 3721 | * @vport: pointer to a host virtual N_Port data structure. |
| 3722 | * |
| 3723 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 3724 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 3725 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 3726 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 3727 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 3728 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 3729 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 3730 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 3731 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 3732 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 3733 | * no more ADISC need to be sent. |
| 3734 | * |
| 3735 | * Return code |
| 3736 | * The number of N_Ports with adisc issued. |
| 3737 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3738 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3739 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3740 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3741 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3742 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3743 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3744 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3745 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3746 | 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] | 3747 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3748 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3749 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3750 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3751 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3752 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3753 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3754 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3755 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3756 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 3757 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3758 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3759 | vport->num_disc_nodes++; |
| 3760 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3761 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3762 | spin_lock_irq(shost->host_lock); |
| 3763 | vport->fc_flag |= FC_NLP_MORE; |
| 3764 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3765 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3766 | } |
| 3767 | } |
| 3768 | } |
| 3769 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3770 | spin_lock_irq(shost->host_lock); |
| 3771 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3772 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3773 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3774 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3775 | } |
| 3776 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3777 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3778 | * 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] | 3779 | * @vport: pointer to a host virtual N_Port data structure. |
| 3780 | * |
| 3781 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 3782 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 3783 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 3784 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 3785 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 3786 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 3787 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 3788 | * later pick up. On the other hand, after walking through all the ndlps with |
| 3789 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 3790 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 3791 | * PLOGI need to be sent. |
| 3792 | * |
| 3793 | * Return code |
| 3794 | * The number of N_Ports with plogi issued. |
| 3795 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3796 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3797 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3798 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3799 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3800 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3801 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3802 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3803 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 3804 | 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] | 3805 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3806 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3807 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3808 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3809 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 3810 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 3811 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3812 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 3813 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3814 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3815 | vport->num_disc_nodes++; |
| 3816 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3817 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3818 | spin_lock_irq(shost->host_lock); |
| 3819 | vport->fc_flag |= FC_NLP_MORE; |
| 3820 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3821 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3822 | } |
| 3823 | } |
| 3824 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3825 | if (sentplogi) { |
| 3826 | lpfc_set_disctmo(vport); |
| 3827 | } |
| 3828 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3829 | spin_lock_irq(shost->host_lock); |
| 3830 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3831 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3832 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3833 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3834 | } |
| 3835 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3836 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3837 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3838 | * @vport: pointer to a host virtual N_Port data structure. |
| 3839 | * |
| 3840 | * This routine cleans up any Registration State Change Notification |
| 3841 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 3842 | * @vport together with the host_lock is used to prevent multiple thread |
| 3843 | * trying to access the RSCN array on a same @vport at the same time. |
| 3844 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3845 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3846 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3847 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3848 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3849 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3850 | int i; |
| 3851 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3852 | spin_lock_irq(shost->host_lock); |
| 3853 | if (vport->fc_rscn_flush) { |
| 3854 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3855 | spin_unlock_irq(shost->host_lock); |
| 3856 | return; |
| 3857 | } |
| 3858 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 3859 | vport->fc_rscn_flush = 1; |
| 3860 | spin_unlock_irq(shost->host_lock); |
| 3861 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3862 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3863 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3864 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3865 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3866 | spin_lock_irq(shost->host_lock); |
| 3867 | vport->fc_rscn_id_cnt = 0; |
| 3868 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 3869 | spin_unlock_irq(shost->host_lock); |
| 3870 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3871 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 3872 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3873 | } |
| 3874 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3875 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3876 | * 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] | 3877 | * @vport: pointer to a host virtual N_Port data structure. |
| 3878 | * @did: remote destination port identifier. |
| 3879 | * |
| 3880 | * This routine checks whether there is any pending Registration State |
| 3881 | * Configuration Notification (RSCN) to a @did on @vport. |
| 3882 | * |
| 3883 | * Return code |
| 3884 | * None zero - The @did matched with a pending rscn |
| 3885 | * 0 - not able to match @did with a pending rscn |
| 3886 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3887 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3888 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3889 | { |
| 3890 | D_ID ns_did; |
| 3891 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3892 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3893 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3894 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3895 | |
| 3896 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3897 | |
| 3898 | /* Never match fabric nodes for RSCNs */ |
| 3899 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3900 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3901 | |
| 3902 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3903 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3904 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3905 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3906 | spin_lock_irq(shost->host_lock); |
| 3907 | if (vport->fc_rscn_flush) { |
| 3908 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3909 | spin_unlock_irq(shost->host_lock); |
| 3910 | return 0; |
| 3911 | } |
| 3912 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 3913 | vport->fc_rscn_flush = 1; |
| 3914 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3915 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3916 | lp = vport->fc_rscn_id_list[i]->virt; |
| 3917 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 3918 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3919 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3920 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 3921 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3922 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 3923 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3924 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 3925 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 3926 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3927 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3928 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3929 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3930 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 3931 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3932 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3933 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3934 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3935 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3936 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3937 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3938 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3939 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3940 | } |
| 3941 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3942 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3943 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 3944 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3945 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3946 | return_did_out: |
| 3947 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 3948 | vport->fc_rscn_flush = 0; |
| 3949 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3950 | } |
| 3951 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3952 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3953 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3954 | * @vport: pointer to a host virtual N_Port data structure. |
| 3955 | * |
| 3956 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 3957 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 3958 | * State Change Notification). |
| 3959 | * |
| 3960 | * Return code |
| 3961 | * 0 - Successful (currently alway return 0) |
| 3962 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3963 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3964 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3965 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3966 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3967 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3968 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3969 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3970 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3971 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 3972 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3973 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3974 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3975 | NLP_EVT_DEVICE_RECOVERY); |
| 3976 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3977 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3978 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3979 | } |
| 3980 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3981 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3982 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 3983 | * @vport: pointer to a host virtual N_Port data structure. |
| 3984 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3985 | * |
| 3986 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 3987 | * applications. |
| 3988 | */ |
| 3989 | static void |
| 3990 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 3991 | struct lpfc_iocbq *cmdiocb) |
| 3992 | { |
| 3993 | struct lpfc_dmabuf *pcmd; |
| 3994 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3995 | uint32_t *payload_ptr; |
| 3996 | uint32_t payload_len; |
| 3997 | struct lpfc_rscn_event_header *rscn_event_data; |
| 3998 | |
| 3999 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4000 | payload_ptr = (uint32_t *) pcmd->virt; |
| 4001 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 4002 | |
| 4003 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 4004 | payload_len, GFP_KERNEL); |
| 4005 | if (!rscn_event_data) { |
| 4006 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4007 | "0147 Failed to allocate memory for RSCN event\n"); |
| 4008 | return; |
| 4009 | } |
| 4010 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 4011 | rscn_event_data->payload_length = payload_len; |
| 4012 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 4013 | payload_len); |
| 4014 | |
| 4015 | fc_host_post_vendor_event(shost, |
| 4016 | fc_get_event_number(), |
| 4017 | sizeof(struct lpfc_els_event_header) + payload_len, |
| 4018 | (char *)rscn_event_data, |
| 4019 | LPFC_NL_VENDOR_ID); |
| 4020 | |
| 4021 | kfree(rscn_event_data); |
| 4022 | } |
| 4023 | |
| 4024 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4025 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4026 | * @vport: pointer to a host virtual N_Port data structure. |
| 4027 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4028 | * @ndlp: pointer to a node-list data structure. |
| 4029 | * |
| 4030 | * This routine processes an unsolicited RSCN (Registration State Change |
| 4031 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 4032 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 4033 | * discover state machine is about to begin discovery, it just accepts the |
| 4034 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 4035 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 4036 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 4037 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 4038 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 4039 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 4040 | * routine is invoked to handle the RSCN event. |
| 4041 | * |
| 4042 | * Return code |
| 4043 | * 0 - Just sent the acc response |
| 4044 | * 1 - Sent the acc response and waited for name server completion |
| 4045 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4046 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4047 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4048 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4049 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4050 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4051 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4052 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4053 | uint32_t *lp, *datap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4054 | IOCB_t *icmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4055 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4056 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4057 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4058 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4059 | |
| 4060 | icmd = &cmdiocb->iocb; |
| 4061 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4062 | lp = (uint32_t *) pcmd->virt; |
| 4063 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4064 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4065 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4066 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4067 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4068 | "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] | 4069 | vport->fc_flag, payload_len, *lp, |
| 4070 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4071 | |
| 4072 | /* Send an RSCN event to the management application */ |
| 4073 | lpfc_send_rscn_event(vport, cmdiocb); |
| 4074 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4075 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4076 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4077 | FCH_EVT_RSCN, lp[i]); |
| 4078 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4079 | /* If we are about to begin discovery, just ACC the RSCN. |
| 4080 | * Discovery processing will satisfy it. |
| 4081 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4082 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4083 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4084 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 4085 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4086 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4087 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4088 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4089 | } |
| 4090 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4091 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 4092 | * just ACC and ignore it. |
| 4093 | */ |
| 4094 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4095 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4096 | i = payload_len; |
| 4097 | datap = lp; |
| 4098 | while (i > 0) { |
| 4099 | nportid = *datap++; |
| 4100 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 4101 | i -= sizeof(uint32_t); |
| 4102 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4103 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 4104 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4105 | } |
| 4106 | if (rscn_id == hba_id) { |
| 4107 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4108 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4109 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4110 | "Data: x%x x%x x%x x%x\n", |
| 4111 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4112 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4113 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4114 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 4115 | ndlp->nlp_DID, vport->port_state, |
| 4116 | ndlp->nlp_flag); |
| 4117 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4118 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4119 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4120 | return 0; |
| 4121 | } |
| 4122 | } |
| 4123 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4124 | spin_lock_irq(shost->host_lock); |
| 4125 | if (vport->fc_rscn_flush) { |
| 4126 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4127 | spin_unlock_irq(shost->host_lock); |
| 4128 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4129 | /* Send back ACC */ |
| 4130 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4131 | return 0; |
| 4132 | } |
| 4133 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4134 | vport->fc_rscn_flush = 1; |
| 4135 | spin_unlock_irq(shost->host_lock); |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame^] | 4136 | /* Get the array count after successfully have the token */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4137 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4138 | /* If we are already processing an RSCN, save the received |
| 4139 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 4140 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4141 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4142 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4143 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 4144 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4145 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4146 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4147 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 4148 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4149 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4150 | vport->fc_flag |= FC_RSCN_MODE; |
| 4151 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4152 | if (rscn_cnt) { |
| 4153 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 4154 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 4155 | } |
| 4156 | if ((rscn_cnt) && |
| 4157 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 4158 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4159 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4160 | memcpy(((uint8_t *)cmd) + length, lp, |
| 4161 | payload_len); |
| 4162 | } else { |
| 4163 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 4164 | vport->fc_rscn_id_cnt++; |
| 4165 | /* If we zero, cmdiocb->context2, the calling |
| 4166 | * routine will not try to free it. |
| 4167 | */ |
| 4168 | cmdiocb->context2 = NULL; |
| 4169 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4170 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4171 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4172 | "0235 Deferred RSCN " |
| 4173 | "Data: x%x x%x x%x\n", |
| 4174 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4175 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4176 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4177 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 4178 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4179 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4180 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4181 | "0234 ReDiscovery RSCN " |
| 4182 | "Data: x%x x%x x%x\n", |
| 4183 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4184 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4185 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4186 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4187 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4188 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4189 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4190 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4191 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4192 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4193 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4194 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4195 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4196 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4197 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4198 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 4199 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4200 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4201 | spin_lock_irq(shost->host_lock); |
| 4202 | vport->fc_flag |= FC_RSCN_MODE; |
| 4203 | spin_unlock_irq(shost->host_lock); |
| 4204 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4205 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4206 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4207 | /* |
| 4208 | * If we zero, cmdiocb->context2, the calling routine will |
| 4209 | * not try to free it. |
| 4210 | */ |
| 4211 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4212 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4213 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4214 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4215 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4216 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4217 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4218 | } |
| 4219 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4220 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4221 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4222 | * @vport: pointer to a host virtual N_Port data structure. |
| 4223 | * |
| 4224 | * This routine handles the Registration State Configuration Notification |
| 4225 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 4226 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 4227 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 4228 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 4229 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 4230 | * RSCN activities with the @vport. |
| 4231 | * |
| 4232 | * Return code |
| 4233 | * 0 - Cleaned up rscn on the @vport |
| 4234 | * 1 - Wait for plogi to name server before proceed |
| 4235 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4236 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4237 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4238 | { |
| 4239 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4240 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4241 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4242 | /* Ignore RSCN if the port is being torn down. */ |
| 4243 | if (vport->load_flag & FC_UNLOADING) { |
| 4244 | lpfc_els_flush_rscn(vport); |
| 4245 | return 0; |
| 4246 | } |
| 4247 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4248 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4249 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4250 | |
| 4251 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4252 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4253 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 4254 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 4255 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4256 | |
| 4257 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4258 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4259 | vport->num_disc_nodes = 0; |
| 4260 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4261 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4262 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 4263 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4264 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4265 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4266 | /* Wait for NameServer query cmpl before we can |
| 4267 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4268 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4269 | } else { |
| 4270 | /* If login to NameServer does not exist, issue one */ |
| 4271 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4272 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4273 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4274 | /* Wait for NameServer login cmpl before we can |
| 4275 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4276 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4277 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4278 | if (ndlp) { |
| 4279 | ndlp = lpfc_enable_node(vport, ndlp, |
| 4280 | NLP_STE_PLOGI_ISSUE); |
| 4281 | if (!ndlp) { |
| 4282 | lpfc_els_flush_rscn(vport); |
| 4283 | return 0; |
| 4284 | } |
| 4285 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4286 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4287 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4288 | if (!ndlp) { |
| 4289 | lpfc_els_flush_rscn(vport); |
| 4290 | return 0; |
| 4291 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4292 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4293 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4294 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4295 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4296 | ndlp->nlp_type |= NLP_FABRIC; |
| 4297 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 4298 | /* Wait for NameServer login cmpl before we can |
| 4299 | * continue |
| 4300 | */ |
| 4301 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4302 | } |
| 4303 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4304 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4305 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4306 | } |
| 4307 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4308 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4309 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4310 | * @vport: pointer to a host virtual N_Port data structure. |
| 4311 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4312 | * @ndlp: pointer to a node-list data structure. |
| 4313 | * |
| 4314 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 4315 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 4316 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 4317 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 4318 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 4319 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 4320 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 4321 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 4322 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 4323 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 4324 | * higher priority (as the winning port) and will initiate PLOGI and |
| 4325 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 4326 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 4327 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 4328 | * |
| 4329 | * Return code |
| 4330 | * 0 - Successfully processed the unsolicited flogi |
| 4331 | * 1 - Failed to process the unsolicited flogi |
| 4332 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4333 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4334 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4335 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4336 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4337 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4338 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4339 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4340 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 4341 | IOCB_t *icmd = &cmdiocb->iocb; |
| 4342 | struct serv_parm *sp; |
| 4343 | LPFC_MBOXQ_t *mbox; |
| 4344 | struct ls_rjt stat; |
| 4345 | uint32_t cmd, did; |
| 4346 | int rc; |
| 4347 | |
| 4348 | cmd = *lp++; |
| 4349 | sp = (struct serv_parm *) lp; |
| 4350 | |
| 4351 | /* FLOGI received */ |
| 4352 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4353 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4354 | |
| 4355 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 4356 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 4357 | did = icmd->un.elsreq64.remoteID; |
| 4358 | |
| 4359 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 4360 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4361 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4362 | "0113 An FLOGI ELS command x%x was " |
| 4363 | "received from DID x%x in Loop Mode\n", |
| 4364 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4365 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4366 | } |
| 4367 | |
| 4368 | did = Fabric_DID; |
| 4369 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4370 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4371 | /* For a FLOGI we accept, then if our portname is greater |
| 4372 | * then the remote portname we initiate Nport login. |
| 4373 | */ |
| 4374 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4375 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4376 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4377 | |
| 4378 | if (!rc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4379 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4380 | if (!mbox) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4381 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4382 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4383 | lpfc_linkdown(phba); |
| 4384 | lpfc_init_link(phba, mbox, |
| 4385 | phba->cfg_topology, |
| 4386 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4387 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4388 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4389 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4390 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4391 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4392 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4393 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4394 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4395 | return 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4396 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4397 | spin_lock_irq(shost->host_lock); |
| 4398 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 4399 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4400 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4401 | spin_lock_irq(shost->host_lock); |
| 4402 | vport->fc_flag |= FC_PT2PT; |
| 4403 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 4404 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4405 | } else { |
| 4406 | /* Reject this request because invalid parameters */ |
| 4407 | stat.un.b.lsRjtRsvd0 = 0; |
| 4408 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4409 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 4410 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4411 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4412 | NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4413 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4414 | } |
| 4415 | |
| 4416 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4417 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4418 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4419 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4420 | } |
| 4421 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4422 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4423 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4424 | * @vport: pointer to a host virtual N_Port data structure. |
| 4425 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4426 | * @ndlp: pointer to a node-list data structure. |
| 4427 | * |
| 4428 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 4429 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 4430 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 4431 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 4432 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 4433 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 4434 | * |
| 4435 | * Return code |
| 4436 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 4437 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4438 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4439 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4440 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4441 | { |
| 4442 | struct lpfc_dmabuf *pcmd; |
| 4443 | uint32_t *lp; |
| 4444 | IOCB_t *icmd; |
| 4445 | RNID *rn; |
| 4446 | struct ls_rjt stat; |
| 4447 | uint32_t cmd, did; |
| 4448 | |
| 4449 | icmd = &cmdiocb->iocb; |
| 4450 | did = icmd->un.elsreq64.remoteID; |
| 4451 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4452 | lp = (uint32_t *) pcmd->virt; |
| 4453 | |
| 4454 | cmd = *lp++; |
| 4455 | rn = (RNID *) lp; |
| 4456 | |
| 4457 | /* RNID received */ |
| 4458 | |
| 4459 | switch (rn->Format) { |
| 4460 | case 0: |
| 4461 | case RNID_TOPOLOGY_DISC: |
| 4462 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4463 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4464 | break; |
| 4465 | default: |
| 4466 | /* Reject this request because format not supported */ |
| 4467 | stat.un.b.lsRjtRsvd0 = 0; |
| 4468 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4469 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4470 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4471 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4472 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4473 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4474 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4475 | } |
| 4476 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4477 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4478 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4479 | * @vport: pointer to a host virtual N_Port data structure. |
| 4480 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4481 | * @ndlp: pointer to a node-list data structure. |
| 4482 | * |
| 4483 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 4484 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 4485 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 4486 | * |
| 4487 | * Return code |
| 4488 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 4489 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4490 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4491 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4492 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4493 | { |
| 4494 | struct ls_rjt stat; |
| 4495 | |
| 4496 | /* For now, unconditionally reject this command */ |
| 4497 | stat.un.b.lsRjtRsvd0 = 0; |
| 4498 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4499 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4500 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4501 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4502 | return 0; |
| 4503 | } |
| 4504 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4505 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4506 | * 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] | 4507 | * @phba: pointer to lpfc hba data structure. |
| 4508 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4509 | * |
| 4510 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 4511 | * mailbox command. This callback function is to actually send the Accept |
| 4512 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 4513 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 4514 | * mailbox command, constructs the RPS response with the link statistics |
| 4515 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 4516 | * response to the RPS. |
| 4517 | * |
| 4518 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4519 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4520 | * will be stored into the context1 field of the IOCB for the completion |
| 4521 | * callback function to the RPS Accept Response ELS IOCB command. |
| 4522 | * |
| 4523 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4524 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4525 | 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] | 4526 | { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4527 | MAILBOX_t *mb; |
| 4528 | IOCB_t *icmd; |
| 4529 | RPS_RSP *rps_rsp; |
| 4530 | uint8_t *pcmd; |
| 4531 | struct lpfc_iocbq *elsiocb; |
| 4532 | struct lpfc_nodelist *ndlp; |
| 4533 | uint16_t xri, status; |
| 4534 | uint32_t cmdsize; |
| 4535 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4536 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4537 | |
| 4538 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4539 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 4540 | pmb->context1 = NULL; |
| 4541 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4542 | |
| 4543 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4544 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4545 | return; |
| 4546 | } |
| 4547 | |
| 4548 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4549 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4550 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 4551 | lpfc_max_els_tries, ndlp, |
| 4552 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4553 | |
| 4554 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4555 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4556 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4557 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4558 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4559 | |
| 4560 | icmd = &elsiocb->iocb; |
| 4561 | icmd->ulpContext = xri; |
| 4562 | |
| 4563 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4564 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4565 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4566 | rps_rsp = (RPS_RSP *)pcmd; |
| 4567 | |
| 4568 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| 4569 | status = 0x10; |
| 4570 | else |
| 4571 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4572 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4573 | status |= 0x4; |
| 4574 | |
| 4575 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4576 | rps_rsp->portStatus = cpu_to_be16(status); |
| 4577 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 4578 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 4579 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 4580 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 4581 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 4582 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4583 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4584 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 4585 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 4586 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4587 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4588 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4589 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4590 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4591 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4592 | 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] | 4593 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4594 | return; |
| 4595 | } |
| 4596 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4597 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4598 | * lpfc_els_rcv_rps - Process an unsolicited rps iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4599 | * @vport: pointer to a host virtual N_Port data structure. |
| 4600 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4601 | * @ndlp: pointer to a node-list data structure. |
| 4602 | * |
| 4603 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 4604 | * ELS unsolicited event. It first checks the remote port state. If the |
| 4605 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 4606 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 4607 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 4608 | * for reading the HBA link statistics. It is for the callback function, |
| 4609 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 4610 | * to actually sending out RPS Accept (ACC) response. |
| 4611 | * |
| 4612 | * Return codes |
| 4613 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 4614 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4615 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4616 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4617 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4618 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4619 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4620 | uint32_t *lp; |
| 4621 | uint8_t flag; |
| 4622 | LPFC_MBOXQ_t *mbox; |
| 4623 | struct lpfc_dmabuf *pcmd; |
| 4624 | RPS *rps; |
| 4625 | struct ls_rjt stat; |
| 4626 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4627 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4628 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 4629 | /* reject the unsolicited RPS request and done with it */ |
| 4630 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4631 | |
| 4632 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4633 | lp = (uint32_t *) pcmd->virt; |
| 4634 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 4635 | rps = (RPS *) lp; |
| 4636 | |
| 4637 | if ((flag == 0) || |
| 4638 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4639 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4640 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4641 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4642 | printk("Fix me....\n"); |
| 4643 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4644 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 4645 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4646 | lpfc_read_lnk_stat(phba, mbox); |
| 4647 | mbox->context1 = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4648 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4649 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4650 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4651 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4652 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4653 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4654 | /* Mbox completion will send ELS Response */ |
| 4655 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4656 | /* Decrement reference count used for the failed mbox |
| 4657 | * command. |
| 4658 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4659 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4660 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4661 | } |
| 4662 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4663 | |
| 4664 | reject_out: |
| 4665 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4666 | stat.un.b.lsRjtRsvd0 = 0; |
| 4667 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4668 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4669 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4670 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4671 | return 0; |
| 4672 | } |
| 4673 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4674 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4675 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4676 | * @vport: pointer to a host virtual N_Port data structure. |
| 4677 | * @cmdsize: size of the ELS command. |
| 4678 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4679 | * @ndlp: pointer to a node-list data structure. |
| 4680 | * |
| 4681 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 4682 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 4683 | * |
| 4684 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4685 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4686 | * will be stored into the context1 field of the IOCB for the completion |
| 4687 | * callback function to the RPL Accept Response ELS command. |
| 4688 | * |
| 4689 | * Return code |
| 4690 | * 0 - Successfully issued ACC RPL ELS command |
| 4691 | * 1 - Failed to issue ACC RPL ELS command |
| 4692 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4693 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4694 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 4695 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4696 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4697 | struct lpfc_hba *phba = vport->phba; |
| 4698 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4699 | RPL_RSP rpl_rsp; |
| 4700 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4701 | uint8_t *pcmd; |
| 4702 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4703 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4704 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4705 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4706 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4707 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4708 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4709 | icmd = &elsiocb->iocb; |
| 4710 | oldcmd = &oldiocb->iocb; |
| 4711 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 4712 | |
| 4713 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4714 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4715 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4716 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 4717 | pcmd += sizeof(uint16_t); |
| 4718 | |
| 4719 | /* Setup the RPL ACC payload */ |
| 4720 | rpl_rsp.listLen = be32_to_cpu(1); |
| 4721 | rpl_rsp.index = 0; |
| 4722 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4723 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 4724 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4725 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4726 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4727 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4728 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4729 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 4730 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 4731 | "rpi x%x\n", |
| 4732 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4733 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4734 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4735 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4736 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4737 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 4738 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4739 | lpfc_els_free_iocb(phba, elsiocb); |
| 4740 | return 1; |
| 4741 | } |
| 4742 | return 0; |
| 4743 | } |
| 4744 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4745 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4746 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4747 | * @vport: pointer to a host virtual N_Port data structure. |
| 4748 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4749 | * @ndlp: pointer to a node-list data structure. |
| 4750 | * |
| 4751 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 4752 | * unsolicited event. It first checks the remote port state. If the remote |
| 4753 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 4754 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 4755 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 4756 | * to accept the RPL. |
| 4757 | * |
| 4758 | * Return code |
| 4759 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 4760 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4761 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4762 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4763 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4764 | { |
| 4765 | struct lpfc_dmabuf *pcmd; |
| 4766 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4767 | uint32_t maxsize; |
| 4768 | uint16_t cmdsize; |
| 4769 | RPL *rpl; |
| 4770 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4771 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4772 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 4773 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4774 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4775 | stat.un.b.lsRjtRsvd0 = 0; |
| 4776 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4777 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4778 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4779 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4780 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4781 | /* rejected the unsolicited RPL request and done with it */ |
| 4782 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4783 | } |
| 4784 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4785 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4786 | lp = (uint32_t *) pcmd->virt; |
| 4787 | rpl = (RPL *) (lp + 1); |
| 4788 | |
| 4789 | maxsize = be32_to_cpu(rpl->maxsize); |
| 4790 | |
| 4791 | /* We support only one port */ |
| 4792 | if ((rpl->index == 0) && |
| 4793 | ((maxsize == 0) || |
| 4794 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 4795 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4796 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4797 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 4798 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4799 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4800 | |
| 4801 | return 0; |
| 4802 | } |
| 4803 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4804 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4805 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4806 | * @vport: pointer to a virtual N_Port data structure. |
| 4807 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4808 | * @ndlp: pointer to a node-list data structure. |
| 4809 | * |
| 4810 | * This routine processes Fibre Channel Address Resolution Protocol |
| 4811 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 4812 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 4813 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 4814 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 4815 | * remote PortName is compared against the FC PortName stored in the @vport |
| 4816 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 4817 | * compared against the FC NodeName stored in the @vport data structure. |
| 4818 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 4819 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 4820 | * invoked to send out FARP Response to the remote node. Before sending the |
| 4821 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 4822 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 4823 | * routine is invoked to log into the remote port first. |
| 4824 | * |
| 4825 | * Return code |
| 4826 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 4827 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4828 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4829 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4830 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4831 | { |
| 4832 | struct lpfc_dmabuf *pcmd; |
| 4833 | uint32_t *lp; |
| 4834 | IOCB_t *icmd; |
| 4835 | FARP *fp; |
| 4836 | uint32_t cmd, cnt, did; |
| 4837 | |
| 4838 | icmd = &cmdiocb->iocb; |
| 4839 | did = icmd->un.elsreq64.remoteID; |
| 4840 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4841 | lp = (uint32_t *) pcmd->virt; |
| 4842 | |
| 4843 | cmd = *lp++; |
| 4844 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4845 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4846 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4847 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4848 | /* We will only support match on WWPN or WWNN */ |
| 4849 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4850 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4851 | } |
| 4852 | |
| 4853 | cnt = 0; |
| 4854 | /* If this FARP command is searching for my portname */ |
| 4855 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4856 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4857 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4858 | cnt = 1; |
| 4859 | } |
| 4860 | |
| 4861 | /* If this FARP command is searching for my nodename */ |
| 4862 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4863 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4864 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4865 | cnt = 1; |
| 4866 | } |
| 4867 | |
| 4868 | if (cnt) { |
| 4869 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 4870 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 4871 | /* Log back into the node before sending the FARP. */ |
| 4872 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4873 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4874 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4875 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4876 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4877 | } |
| 4878 | |
| 4879 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4880 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 4881 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4882 | } |
| 4883 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4884 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4885 | } |
| 4886 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4887 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4888 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4889 | * @vport: pointer to a host virtual N_Port data structure. |
| 4890 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4891 | * @ndlp: pointer to a node-list data structure. |
| 4892 | * |
| 4893 | * This routine processes Fibre Channel Address Resolution Protocol |
| 4894 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 4895 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 4896 | * the FARP response request. |
| 4897 | * |
| 4898 | * Return code |
| 4899 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 4900 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4901 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4902 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4903 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4904 | { |
| 4905 | struct lpfc_dmabuf *pcmd; |
| 4906 | uint32_t *lp; |
| 4907 | IOCB_t *icmd; |
| 4908 | uint32_t cmd, did; |
| 4909 | |
| 4910 | icmd = &cmdiocb->iocb; |
| 4911 | did = icmd->un.elsreq64.remoteID; |
| 4912 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4913 | lp = (uint32_t *) pcmd->virt; |
| 4914 | |
| 4915 | cmd = *lp++; |
| 4916 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4917 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4918 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4919 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4920 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4921 | |
| 4922 | return 0; |
| 4923 | } |
| 4924 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4925 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4926 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4927 | * @vport: pointer to a host virtual N_Port data structure. |
| 4928 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4929 | * @fan_ndlp: pointer to a node-list data structure. |
| 4930 | * |
| 4931 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 4932 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 4933 | * only be processed on a physical port (i.e., the @vport represents the |
| 4934 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 4935 | * compared against those in the phba data structure. If any of those is |
| 4936 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 4937 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 4938 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 4939 | * is invoked to register login to the fabric. |
| 4940 | * |
| 4941 | * Return code |
| 4942 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 4943 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4944 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4945 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4946 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4947 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4948 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4949 | uint32_t *lp; |
| 4950 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4951 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4952 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 4953 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 4954 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4955 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4956 | if ((vport == phba->pport) && |
| 4957 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4958 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4959 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4960 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4961 | sizeof(struct lpfc_name)))) { |
| 4962 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4963 | lpfc_initial_flogi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4964 | } else { |
| 4965 | /* FAN verified - skip FLOGI */ |
| 4966 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4967 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 4968 | lpfc_issue_fabric_reglogin(vport); |
| 4969 | else |
| 4970 | lpfc_issue_reg_vfi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4971 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4972 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4973 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4974 | } |
| 4975 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4976 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4977 | * lpfc_els_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4978 | * @ptr: holder for the timer function associated data. |
| 4979 | * |
| 4980 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 4981 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 4982 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 4983 | * up the worker thread. It is for the worker thread to invoke the routine |
| 4984 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 4985 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4986 | void |
| 4987 | lpfc_els_timeout(unsigned long ptr) |
| 4988 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4989 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 4990 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4991 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4992 | unsigned long iflag; |
| 4993 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4994 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4995 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
| 4996 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4997 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4998 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4999 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5000 | if (!tmo_posted) |
| 5001 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5002 | return; |
| 5003 | } |
| 5004 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5005 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5006 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5007 | * @vport: pointer to a virtual N_Port data structure. |
| 5008 | * |
| 5009 | * This routine is the actual handler function that processes an ELS timeout |
| 5010 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 5011 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 5012 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5013 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5014 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5015 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5016 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5017 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5018 | struct lpfc_sli_ring *pring; |
| 5019 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5020 | IOCB_t *cmd = NULL; |
| 5021 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5022 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5023 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5024 | uint32_t remote_ID = 0xffffffff; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5025 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5026 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5027 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 5028 | |
| 5029 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5030 | |
| 5031 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5032 | cmd = &piocb->iocb; |
| 5033 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5034 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 5035 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 5036 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5037 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5038 | |
| 5039 | if (piocb->vport != vport) |
| 5040 | continue; |
| 5041 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5042 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5043 | if (pcmd) |
| 5044 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5045 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5046 | if (els_command == ELS_CMD_FARP || |
| 5047 | els_command == ELS_CMD_FARPR || |
| 5048 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5049 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5050 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5051 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5052 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5053 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5054 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5055 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5056 | continue; |
| 5057 | } |
| 5058 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5059 | remote_ID = 0xffffffff; |
| 5060 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5061 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5062 | else { |
| 5063 | struct lpfc_nodelist *ndlp; |
| 5064 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5065 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5066 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5067 | } |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5068 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5069 | "0127 ELS timeout Data: x%x x%x x%x " |
| 5070 | "x%x\n", els_command, |
| 5071 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5072 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5073 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5074 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 5075 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5076 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
| 5077 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5078 | } |
| 5079 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5080 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5081 | * 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] | 5082 | * @vport: pointer to a host virtual N_Port data structure. |
| 5083 | * |
| 5084 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5085 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 5086 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5087 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5088 | * the IOCBs with a non-NULL completion callback function, the callback |
| 5089 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5090 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 5091 | * callback function, the IOCB will simply be released. Finally, it walks |
| 5092 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 5093 | * completion queue IOCB that is associated with the @vport and is not |
| 5094 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 5095 | * part of the discovery state machine) out to HBA by invoking the |
| 5096 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 5097 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 5098 | * the IOCBs are aborted when this function returns. |
| 5099 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5100 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5101 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5102 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5103 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5104 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5105 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5106 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5107 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5108 | |
| 5109 | lpfc_fabric_abort_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5110 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5111 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5112 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5113 | cmd = &piocb->iocb; |
| 5114 | |
| 5115 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5116 | continue; |
| 5117 | } |
| 5118 | |
| 5119 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5120 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5121 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5122 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5123 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5124 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5125 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5126 | if (piocb->vport != vport) |
| 5127 | continue; |
| 5128 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5129 | list_move_tail(&piocb->list, &completions); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5130 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5131 | } |
| 5132 | |
| 5133 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5134 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5135 | continue; |
| 5136 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5137 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5138 | if (piocb->vport != vport) |
| 5139 | continue; |
| 5140 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5141 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5142 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5143 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5144 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5145 | /* Cancell all the IOCBs from the completions list */ |
| 5146 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5147 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5148 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5149 | return; |
| 5150 | } |
| 5151 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5152 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5153 | * 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] | 5154 | * @phba: pointer to lpfc hba data structure. |
| 5155 | * |
| 5156 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5157 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 5158 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5159 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5160 | * the IOCBs with the completion callback function associated, the callback |
| 5161 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5162 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 5163 | * callback function associated, the IOCB will simply be released. Finally, |
| 5164 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 5165 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 5166 | * management plane IOCBs that are not part of the discovery state machine) |
| 5167 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5168 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5169 | void |
| 5170 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 5171 | { |
| 5172 | LIST_HEAD(completions); |
| 5173 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 5174 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5175 | IOCB_t *cmd = NULL; |
| 5176 | |
| 5177 | lpfc_fabric_abort_hba(phba); |
| 5178 | spin_lock_irq(&phba->hbalock); |
| 5179 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5180 | cmd = &piocb->iocb; |
| 5181 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5182 | continue; |
| 5183 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
| 5184 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5185 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5186 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5187 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| 5188 | continue; |
| 5189 | list_move_tail(&piocb->list, &completions); |
| 5190 | pring->txq_cnt--; |
| 5191 | } |
| 5192 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5193 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5194 | continue; |
| 5195 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5196 | } |
| 5197 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5198 | |
| 5199 | /* Cancel all the IOCBs from the completions list */ |
| 5200 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5201 | IOERR_SLI_ABORTED); |
| 5202 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5203 | return; |
| 5204 | } |
| 5205 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5206 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5207 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5208 | * @phba: Pointer to hba context object. |
| 5209 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 5210 | * @rspiocbp: Pointer to response iocb which reported error. |
| 5211 | * |
| 5212 | * This function sends an event when there is an ELS command |
| 5213 | * failure. |
| 5214 | **/ |
| 5215 | void |
| 5216 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 5217 | struct lpfc_iocbq *cmdiocbp, |
| 5218 | struct lpfc_iocbq *rspiocbp) |
| 5219 | { |
| 5220 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 5221 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5222 | struct lpfc_lsrjt_event lsrjt_event; |
| 5223 | struct lpfc_fabric_event_header fabric_event; |
| 5224 | struct ls_rjt stat; |
| 5225 | struct lpfc_nodelist *ndlp; |
| 5226 | uint32_t *pcmd; |
| 5227 | |
| 5228 | ndlp = cmdiocbp->context1; |
| 5229 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 5230 | return; |
| 5231 | |
| 5232 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 5233 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 5234 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 5235 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 5236 | sizeof(struct lpfc_name)); |
| 5237 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 5238 | sizeof(struct lpfc_name)); |
| 5239 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 5240 | cmdiocbp->context2)->virt); |
| 5241 | lsrjt_event.command = *pcmd; |
| 5242 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 5243 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 5244 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 5245 | fc_host_post_vendor_event(shost, |
| 5246 | fc_get_event_number(), |
| 5247 | sizeof(lsrjt_event), |
| 5248 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5249 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5250 | return; |
| 5251 | } |
| 5252 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 5253 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 5254 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 5255 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 5256 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 5257 | else |
| 5258 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 5259 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 5260 | sizeof(struct lpfc_name)); |
| 5261 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 5262 | sizeof(struct lpfc_name)); |
| 5263 | fc_host_post_vendor_event(shost, |
| 5264 | fc_get_event_number(), |
| 5265 | sizeof(fabric_event), |
| 5266 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5267 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5268 | return; |
| 5269 | } |
| 5270 | |
| 5271 | } |
| 5272 | |
| 5273 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5274 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5275 | * @vport: Pointer to vport object. |
| 5276 | * @ndlp: Pointer FC node object. |
| 5277 | * @cmd: ELS command code. |
| 5278 | * |
| 5279 | * This function posts an event when there is an incoming |
| 5280 | * unsolicited ELS command. |
| 5281 | **/ |
| 5282 | static void |
| 5283 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 5284 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5285 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5286 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5287 | struct lpfc_els_event_header *els_data = NULL; |
| 5288 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5289 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5290 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5291 | if (*payload == ELS_CMD_LOGO) { |
| 5292 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 5293 | if (!logo_data) { |
| 5294 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5295 | "0148 Failed to allocate memory " |
| 5296 | "for LOGO event\n"); |
| 5297 | return; |
| 5298 | } |
| 5299 | els_data = &logo_data->header; |
| 5300 | } else { |
| 5301 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 5302 | GFP_KERNEL); |
| 5303 | if (!els_data) { |
| 5304 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5305 | "0149 Failed to allocate memory " |
| 5306 | "for ELS event\n"); |
| 5307 | return; |
| 5308 | } |
| 5309 | } |
| 5310 | els_data->event_type = FC_REG_ELS_EVENT; |
| 5311 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5312 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5313 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5314 | break; |
| 5315 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5316 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5317 | break; |
| 5318 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5319 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 5320 | break; |
| 5321 | case ELS_CMD_LOGO: |
| 5322 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 5323 | /* Copy the WWPN in the LOGO payload */ |
| 5324 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 5325 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5326 | break; |
| 5327 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 5328 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5329 | return; |
| 5330 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5331 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 5332 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 5333 | if (*payload == ELS_CMD_LOGO) { |
| 5334 | fc_host_post_vendor_event(shost, |
| 5335 | fc_get_event_number(), |
| 5336 | sizeof(struct lpfc_logo_event), |
| 5337 | (char *)logo_data, |
| 5338 | LPFC_NL_VENDOR_ID); |
| 5339 | kfree(logo_data); |
| 5340 | } else { |
| 5341 | fc_host_post_vendor_event(shost, |
| 5342 | fc_get_event_number(), |
| 5343 | sizeof(struct lpfc_els_event_header), |
| 5344 | (char *)els_data, |
| 5345 | LPFC_NL_VENDOR_ID); |
| 5346 | kfree(els_data); |
| 5347 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5348 | |
| 5349 | return; |
| 5350 | } |
| 5351 | |
| 5352 | |
| 5353 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5354 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5355 | * @phba: pointer to lpfc hba data structure. |
| 5356 | * @pring: pointer to a SLI ring. |
| 5357 | * @vport: pointer to a host virtual N_Port data structure. |
| 5358 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 5359 | * |
| 5360 | * This routine is used for processing the IOCB associated with a unsolicited |
| 5361 | * event. It first determines whether there is an existing ndlp that matches |
| 5362 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 5363 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 5364 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 5365 | * of the discovery state machine. |
| 5366 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5367 | static void |
| 5368 | 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] | 5369 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5370 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5371 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5372 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5373 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5374 | uint32_t *payload; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5375 | uint32_t cmd, did, newnode, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5376 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5377 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5378 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5379 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5380 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5381 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5382 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 5383 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5384 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5385 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5386 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5387 | did = icmd->un.rcvels.remoteID; |
| 5388 | if (icmd->ulpStatus) { |
| 5389 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5390 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 5391 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5392 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5393 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5394 | |
| 5395 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5396 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5397 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5398 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5399 | /* Ignore traffic recevied during vport shutdown. */ |
| 5400 | if (vport->load_flag & FC_UNLOADING) |
| 5401 | goto dropit; |
| 5402 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5403 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5404 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5405 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5406 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5407 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5408 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5409 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5410 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5411 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5412 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5413 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5414 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5415 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5416 | ndlp = lpfc_enable_node(vport, ndlp, |
| 5417 | NLP_STE_UNUSED_NODE); |
| 5418 | if (!ndlp) |
| 5419 | goto dropit; |
| 5420 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5421 | newnode = 1; |
| 5422 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 5423 | ndlp->nlp_type |= NLP_FABRIC; |
| 5424 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 5425 | /* This is similar to the new node path */ |
| 5426 | ndlp = lpfc_nlp_get(ndlp); |
| 5427 | if (!ndlp) |
| 5428 | goto dropit; |
| 5429 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5430 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5431 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5432 | |
| 5433 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5434 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5435 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5436 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5437 | |
| 5438 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 5439 | cmd &= ELS_CMD_MASK; |
| 5440 | } |
| 5441 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5442 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5443 | "0112 ELS command x%x received from NPORT x%x " |
| 5444 | "Data: x%x\n", cmd, did, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5445 | switch (cmd) { |
| 5446 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5447 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5448 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 5449 | did, vport->port_state, ndlp->nlp_flag); |
| 5450 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5451 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5452 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
| 5453 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5454 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5455 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5456 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 5457 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 5458 | rjt_err = LSRJT_UNABLE_TPC; |
| 5459 | break; |
| 5460 | } |
| 5461 | /* We get here, and drop thru, if we are PT2PT with |
| 5462 | * another NPort and the other side has initiated |
| 5463 | * the PLOGI before responding to our FLOGI. |
| 5464 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5465 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5466 | |
| 5467 | shost = lpfc_shost_from_vport(vport); |
| 5468 | spin_lock_irq(shost->host_lock); |
| 5469 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 5470 | spin_unlock_irq(shost->host_lock); |
| 5471 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5472 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5473 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5474 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5475 | break; |
| 5476 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5477 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5478 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 5479 | did, vport->port_state, ndlp->nlp_flag); |
| 5480 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5481 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5482 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5483 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5484 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5485 | break; |
| 5486 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5487 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5488 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 5489 | did, vport->port_state, ndlp->nlp_flag); |
| 5490 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5491 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5492 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5493 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5494 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5495 | break; |
| 5496 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5497 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5498 | break; |
| 5499 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5500 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5501 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 5502 | did, vport->port_state, ndlp->nlp_flag); |
| 5503 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5504 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5505 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5506 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5507 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5508 | break; |
| 5509 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5510 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5511 | break; |
| 5512 | case ELS_CMD_RSCN: |
| 5513 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5514 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5515 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5516 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5517 | break; |
| 5518 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5519 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5520 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 5521 | did, vport->port_state, ndlp->nlp_flag); |
| 5522 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5523 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5524 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5525 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5526 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5527 | break; |
| 5528 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5529 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5530 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5531 | break; |
| 5532 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5533 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5534 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 5535 | did, vport->port_state, ndlp->nlp_flag); |
| 5536 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5537 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5538 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5539 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5540 | break; |
| 5541 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5542 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5543 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5544 | break; |
| 5545 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5546 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5547 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 5548 | did, vport->port_state, ndlp->nlp_flag); |
| 5549 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5550 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5551 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5552 | break; |
| 5553 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5554 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5555 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 5556 | did, vport->port_state, ndlp->nlp_flag); |
| 5557 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5558 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5559 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5560 | break; |
| 5561 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5562 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5563 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 5564 | did, vport->port_state, ndlp->nlp_flag); |
| 5565 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5566 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5567 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5568 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5569 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5570 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5571 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 5572 | did, vport->port_state, ndlp->nlp_flag); |
| 5573 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5574 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5575 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5576 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5577 | break; |
| 5578 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5579 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5580 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5581 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5582 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5583 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 5584 | did, vport->port_state, ndlp->nlp_flag); |
| 5585 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5586 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5587 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5588 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5589 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5590 | break; |
| 5591 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5592 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5593 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 5594 | did, vport->port_state, ndlp->nlp_flag); |
| 5595 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5596 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5597 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5598 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5599 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5600 | break; |
| 5601 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5602 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5603 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 5604 | did, vport->port_state, ndlp->nlp_flag); |
| 5605 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5606 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5607 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5608 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5609 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5610 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5611 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5612 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5613 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 5614 | did, vport->port_state, ndlp->nlp_flag); |
| 5615 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5616 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5617 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5618 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5619 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5620 | break; |
| 5621 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5622 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5623 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 5624 | cmd, did, vport->port_state); |
| 5625 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5626 | /* Unsupported ELS command, reject */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5627 | rjt_err = LSRJT_INVALID_CMD; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5628 | |
| 5629 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5630 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5631 | "0115 Unknown ELS command x%x " |
| 5632 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5633 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5634 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5635 | break; |
| 5636 | } |
| 5637 | |
| 5638 | /* check if need to LS_RJT received ELS cmd */ |
| 5639 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5640 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5641 | stat.un.b.lsRjtRsnCode = rjt_err; |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 5642 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5643 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 5644 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5645 | } |
| 5646 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5647 | lpfc_nlp_put(elsiocb->context1); |
| 5648 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5649 | return; |
| 5650 | |
| 5651 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5652 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5653 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5654 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5655 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5656 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5657 | phba->fc_stat.elsRcvDrop++; |
| 5658 | } |
| 5659 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5660 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5661 | * 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] | 5662 | * @phba: pointer to lpfc hba data structure. |
| 5663 | * @vpi: host virtual N_Port identifier. |
| 5664 | * |
| 5665 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 5666 | * @vpi. The function walks the HBA's vport list and returns the address |
| 5667 | * of the vport with the matching @vpi. |
| 5668 | * |
| 5669 | * Return code |
| 5670 | * NULL - No vport with the matching @vpi found |
| 5671 | * Otherwise - Address to the vport with the matching @vpi. |
| 5672 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5673 | static struct lpfc_vport * |
| 5674 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 5675 | { |
| 5676 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5677 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5678 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5679 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5680 | list_for_each_entry(vport, &phba->port_list, listentry) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5681 | if (vport->vpi == vpi) { |
| 5682 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5683 | return vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5684 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5685 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5686 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5687 | return NULL; |
| 5688 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5689 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5690 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5691 | * 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] | 5692 | * @phba: pointer to lpfc hba data structure. |
| 5693 | * @pring: pointer to a SLI ring. |
| 5694 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 5695 | * |
| 5696 | * This routine is used to process an unsolicited event received from a SLI |
| 5697 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 5698 | * associated with the unsolicited event is done by invoking the routine |
| 5699 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 5700 | * SLI ring on which the unsolicited event was received. |
| 5701 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5702 | void |
| 5703 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 5704 | struct lpfc_iocbq *elsiocb) |
| 5705 | { |
| 5706 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5707 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5708 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5709 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 5710 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5711 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5712 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5713 | elsiocb->context2 = NULL; |
| 5714 | elsiocb->context3 = NULL; |
| 5715 | |
| 5716 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 5717 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 5718 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 5719 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5720 | phba->fc_stat.NoRcvBuf++; |
| 5721 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5722 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5723 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5724 | return; |
| 5725 | } |
| 5726 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5727 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 5728 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 5729 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 5730 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 5731 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5732 | else |
| 5733 | vport = lpfc_find_vport_by_vpid(phba, |
| 5734 | icmd->unsli3.rcvsli3.vpi - phba->vpi_base); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5735 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5736 | /* If there are no BDEs associated |
| 5737 | * with this IOCB, there is nothing to do. |
| 5738 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5739 | if (icmd->ulpBdeCount == 0) |
| 5740 | return; |
| 5741 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5742 | /* type of ELS cmd is first 32bit word |
| 5743 | * in packet |
| 5744 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5745 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5746 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5747 | } else { |
| 5748 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 5749 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5750 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 5751 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5752 | } |
| 5753 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5754 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 5755 | /* |
| 5756 | * The different unsolicited event handlers would tell us |
| 5757 | * if they are done with "mp" by setting context2 to NULL. |
| 5758 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5759 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5760 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 5761 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5762 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5763 | |
| 5764 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5765 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5766 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5767 | elsiocb->context2 = bdeBuf2; |
| 5768 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5769 | /* free mp if we are done with it */ |
| 5770 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5771 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 5772 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5773 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5774 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5775 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5776 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5777 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5778 | * 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] | 5779 | * @phba: pointer to lpfc hba data structure. |
| 5780 | * @vport: pointer to a virtual N_Port data structure. |
| 5781 | * |
| 5782 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 5783 | * State Change Request (SCR) for a @vport. This routine will create an |
| 5784 | * ndlp for the Name Server associated to the @vport if such node does |
| 5785 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 5786 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 5787 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 5788 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 5789 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5790 | void |
| 5791 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 5792 | { |
| 5793 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
| 5794 | |
| 5795 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 5796 | if (!ndlp) { |
| 5797 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 5798 | if (!ndlp) { |
| 5799 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5800 | lpfc_disc_start(vport); |
| 5801 | return; |
| 5802 | } |
| 5803 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5804 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5805 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5806 | return; |
| 5807 | } |
| 5808 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5809 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5810 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 5811 | if (!ndlp) { |
| 5812 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5813 | lpfc_disc_start(vport); |
| 5814 | return; |
| 5815 | } |
| 5816 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5817 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5818 | "0348 NameServer login: node freed\n"); |
| 5819 | return; |
| 5820 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5821 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5822 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5823 | |
| 5824 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 5825 | |
| 5826 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 5827 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5828 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5829 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5830 | return; |
| 5831 | } |
| 5832 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5833 | if (vport->cfg_fdmi_on) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5834 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 5835 | GFP_KERNEL); |
| 5836 | if (ndlp_fdmi) { |
| 5837 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 5838 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5839 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
| 5840 | NLP_STE_PLOGI_ISSUE); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5841 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, |
| 5842 | 0); |
| 5843 | } |
| 5844 | } |
| 5845 | return; |
| 5846 | } |
| 5847 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5848 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5849 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5850 | * @phba: pointer to lpfc hba data structure. |
| 5851 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 5852 | * |
| 5853 | * This routine is the completion callback function to register new vport |
| 5854 | * mailbox command. If the new vport mailbox command completes successfully, |
| 5855 | * the fabric registration login shall be performed on physical port (the |
| 5856 | * new vport created is actually a physical port, with VPI 0) or the port |
| 5857 | * login to Name Server for State Change Request (SCR) will be performed |
| 5858 | * on virtual port (real virtual port, with VPI greater than 0). |
| 5859 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5860 | static void |
| 5861 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 5862 | { |
| 5863 | struct lpfc_vport *vport = pmb->vport; |
| 5864 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5865 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5866 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5867 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5868 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5869 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5870 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5871 | |
| 5872 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5873 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 5874 | "0915 Register VPI failed: 0x%x\n", |
| 5875 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5876 | |
| 5877 | switch (mb->mbxStatus) { |
| 5878 | case 0x11: /* unsupported feature */ |
| 5879 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5880 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5881 | /* giving up on vport registration */ |
| 5882 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5883 | spin_lock_irq(shost->host_lock); |
| 5884 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 5885 | spin_unlock_irq(shost->host_lock); |
| 5886 | lpfc_can_disctmo(vport); |
| 5887 | break; |
| 5888 | default: |
| 5889 | /* Try to recover from this error */ |
| 5890 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5891 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5892 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5893 | spin_unlock_irq(shost->host_lock); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5894 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 5895 | lpfc_initial_flogi(vport); |
| 5896 | else |
| 5897 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5898 | break; |
| 5899 | } |
| 5900 | |
| 5901 | } else { |
| 5902 | if (vport == phba->pport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5903 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5904 | lpfc_issue_fabric_reglogin(vport); |
| 5905 | else |
| 5906 | lpfc_issue_reg_vfi(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5907 | else |
| 5908 | lpfc_do_scr_ns_plogi(phba, vport); |
| 5909 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5910 | |
| 5911 | /* Now, we decrement the ndlp reference count held for this |
| 5912 | * callback function |
| 5913 | */ |
| 5914 | lpfc_nlp_put(ndlp); |
| 5915 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5916 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5917 | return; |
| 5918 | } |
| 5919 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5920 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5921 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5922 | * @phba: pointer to lpfc hba data structure. |
| 5923 | * @vport: pointer to a host virtual N_Port data structure. |
| 5924 | * @ndlp: pointer to a node-list data structure. |
| 5925 | * |
| 5926 | * This routine registers the @vport as a new virtual port with a HBA. |
| 5927 | * It is done through a registering vpi mailbox command. |
| 5928 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5929 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5930 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 5931 | struct lpfc_nodelist *ndlp) |
| 5932 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5933 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5934 | LPFC_MBOXQ_t *mbox; |
| 5935 | |
| 5936 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5937 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5938 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5939 | mbox->vport = vport; |
| 5940 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 5941 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5942 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5943 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5944 | /* mailbox command not success, decrement ndlp |
| 5945 | * reference count for this command |
| 5946 | */ |
| 5947 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5948 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5949 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5950 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 5951 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5952 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5953 | } |
| 5954 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5955 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 5956 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5957 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5958 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5959 | return; |
| 5960 | |
| 5961 | mbox_err_exit: |
| 5962 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5963 | spin_lock_irq(shost->host_lock); |
| 5964 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 5965 | spin_unlock_irq(shost->host_lock); |
| 5966 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5967 | } |
| 5968 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5969 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5970 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5971 | * @phba: pointer to lpfc hba data structure. |
| 5972 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5973 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 5974 | * |
| 5975 | * This routine is the completion callback function to a Fabric Discover |
| 5976 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 5977 | * single threaded, each FDISC completion callback function will reset |
| 5978 | * the discovery timer for all vports such that the timers will not get |
| 5979 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 5980 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 5981 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 5982 | * assigned to the vport has been changed with the completion of the FDISC |
| 5983 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 5984 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 5985 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 5986 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 5987 | * Server for State Change Request (SCR). |
| 5988 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5989 | static void |
| 5990 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 5991 | struct lpfc_iocbq *rspiocb) |
| 5992 | { |
| 5993 | struct lpfc_vport *vport = cmdiocb->vport; |
| 5994 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5995 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 5996 | struct lpfc_nodelist *np; |
| 5997 | struct lpfc_nodelist *next_np; |
| 5998 | IOCB_t *irsp = &rspiocb->iocb; |
| 5999 | struct lpfc_iocbq *piocb; |
| 6000 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6001 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 6002 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 6003 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 6004 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6005 | /* Since all FDISCs are being single threaded, we |
| 6006 | * must reset the discovery timer for ALL vports |
| 6007 | * waiting to send FDISC when one completes. |
| 6008 | */ |
| 6009 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 6010 | lpfc_set_disctmo(piocb->vport); |
| 6011 | } |
| 6012 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6013 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6014 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 6015 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 6016 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6017 | if (irsp->ulpStatus) { |
| 6018 | /* Check for retry */ |
| 6019 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 6020 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6021 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6022 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6023 | "0126 FDISC failed. (%d/%d)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6024 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6025 | goto fdisc_failed; |
| 6026 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6027 | if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING) |
| 6028 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6029 | lpfc_nlp_put(ndlp); |
| 6030 | /* giving up on FDISC. Cancel discovery timer */ |
| 6031 | lpfc_can_disctmo(vport); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6032 | spin_lock_irq(shost->host_lock); |
| 6033 | vport->fc_flag |= FC_FABRIC; |
| 6034 | if (vport->phba->fc_topology == TOPOLOGY_LOOP) |
| 6035 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 6036 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6037 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6038 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 6039 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
| 6040 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 6041 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 6042 | /* If our NportID changed, we need to ensure all |
| 6043 | * remaining NPORTs get unreg_login'ed so we can |
| 6044 | * issue unreg_vpi. |
| 6045 | */ |
| 6046 | list_for_each_entry_safe(np, next_np, |
| 6047 | &vport->fc_nodes, nlp_listp) { |
| 6048 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 6049 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 6050 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 6051 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6052 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6053 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6054 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6055 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6056 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6057 | lpfc_mbx_unreg_vpi(vport); |
| 6058 | spin_lock_irq(shost->host_lock); |
| 6059 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 6060 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6061 | } |
| 6062 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6063 | if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 6064 | lpfc_register_new_vport(phba, vport, ndlp); |
| 6065 | else |
| 6066 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6067 | goto out; |
| 6068 | fdisc_failed: |
| 6069 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6070 | /* Cancel discovery timer */ |
| 6071 | lpfc_can_disctmo(vport); |
| 6072 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6073 | out: |
| 6074 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6075 | } |
| 6076 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6077 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6078 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6079 | * @vport: pointer to a virtual N_Port data structure. |
| 6080 | * @ndlp: pointer to a node-list data structure. |
| 6081 | * @retry: number of retries to the command IOCB. |
| 6082 | * |
| 6083 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 6084 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 6085 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 6086 | * IOCB will be sent off HBA at any given time. |
| 6087 | * |
| 6088 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6089 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6090 | * will be stored into the context1 field of the IOCB for the completion |
| 6091 | * callback function to the FDISC ELS command. |
| 6092 | * |
| 6093 | * Return code |
| 6094 | * 0 - Successfully issued fdisc iocb command |
| 6095 | * 1 - Failed to issue fdisc iocb command |
| 6096 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6097 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6098 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 6099 | uint8_t retry) |
| 6100 | { |
| 6101 | struct lpfc_hba *phba = vport->phba; |
| 6102 | IOCB_t *icmd; |
| 6103 | struct lpfc_iocbq *elsiocb; |
| 6104 | struct serv_parm *sp; |
| 6105 | uint8_t *pcmd; |
| 6106 | uint16_t cmdsize; |
| 6107 | int did = ndlp->nlp_DID; |
| 6108 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6109 | |
| 6110 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 6111 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 6112 | ELS_CMD_FDISC); |
| 6113 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6114 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6115 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6116 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6117 | return 1; |
| 6118 | } |
| 6119 | |
| 6120 | icmd = &elsiocb->iocb; |
| 6121 | icmd->un.elsreq64.myID = 0; |
| 6122 | icmd->un.elsreq64.fl = 1; |
| 6123 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6124 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 6125 | /* FDISC needs to be 1 for WQE VPI */ |
| 6126 | elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1; |
| 6127 | elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ; |
| 6128 | /* Set the ulpContext to the vpi */ |
| 6129 | elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base; |
| 6130 | } else { |
| 6131 | /* For FDISC, Let FDISC rsp set the NPortID for this VPI */ |
| 6132 | icmd->ulpCt_h = 1; |
| 6133 | icmd->ulpCt_l = 0; |
| 6134 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6135 | |
| 6136 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6137 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 6138 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 6139 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 6140 | sp = (struct serv_parm *) pcmd; |
| 6141 | /* Setup CSPs accordingly for Fabric */ |
| 6142 | sp->cmn.e_d_tov = 0; |
| 6143 | sp->cmn.w2.r_a_tov = 0; |
| 6144 | sp->cls1.classValid = 0; |
| 6145 | sp->cls2.seqDelivery = 1; |
| 6146 | sp->cls3.seqDelivery = 1; |
| 6147 | |
| 6148 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 6149 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 6150 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 6151 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 6152 | memcpy(pcmd, &vport->fc_portname, 8); |
| 6153 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6154 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6155 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 6156 | |
| 6157 | lpfc_set_disctmo(vport); |
| 6158 | |
| 6159 | phba->fc_stat.elsXmitFDISC++; |
| 6160 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 6161 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6162 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6163 | "Issue FDISC: did:x%x", |
| 6164 | did, 0, 0); |
| 6165 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6166 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 6167 | if (rc == IOCB_ERROR) { |
| 6168 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6169 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6170 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6171 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6172 | return 1; |
| 6173 | } |
| 6174 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
| 6175 | vport->port_state = LPFC_FDISC; |
| 6176 | return 0; |
| 6177 | } |
| 6178 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6179 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6180 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6181 | * @phba: pointer to lpfc hba data structure. |
| 6182 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6183 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6184 | * |
| 6185 | * This routine is the completion callback function to the issuing of a LOGO |
| 6186 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 6187 | * reference count held on ndlp for this completion function, indicating that |
| 6188 | * the reference to the ndlp is no long needed. Note that the |
| 6189 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 6190 | * callback function and an additional explicit ndlp reference decrementation |
| 6191 | * will trigger the actual release of the ndlp. |
| 6192 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6193 | static void |
| 6194 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6195 | struct lpfc_iocbq *rspiocb) |
| 6196 | { |
| 6197 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6198 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6199 | struct lpfc_nodelist *ndlp; |
| 6200 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6201 | |
| 6202 | irsp = &rspiocb->iocb; |
| 6203 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6204 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 6205 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6206 | |
| 6207 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6208 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6209 | |
| 6210 | /* Trigger the release of the ndlp after logo */ |
| 6211 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6212 | } |
| 6213 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6214 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6215 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6216 | * @vport: pointer to a virtual N_Port data structure. |
| 6217 | * @ndlp: pointer to a node-list data structure. |
| 6218 | * |
| 6219 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 6220 | * |
| 6221 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6222 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6223 | * will be stored into the context1 field of the IOCB for the completion |
| 6224 | * callback function to the LOGO ELS command. |
| 6225 | * |
| 6226 | * Return codes |
| 6227 | * 0 - Successfully issued logo off the @vport |
| 6228 | * 1 - Failed to issue logo off the @vport |
| 6229 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6230 | int |
| 6231 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 6232 | { |
| 6233 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6234 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6235 | IOCB_t *icmd; |
| 6236 | struct lpfc_iocbq *elsiocb; |
| 6237 | uint8_t *pcmd; |
| 6238 | uint16_t cmdsize; |
| 6239 | |
| 6240 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 6241 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 6242 | ELS_CMD_LOGO); |
| 6243 | if (!elsiocb) |
| 6244 | return 1; |
| 6245 | |
| 6246 | icmd = &elsiocb->iocb; |
| 6247 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6248 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 6249 | pcmd += sizeof(uint32_t); |
| 6250 | |
| 6251 | /* Fill in LOGO payload */ |
| 6252 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 6253 | pcmd += sizeof(uint32_t); |
| 6254 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 6255 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6256 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6257 | "Issue LOGO npiv did:x%x flg:x%x", |
| 6258 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 6259 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6260 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 6261 | spin_lock_irq(shost->host_lock); |
| 6262 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 6263 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6264 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 6265 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6266 | spin_lock_irq(shost->host_lock); |
| 6267 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 6268 | spin_unlock_irq(shost->host_lock); |
| 6269 | lpfc_els_free_iocb(phba, elsiocb); |
| 6270 | return 1; |
| 6271 | } |
| 6272 | return 0; |
| 6273 | } |
| 6274 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6275 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6276 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6277 | * @ptr: holder for the timer function associated data. |
| 6278 | * |
| 6279 | * This routine is invoked by the fabric iocb block timer after |
| 6280 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 6281 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 6282 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 6283 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 6284 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 6285 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6286 | void |
| 6287 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 6288 | { |
| 6289 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 6290 | unsigned long iflags; |
| 6291 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6292 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6293 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 6294 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 6295 | if (!tmo_posted) |
| 6296 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 6297 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 6298 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6299 | if (!tmo_posted) |
| 6300 | lpfc_worker_wake_up(phba); |
| 6301 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6302 | } |
| 6303 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6304 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6305 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6306 | * @phba: pointer to lpfc hba data structure. |
| 6307 | * |
| 6308 | * This routine issues one fabric iocb from the driver internal list to |
| 6309 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 6310 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 6311 | * remove one pending fabric iocb from the driver internal list and invokes |
| 6312 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 6313 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6314 | static void |
| 6315 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 6316 | { |
| 6317 | struct lpfc_iocbq *iocb; |
| 6318 | unsigned long iflags; |
| 6319 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6320 | IOCB_t *cmd; |
| 6321 | |
| 6322 | repeat: |
| 6323 | iocb = NULL; |
| 6324 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6325 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6326 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 6327 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 6328 | list); |
| 6329 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6330 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6331 | atomic_inc(&phba->fabric_iocb_count); |
| 6332 | } |
| 6333 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6334 | if (iocb) { |
| 6335 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6336 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6337 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6338 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6339 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6340 | "Fabric sched1: ste:x%x", |
| 6341 | iocb->vport->port_state, 0, 0); |
| 6342 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6343 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6344 | |
| 6345 | if (ret == IOCB_ERROR) { |
| 6346 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6347 | iocb->fabric_iocb_cmpl = NULL; |
| 6348 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6349 | cmd = &iocb->iocb; |
| 6350 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6351 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6352 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 6353 | |
| 6354 | atomic_dec(&phba->fabric_iocb_count); |
| 6355 | goto repeat; |
| 6356 | } |
| 6357 | } |
| 6358 | |
| 6359 | return; |
| 6360 | } |
| 6361 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6362 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6363 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6364 | * @phba: pointer to lpfc hba data structure. |
| 6365 | * |
| 6366 | * This routine unblocks the issuing fabric iocb command. The function |
| 6367 | * will clear the fabric iocb block bit and then invoke the routine |
| 6368 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 6369 | * from the driver internal fabric iocb list. |
| 6370 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6371 | void |
| 6372 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 6373 | { |
| 6374 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6375 | |
| 6376 | lpfc_resume_fabric_iocbs(phba); |
| 6377 | return; |
| 6378 | } |
| 6379 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6380 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6381 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6382 | * @phba: pointer to lpfc hba data structure. |
| 6383 | * |
| 6384 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 6385 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 6386 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 6387 | * fabric iocb will be issued out of the HBA. |
| 6388 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6389 | static void |
| 6390 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 6391 | { |
| 6392 | int blocked; |
| 6393 | |
| 6394 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6395 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6396 | if (!blocked) |
| 6397 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); |
| 6398 | |
| 6399 | return; |
| 6400 | } |
| 6401 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6402 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6403 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6404 | * @phba: pointer to lpfc hba data structure. |
| 6405 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6406 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6407 | * |
| 6408 | * This routine is the callback function that is put to the fabric iocb's |
| 6409 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 6410 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 6411 | * function first restores and invokes the original iocb's callback function |
| 6412 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 6413 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 6414 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6415 | static void |
| 6416 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6417 | struct lpfc_iocbq *rspiocb) |
| 6418 | { |
| 6419 | struct ls_rjt stat; |
| 6420 | |
| 6421 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 6422 | BUG(); |
| 6423 | |
| 6424 | switch (rspiocb->iocb.ulpStatus) { |
| 6425 | case IOSTAT_NPORT_RJT: |
| 6426 | case IOSTAT_FABRIC_RJT: |
| 6427 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 6428 | lpfc_block_fabric_iocbs(phba); |
| 6429 | } |
| 6430 | break; |
| 6431 | |
| 6432 | case IOSTAT_NPORT_BSY: |
| 6433 | case IOSTAT_FABRIC_BSY: |
| 6434 | lpfc_block_fabric_iocbs(phba); |
| 6435 | break; |
| 6436 | |
| 6437 | case IOSTAT_LS_RJT: |
| 6438 | stat.un.lsRjtError = |
| 6439 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 6440 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 6441 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 6442 | lpfc_block_fabric_iocbs(phba); |
| 6443 | break; |
| 6444 | } |
| 6445 | |
| 6446 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 6447 | BUG(); |
| 6448 | |
| 6449 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 6450 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 6451 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6452 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 6453 | |
| 6454 | atomic_dec(&phba->fabric_iocb_count); |
| 6455 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6456 | /* Post any pending iocbs to HBA */ |
| 6457 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6458 | } |
| 6459 | } |
| 6460 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6461 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6462 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6463 | * @phba: pointer to lpfc hba data structure. |
| 6464 | * @iocb: pointer to lpfc command iocb data structure. |
| 6465 | * |
| 6466 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 6467 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 6468 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 6469 | * any given time. As such, this function will first check to see whether there |
| 6470 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 6471 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 6472 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 6473 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 6474 | * |
| 6475 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 6476 | * order. The problem is caused by the construction of the "ready" boolen does |
| 6477 | * not include the condition that the internal fabric IOCB list is empty. As |
| 6478 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 6479 | * ahead of the fabric IOCBs in the internal list. |
| 6480 | * |
| 6481 | * Return code |
| 6482 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 6483 | * IOCB_ERROR - failed to issue fabric iocb |
| 6484 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6485 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6486 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 6487 | { |
| 6488 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6489 | int ready; |
| 6490 | int ret; |
| 6491 | |
| 6492 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 6493 | BUG(); |
| 6494 | |
| 6495 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6496 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 6497 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6498 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6499 | if (ready) |
| 6500 | /* Increment fabric iocb count to hold the position */ |
| 6501 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6502 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6503 | if (ready) { |
| 6504 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6505 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6506 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6507 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6508 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6509 | "Fabric sched2: ste:x%x", |
| 6510 | iocb->vport->port_state, 0, 0); |
| 6511 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6512 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6513 | |
| 6514 | if (ret == IOCB_ERROR) { |
| 6515 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6516 | iocb->fabric_iocb_cmpl = NULL; |
| 6517 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6518 | atomic_dec(&phba->fabric_iocb_count); |
| 6519 | } |
| 6520 | } else { |
| 6521 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6522 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 6523 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6524 | ret = IOCB_SUCCESS; |
| 6525 | } |
| 6526 | return ret; |
| 6527 | } |
| 6528 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6529 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6530 | * 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] | 6531 | * @vport: pointer to a virtual N_Port data structure. |
| 6532 | * |
| 6533 | * This routine aborts all the IOCBs associated with a @vport from the |
| 6534 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6535 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6536 | * list, removes each IOCB associated with the @vport off the list, set the |
| 6537 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6538 | * associated with the IOCB. |
| 6539 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6540 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6541 | { |
| 6542 | LIST_HEAD(completions); |
| 6543 | struct lpfc_hba *phba = vport->phba; |
| 6544 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6545 | |
| 6546 | spin_lock_irq(&phba->hbalock); |
| 6547 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6548 | list) { |
| 6549 | |
| 6550 | if (piocb->vport != vport) |
| 6551 | continue; |
| 6552 | |
| 6553 | list_move_tail(&piocb->list, &completions); |
| 6554 | } |
| 6555 | spin_unlock_irq(&phba->hbalock); |
| 6556 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6557 | /* Cancel all the IOCBs from the completions list */ |
| 6558 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6559 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6560 | } |
| 6561 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6562 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6563 | * 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] | 6564 | * @ndlp: pointer to a node-list data structure. |
| 6565 | * |
| 6566 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 6567 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6568 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6569 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 6570 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6571 | * associated with the IOCB. |
| 6572 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6573 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 6574 | { |
| 6575 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6576 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6577 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6578 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6579 | |
| 6580 | spin_lock_irq(&phba->hbalock); |
| 6581 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6582 | list) { |
| 6583 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 6584 | |
| 6585 | list_move_tail(&piocb->list, &completions); |
| 6586 | } |
| 6587 | } |
| 6588 | spin_unlock_irq(&phba->hbalock); |
| 6589 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6590 | /* Cancel all the IOCBs from the completions list */ |
| 6591 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6592 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6593 | } |
| 6594 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6595 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6596 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6597 | * @phba: pointer to lpfc hba data structure. |
| 6598 | * |
| 6599 | * This routine aborts all the IOCBs currently on the driver internal |
| 6600 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 6601 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 6602 | * list, removes IOCBs off the list, set the status feild to |
| 6603 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 6604 | * the IOCB. |
| 6605 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6606 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 6607 | { |
| 6608 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6609 | |
| 6610 | spin_lock_irq(&phba->hbalock); |
| 6611 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 6612 | spin_unlock_irq(&phba->hbalock); |
| 6613 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6614 | /* Cancel all the IOCBs from the completions list */ |
| 6615 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6616 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6617 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6618 | |
| 6619 | /** |
| 6620 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 6621 | * @phba: pointer to lpfc hba data structure. |
| 6622 | * @axri: pointer to the els xri abort wcqe structure. |
| 6623 | * |
| 6624 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 6625 | * ELS aborted xri. |
| 6626 | **/ |
| 6627 | void |
| 6628 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 6629 | struct sli4_wcqe_xri_aborted *axri) |
| 6630 | { |
| 6631 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
| 6632 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 6633 | unsigned long iflag = 0; |
| 6634 | |
| 6635 | spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, iflag); |
| 6636 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 6637 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 6638 | if (sglq_entry->sli4_xritag == xri) { |
| 6639 | list_del(&sglq_entry->list); |
| 6640 | spin_unlock_irqrestore( |
| 6641 | &phba->sli4_hba.abts_sgl_list_lock, |
| 6642 | iflag); |
| 6643 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 6644 | |
| 6645 | list_add_tail(&sglq_entry->list, |
| 6646 | &phba->sli4_hba.lpfc_sgl_list); |
| 6647 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 6648 | return; |
| 6649 | } |
| 6650 | } |
| 6651 | spin_unlock_irqrestore(&phba->sli4_hba.abts_sgl_list_lock, iflag); |
| 6652 | } |