| 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 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 149 | static 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 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 171 | icmd = &elsiocb->iocb; |
| 172 | |
| 173 | /* fill in BDEs for command */ |
| 174 | /* Allocate buffer for command payload */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 175 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 176 | if (pcmd) |
| 177 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 178 | if (!pcmd || !pcmd->virt) |
| 179 | goto els_iocb_free_pcmb_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 180 | |
| 181 | INIT_LIST_HEAD(&pcmd->list); |
| 182 | |
| 183 | /* Allocate buffer for response payload */ |
| 184 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 185 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 186 | if (prsp) |
| 187 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 188 | &prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 189 | if (!prsp || !prsp->virt) |
| 190 | goto els_iocb_free_prsp_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 191 | INIT_LIST_HEAD(&prsp->list); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 192 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 193 | prsp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 194 | |
| 195 | /* Allocate buffer for Buffer ptr list */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 196 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 197 | if (pbuflist) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 198 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 199 | &pbuflist->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 200 | if (!pbuflist || !pbuflist->virt) |
| 201 | goto els_iocb_free_pbuf_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 202 | |
| 203 | INIT_LIST_HEAD(&pbuflist->list); |
| 204 | |
| 205 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 206 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 207 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 208 | icmd->un.elsreq64.remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 209 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 210 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 211 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 212 | icmd->ulpTimeout = phba->fc_ratov * 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 213 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 214 | icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 215 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; |
| 216 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 217 | icmd->ulpBdeCount = 1; |
| 218 | icmd->ulpLe = 1; |
| 219 | icmd->ulpClass = CLASS3; |
| 220 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 221 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 222 | icmd->un.elsreq64.myID = vport->fc_myDID; |
| 223 | |
| 224 | /* For ELS_REQUEST64_CR, use the VPI by default */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 225 | icmd->ulpContext = vport->vpi + phba->vpi_base; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 226 | icmd->ulpCt_h = 0; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 227 | /* The CT field must be 0=INVALID_RPI for the ECHO cmd */ |
| 228 | if (elscmd == ELS_CMD_ECHO) |
| 229 | icmd->ulpCt_l = 0; /* context = invalid RPI */ |
| 230 | else |
| 231 | icmd->ulpCt_l = 1; /* context = VPI */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 232 | } |
| 233 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 234 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
| 235 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); |
| 236 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); |
| 237 | bpl->tus.f.bdeSize = cmdSize; |
| 238 | bpl->tus.f.bdeFlags = 0; |
| 239 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 240 | |
| 241 | if (expectRsp) { |
| 242 | bpl++; |
| 243 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); |
| 244 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); |
| 245 | bpl->tus.f.bdeSize = FCELSSIZE; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 246 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 247 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 248 | } |
| 249 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 250 | /* prevent preparing iocb with NULL ndlp reference */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 251 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 252 | if (!elsiocb->context1) |
| 253 | goto els_iocb_free_pbuf_exit; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 254 | elsiocb->context2 = pcmd; |
| 255 | elsiocb->context3 = pbuflist; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 256 | elsiocb->retry = retry; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 257 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 258 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
| 259 | |
| 260 | if (prsp) { |
| 261 | list_add(&prsp->list, &pcmd->list); |
| 262 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 263 | if (expectRsp) { |
| 264 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 265 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 266 | "0116 Xmit ELS command x%x to remote " |
| 267 | "NPORT x%x I/O tag: x%x, port state: x%x\n", |
| 268 | elscmd, did, elsiocb->iotag, |
| 269 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 270 | } else { |
| 271 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 272 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 273 | "0117 Xmit ELS response x%x to remote " |
| 274 | "NPORT x%x I/O tag: x%x, size: x%x\n", |
| 275 | elscmd, ndlp->nlp_DID, elsiocb->iotag, |
| 276 | cmdSize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 277 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 278 | return elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 279 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 280 | els_iocb_free_pbuf_exit: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 281 | if (expectRsp) |
| 282 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 283 | kfree(pbuflist); |
| 284 | |
| 285 | els_iocb_free_prsp_exit: |
| 286 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 287 | kfree(prsp); |
| 288 | |
| 289 | els_iocb_free_pcmb_exit: |
| 290 | kfree(pcmd); |
| 291 | lpfc_sli_release_iocbq(phba, elsiocb); |
| 292 | return NULL; |
| 293 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 294 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 295 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 296 | * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 297 | * @vport: pointer to a host virtual N_Port data structure. |
| 298 | * |
| 299 | * This routine issues a fabric registration login for a @vport. An |
| 300 | * active ndlp node with Fabric_DID must already exist for this @vport. |
| 301 | * The routine invokes two mailbox commands to carry out fabric registration |
| 302 | * login through the HBA firmware: the first mailbox command requests the |
| 303 | * HBA to perform link configuration for the @vport; and the second mailbox |
| 304 | * command requests the HBA to perform the actual fabric registration login |
| 305 | * with the @vport. |
| 306 | * |
| 307 | * Return code |
| 308 | * 0 - successfully issued fabric registration login for @vport |
| 309 | * -ENXIO -- failed to issue fabric registration login for @vport |
| 310 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 311 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 312 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
| 313 | { |
| 314 | struct lpfc_hba *phba = vport->phba; |
| 315 | LPFC_MBOXQ_t *mbox; |
| 316 | struct lpfc_dmabuf *mp; |
| 317 | struct lpfc_nodelist *ndlp; |
| 318 | struct serv_parm *sp; |
| 319 | int rc; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 320 | int err = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 321 | |
| 322 | sp = &phba->fc_fabparam; |
| 323 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 324 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 325 | err = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 326 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 327 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 328 | |
| 329 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 330 | if (!mbox) { |
| 331 | err = 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 332 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 333 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 334 | |
| 335 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 336 | lpfc_config_link(phba, mbox); |
| 337 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 338 | mbox->vport = vport; |
| 339 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 340 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 341 | if (rc == MBX_NOT_FINISHED) { |
| 342 | err = 3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 343 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 344 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 345 | |
| 346 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 347 | if (!mbox) { |
| 348 | err = 4; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 349 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 350 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 351 | 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] | 352 | if (rc) { |
| 353 | err = 5; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 354 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 355 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 356 | |
| 357 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; |
| 358 | mbox->vport = vport; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 359 | /* increment the reference count on ndlp to hold reference |
| 360 | * for the callback routine. |
| 361 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 362 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 363 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 364 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 365 | if (rc == MBX_NOT_FINISHED) { |
| 366 | err = 6; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 367 | goto fail_issue_reg_login; |
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 | return 0; |
| 371 | |
| 372 | fail_issue_reg_login: |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 373 | /* decrement the reference count on ndlp just incremented |
| 374 | * for the failed mbox command. |
| 375 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 376 | lpfc_nlp_put(ndlp); |
| 377 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 378 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 379 | kfree(mp); |
| 380 | fail_free_mbox: |
| 381 | mempool_free(mbox, phba->mbox_mem_pool); |
| 382 | |
| 383 | fail: |
| 384 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 385 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 386 | "0249 Cannot issue Register Fabric login: Err %d\n", err); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 387 | return -ENXIO; |
| 388 | } |
| 389 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 390 | /** |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 391 | * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login |
| 392 | * @vport: pointer to a host virtual N_Port data structure. |
| 393 | * |
| 394 | * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for |
| 395 | * the @vport. This mailbox command is necessary for FCoE only. |
| 396 | * |
| 397 | * Return code |
| 398 | * 0 - successfully issued REG_VFI for @vport |
| 399 | * A failure code otherwise. |
| 400 | **/ |
| 401 | static int |
| 402 | lpfc_issue_reg_vfi(struct lpfc_vport *vport) |
| 403 | { |
| 404 | struct lpfc_hba *phba = vport->phba; |
| 405 | LPFC_MBOXQ_t *mboxq; |
| 406 | struct lpfc_nodelist *ndlp; |
| 407 | struct serv_parm *sp; |
| 408 | struct lpfc_dmabuf *dmabuf; |
| 409 | int rc = 0; |
| 410 | |
| 411 | sp = &phba->fc_fabparam; |
| 412 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 413 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
| 414 | rc = -ENODEV; |
| 415 | goto fail; |
| 416 | } |
| 417 | |
| 418 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 419 | if (!dmabuf) { |
| 420 | rc = -ENOMEM; |
| 421 | goto fail; |
| 422 | } |
| 423 | dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys); |
| 424 | if (!dmabuf->virt) { |
| 425 | rc = -ENOMEM; |
| 426 | goto fail_free_dmabuf; |
| 427 | } |
| 428 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 429 | if (!mboxq) { |
| 430 | rc = -ENOMEM; |
| 431 | goto fail_free_coherent; |
| 432 | } |
| 433 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 434 | memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam)); |
| 435 | lpfc_reg_vfi(mboxq, vport, dmabuf->phys); |
| 436 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi; |
| 437 | mboxq->vport = vport; |
| 438 | mboxq->context1 = dmabuf; |
| 439 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 440 | if (rc == MBX_NOT_FINISHED) { |
| 441 | rc = -ENXIO; |
| 442 | goto fail_free_mbox; |
| 443 | } |
| 444 | return 0; |
| 445 | |
| 446 | fail_free_mbox: |
| 447 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 448 | fail_free_coherent: |
| 449 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 450 | fail_free_dmabuf: |
| 451 | kfree(dmabuf); |
| 452 | fail: |
| 453 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 454 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 455 | "0289 Issue Register VFI failed: Err %d\n", rc); |
| 456 | return rc; |
| 457 | } |
| 458 | |
| 459 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 460 | * 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] | 461 | * @vport: pointer to a host virtual N_Port data structure. |
| 462 | * @ndlp: pointer to a node-list data structure. |
| 463 | * @sp: pointer to service parameter data structure. |
| 464 | * @irsp: pointer to the IOCB within the lpfc response IOCB. |
| 465 | * |
| 466 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 467 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric |
| 468 | * port in a fabric topology. It properly sets up the parameters to the @ndlp |
| 469 | * from the IOCB response. It also check the newly assigned N_Port ID to the |
| 470 | * @vport against the previously assigned N_Port ID. If it is different from |
| 471 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine |
| 472 | * is invoked on all the remaining nodes with the @vport to unregister the |
| 473 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() |
| 474 | * is invoked to register login to the fabric. |
| 475 | * |
| 476 | * Return code |
| 477 | * 0 - Success (currently, always return 0) |
| 478 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 479 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 480 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 481 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 482 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 483 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 484 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 485 | struct lpfc_nodelist *np; |
| 486 | struct lpfc_nodelist *next_np; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 487 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 488 | spin_lock_irq(shost->host_lock); |
| 489 | vport->fc_flag |= FC_FABRIC; |
| 490 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 491 | |
| 492 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 493 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 494 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 495 | |
| 496 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 497 | |
| 498 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 499 | spin_lock_irq(shost->host_lock); |
| 500 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 501 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 502 | } else { |
| 503 | /* |
| 504 | * If we are a N-port connected to a Fabric, fixup sparam's so |
| 505 | * logins to devices on remote loops work. |
| 506 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 507 | vport->fc_sparam.cmn.altBbCredit = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 508 | } |
| 509 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 510 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 511 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 512 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 513 | ndlp->nlp_class_sup = 0; |
| 514 | if (sp->cls1.classValid) |
| 515 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 516 | if (sp->cls2.classValid) |
| 517 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 518 | if (sp->cls3.classValid) |
| 519 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 520 | if (sp->cls4.classValid) |
| 521 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 522 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 523 | sp->cmn.bbRcvSizeLsb; |
| 524 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 525 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 526 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 527 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 528 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 529 | LOG_ELS | LOG_VPORT, |
| 530 | "1816 FLOGI NPIV supported, " |
| 531 | "response data 0x%x\n", |
| 532 | sp->cmn.response_multiple_NPort); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 533 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 534 | } else { |
| 535 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 536 | to call reg_vnpid atleast for the physcial host */ |
| 537 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 538 | LOG_ELS | LOG_VPORT, |
| 539 | "1817 Fabric does not support NPIV " |
| 540 | "- configuring single port mode.\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 541 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 546 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 547 | |
| 548 | /* If our NportID changed, we need to ensure all |
| 549 | * remaining NPORTs get unreg_login'ed. |
| 550 | */ |
| 551 | list_for_each_entry_safe(np, next_np, |
| 552 | &vport->fc_nodes, nlp_listp) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 553 | if (!NLP_CHK_NODE_ACT(np)) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 554 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 555 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 556 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 557 | continue; |
| 558 | spin_lock_irq(shost->host_lock); |
| 559 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 560 | spin_unlock_irq(shost->host_lock); |
| 561 | lpfc_unreg_rpi(vport, np); |
| 562 | } |
| 563 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 564 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 565 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 566 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 567 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 568 | } |
| 569 | } |
| 570 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 571 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 572 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
| 573 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 574 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 575 | lpfc_register_new_vport(phba, vport, ndlp); |
| 576 | else |
| 577 | lpfc_issue_fabric_reglogin(vport); |
| 578 | } else { |
| 579 | ndlp->nlp_type |= NLP_FABRIC; |
| 580 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
| 581 | if (vport->vfi_state & LPFC_VFI_REGISTERED) { |
| 582 | lpfc_start_fdiscs(phba); |
| 583 | lpfc_do_scr_ns_plogi(phba, vport); |
| 584 | } else |
| 585 | lpfc_issue_reg_vfi(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 586 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 587 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 588 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 589 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 590 | * 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] | 591 | * @vport: pointer to a host virtual N_Port data structure. |
| 592 | * @ndlp: pointer to a node-list data structure. |
| 593 | * @sp: pointer to service parameter data structure. |
| 594 | * |
| 595 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 596 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 597 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 598 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 599 | * the received N_Port Name lexicographically, this node shall assign local |
| 600 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 601 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 602 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 603 | * N_Port IDs. |
| 604 | * |
| 605 | * Return code |
| 606 | * 0 - Success |
| 607 | * -ENXIO - Fail |
| 608 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 609 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 610 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 611 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 612 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 613 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 614 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 615 | LPFC_MBOXQ_t *mbox; |
| 616 | int rc; |
| 617 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 618 | spin_lock_irq(shost->host_lock); |
| 619 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 620 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 621 | |
| 622 | phba->fc_edtov = FF_DEF_EDTOV; |
| 623 | phba->fc_ratov = FF_DEF_RATOV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 624 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 625 | sizeof(vport->fc_portname)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 626 | if (rc >= 0) { |
| 627 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 628 | spin_lock_irq(shost->host_lock); |
| 629 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 630 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 631 | |
| 632 | /* |
| 633 | * N_Port ID cannot be 0, set our to LocalID the other |
| 634 | * side will be RemoteID. |
| 635 | */ |
| 636 | |
| 637 | /* not equal */ |
| 638 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 639 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 640 | |
| 641 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 642 | if (!mbox) |
| 643 | goto fail; |
| 644 | |
| 645 | lpfc_config_link(phba, mbox); |
| 646 | |
| 647 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 648 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 649 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 650 | if (rc == MBX_NOT_FINISHED) { |
| 651 | mempool_free(mbox, phba->mbox_mem_pool); |
| 652 | goto fail; |
| 653 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 654 | /* Decrement ndlp reference count indicating that ndlp can be |
| 655 | * safely released when other references to it are done. |
| 656 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 657 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 658 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 659 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 660 | if (!ndlp) { |
| 661 | /* |
| 662 | * Cannot find existing Fabric ndlp, so allocate a |
| 663 | * new one |
| 664 | */ |
| 665 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 666 | if (!ndlp) |
| 667 | goto fail; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 668 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 669 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 670 | ndlp = lpfc_enable_node(vport, ndlp, |
| 671 | NLP_STE_UNUSED_NODE); |
| 672 | if(!ndlp) |
| 673 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 677 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 678 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 679 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 680 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 681 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 682 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 683 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 684 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 685 | } else |
| 686 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 687 | * count indicating that ndlp can be released when other |
| 688 | * references to it are done. |
| 689 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 690 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 691 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 692 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 693 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 694 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 695 | spin_lock_irq(shost->host_lock); |
| 696 | vport->fc_flag |= FC_PT2PT; |
| 697 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 698 | |
| 699 | /* Start discovery - this should just do CLEAR_LA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 700 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 701 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 702 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 703 | return -ENXIO; |
| 704 | } |
| 705 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 706 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 707 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 708 | * @phba: pointer to lpfc hba data structure. |
| 709 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 710 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 711 | * |
| 712 | * This routine is the top-level completion callback function for issuing |
| 713 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 714 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 715 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 716 | * returning 1), the command IOCB will be released and function returned. |
| 717 | * If the retry attempt has been given up (possibly reach the maximum |
| 718 | * number of retries), one additional decrement of ndlp reference shall be |
| 719 | * invoked before going out after releasing the command IOCB. This will |
| 720 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 721 | * invoke one decrement of ndlp reference count). If no error reported in |
| 722 | * the IOCB status, the command Port ID field is used to determine whether |
| 723 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 724 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 725 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 726 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 727 | * specific topology completion conditions. |
| 728 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 729 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 730 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 731 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 732 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 733 | struct lpfc_vport *vport = cmdiocb->vport; |
| 734 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 735 | IOCB_t *irsp = &rspiocb->iocb; |
| 736 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 737 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 738 | struct serv_parm *sp; |
| 739 | int rc; |
| 740 | |
| 741 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 742 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 743 | /* One additional decrement on node reference count to |
| 744 | * trigger the release of the node |
| 745 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 746 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 747 | goto out; |
| 748 | } |
| 749 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 750 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 751 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 752 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 753 | vport->port_state); |
| 754 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 755 | if (irsp->ulpStatus) { |
| 756 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 757 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 758 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 759 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 760 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 761 | spin_lock_irq(shost->host_lock); |
| 762 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 763 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 764 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 765 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 766 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 767 | * alpa map would take too long otherwise. |
| 768 | */ |
| 769 | if (phba->alpa_map[0] == 0) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 770 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | /* FLOGI failure */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 774 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 775 | "0100 FLOGI failure Data: x%x x%x " |
| 776 | "x%x\n", |
| 777 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 778 | irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 779 | goto flogifail; |
| 780 | } |
| 781 | |
| 782 | /* |
| 783 | * The FLogI succeeded. Sync the data for the CPU before |
| 784 | * accessing it. |
| 785 | */ |
| 786 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 787 | |
| 788 | sp = prsp->virt + sizeof(uint32_t); |
| 789 | |
| 790 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 791 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 792 | "0101 FLOGI completes sucessfully " |
| 793 | "Data: x%x x%x x%x x%x\n", |
| 794 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
| 795 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 796 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 797 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 798 | /* |
| 799 | * If Common Service Parameters indicate Nport |
| 800 | * we are point to point, if Fport we are Fabric. |
| 801 | */ |
| 802 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 803 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 804 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 805 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 806 | |
| 807 | if (!rc) |
| 808 | goto out; |
| 809 | } |
| 810 | |
| 811 | flogifail: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 812 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 813 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 814 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 815 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 816 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 817 | |
| 818 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 819 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 820 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 821 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && |
| 822 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) && |
| 823 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 824 | /* If FLOGI failed enable link interrupt. */ |
| 825 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 826 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 827 | out: |
| 828 | lpfc_els_free_iocb(phba, cmdiocb); |
| 829 | } |
| 830 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 831 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 832 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 833 | * @vport: pointer to a host virtual N_Port data structure. |
| 834 | * @ndlp: pointer to a node-list data structure. |
| 835 | * @retry: number of retries to the command IOCB. |
| 836 | * |
| 837 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 838 | * for a @vport. The initiator service parameters are put into the payload |
| 839 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 840 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 841 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 842 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 843 | * |
| 844 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 845 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 846 | * will be stored into the context1 field of the IOCB for the completion |
| 847 | * callback function to the FLOGI ELS command. |
| 848 | * |
| 849 | * Return code |
| 850 | * 0 - successfully issued flogi iocb for @vport |
| 851 | * 1 - failed to issue flogi iocb for @vport |
| 852 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 853 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 854 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 855 | uint8_t retry) |
| 856 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 857 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 858 | struct serv_parm *sp; |
| 859 | IOCB_t *icmd; |
| 860 | struct lpfc_iocbq *elsiocb; |
| 861 | struct lpfc_sli_ring *pring; |
| 862 | uint8_t *pcmd; |
| 863 | uint16_t cmdsize; |
| 864 | uint32_t tmo; |
| 865 | int rc; |
| 866 | |
| 867 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 868 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 869 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 870 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 871 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 872 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 873 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 874 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 875 | |
| 876 | icmd = &elsiocb->iocb; |
| 877 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 878 | |
| 879 | /* For FLOGI request, remainder of payload is service parameters */ |
| 880 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 881 | pcmd += sizeof(uint32_t); |
| 882 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 883 | sp = (struct serv_parm *) pcmd; |
| 884 | |
| 885 | /* Setup CSPs accordingly for Fabric */ |
| 886 | sp->cmn.e_d_tov = 0; |
| 887 | sp->cmn.w2.r_a_tov = 0; |
| 888 | sp->cls1.classValid = 0; |
| 889 | sp->cls2.seqDelivery = 1; |
| 890 | sp->cls3.seqDelivery = 1; |
| 891 | if (sp->cmn.fcphLow < FC_PH3) |
| 892 | sp->cmn.fcphLow = FC_PH3; |
| 893 | if (sp->cmn.fcphHigh < FC_PH3) |
| 894 | sp->cmn.fcphHigh = FC_PH3; |
| 895 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 896 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 897 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); |
| 898 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); |
| 899 | /* FLOGI needs to be 3 for WQE FCFI */ |
| 900 | /* Set the fcfi to the fcfi we registered with */ |
| 901 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; |
| 902 | } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 903 | sp->cmn.request_multiple_Nport = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 904 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 905 | icmd->ulpCt_h = 1; |
| 906 | icmd->ulpCt_l = 0; |
| 907 | } |
| 908 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 909 | if (phba->fc_topology != TOPOLOGY_LOOP) { |
| 910 | icmd->un.elsreq64.myID = 0; |
| 911 | icmd->un.elsreq64.fl = 1; |
| 912 | } |
| 913 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 914 | tmo = phba->fc_ratov; |
| 915 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 916 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 917 | phba->fc_ratov = tmo; |
| 918 | |
| 919 | phba->fc_stat.elsXmitFLOGI++; |
| 920 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 921 | |
| 922 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 923 | "Issue FLOGI: opt:x%x", |
| 924 | phba->sli3_options, 0, 0); |
| 925 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 926 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 927 | if (rc == IOCB_ERROR) { |
| 928 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 929 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 930 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 931 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 932 | } |
| 933 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 934 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 935 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 936 | * @phba: pointer to lpfc hba data structure. |
| 937 | * |
| 938 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 939 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 940 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 941 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 942 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 943 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 944 | * |
| 945 | * Return code |
| 946 | * 0 - Sucessfully issued abort iocb on all outstanding flogis (Always 0) |
| 947 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 948 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 949 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 950 | { |
| 951 | struct lpfc_sli_ring *pring; |
| 952 | struct lpfc_iocbq *iocb, *next_iocb; |
| 953 | struct lpfc_nodelist *ndlp; |
| 954 | IOCB_t *icmd; |
| 955 | |
| 956 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 957 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 958 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 959 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 960 | |
| 961 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 962 | |
| 963 | /* |
| 964 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 965 | * searching for. |
| 966 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 967 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 968 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 969 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 970 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR && |
| 971 | icmd->un.elsreq64.bdl.ulpIoTag32) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 972 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 973 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 974 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 975 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 976 | } |
| 977 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 978 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 979 | |
| 980 | return 0; |
| 981 | } |
| 982 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 983 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 984 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 985 | * @vport: pointer to a host virtual N_Port data structure. |
| 986 | * |
| 987 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 988 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 989 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 990 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 991 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 992 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 993 | * @vport. |
| 994 | * |
| 995 | * Return code |
| 996 | * 0 - failed to issue initial flogi for @vport |
| 997 | * 1 - successfully issued initial flogi for @vport |
| 998 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 999 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1000 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1001 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1002 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1003 | struct lpfc_nodelist *ndlp; |
| 1004 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1005 | vport->port_state = LPFC_FLOGI; |
| 1006 | lpfc_set_disctmo(vport); |
| 1007 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1008 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1009 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1010 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1011 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1012 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1013 | if (!ndlp) |
| 1014 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1015 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1016 | /* Set the node type */ |
| 1017 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1018 | /* Put ndlp onto node list */ |
| 1019 | lpfc_enqueue_node(vport, ndlp); |
| 1020 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1021 | /* re-setup ndlp without removing from node list */ |
| 1022 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1023 | if (!ndlp) |
| 1024 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1025 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1026 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1027 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1028 | /* This decrement of reference count to node shall kick off |
| 1029 | * the release of the node. |
| 1030 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1031 | lpfc_nlp_put(ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1032 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1033 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1034 | } |
| 1035 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1036 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1037 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1038 | * @vport: pointer to a host virtual N_Port data structure. |
| 1039 | * |
| 1040 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 1041 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 1042 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 1043 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 1044 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 1045 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 1046 | * @vport. |
| 1047 | * |
| 1048 | * Return code |
| 1049 | * 0 - failed to issue initial fdisc for @vport |
| 1050 | * 1 - successfully issued initial fdisc for @vport |
| 1051 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1052 | int |
| 1053 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 1054 | { |
| 1055 | struct lpfc_hba *phba = vport->phba; |
| 1056 | struct lpfc_nodelist *ndlp; |
| 1057 | |
| 1058 | /* First look for the Fabric ndlp */ |
| 1059 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 1060 | if (!ndlp) { |
| 1061 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 1062 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1063 | if (!ndlp) |
| 1064 | return 0; |
| 1065 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1066 | /* Put ndlp onto node list */ |
| 1067 | lpfc_enqueue_node(vport, ndlp); |
| 1068 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1069 | /* re-setup ndlp without removing from node list */ |
| 1070 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1071 | if (!ndlp) |
| 1072 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1073 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1074 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1075 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1076 | /* decrement node reference count to trigger the release of |
| 1077 | * the node. |
| 1078 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1079 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1080 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1081 | } |
| 1082 | return 1; |
| 1083 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1084 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1085 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1086 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1087 | * @vport: pointer to a host virtual N_Port data structure. |
| 1088 | * |
| 1089 | * This routine checks whether there are more remaining Port Logins |
| 1090 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1091 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1092 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1093 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1094 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1095 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1096 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1097 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1098 | { |
| 1099 | int sentplogi; |
| 1100 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1101 | if (vport->num_disc_nodes) |
| 1102 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1103 | |
| 1104 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1105 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1106 | "0232 Continue discovery with %d PLOGIs to go " |
| 1107 | "Data: x%x x%x x%x\n", |
| 1108 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1109 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1110 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1111 | if (vport->fc_flag & FC_NLP_MORE) |
| 1112 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 1113 | sentplogi = lpfc_els_disc_plogi(vport); |
| 1114 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1115 | return; |
| 1116 | } |
| 1117 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1118 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1119 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1120 | * @phba: pointer to lpfc hba data structure. |
| 1121 | * @prsp: pointer to response IOCB payload. |
| 1122 | * @ndlp: pointer to a node-list data structure. |
| 1123 | * |
| 1124 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1125 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1126 | * The following cases are considered N_Port confirmed: |
| 1127 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1128 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1129 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1130 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1131 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1132 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1133 | * on that node to release the RPI associated with the node; 2) if there is |
| 1134 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1135 | * into, a new node shall be allocated (or activated). In either case, the |
| 1136 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1137 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1138 | * its pointer returned as the confirmed node. |
| 1139 | * |
| 1140 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1141 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1142 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1143 | * into an inactive state on the vport node list and the vport node list |
| 1144 | * management algorithm does not allow two node with a same DID. |
| 1145 | * |
| 1146 | * Return code |
| 1147 | * pointer to the PLOGI N_Port @ndlp |
| 1148 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1149 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1150 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1151 | struct lpfc_nodelist *ndlp) |
| 1152 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1153 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1154 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1155 | struct lpfc_rport_data *rdata; |
| 1156 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1157 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1158 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1159 | uint32_t rc, keepDID = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1160 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1161 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1162 | * by WWPN. Just return the ndlp that was given to us. |
| 1163 | */ |
| 1164 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1165 | return ndlp; |
| 1166 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1167 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1168 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1169 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1170 | /* 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] | 1171 | * we have for that ndlp. If not, we have some work to do. |
| 1172 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1173 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1174 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1175 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1176 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1177 | |
| 1178 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1179 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1180 | sizeof(struct lpfc_name)); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1181 | if (!rc) |
| 1182 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1183 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
| 1184 | if (!new_ndlp) |
| 1185 | return ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1186 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1187 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1188 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1189 | sizeof(struct lpfc_name)); |
| 1190 | if (!rc) |
| 1191 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1192 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1193 | NLP_STE_UNUSED_NODE); |
| 1194 | if (!new_ndlp) |
| 1195 | return ndlp; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1196 | keepDID = new_ndlp->nlp_DID; |
| 1197 | } else |
| 1198 | keepDID = new_ndlp->nlp_DID; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1199 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1200 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1201 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1202 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1203 | |
| 1204 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) |
| 1205 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 1206 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 1207 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1208 | /* 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] | 1209 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1210 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1211 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1212 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1213 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1214 | * to put ndlp on UNUSED list and try to free it. |
| 1215 | */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1216 | |
| 1217 | /* Fix up the rport accordingly */ |
| 1218 | rport = ndlp->rport; |
| 1219 | if (rport) { |
| 1220 | rdata = rport->dd_data; |
| 1221 | if (rdata->pnode == ndlp) { |
| 1222 | lpfc_nlp_put(ndlp); |
| 1223 | ndlp->rport = NULL; |
| 1224 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1225 | new_ndlp->rport = rport; |
| 1226 | } |
| 1227 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1228 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1229 | /* We shall actually free the ndlp with both nlp_DID and |
| 1230 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1231 | * nodelist never to be used. |
| 1232 | */ |
| 1233 | if (ndlp->nlp_DID == 0) { |
| 1234 | spin_lock_irq(&phba->ndlp_lock); |
| 1235 | NLP_SET_FREE_REQ(ndlp); |
| 1236 | spin_unlock_irq(&phba->ndlp_lock); |
| 1237 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1238 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1239 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1240 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1241 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1242 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1243 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1244 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1245 | /* Two ndlps cannot have the same did */ |
| 1246 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1247 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1248 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1249 | return new_ndlp; |
| 1250 | } |
| 1251 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1252 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1253 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1254 | * @vport: pointer to a host virtual N_Port data structure. |
| 1255 | * |
| 1256 | * This routine checks whether more Registration State Change |
| 1257 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1258 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1259 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1260 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1261 | * handling the RSCNs. |
| 1262 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1263 | void |
| 1264 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1265 | { |
| 1266 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1267 | |
| 1268 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1269 | /* |
| 1270 | * Check to see if more RSCNs came in while we were |
| 1271 | * processing this one. |
| 1272 | */ |
| 1273 | if (vport->fc_rscn_id_cnt || |
| 1274 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1275 | lpfc_els_handle_rscn(vport); |
| 1276 | else { |
| 1277 | spin_lock_irq(shost->host_lock); |
| 1278 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1279 | spin_unlock_irq(shost->host_lock); |
| 1280 | } |
| 1281 | } |
| 1282 | } |
| 1283 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1284 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1285 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1286 | * @phba: pointer to lpfc hba data structure. |
| 1287 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1288 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1289 | * |
| 1290 | * This routine is the completion callback function for issuing the Port |
| 1291 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1292 | * ndlp on the vport node list that matches the remote node ID from the |
| 1293 | * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply |
| 1294 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1295 | * checked for error conditons. If there is error status reported, PLOGI |
| 1296 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1297 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1298 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1299 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1300 | * there are additional N_Port nodes with the vport that need to perform |
| 1301 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1302 | * PLOGIs. |
| 1303 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1304 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1305 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1306 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1307 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1308 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1309 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1310 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1311 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1312 | struct lpfc_dmabuf *prsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1313 | int disc, rc, did, type; |
| 1314 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1315 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1316 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1317 | |
| 1318 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1319 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1320 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1321 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1322 | irsp->un.elsreq64.remoteID); |
| 1323 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1324 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1325 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1326 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1327 | "0136 PLOGI completes to NPort x%x " |
| 1328 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1329 | irsp->un.elsreq64.remoteID, |
| 1330 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1331 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1332 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1333 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1334 | |
| 1335 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1336 | * is being used during discovery. |
| 1337 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1338 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1339 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1340 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1341 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1342 | rc = 0; |
| 1343 | |
| 1344 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1345 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1346 | "0102 PLOGI completes to NPort x%x " |
| 1347 | "Data: x%x x%x x%x x%x x%x\n", |
| 1348 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1349 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1350 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1351 | if (lpfc_els_chk_latt(vport)) { |
| 1352 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -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 | goto out; |
| 1356 | } |
| 1357 | |
| 1358 | /* ndlp could be freed in DSM, save these values now */ |
| 1359 | type = ndlp->nlp_type; |
| 1360 | did = ndlp->nlp_DID; |
| 1361 | |
| 1362 | if (irsp->ulpStatus) { |
| 1363 | /* Check for retry */ |
| 1364 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1365 | /* ELS command is being retried */ |
| 1366 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1367 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1368 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1369 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1370 | } |
| 1371 | goto out; |
| 1372 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1373 | /* PLOGI failed */ |
| 1374 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1375 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1376 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1377 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1378 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1379 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1380 | } else { |
| 1381 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1382 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1383 | cmdiocb->context2)->list.next, |
| 1384 | struct lpfc_dmabuf, list); |
| 1385 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1386 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1387 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1388 | } |
| 1389 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1390 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1391 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1392 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1393 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1394 | if (vport->num_disc_nodes == 0) { |
| 1395 | spin_lock_irq(shost->host_lock); |
| 1396 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1397 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1398 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1399 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1400 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1401 | } |
| 1402 | } |
| 1403 | |
| 1404 | out: |
| 1405 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1406 | return; |
| 1407 | } |
| 1408 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1409 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1410 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1411 | * @vport: pointer to a host virtual N_Port data structure. |
| 1412 | * @did: destination port identifier. |
| 1413 | * @retry: number of retries to the command IOCB. |
| 1414 | * |
| 1415 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1416 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1417 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1418 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1419 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1420 | * |
| 1421 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1422 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1423 | * will be stored into the context1 field of the IOCB for the completion |
| 1424 | * callback function to the PLOGI ELS command. |
| 1425 | * |
| 1426 | * Return code |
| 1427 | * 0 - Successfully issued a plogi for @vport |
| 1428 | * 1 - failed to issue a plogi for @vport |
| 1429 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1430 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1431 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1432 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1433 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1434 | struct serv_parm *sp; |
| 1435 | IOCB_t *icmd; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1436 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1437 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1438 | struct lpfc_sli *psli; |
| 1439 | uint8_t *pcmd; |
| 1440 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1441 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1442 | |
| 1443 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1444 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1445 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1446 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1447 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1448 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1449 | /* 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] | 1450 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1451 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1452 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1453 | if (!elsiocb) |
| 1454 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1455 | |
| 1456 | icmd = &elsiocb->iocb; |
| 1457 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1458 | |
| 1459 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1460 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1461 | pcmd += sizeof(uint32_t); |
| 1462 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1463 | sp = (struct serv_parm *) pcmd; |
| 1464 | |
| 1465 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1466 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1467 | |
| 1468 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1469 | sp->cmn.fcphHigh = FC_PH3; |
| 1470 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1471 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1472 | "Issue PLOGI: did:x%x", |
| 1473 | did, 0, 0); |
| 1474 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1475 | phba->fc_stat.elsXmitPLOGI++; |
| 1476 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1477 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1478 | |
| 1479 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1480 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1481 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1482 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1483 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1484 | } |
| 1485 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1486 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1487 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1488 | * @phba: pointer to lpfc hba data structure. |
| 1489 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1490 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1491 | * |
| 1492 | * This routine is the completion callback function for a Process Login |
| 1493 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 1494 | * status. If there is error status reported, PRLI retry shall be attempted |
| 1495 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 1496 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 1497 | * ndlp to mark the PRLI completion. |
| 1498 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1499 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1500 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1501 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1502 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1503 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1504 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1505 | IOCB_t *irsp; |
| 1506 | struct lpfc_sli *psli; |
| 1507 | struct lpfc_nodelist *ndlp; |
| 1508 | |
| 1509 | psli = &phba->sli; |
| 1510 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1511 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1512 | |
| 1513 | irsp = &(rspiocb->iocb); |
| 1514 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1515 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1516 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1517 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1518 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1519 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1520 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 1521 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1522 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1523 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1524 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1525 | "0103 PRLI completes to NPort x%x " |
| 1526 | "Data: x%x x%x x%x x%x\n", |
| 1527 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1528 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1529 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1530 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1531 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1532 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1533 | goto out; |
| 1534 | |
| 1535 | if (irsp->ulpStatus) { |
| 1536 | /* Check for retry */ |
| 1537 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1538 | /* ELS command is being retried */ |
| 1539 | goto out; |
| 1540 | } |
| 1541 | /* PRLI failed */ |
| 1542 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1543 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1544 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1545 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1546 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1547 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1548 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1549 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1550 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1551 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1552 | out: |
| 1553 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1554 | return; |
| 1555 | } |
| 1556 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1557 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1558 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1559 | * @vport: pointer to a host virtual N_Port data structure. |
| 1560 | * @ndlp: pointer to a node-list data structure. |
| 1561 | * @retry: number of retries to the command IOCB. |
| 1562 | * |
| 1563 | * This routine issues a Process Login (PRLI) ELS command for the |
| 1564 | * @vport. The PRLI service parameters are set up in the payload of the |
| 1565 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 1566 | * is put to the IOCB completion callback func field before invoking the |
| 1567 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 1568 | * |
| 1569 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1570 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1571 | * will be stored into the context1 field of the IOCB for the completion |
| 1572 | * callback function to the PRLI ELS command. |
| 1573 | * |
| 1574 | * Return code |
| 1575 | * 0 - successfully issued prli iocb command for @vport |
| 1576 | * 1 - failed to issue prli iocb command for @vport |
| 1577 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1578 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1579 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1580 | uint8_t retry) |
| 1581 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1582 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1583 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1584 | PRLI *npr; |
| 1585 | IOCB_t *icmd; |
| 1586 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1587 | uint8_t *pcmd; |
| 1588 | uint16_t cmdsize; |
| 1589 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1590 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1591 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1592 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1593 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1594 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1595 | |
| 1596 | icmd = &elsiocb->iocb; |
| 1597 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1598 | |
| 1599 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1600 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1601 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1602 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1603 | |
| 1604 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 1605 | npr = (PRLI *) pcmd; |
| 1606 | /* |
| 1607 | * If our firmware version is 3.20 or later, |
| 1608 | * set the following bits for FC-TAPE support. |
| 1609 | */ |
| 1610 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 1611 | npr->ConfmComplAllowed = 1; |
| 1612 | npr->Retry = 1; |
| 1613 | npr->TaskRetryIdReq = 1; |
| 1614 | } |
| 1615 | npr->estabImagePair = 1; |
| 1616 | npr->readXferRdyDis = 1; |
| 1617 | |
| 1618 | /* For FCP support */ |
| 1619 | npr->prliType = PRLI_FCP_TYPE; |
| 1620 | npr->initiatorFunc = 1; |
| 1621 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1622 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1623 | "Issue PRLI: did:x%x", |
| 1624 | ndlp->nlp_DID, 0, 0); |
| 1625 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1626 | phba->fc_stat.elsXmitPRLI++; |
| 1627 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1628 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1629 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1630 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1631 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 1632 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1633 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1634 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1635 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1636 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1637 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1638 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1639 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1640 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1641 | } |
| 1642 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1643 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1644 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1645 | * @vport: pointer to a host virtual N_Port data structure. |
| 1646 | * |
| 1647 | * This routine performs Registration State Change Notification (RSCN) |
| 1648 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 1649 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 1650 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 1651 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 1652 | * invoked to check and handle possible more RSCN came in during the period |
| 1653 | * of processing the current ones. |
| 1654 | **/ |
| 1655 | static void |
| 1656 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 1657 | { |
| 1658 | lpfc_can_disctmo(vport); |
| 1659 | |
| 1660 | /* RSCN discovery */ |
| 1661 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 1662 | if (vport->fc_npr_cnt) |
| 1663 | if (lpfc_els_disc_plogi(vport)) |
| 1664 | return; |
| 1665 | |
| 1666 | lpfc_end_rscn(vport); |
| 1667 | } |
| 1668 | |
| 1669 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1670 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1671 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 1672 | * |
| 1673 | * This function is called when the final ADISC is completed during discovery. |
| 1674 | * This function handles clearing link attention or issuing reg_vpi depending |
| 1675 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 1676 | * discovery. |
| 1677 | * This function is called with no locks held. |
| 1678 | **/ |
| 1679 | static void |
| 1680 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 1681 | { |
| 1682 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1683 | struct lpfc_hba *phba = vport->phba; |
| 1684 | |
| 1685 | /* |
| 1686 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 1687 | * and continue discovery. |
| 1688 | */ |
| 1689 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1690 | !(vport->fc_flag & FC_RSCN_MODE) && |
| 1691 | (phba->sli_rev < LPFC_SLI_REV4)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1692 | lpfc_issue_reg_vpi(phba, vport); |
| 1693 | return; |
| 1694 | } |
| 1695 | /* |
| 1696 | * For SLI2, we need to set port_state to READY |
| 1697 | * and continue discovery. |
| 1698 | */ |
| 1699 | if (vport->port_state < LPFC_VPORT_READY) { |
| 1700 | /* If we get here, there is nothing to ADISC */ |
| 1701 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1702 | lpfc_issue_clear_la(phba, vport); |
| 1703 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 1704 | vport->num_disc_nodes = 0; |
| 1705 | /* go thru NPR list, issue ELS PLOGIs */ |
| 1706 | if (vport->fc_npr_cnt) |
| 1707 | lpfc_els_disc_plogi(vport); |
| 1708 | if (!vport->num_disc_nodes) { |
| 1709 | spin_lock_irq(shost->host_lock); |
| 1710 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1711 | spin_unlock_irq(shost->host_lock); |
| 1712 | lpfc_can_disctmo(vport); |
| 1713 | lpfc_end_rscn(vport); |
| 1714 | } |
| 1715 | } |
| 1716 | vport->port_state = LPFC_VPORT_READY; |
| 1717 | } else |
| 1718 | lpfc_rscn_disc(vport); |
| 1719 | } |
| 1720 | |
| 1721 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1722 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1723 | * @vport: pointer to a host virtual N_Port data structure. |
| 1724 | * |
| 1725 | * This routine determines whether there are more ndlps on a @vport |
| 1726 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 1727 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 1728 | * remaining nodes which need to have ADISC sent. |
| 1729 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1730 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1731 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1732 | { |
| 1733 | int sentadisc; |
| 1734 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1735 | if (vport->num_disc_nodes) |
| 1736 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1737 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1738 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1739 | "0210 Continue discovery with %d ADISCs to go " |
| 1740 | "Data: x%x x%x x%x\n", |
| 1741 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 1742 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1743 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1744 | if (vport->fc_flag & FC_NLP_MORE) { |
| 1745 | lpfc_set_disctmo(vport); |
| 1746 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 1747 | sentadisc = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1748 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1749 | if (!vport->num_disc_nodes) |
| 1750 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1751 | return; |
| 1752 | } |
| 1753 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1754 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1755 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1756 | * @phba: pointer to lpfc hba data structure. |
| 1757 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1758 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1759 | * |
| 1760 | * This routine is the completion function for issuing the Address Discover |
| 1761 | * (ADISC) command. It first checks to see whether link went down during |
| 1762 | * the discovery process. If so, the node will be marked as node port |
| 1763 | * recovery for issuing discover IOCB by the link attention handler and |
| 1764 | * exit. Otherwise, the response status is checked. If error was reported |
| 1765 | * in the response status, the ADISC command shall be retried by invoking |
| 1766 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 1767 | * the response status, the state machine is invoked to set transition |
| 1768 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 1769 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1770 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1771 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1772 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1773 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1774 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1775 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1776 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1777 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1778 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1779 | |
| 1780 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1781 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1782 | |
| 1783 | irsp = &(rspiocb->iocb); |
| 1784 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1785 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1786 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1787 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 1788 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1789 | ndlp->nlp_DID); |
| 1790 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1791 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1792 | * is being used during discovery. |
| 1793 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1794 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1795 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1796 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1797 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1798 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1799 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1800 | "0104 ADISC completes to NPort x%x " |
| 1801 | "Data: x%x x%x x%x x%x x%x\n", |
| 1802 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1803 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1804 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1805 | if (lpfc_els_chk_latt(vport)) { |
| 1806 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1807 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1808 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1809 | goto out; |
| 1810 | } |
| 1811 | |
| 1812 | if (irsp->ulpStatus) { |
| 1813 | /* Check for retry */ |
| 1814 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1815 | /* ELS command is being retried */ |
| 1816 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1817 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1818 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1819 | spin_unlock_irq(shost->host_lock); |
| 1820 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1821 | } |
| 1822 | goto out; |
| 1823 | } |
| 1824 | /* ADISC failed */ |
| 1825 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1826 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1827 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1828 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1829 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1830 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1831 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1832 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1833 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1834 | /* Check to see if there are more ADISCs to be sent */ |
| 1835 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1836 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1837 | out: |
| 1838 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1839 | return; |
| 1840 | } |
| 1841 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1842 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1843 | * 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] | 1844 | * @vport: pointer to a virtual N_Port data structure. |
| 1845 | * @ndlp: pointer to a node-list data structure. |
| 1846 | * @retry: number of retries to the command IOCB. |
| 1847 | * |
| 1848 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 1849 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 1850 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 1851 | * to issue the ADISC ELS command. |
| 1852 | * |
| 1853 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1854 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1855 | * will be stored into the context1 field of the IOCB for the completion |
| 1856 | * callback function to the ADISC ELS command. |
| 1857 | * |
| 1858 | * Return code |
| 1859 | * 0 - successfully issued adisc |
| 1860 | * 1 - failed to issue adisc |
| 1861 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1862 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1863 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1864 | uint8_t retry) |
| 1865 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1866 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1867 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1868 | ADISC *ap; |
| 1869 | IOCB_t *icmd; |
| 1870 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1871 | uint8_t *pcmd; |
| 1872 | uint16_t cmdsize; |
| 1873 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1874 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1875 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1876 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1877 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1878 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1879 | |
| 1880 | icmd = &elsiocb->iocb; |
| 1881 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1882 | |
| 1883 | /* For ADISC request, remainder of payload is service parameters */ |
| 1884 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1885 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1886 | |
| 1887 | /* Fill in ADISC payload */ |
| 1888 | ap = (ADISC *) pcmd; |
| 1889 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1890 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 1891 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1892 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1893 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1894 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1895 | "Issue ADISC: did:x%x", |
| 1896 | ndlp->nlp_DID, 0, 0); |
| 1897 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1898 | phba->fc_stat.elsXmitADISC++; |
| 1899 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1900 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1901 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1902 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1903 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 1904 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1905 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1906 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1907 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1908 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1909 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1910 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1911 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1912 | } |
| 1913 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1914 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1915 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1916 | * @phba: pointer to lpfc hba data structure. |
| 1917 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1918 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1919 | * |
| 1920 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 1921 | * command. If no error status was reported from the LOGO response, the |
| 1922 | * state machine of the associated ndlp shall be invoked for transition with |
| 1923 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 1924 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 1925 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1926 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1927 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1928 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1929 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1930 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 1931 | struct lpfc_vport *vport = ndlp->vport; |
| 1932 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1933 | IOCB_t *irsp; |
| 1934 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1935 | |
| 1936 | psli = &phba->sli; |
| 1937 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1938 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1939 | |
| 1940 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1941 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1942 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1943 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1944 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1945 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1946 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 1947 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1948 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1949 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1950 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1951 | "0105 LOGO completes to NPort x%x " |
| 1952 | "Data: x%x x%x x%x x%x\n", |
| 1953 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1954 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1955 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1956 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1957 | goto out; |
| 1958 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1959 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 1960 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 1961 | * which should abort all outstanding IOs. |
| 1962 | */ |
| 1963 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 1964 | NLP_EVT_DEVICE_RM); |
| 1965 | goto out; |
| 1966 | } |
| 1967 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1968 | if (irsp->ulpStatus) { |
| 1969 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1970 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1971 | /* ELS command is being retried */ |
| 1972 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1973 | /* LOGO failed */ |
| 1974 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1975 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1976 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1977 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1978 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1979 | NLP_EVT_CMPL_LOGO); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1980 | } else |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1981 | /* Good status, call state machine. |
| 1982 | * This will unregister the rpi if needed. |
| 1983 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1984 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1985 | NLP_EVT_CMPL_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1986 | out: |
| 1987 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1988 | return; |
| 1989 | } |
| 1990 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1991 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1992 | * 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] | 1993 | * @vport: pointer to a virtual N_Port data structure. |
| 1994 | * @ndlp: pointer to a node-list data structure. |
| 1995 | * @retry: number of retries to the command IOCB. |
| 1996 | * |
| 1997 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 1998 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 1999 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 2000 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 2001 | * |
| 2002 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2003 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2004 | * will be stored into the context1 field of the IOCB for the completion |
| 2005 | * callback function to the LOGO ELS command. |
| 2006 | * |
| 2007 | * Return code |
| 2008 | * 0 - successfully issued logo |
| 2009 | * 1 - failed to issue logo |
| 2010 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2011 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2012 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2013 | uint8_t retry) |
| 2014 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2015 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2016 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2017 | IOCB_t *icmd; |
| 2018 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2019 | uint8_t *pcmd; |
| 2020 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2021 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2022 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2023 | spin_lock_irq(shost->host_lock); |
| 2024 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 2025 | spin_unlock_irq(shost->host_lock); |
| 2026 | return 0; |
| 2027 | } |
| 2028 | spin_unlock_irq(shost->host_lock); |
| 2029 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2030 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2031 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2032 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2033 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2034 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2035 | |
| 2036 | icmd = &elsiocb->iocb; |
| 2037 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2038 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2039 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2040 | |
| 2041 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2042 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2043 | pcmd += sizeof(uint32_t); |
| 2044 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2045 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2046 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2047 | "Issue LOGO: did:x%x", |
| 2048 | ndlp->nlp_DID, 0, 0); |
| 2049 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2050 | phba->fc_stat.elsXmitLOGO++; |
| 2051 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2052 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2053 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2054 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2055 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2056 | |
| 2057 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2058 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2059 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2060 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2061 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2062 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2063 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2064 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2065 | } |
| 2066 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2067 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2068 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2069 | * @phba: pointer to lpfc hba data structure. |
| 2070 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2071 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2072 | * |
| 2073 | * This routine is a generic completion callback function for ELS commands. |
| 2074 | * Specifically, it is the callback function which does not need to perform |
| 2075 | * any command specific operations. It is currently used by the ELS command |
| 2076 | * issuing routines for the ELS State Change Request (SCR), |
| 2077 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 2078 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2079 | * certain debug loggings, this callback function simply invokes the |
| 2080 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2081 | * discovery process. |
| 2082 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2083 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2084 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2085 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2086 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2087 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2088 | IOCB_t *irsp; |
| 2089 | |
| 2090 | irsp = &rspiocb->iocb; |
| 2091 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2092 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2093 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2094 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2095 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2096 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2097 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2098 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2099 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2100 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2101 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2102 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2103 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2104 | return; |
| 2105 | } |
| 2106 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2107 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2108 | * 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] | 2109 | * @vport: pointer to a host virtual N_Port data structure. |
| 2110 | * @nportid: N_Port identifier to the remote node. |
| 2111 | * @retry: number of retries to the command IOCB. |
| 2112 | * |
| 2113 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2114 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2115 | * first search the @vport node list to find the matching ndlp. If no such |
| 2116 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2117 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2118 | * routine is invoked to send the SCR IOCB. |
| 2119 | * |
| 2120 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2121 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2122 | * will be stored into the context1 field of the IOCB for the completion |
| 2123 | * callback function to the SCR ELS command. |
| 2124 | * |
| 2125 | * Return code |
| 2126 | * 0 - Successfully issued scr command |
| 2127 | * 1 - Failed to issue scr command |
| 2128 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2129 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2130 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2131 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2132 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2133 | IOCB_t *icmd; |
| 2134 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2135 | struct lpfc_sli *psli; |
| 2136 | uint8_t *pcmd; |
| 2137 | uint16_t cmdsize; |
| 2138 | struct lpfc_nodelist *ndlp; |
| 2139 | |
| 2140 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2141 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2142 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2143 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2144 | if (!ndlp) { |
| 2145 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2146 | if (!ndlp) |
| 2147 | return 1; |
| 2148 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2149 | lpfc_enqueue_node(vport, ndlp); |
| 2150 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2151 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2152 | if (!ndlp) |
| 2153 | return 1; |
| 2154 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2155 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2156 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2157 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2158 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2159 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2160 | /* This will trigger the release of the node just |
| 2161 | * allocated |
| 2162 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2163 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2164 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2165 | } |
| 2166 | |
| 2167 | icmd = &elsiocb->iocb; |
| 2168 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2169 | |
| 2170 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2171 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2172 | |
| 2173 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2174 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2175 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2176 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2177 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2178 | "Issue SCR: did:x%x", |
| 2179 | ndlp->nlp_DID, 0, 0); |
| 2180 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2181 | phba->fc_stat.elsXmitSCR++; |
| 2182 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2183 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2184 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2185 | /* The additional lpfc_nlp_put will cause the following |
| 2186 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2187 | * the node. |
| 2188 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2189 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2190 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2191 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2192 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2193 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2194 | * trigger the release of node. |
| 2195 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2196 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2197 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2198 | } |
| 2199 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2200 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2201 | * 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] | 2202 | * @vport: pointer to a host virtual N_Port data structure. |
| 2203 | * @nportid: N_Port identifier to the remote node. |
| 2204 | * @retry: number of retries to the command IOCB. |
| 2205 | * |
| 2206 | * This routine issues a Fibre Channel Address Resolution Response |
| 2207 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2208 | * is passed into the function. It first search the @vport node list to find |
| 2209 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2210 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2211 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2212 | * |
| 2213 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2214 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2215 | * will be stored into the context1 field of the IOCB for the completion |
| 2216 | * callback function to the PARPR ELS command. |
| 2217 | * |
| 2218 | * Return code |
| 2219 | * 0 - Successfully issued farpr command |
| 2220 | * 1 - Failed to issue farpr command |
| 2221 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2222 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2223 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2224 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2225 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2226 | IOCB_t *icmd; |
| 2227 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2228 | struct lpfc_sli *psli; |
| 2229 | FARP *fp; |
| 2230 | uint8_t *pcmd; |
| 2231 | uint32_t *lp; |
| 2232 | uint16_t cmdsize; |
| 2233 | struct lpfc_nodelist *ondlp; |
| 2234 | struct lpfc_nodelist *ndlp; |
| 2235 | |
| 2236 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2237 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2238 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2239 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2240 | if (!ndlp) { |
| 2241 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2242 | if (!ndlp) |
| 2243 | return 1; |
| 2244 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2245 | lpfc_enqueue_node(vport, ndlp); |
| 2246 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2247 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2248 | if (!ndlp) |
| 2249 | return 1; |
| 2250 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2251 | |
| 2252 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2253 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2254 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2255 | /* This will trigger the release of the node just |
| 2256 | * allocated |
| 2257 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2258 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2259 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2260 | } |
| 2261 | |
| 2262 | icmd = &elsiocb->iocb; |
| 2263 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2264 | |
| 2265 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2266 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2267 | |
| 2268 | /* Fill in FARPR payload */ |
| 2269 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2270 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2271 | lp = (uint32_t *) pcmd; |
| 2272 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2273 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2274 | fp->Rflags = 0; |
| 2275 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2276 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2277 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2278 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2279 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2280 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2281 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2282 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2283 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2284 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2285 | } |
| 2286 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2287 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2288 | "Issue FARPR: did:x%x", |
| 2289 | ndlp->nlp_DID, 0, 0); |
| 2290 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2291 | phba->fc_stat.elsXmitFARPR++; |
| 2292 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2293 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2294 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2295 | /* The additional lpfc_nlp_put will cause the following |
| 2296 | * lpfc_els_free_iocb routine to trigger the release of |
| 2297 | * the node. |
| 2298 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2299 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2300 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2301 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2302 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2303 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2304 | * trigger the release of the node. |
| 2305 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2306 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2307 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2308 | } |
| 2309 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2310 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2311 | * 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] | 2312 | * @vport: pointer to a host virtual N_Port data structure. |
| 2313 | * @nlp: pointer to a node-list data structure. |
| 2314 | * |
| 2315 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2316 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2317 | * removes the ELS retry event if it presents. In addition, if the |
| 2318 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2319 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2320 | * ADISC. |
| 2321 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2322 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2323 | 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] | 2324 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2325 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2326 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2327 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2328 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2329 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2330 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2331 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2332 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2333 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2334 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2335 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2336 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2337 | /* Decrement nlp reference count held for the delayed retry */ |
| 2338 | evtp = &nlp->els_retry_evt; |
| 2339 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2340 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2341 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2342 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2343 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2344 | spin_unlock_irq(shost->host_lock); |
| 2345 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2346 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2347 | /* Check if there are more ADISCs to be sent */ |
| 2348 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2349 | } else { |
| 2350 | /* Check if there are more PLOGIs to be sent */ |
| 2351 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2352 | if (vport->num_disc_nodes == 0) { |
| 2353 | spin_lock_irq(shost->host_lock); |
| 2354 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2355 | spin_unlock_irq(shost->host_lock); |
| 2356 | lpfc_can_disctmo(vport); |
| 2357 | lpfc_end_rscn(vport); |
| 2358 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2359 | } |
| 2360 | } |
| 2361 | } |
| 2362 | return; |
| 2363 | } |
| 2364 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2365 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2366 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2367 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2368 | * |
| 2369 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2370 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2371 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2372 | * adds the delayed events to the HBA work list and invokes the |
| 2373 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2374 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2375 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2376 | * reference to ndlp will still be available when the worker thread gets |
| 2377 | * to the event associated with the ndlp. |
| 2378 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2379 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2380 | lpfc_els_retry_delay(unsigned long ptr) |
| 2381 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2382 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2383 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2384 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2385 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2386 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2387 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2388 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2389 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2390 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2391 | return; |
| 2392 | } |
| 2393 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2394 | /* We need to hold the node by incrementing the reference |
| 2395 | * count until the queued work is done |
| 2396 | */ |
| 2397 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2398 | if (evtp->evt_arg1) { |
| 2399 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2400 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2401 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2402 | } |
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 | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2407 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2408 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2409 | * @ndlp: pointer to a node-list data structure. |
| 2410 | * |
| 2411 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 2412 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 2413 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 2414 | * function according to the delayed ELS command to retry the command. |
| 2415 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2416 | void |
| 2417 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 2418 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2419 | struct lpfc_vport *vport = ndlp->vport; |
| 2420 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2421 | uint32_t cmd, did, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2422 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2423 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2424 | did = ndlp->nlp_DID; |
| 2425 | cmd = ndlp->nlp_last_elscmd; |
| 2426 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2427 | |
| 2428 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2429 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2430 | return; |
| 2431 | } |
| 2432 | |
| 2433 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2434 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 2435 | /* |
| 2436 | * If a discovery event readded nlp_delayfunc after timer |
| 2437 | * firing and before processing the timer, cancel the |
| 2438 | * nlp_delayfunc. |
| 2439 | */ |
| 2440 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2441 | retry = ndlp->nlp_retry; |
| 2442 | |
| 2443 | switch (cmd) { |
| 2444 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2445 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2446 | break; |
| 2447 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2448 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2449 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2450 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2451 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2452 | break; |
| 2453 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2454 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2455 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2456 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2457 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2458 | break; |
| 2459 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2460 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2461 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2462 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2463 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2464 | break; |
| 2465 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2466 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2467 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2468 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2469 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2470 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2471 | case ELS_CMD_FDISC: |
| 2472 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
| 2473 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2474 | } |
| 2475 | return; |
| 2476 | } |
| 2477 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2478 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2479 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2480 | * @phba: pointer to lpfc hba data structure. |
| 2481 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2482 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2483 | * |
| 2484 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 2485 | * failed. The following ELS IOCBs use this function for retrying the command |
| 2486 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 2487 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 2488 | * returned error status, it makes the decision whether a retry shall be |
| 2489 | * issued for the command, and whether a retry shall be made immediately or |
| 2490 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 2491 | * is called to retry the command. In the later case, the ELS command shall |
| 2492 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 2493 | * ndlp for the delayed command issusing. |
| 2494 | * |
| 2495 | * Return code |
| 2496 | * 0 - No retry of els command is made |
| 2497 | * 1 - Immediate or delayed retry of els command is made |
| 2498 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2499 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2500 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2501 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2502 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2503 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2504 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2505 | IOCB_t *irsp = &rspiocb->iocb; |
| 2506 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2507 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2508 | uint32_t *elscmd; |
| 2509 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2510 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2511 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2512 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2513 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2514 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2515 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2516 | /* Note: context2 may be 0 for internal driver abort |
| 2517 | * of delays ELS command. |
| 2518 | */ |
| 2519 | |
| 2520 | if (pcmd && pcmd->virt) { |
| 2521 | elscmd = (uint32_t *) (pcmd->virt); |
| 2522 | cmd = *elscmd++; |
| 2523 | } |
| 2524 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2525 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2526 | did = ndlp->nlp_DID; |
| 2527 | else { |
| 2528 | /* We should only hit this case for retrying PLOGI */ |
| 2529 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2530 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2531 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 2532 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2533 | return 1; |
| 2534 | } |
| 2535 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2536 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2537 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 2538 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 2539 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2540 | switch (irsp->ulpStatus) { |
| 2541 | case IOSTAT_FCP_RSP_ERROR: |
| 2542 | case IOSTAT_REMOTE_STOP: |
| 2543 | break; |
| 2544 | |
| 2545 | case IOSTAT_LOCAL_REJECT: |
| 2546 | switch ((irsp->un.ulpWord[4] & 0xff)) { |
| 2547 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2548 | if (cmd == ELS_CMD_FLOGI) { |
| 2549 | if (PCI_DEVICE_ID_HORNET == |
| 2550 | phba->pcidev->device) { |
| 2551 | phba->fc_topology = TOPOLOGY_LOOP; |
| 2552 | phba->pport->fc_myDID = 0; |
| 2553 | phba->alpa_map[0] = 0; |
| 2554 | phba->alpa_map[1] = 0; |
| 2555 | } |
| 2556 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2557 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2558 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2559 | retry = 1; |
| 2560 | break; |
| 2561 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2562 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2563 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2564 | "0124 Retry illegal cmd x%x " |
| 2565 | "retry:x%x delay:x%x\n", |
| 2566 | cmd, cmdiocb->retry, delay); |
| 2567 | retry = 1; |
| 2568 | /* All command's retry policy */ |
| 2569 | maxretry = 8; |
| 2570 | if (cmdiocb->retry > 2) |
| 2571 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2572 | break; |
| 2573 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2574 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2575 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2576 | retry = 1; |
| 2577 | if (cmdiocb->retry > 100) |
| 2578 | delay = 100; |
| 2579 | maxretry = 250; |
| 2580 | break; |
| 2581 | |
| 2582 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2583 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2584 | retry = 1; |
| 2585 | break; |
| 2586 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2587 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2588 | case IOERR_INVALID_RPI: |
| 2589 | retry = 1; |
| 2590 | break; |
| 2591 | } |
| 2592 | break; |
| 2593 | |
| 2594 | case IOSTAT_NPORT_RJT: |
| 2595 | case IOSTAT_FABRIC_RJT: |
| 2596 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 2597 | retry = 1; |
| 2598 | break; |
| 2599 | } |
| 2600 | break; |
| 2601 | |
| 2602 | case IOSTAT_NPORT_BSY: |
| 2603 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2604 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2605 | retry = 1; |
| 2606 | break; |
| 2607 | |
| 2608 | case IOSTAT_LS_RJT: |
| 2609 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 2610 | /* Added for Vendor specifc support |
| 2611 | * Just keep retrying for these Rsn / Exp codes |
| 2612 | */ |
| 2613 | switch (stat.un.b.lsRjtRsnCode) { |
| 2614 | case LSRJT_UNABLE_TPC: |
| 2615 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2616 | LSEXP_CMD_IN_PROGRESS) { |
| 2617 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2618 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2619 | maxretry = 48; |
| 2620 | } |
| 2621 | retry = 1; |
| 2622 | break; |
| 2623 | } |
| 2624 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2625 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2626 | maxretry = lpfc_max_els_tries + 1; |
| 2627 | retry = 1; |
| 2628 | break; |
| 2629 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2630 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2631 | (cmd == ELS_CMD_FDISC) && |
| 2632 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2633 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2634 | "0125 FDISC Failed (x%x). " |
| 2635 | "Fabric out of resources\n", |
| 2636 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2637 | lpfc_vport_set_state(vport, |
| 2638 | FC_VPORT_NO_FABRIC_RSCS); |
| 2639 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2640 | break; |
| 2641 | |
| 2642 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2643 | if ((cmd == ELS_CMD_PLOGI) || |
| 2644 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2645 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2646 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2647 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2648 | /* FDISC retry policy */ |
| 2649 | maxretry = 48; |
| 2650 | if (cmdiocb->retry >= 32) |
| 2651 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2652 | } |
| 2653 | retry = 1; |
| 2654 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2655 | |
| 2656 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2657 | /* There are some cases where switches return this |
| 2658 | * error when they are not ready and should be returning |
| 2659 | * Logical Busy. We should delay every time. |
| 2660 | */ |
| 2661 | if (cmd == ELS_CMD_FDISC && |
| 2662 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 2663 | maxretry = 3; |
| 2664 | delay = 1000; |
| 2665 | retry = 1; |
| 2666 | break; |
| 2667 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2668 | case LSRJT_PROTOCOL_ERR: |
| 2669 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2670 | (cmd == ELS_CMD_FDISC) && |
| 2671 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 2672 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 2673 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2674 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2675 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2676 | "Fabric Detected Bad WWN\n", |
| 2677 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2678 | lpfc_vport_set_state(vport, |
| 2679 | FC_VPORT_FABRIC_REJ_WWN); |
| 2680 | } |
| 2681 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2682 | } |
| 2683 | break; |
| 2684 | |
| 2685 | case IOSTAT_INTERMED_RSP: |
| 2686 | case IOSTAT_BA_RJT: |
| 2687 | break; |
| 2688 | |
| 2689 | default: |
| 2690 | break; |
| 2691 | } |
| 2692 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2693 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2694 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2695 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2696 | if ((cmd == ELS_CMD_FLOGI) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 2697 | (phba->fc_topology != TOPOLOGY_LOOP) && |
| 2698 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2699 | /* FLOGI retry policy */ |
| 2700 | retry = 1; |
| 2701 | maxretry = 48; |
| 2702 | if (cmdiocb->retry >= 32) |
| 2703 | delay = 1000; |
| 2704 | } |
| 2705 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2706 | if ((++cmdiocb->retry) >= maxretry) { |
| 2707 | phba->fc_stat.elsRetryExceeded++; |
| 2708 | retry = 0; |
| 2709 | } |
| 2710 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2711 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 2712 | retry = 0; |
| 2713 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2714 | if (retry) { |
| 2715 | |
| 2716 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2717 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2718 | "0107 Retry ELS command x%x to remote " |
| 2719 | "NPORT x%x Data: x%x x%x\n", |
| 2720 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2721 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2722 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 2723 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 2724 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { |
| 2725 | /* Don't reset timer for no resources */ |
| 2726 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2727 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2728 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2729 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2730 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2731 | } |
| 2732 | |
| 2733 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2734 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2735 | phba->fc_stat.elsDelayRetry++; |
| 2736 | ndlp->nlp_retry = cmdiocb->retry; |
| 2737 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2738 | /* delay is specified in milliseconds */ |
| 2739 | mod_timer(&ndlp->nlp_delayfunc, |
| 2740 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2741 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2742 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2743 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2744 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2745 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2746 | if (cmd == ELS_CMD_PRLI) |
| 2747 | lpfc_nlp_set_state(vport, ndlp, |
| 2748 | NLP_STE_REG_LOGIN_ISSUE); |
| 2749 | else |
| 2750 | lpfc_nlp_set_state(vport, ndlp, |
| 2751 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2752 | ndlp->nlp_last_elscmd = cmd; |
| 2753 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2754 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2755 | } |
| 2756 | switch (cmd) { |
| 2757 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2758 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2759 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2760 | case ELS_CMD_FDISC: |
| 2761 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 2762 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2763 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2764 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2765 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2766 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2767 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2768 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2769 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2770 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2771 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2772 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2773 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 2774 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2775 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2776 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2777 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2778 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 2779 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2780 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2781 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2782 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2783 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 2784 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2785 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2786 | } |
| 2787 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2788 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2789 | if (logerr) { |
| 2790 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2791 | "0137 No retry ELS command x%x to remote " |
| 2792 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 2793 | cmd, did, irsp->ulpStatus, |
| 2794 | irsp->un.ulpWord[4]); |
| 2795 | } |
| 2796 | else { |
| 2797 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2798 | "0108 No retry ELS command x%x to remote " |
| 2799 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 2800 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 2801 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2802 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2803 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2804 | } |
| 2805 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2806 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2807 | * 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] | 2808 | * @phba: pointer to lpfc hba data structure. |
| 2809 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 2810 | * |
| 2811 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 2812 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 2813 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 2814 | * response of the command IOCB. If so, it will be released before releasing |
| 2815 | * the lpfc DMA buffer associated with the IOCB itself. |
| 2816 | * |
| 2817 | * Return code |
| 2818 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2819 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2820 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2821 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 2822 | { |
| 2823 | struct lpfc_dmabuf *buf_ptr; |
| 2824 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2825 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2826 | if (!list_empty(&buf_ptr1->list)) { |
| 2827 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 2828 | struct lpfc_dmabuf, |
| 2829 | list); |
| 2830 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2831 | kfree(buf_ptr); |
| 2832 | } |
| 2833 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 2834 | kfree(buf_ptr1); |
| 2835 | return 0; |
| 2836 | } |
| 2837 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2838 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2839 | * 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] | 2840 | * @phba: pointer to lpfc hba data structure. |
| 2841 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 2842 | * |
| 2843 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 2844 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 2845 | * pool. |
| 2846 | * |
| 2847 | * Return code |
| 2848 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2849 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2850 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2851 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 2852 | { |
| 2853 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2854 | kfree(buf_ptr); |
| 2855 | return 0; |
| 2856 | } |
| 2857 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2858 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2859 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2860 | * @phba: pointer to lpfc hba data structure. |
| 2861 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 2862 | * |
| 2863 | * This routine frees a command IOCB and its associated resources. The |
| 2864 | * command IOCB data structure contains the reference to various associated |
| 2865 | * resources, these fields must be set to NULL if the associated reference |
| 2866 | * not present: |
| 2867 | * context1 - reference to ndlp |
| 2868 | * context2 - reference to cmd |
| 2869 | * context2->next - reference to rsp |
| 2870 | * context3 - reference to bpl |
| 2871 | * |
| 2872 | * It first properly decrements the reference count held on ndlp for the |
| 2873 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 2874 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 2875 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 2876 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 2877 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 2878 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 2879 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 2880 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 2881 | * |
| 2882 | * Return code |
| 2883 | * 0 - Success (currently, always return 0) |
| 2884 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2885 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2886 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2887 | { |
| 2888 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2889 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2890 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2891 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 2892 | if (ndlp) { |
| 2893 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 2894 | lpfc_nlp_put(ndlp); |
| 2895 | |
| 2896 | /* If the ndlp is not being used by another discovery |
| 2897 | * thread, free it. |
| 2898 | */ |
| 2899 | if (!lpfc_nlp_not_used(ndlp)) { |
| 2900 | /* If ndlp is being used by another discovery |
| 2901 | * thread, just clear NLP_DEFER_RM |
| 2902 | */ |
| 2903 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 2904 | } |
| 2905 | } |
| 2906 | else |
| 2907 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2908 | elsiocb->context1 = NULL; |
| 2909 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2910 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 2911 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2912 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 2913 | /* Firmware could still be in progress of DMAing |
| 2914 | * payload, so don't free data buffer till after |
| 2915 | * a hbeat. |
| 2916 | */ |
| 2917 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 2918 | buf_ptr = elsiocb->context2; |
| 2919 | elsiocb->context2 = NULL; |
| 2920 | if (buf_ptr) { |
| 2921 | buf_ptr1 = NULL; |
| 2922 | spin_lock_irq(&phba->hbalock); |
| 2923 | if (!list_empty(&buf_ptr->list)) { |
| 2924 | list_remove_head(&buf_ptr->list, |
| 2925 | buf_ptr1, struct lpfc_dmabuf, |
| 2926 | list); |
| 2927 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 2928 | list_add_tail(&buf_ptr1->list, |
| 2929 | &phba->elsbuf); |
| 2930 | phba->elsbuf_cnt++; |
| 2931 | } |
| 2932 | INIT_LIST_HEAD(&buf_ptr->list); |
| 2933 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 2934 | phba->elsbuf_cnt++; |
| 2935 | spin_unlock_irq(&phba->hbalock); |
| 2936 | } |
| 2937 | } else { |
| 2938 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 2939 | lpfc_els_free_data(phba, buf_ptr1); |
| 2940 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2941 | } |
| 2942 | |
| 2943 | if (elsiocb->context3) { |
| 2944 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2945 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2946 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2947 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2948 | return 0; |
| 2949 | } |
| 2950 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2951 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2952 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2953 | * @phba: pointer to lpfc hba data structure. |
| 2954 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2955 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2956 | * |
| 2957 | * This routine is the completion callback function to the Logout (LOGO) |
| 2958 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 2959 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 2960 | * release the ndlp if it has the last reference remaining (reference count |
| 2961 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 2962 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 2963 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 2964 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 2965 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 2966 | * IOCB data structure. |
| 2967 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2968 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2969 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2970 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2971 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2972 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2973 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2974 | IOCB_t *irsp; |
| 2975 | |
| 2976 | irsp = &rspiocb->iocb; |
| 2977 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 2978 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 2979 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2980 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2981 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2982 | "0109 ACC to LOGO completes to NPort x%x " |
| 2983 | "Data: x%x x%x x%x\n", |
| 2984 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 2985 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2986 | |
| 2987 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 2988 | /* NPort Recovery mode or node is just allocated */ |
| 2989 | if (!lpfc_nlp_not_used(ndlp)) { |
| 2990 | /* If the ndlp is being used by another discovery |
| 2991 | * thread, just unregister the RPI. |
| 2992 | */ |
| 2993 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2994 | } else { |
| 2995 | /* Indicate the node has already released, should |
| 2996 | * not reference to it from within lpfc_els_free_iocb. |
| 2997 | */ |
| 2998 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2999 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3000 | } |
| 3001 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3002 | return; |
| 3003 | } |
| 3004 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3005 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3006 | * 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] | 3007 | * @phba: pointer to lpfc hba data structure. |
| 3008 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 3009 | * |
| 3010 | * This routine is the completion callback function for unregister default |
| 3011 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 3012 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 3013 | * decrements the ndlp reference count held for this completion callback |
| 3014 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 3015 | * whether there is only one reference left on the ndlp. If so, it will |
| 3016 | * perform one more decrement and trigger the release of the ndlp. |
| 3017 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3018 | void |
| 3019 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 3020 | { |
| 3021 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 3022 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3023 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3024 | /* |
| 3025 | * This routine is used to register and unregister in previous SLI |
| 3026 | * modes. |
| 3027 | */ |
| 3028 | if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) && |
| 3029 | (phba->sli_rev == LPFC_SLI_REV4)) |
| 3030 | lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi); |
| 3031 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3032 | pmb->context1 = NULL; |
| 3033 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3034 | kfree(mp); |
| 3035 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3036 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3037 | lpfc_nlp_put(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3038 | /* This is the end of the default RPI cleanup logic for this |
| 3039 | * ndlp. If no other discovery threads are using this ndlp. |
| 3040 | * we should free all resources associated with it. |
| 3041 | */ |
| 3042 | lpfc_nlp_not_used(ndlp); |
| 3043 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3044 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3045 | return; |
| 3046 | } |
| 3047 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3048 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3049 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3050 | * @phba: pointer to lpfc hba data structure. |
| 3051 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3052 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 3053 | * |
| 3054 | * This routine is the completion callback function for ELS Response IOCB |
| 3055 | * command. In normal case, this callback function just properly sets the |
| 3056 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 3057 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 3058 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 3059 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 3060 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 3061 | * routine shall be invoked trying to release the ndlp if no other threads |
| 3062 | * are currently referring it. |
| 3063 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3064 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3065 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3066 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3067 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3068 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 3069 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 3070 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3071 | IOCB_t *irsp; |
| 3072 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3073 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3074 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3075 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3076 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3077 | irsp = &rspiocb->iocb; |
| 3078 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3079 | if (cmdiocb->context_un.mbox) |
| 3080 | mbox = cmdiocb->context_un.mbox; |
| 3081 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3082 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 3083 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 3084 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3085 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3086 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3087 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3088 | /* A LS_RJT associated with Default RPI cleanup has its own |
| 3089 | * seperate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3090 | */ |
| 3091 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 3092 | ls_rjt = 1; |
| 3093 | } |
| 3094 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3095 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3096 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3097 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3098 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3099 | if (mp) { |
| 3100 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3101 | kfree(mp); |
| 3102 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3103 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3104 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3105 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3106 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3107 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3108 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3109 | /* Indicate the node has already released, |
| 3110 | * should not reference to it from within |
| 3111 | * the routine lpfc_els_free_iocb. |
| 3112 | */ |
| 3113 | cmdiocb->context1 = NULL; |
| 3114 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3115 | goto out; |
| 3116 | } |
| 3117 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3118 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3119 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3120 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3121 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3122 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3123 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3124 | "0110 ELS response tag x%x completes " |
| 3125 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3126 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3127 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3128 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3129 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3130 | if (mbox) { |
| 3131 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3132 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3133 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3134 | /* Increment reference count to ndlp to hold the |
| 3135 | * reference to ndlp for the callback function. |
| 3136 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3137 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3138 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3139 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3140 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3141 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3142 | } |
| 3143 | else { |
| 3144 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3145 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3146 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3147 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3148 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3149 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3150 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3151 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3152 | else |
| 3153 | /* Decrement the ndlp reference count we |
| 3154 | * set for this failed mailbox command. |
| 3155 | */ |
| 3156 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3157 | |
| 3158 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3159 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3160 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3161 | "Data: x%x x%x x%x\n", |
| 3162 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3163 | ndlp->nlp_rpi); |
| 3164 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3165 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3166 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3167 | /* Indicate node has already been released, |
| 3168 | * should not reference to it from within |
| 3169 | * the routine lpfc_els_free_iocb. |
| 3170 | */ |
| 3171 | cmdiocb->context1 = NULL; |
| 3172 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3173 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3174 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3175 | if (!lpfc_error_lost_link(irsp) && |
| 3176 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3177 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3178 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3179 | /* Indicate node has already been |
| 3180 | * released, should not reference |
| 3181 | * to it from within the routine |
| 3182 | * lpfc_els_free_iocb. |
| 3183 | */ |
| 3184 | cmdiocb->context1 = NULL; |
| 3185 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3186 | } |
| 3187 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3188 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3189 | if (mp) { |
| 3190 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3191 | kfree(mp); |
| 3192 | } |
| 3193 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3194 | } |
| 3195 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3196 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3197 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3198 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3199 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3200 | |
| 3201 | /* If the node is not being used by another discovery thread, |
| 3202 | * and we are sending a reject, we are done with it. |
| 3203 | * Release driver reference count here and free associated |
| 3204 | * resources. |
| 3205 | */ |
| 3206 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3207 | if (lpfc_nlp_not_used(ndlp)) |
| 3208 | /* Indicate node has already been released, |
| 3209 | * should not reference to it from within |
| 3210 | * the routine lpfc_els_free_iocb. |
| 3211 | */ |
| 3212 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3213 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3214 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3215 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3216 | return; |
| 3217 | } |
| 3218 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3219 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3220 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3221 | * @vport: pointer to a host virtual N_Port data structure. |
| 3222 | * @flag: the els command code to be accepted. |
| 3223 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3224 | * @ndlp: pointer to a node-list data structure. |
| 3225 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3226 | * |
| 3227 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3228 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3229 | * specific ACC response command to be issued and invokes the |
| 3230 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3231 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3232 | * field of the IOCB for the completion callback function to issue the |
| 3233 | * mailbox command to the HBA later when callback is invoked. |
| 3234 | * |
| 3235 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3236 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3237 | * will be stored into the context1 field of the IOCB for the completion |
| 3238 | * callback function to the corresponding response ELS IOCB command. |
| 3239 | * |
| 3240 | * Return code |
| 3241 | * 0 - Successfully issued acc response |
| 3242 | * 1 - Failed to issue acc response |
| 3243 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3244 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3245 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3246 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3247 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3248 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3249 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3250 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3251 | IOCB_t *icmd; |
| 3252 | IOCB_t *oldcmd; |
| 3253 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3254 | struct lpfc_sli *psli; |
| 3255 | uint8_t *pcmd; |
| 3256 | uint16_t cmdsize; |
| 3257 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3258 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3259 | |
| 3260 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3261 | oldcmd = &oldiocb->iocb; |
| 3262 | |
| 3263 | switch (flag) { |
| 3264 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3265 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3266 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3267 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3268 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3269 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3270 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3271 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3272 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3273 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3274 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3275 | icmd = &elsiocb->iocb; |
| 3276 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3277 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3278 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3279 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3280 | |
| 3281 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3282 | "Issue ACC: did:x%x flg:x%x", |
| 3283 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3284 | break; |
| 3285 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3286 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3287 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3288 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3289 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3290 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3291 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3292 | icmd = &elsiocb->iocb; |
| 3293 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3294 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3295 | |
| 3296 | if (mbox) |
| 3297 | elsiocb->context_un.mbox = mbox; |
| 3298 | |
| 3299 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3300 | pcmd += sizeof(uint32_t); |
| 3301 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3302 | |
| 3303 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3304 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 3305 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3306 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3307 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3308 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3309 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3310 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3311 | if (!elsiocb) |
| 3312 | return 1; |
| 3313 | |
| 3314 | icmd = &elsiocb->iocb; |
| 3315 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3316 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3317 | |
| 3318 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3319 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3320 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 3321 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 3322 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3323 | |
| 3324 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3325 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 3326 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3327 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3328 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3329 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3330 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3331 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3332 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3333 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
| 3334 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", |
| 3335 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3336 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3337 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3338 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3339 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3340 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3341 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3342 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 3343 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3344 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3345 | } |
| 3346 | |
| 3347 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3348 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3349 | if (rc == IOCB_ERROR) { |
| 3350 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3351 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3352 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3353 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3354 | } |
| 3355 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3356 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3357 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3358 | * @vport: pointer to a virtual N_Port data structure. |
| 3359 | * @rejectError: |
| 3360 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3361 | * @ndlp: pointer to a node-list data structure. |
| 3362 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3363 | * |
| 3364 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 3365 | * command. If a @mbox pointer is passed in, it will be put into the |
| 3366 | * context_un.mbox field of the IOCB for the completion callback function |
| 3367 | * to issue to the HBA later. |
| 3368 | * |
| 3369 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3370 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3371 | * will be stored into the context1 field of the IOCB for the completion |
| 3372 | * callback function to the reject response ELS IOCB command. |
| 3373 | * |
| 3374 | * Return code |
| 3375 | * 0 - Successfully issued reject response |
| 3376 | * 1 - Failed to issue reject response |
| 3377 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3378 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3379 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3380 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 3381 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3382 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3383 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3384 | IOCB_t *icmd; |
| 3385 | IOCB_t *oldcmd; |
| 3386 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3387 | struct lpfc_sli *psli; |
| 3388 | uint8_t *pcmd; |
| 3389 | uint16_t cmdsize; |
| 3390 | int rc; |
| 3391 | |
| 3392 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3393 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3394 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3395 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3396 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3397 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3398 | |
| 3399 | icmd = &elsiocb->iocb; |
| 3400 | oldcmd = &oldiocb->iocb; |
| 3401 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3402 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3403 | |
| 3404 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3405 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3406 | *((uint32_t *) (pcmd)) = rejectError; |
| 3407 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3408 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3409 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3410 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3411 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3412 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3413 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 3414 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 3415 | "rpi x%x\n", |
| 3416 | rejectError, elsiocb->iotag, |
| 3417 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 3418 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3419 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3420 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 3421 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 3422 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3423 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3424 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3425 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3426 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3427 | if (rc == IOCB_ERROR) { |
| 3428 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3429 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3430 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3431 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3432 | } |
| 3433 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3434 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3435 | * 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] | 3436 | * @vport: pointer to a virtual N_Port data structure. |
| 3437 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3438 | * @ndlp: pointer to a node-list data structure. |
| 3439 | * |
| 3440 | * This routine prepares and issues an Accept (ACC) response to Address |
| 3441 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 3442 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3443 | * |
| 3444 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3445 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3446 | * will be stored into the context1 field of the IOCB for the completion |
| 3447 | * callback function to the ADISC Accept response ELS IOCB command. |
| 3448 | * |
| 3449 | * Return code |
| 3450 | * 0 - Successfully issued acc adisc response |
| 3451 | * 1 - Failed to issue adisc acc response |
| 3452 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3453 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3454 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 3455 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3456 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3457 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3458 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3459 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3460 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3461 | uint8_t *pcmd; |
| 3462 | uint16_t cmdsize; |
| 3463 | int rc; |
| 3464 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3465 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3466 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3467 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3468 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3469 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3470 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3471 | icmd = &elsiocb->iocb; |
| 3472 | oldcmd = &oldiocb->iocb; |
| 3473 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3474 | |
| 3475 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3476 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3477 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 3478 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 3479 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3480 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3481 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3482 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3483 | |
| 3484 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3485 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3486 | |
| 3487 | ap = (ADISC *) (pcmd); |
| 3488 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3489 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3490 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3491 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3492 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3493 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3494 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 3495 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3496 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3497 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3498 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3499 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3500 | if (rc == IOCB_ERROR) { |
| 3501 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3502 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3503 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3504 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3505 | } |
| 3506 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3507 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3508 | * 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] | 3509 | * @vport: pointer to a virtual N_Port data structure. |
| 3510 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3511 | * @ndlp: pointer to a node-list data structure. |
| 3512 | * |
| 3513 | * This routine prepares and issues an Accept (ACC) response to Process |
| 3514 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 3515 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3516 | * |
| 3517 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3518 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3519 | * will be stored into the context1 field of the IOCB for the completion |
| 3520 | * callback function to the PRLI Accept response ELS IOCB command. |
| 3521 | * |
| 3522 | * Return code |
| 3523 | * 0 - Successfully issued acc prli response |
| 3524 | * 1 - Failed to issue acc prli response |
| 3525 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3526 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3527 | 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] | 3528 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3529 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3530 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3531 | PRLI *npr; |
| 3532 | lpfc_vpd_t *vpd; |
| 3533 | IOCB_t *icmd; |
| 3534 | IOCB_t *oldcmd; |
| 3535 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3536 | struct lpfc_sli *psli; |
| 3537 | uint8_t *pcmd; |
| 3538 | uint16_t cmdsize; |
| 3539 | int rc; |
| 3540 | |
| 3541 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3542 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3543 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3544 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3545 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3546 | if (!elsiocb) |
| 3547 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3548 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3549 | icmd = &elsiocb->iocb; |
| 3550 | oldcmd = &oldiocb->iocb; |
| 3551 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3552 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3553 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3554 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 3555 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 3556 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3557 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3558 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3559 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3560 | |
| 3561 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3562 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3563 | |
| 3564 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3565 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3566 | |
| 3567 | npr = (PRLI *) pcmd; |
| 3568 | vpd = &phba->vpd; |
| 3569 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3570 | * If the remote port is a target and our firmware version is 3.20 or |
| 3571 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3572 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3573 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 3574 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3575 | npr->ConfmComplAllowed = 1; |
| 3576 | npr->Retry = 1; |
| 3577 | npr->TaskRetryIdReq = 1; |
| 3578 | } |
| 3579 | |
| 3580 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 3581 | npr->estabImagePair = 1; |
| 3582 | npr->readXferRdyDis = 1; |
| 3583 | npr->ConfmComplAllowed = 1; |
| 3584 | |
| 3585 | npr->prliType = PRLI_FCP_TYPE; |
| 3586 | npr->initiatorFunc = 1; |
| 3587 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3588 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3589 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 3590 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3591 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3592 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3593 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3594 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3595 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3596 | if (rc == IOCB_ERROR) { |
| 3597 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3598 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3599 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3600 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3601 | } |
| 3602 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3603 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3604 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3605 | * @vport: pointer to a virtual N_Port data structure. |
| 3606 | * @format: rnid command format. |
| 3607 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3608 | * @ndlp: pointer to a node-list data structure. |
| 3609 | * |
| 3610 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 3611 | * (ACC) response. It constructs the RNID ACC response command according to |
| 3612 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 3613 | * issue the response. Note that this command does not need to hold the ndlp |
| 3614 | * reference count for the callback. So, the ndlp reference count taken by |
| 3615 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 3616 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 3617 | * there is no ndlp reference available. |
| 3618 | * |
| 3619 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3620 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3621 | * will be stored into the context1 field of the IOCB for the completion |
| 3622 | * callback function. However, for the RNID Accept Response ELS command, |
| 3623 | * this is undone later by this routine after the IOCB is allocated. |
| 3624 | * |
| 3625 | * Return code |
| 3626 | * 0 - Successfully issued acc rnid response |
| 3627 | * 1 - Failed to issue acc rnid response |
| 3628 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3629 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3630 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3631 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3632 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3633 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3634 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3635 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3636 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3637 | struct lpfc_sli *psli; |
| 3638 | uint8_t *pcmd; |
| 3639 | uint16_t cmdsize; |
| 3640 | int rc; |
| 3641 | |
| 3642 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3643 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 3644 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3645 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3646 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3647 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3648 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3649 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3650 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3651 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3652 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3653 | icmd = &elsiocb->iocb; |
| 3654 | oldcmd = &oldiocb->iocb; |
| 3655 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3656 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3657 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3658 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 3659 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3660 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3661 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3662 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3663 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3664 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3665 | rn = (RNID *) (pcmd); |
| 3666 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3667 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 3668 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3669 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3670 | switch (format) { |
| 3671 | case 0: |
| 3672 | rn->SpecificLen = 0; |
| 3673 | break; |
| 3674 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3675 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3676 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3677 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3678 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 3679 | rn->un.topologyDisc.physPort = 0; |
| 3680 | rn->un.topologyDisc.attachedNodes = 0; |
| 3681 | break; |
| 3682 | default: |
| 3683 | rn->CommonLen = 0; |
| 3684 | rn->SpecificLen = 0; |
| 3685 | break; |
| 3686 | } |
| 3687 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3688 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3689 | "Issue ACC RNID: did:x%x flg:x%x", |
| 3690 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3691 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3692 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3693 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3694 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3695 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 3696 | * it could be freed */ |
| 3697 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3698 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3699 | if (rc == IOCB_ERROR) { |
| 3700 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3701 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3702 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3703 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3704 | } |
| 3705 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3706 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3707 | * 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] | 3708 | * @vport: pointer to a host virtual N_Port data structure. |
| 3709 | * |
| 3710 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 3711 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 3712 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 3713 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 3714 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 3715 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 3716 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 3717 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 3718 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 3719 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 3720 | * no more ADISC need to be sent. |
| 3721 | * |
| 3722 | * Return code |
| 3723 | * The number of N_Ports with adisc issued. |
| 3724 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3725 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3726 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3727 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3728 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3729 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3730 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3731 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3732 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3733 | 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] | 3734 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3735 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3736 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3737 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3738 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3739 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3740 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3741 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3742 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3743 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 3744 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3745 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3746 | vport->num_disc_nodes++; |
| 3747 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3748 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3749 | spin_lock_irq(shost->host_lock); |
| 3750 | vport->fc_flag |= FC_NLP_MORE; |
| 3751 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3752 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3753 | } |
| 3754 | } |
| 3755 | } |
| 3756 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3757 | spin_lock_irq(shost->host_lock); |
| 3758 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3759 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3760 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3761 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3762 | } |
| 3763 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3764 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3765 | * 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] | 3766 | * @vport: pointer to a host virtual N_Port data structure. |
| 3767 | * |
| 3768 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 3769 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 3770 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 3771 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 3772 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 3773 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 3774 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 3775 | * later pick up. On the other hand, after walking through all the ndlps with |
| 3776 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 3777 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 3778 | * PLOGI need to be sent. |
| 3779 | * |
| 3780 | * Return code |
| 3781 | * The number of N_Ports with plogi issued. |
| 3782 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3783 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3784 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3785 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3786 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3787 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3788 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3789 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3790 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 3791 | 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] | 3792 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3793 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3794 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3795 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3796 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 3797 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 3798 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3799 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 3800 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3801 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3802 | vport->num_disc_nodes++; |
| 3803 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3804 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3805 | spin_lock_irq(shost->host_lock); |
| 3806 | vport->fc_flag |= FC_NLP_MORE; |
| 3807 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3808 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3809 | } |
| 3810 | } |
| 3811 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3812 | if (sentplogi) { |
| 3813 | lpfc_set_disctmo(vport); |
| 3814 | } |
| 3815 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3816 | spin_lock_irq(shost->host_lock); |
| 3817 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3818 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3819 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3820 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3821 | } |
| 3822 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3823 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3824 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3825 | * @vport: pointer to a host virtual N_Port data structure. |
| 3826 | * |
| 3827 | * This routine cleans up any Registration State Change Notification |
| 3828 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 3829 | * @vport together with the host_lock is used to prevent multiple thread |
| 3830 | * trying to access the RSCN array on a same @vport at the same time. |
| 3831 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3832 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3833 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3834 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3835 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3836 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3837 | int i; |
| 3838 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3839 | spin_lock_irq(shost->host_lock); |
| 3840 | if (vport->fc_rscn_flush) { |
| 3841 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3842 | spin_unlock_irq(shost->host_lock); |
| 3843 | return; |
| 3844 | } |
| 3845 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 3846 | vport->fc_rscn_flush = 1; |
| 3847 | spin_unlock_irq(shost->host_lock); |
| 3848 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3849 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3850 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3851 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3852 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3853 | spin_lock_irq(shost->host_lock); |
| 3854 | vport->fc_rscn_id_cnt = 0; |
| 3855 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 3856 | spin_unlock_irq(shost->host_lock); |
| 3857 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3858 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 3859 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3860 | } |
| 3861 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3862 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3863 | * 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] | 3864 | * @vport: pointer to a host virtual N_Port data structure. |
| 3865 | * @did: remote destination port identifier. |
| 3866 | * |
| 3867 | * This routine checks whether there is any pending Registration State |
| 3868 | * Configuration Notification (RSCN) to a @did on @vport. |
| 3869 | * |
| 3870 | * Return code |
| 3871 | * None zero - The @did matched with a pending rscn |
| 3872 | * 0 - not able to match @did with a pending rscn |
| 3873 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3874 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3875 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3876 | { |
| 3877 | D_ID ns_did; |
| 3878 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3879 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3880 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3881 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3882 | |
| 3883 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3884 | |
| 3885 | /* Never match fabric nodes for RSCNs */ |
| 3886 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3887 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3888 | |
| 3889 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3890 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3891 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3892 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3893 | spin_lock_irq(shost->host_lock); |
| 3894 | if (vport->fc_rscn_flush) { |
| 3895 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3896 | spin_unlock_irq(shost->host_lock); |
| 3897 | return 0; |
| 3898 | } |
| 3899 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 3900 | vport->fc_rscn_flush = 1; |
| 3901 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3902 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3903 | lp = vport->fc_rscn_id_list[i]->virt; |
| 3904 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 3905 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3906 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3907 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 3908 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3909 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 3910 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3911 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 3912 | && (ns_did.un.b.area == rscn_did.un.b.area) |
| 3913 | && (ns_did.un.b.id == rscn_did.un.b.id)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3914 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3915 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3916 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3917 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 3918 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3919 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3920 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3921 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3922 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3923 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3924 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3925 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3926 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3927 | } |
| 3928 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3929 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3930 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 3931 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3932 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3933 | return_did_out: |
| 3934 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 3935 | vport->fc_rscn_flush = 0; |
| 3936 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3937 | } |
| 3938 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3939 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3940 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3941 | * @vport: pointer to a host virtual N_Port data structure. |
| 3942 | * |
| 3943 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 3944 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 3945 | * State Change Notification). |
| 3946 | * |
| 3947 | * Return code |
| 3948 | * 0 - Successful (currently alway return 0) |
| 3949 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3950 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3951 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3952 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3953 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3954 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3955 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3956 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3957 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3958 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 3959 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3960 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3961 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3962 | NLP_EVT_DEVICE_RECOVERY); |
| 3963 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3964 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3965 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3966 | } |
| 3967 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3968 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3969 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 3970 | * @vport: pointer to a host virtual N_Port data structure. |
| 3971 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3972 | * |
| 3973 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 3974 | * applications. |
| 3975 | */ |
| 3976 | static void |
| 3977 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 3978 | struct lpfc_iocbq *cmdiocb) |
| 3979 | { |
| 3980 | struct lpfc_dmabuf *pcmd; |
| 3981 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3982 | uint32_t *payload_ptr; |
| 3983 | uint32_t payload_len; |
| 3984 | struct lpfc_rscn_event_header *rscn_event_data; |
| 3985 | |
| 3986 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 3987 | payload_ptr = (uint32_t *) pcmd->virt; |
| 3988 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 3989 | |
| 3990 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 3991 | payload_len, GFP_KERNEL); |
| 3992 | if (!rscn_event_data) { |
| 3993 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3994 | "0147 Failed to allocate memory for RSCN event\n"); |
| 3995 | return; |
| 3996 | } |
| 3997 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 3998 | rscn_event_data->payload_length = payload_len; |
| 3999 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 4000 | payload_len); |
| 4001 | |
| 4002 | fc_host_post_vendor_event(shost, |
| 4003 | fc_get_event_number(), |
| 4004 | sizeof(struct lpfc_els_event_header) + payload_len, |
| 4005 | (char *)rscn_event_data, |
| 4006 | LPFC_NL_VENDOR_ID); |
| 4007 | |
| 4008 | kfree(rscn_event_data); |
| 4009 | } |
| 4010 | |
| 4011 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4012 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4013 | * @vport: pointer to a host virtual N_Port data structure. |
| 4014 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4015 | * @ndlp: pointer to a node-list data structure. |
| 4016 | * |
| 4017 | * This routine processes an unsolicited RSCN (Registration State Change |
| 4018 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 4019 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 4020 | * discover state machine is about to begin discovery, it just accepts the |
| 4021 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 4022 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 4023 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 4024 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 4025 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 4026 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 4027 | * routine is invoked to handle the RSCN event. |
| 4028 | * |
| 4029 | * Return code |
| 4030 | * 0 - Just sent the acc response |
| 4031 | * 1 - Sent the acc response and waited for name server completion |
| 4032 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4033 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4034 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4035 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4036 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4037 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4038 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4039 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4040 | uint32_t *lp, *datap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4041 | IOCB_t *icmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4042 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4043 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4044 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4045 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4046 | |
| 4047 | icmd = &cmdiocb->iocb; |
| 4048 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4049 | lp = (uint32_t *) pcmd->virt; |
| 4050 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4051 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 4052 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4053 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4054 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4055 | "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] | 4056 | vport->fc_flag, payload_len, *lp, |
| 4057 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4058 | |
| 4059 | /* Send an RSCN event to the management application */ |
| 4060 | lpfc_send_rscn_event(vport, cmdiocb); |
| 4061 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4062 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4063 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4064 | FCH_EVT_RSCN, lp[i]); |
| 4065 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4066 | /* If we are about to begin discovery, just ACC the RSCN. |
| 4067 | * Discovery processing will satisfy it. |
| 4068 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4069 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4070 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4071 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 4072 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4073 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4074 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4075 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4076 | } |
| 4077 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4078 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 4079 | * just ACC and ignore it. |
| 4080 | */ |
| 4081 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4082 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4083 | i = payload_len; |
| 4084 | datap = lp; |
| 4085 | while (i > 0) { |
| 4086 | nportid = *datap++; |
| 4087 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 4088 | i -= sizeof(uint32_t); |
| 4089 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4090 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 4091 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4092 | } |
| 4093 | if (rscn_id == hba_id) { |
| 4094 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4095 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4096 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4097 | "Data: x%x x%x x%x x%x\n", |
| 4098 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4099 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4100 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4101 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 4102 | ndlp->nlp_DID, vport->port_state, |
| 4103 | ndlp->nlp_flag); |
| 4104 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4105 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4106 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4107 | return 0; |
| 4108 | } |
| 4109 | } |
| 4110 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4111 | spin_lock_irq(shost->host_lock); |
| 4112 | if (vport->fc_rscn_flush) { |
| 4113 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4114 | spin_unlock_irq(shost->host_lock); |
| 4115 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4116 | /* Send back ACC */ |
| 4117 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4118 | return 0; |
| 4119 | } |
| 4120 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4121 | vport->fc_rscn_flush = 1; |
| 4122 | spin_unlock_irq(shost->host_lock); |
| 4123 | /* Get the array count after sucessfully have the token */ |
| 4124 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4125 | /* If we are already processing an RSCN, save the received |
| 4126 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 4127 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4128 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4129 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4130 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 4131 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4132 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4133 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4134 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 4135 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4136 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4137 | vport->fc_flag |= FC_RSCN_MODE; |
| 4138 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4139 | if (rscn_cnt) { |
| 4140 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 4141 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 4142 | } |
| 4143 | if ((rscn_cnt) && |
| 4144 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 4145 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4146 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4147 | memcpy(((uint8_t *)cmd) + length, lp, |
| 4148 | payload_len); |
| 4149 | } else { |
| 4150 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 4151 | vport->fc_rscn_id_cnt++; |
| 4152 | /* If we zero, cmdiocb->context2, the calling |
| 4153 | * routine will not try to free it. |
| 4154 | */ |
| 4155 | cmdiocb->context2 = NULL; |
| 4156 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4157 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4158 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4159 | "0235 Deferred RSCN " |
| 4160 | "Data: x%x x%x x%x\n", |
| 4161 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4162 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4163 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4164 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 4165 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4166 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4167 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4168 | "0234 ReDiscovery RSCN " |
| 4169 | "Data: x%x x%x x%x\n", |
| 4170 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4171 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4172 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4173 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4174 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4175 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4176 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4177 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4178 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4179 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4180 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4181 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4182 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4183 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4184 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4185 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 4186 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4187 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4188 | spin_lock_irq(shost->host_lock); |
| 4189 | vport->fc_flag |= FC_RSCN_MODE; |
| 4190 | spin_unlock_irq(shost->host_lock); |
| 4191 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4192 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4193 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4194 | /* |
| 4195 | * If we zero, cmdiocb->context2, the calling routine will |
| 4196 | * not try to free it. |
| 4197 | */ |
| 4198 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4199 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4200 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4201 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4202 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4203 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4204 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4205 | } |
| 4206 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4207 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4208 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4209 | * @vport: pointer to a host virtual N_Port data structure. |
| 4210 | * |
| 4211 | * This routine handles the Registration State Configuration Notification |
| 4212 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 4213 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 4214 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 4215 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 4216 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 4217 | * RSCN activities with the @vport. |
| 4218 | * |
| 4219 | * Return code |
| 4220 | * 0 - Cleaned up rscn on the @vport |
| 4221 | * 1 - Wait for plogi to name server before proceed |
| 4222 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4223 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4224 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4225 | { |
| 4226 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4227 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4228 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4229 | /* Ignore RSCN if the port is being torn down. */ |
| 4230 | if (vport->load_flag & FC_UNLOADING) { |
| 4231 | lpfc_els_flush_rscn(vport); |
| 4232 | return 0; |
| 4233 | } |
| 4234 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4235 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4236 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4237 | |
| 4238 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4239 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4240 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 4241 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 4242 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4243 | |
| 4244 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4245 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4246 | vport->num_disc_nodes = 0; |
| 4247 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4248 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4249 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 4250 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4251 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4252 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4253 | /* Wait for NameServer query cmpl before we can |
| 4254 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4255 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4256 | } else { |
| 4257 | /* If login to NameServer does not exist, issue one */ |
| 4258 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4259 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4260 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4261 | /* Wait for NameServer login cmpl before we can |
| 4262 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4263 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4264 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4265 | if (ndlp) { |
| 4266 | ndlp = lpfc_enable_node(vport, ndlp, |
| 4267 | NLP_STE_PLOGI_ISSUE); |
| 4268 | if (!ndlp) { |
| 4269 | lpfc_els_flush_rscn(vport); |
| 4270 | return 0; |
| 4271 | } |
| 4272 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4273 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4274 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4275 | if (!ndlp) { |
| 4276 | lpfc_els_flush_rscn(vport); |
| 4277 | return 0; |
| 4278 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4279 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4280 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4281 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4282 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4283 | ndlp->nlp_type |= NLP_FABRIC; |
| 4284 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 4285 | /* Wait for NameServer login cmpl before we can |
| 4286 | * continue |
| 4287 | */ |
| 4288 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4289 | } |
| 4290 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4291 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4292 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4293 | } |
| 4294 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4295 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4296 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4297 | * @vport: pointer to a host virtual N_Port data structure. |
| 4298 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4299 | * @ndlp: pointer to a node-list data structure. |
| 4300 | * |
| 4301 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 4302 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 4303 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 4304 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 4305 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 4306 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 4307 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 4308 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 4309 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 4310 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 4311 | * higher priority (as the winning port) and will initiate PLOGI and |
| 4312 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 4313 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 4314 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 4315 | * |
| 4316 | * Return code |
| 4317 | * 0 - Successfully processed the unsolicited flogi |
| 4318 | * 1 - Failed to process the unsolicited flogi |
| 4319 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4320 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4321 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4322 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4323 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4324 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4325 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4326 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4327 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 4328 | IOCB_t *icmd = &cmdiocb->iocb; |
| 4329 | struct serv_parm *sp; |
| 4330 | LPFC_MBOXQ_t *mbox; |
| 4331 | struct ls_rjt stat; |
| 4332 | uint32_t cmd, did; |
| 4333 | int rc; |
| 4334 | |
| 4335 | cmd = *lp++; |
| 4336 | sp = (struct serv_parm *) lp; |
| 4337 | |
| 4338 | /* FLOGI received */ |
| 4339 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4340 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4341 | |
| 4342 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 4343 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 4344 | did = icmd->un.elsreq64.remoteID; |
| 4345 | |
| 4346 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 4347 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4348 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4349 | "0113 An FLOGI ELS command x%x was " |
| 4350 | "received from DID x%x in Loop Mode\n", |
| 4351 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4352 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4353 | } |
| 4354 | |
| 4355 | did = Fabric_DID; |
| 4356 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4357 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4358 | /* For a FLOGI we accept, then if our portname is greater |
| 4359 | * then the remote portname we initiate Nport login. |
| 4360 | */ |
| 4361 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4362 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4363 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4364 | |
| 4365 | if (!rc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4366 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4367 | if (!mbox) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4368 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4369 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4370 | lpfc_linkdown(phba); |
| 4371 | lpfc_init_link(phba, mbox, |
| 4372 | phba->cfg_topology, |
| 4373 | phba->cfg_link_speed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4374 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4375 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4376 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4377 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4378 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4379 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4380 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4381 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4382 | return 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4383 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4384 | spin_lock_irq(shost->host_lock); |
| 4385 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 4386 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4387 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4388 | spin_lock_irq(shost->host_lock); |
| 4389 | vport->fc_flag |= FC_PT2PT; |
| 4390 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 4391 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4392 | } else { |
| 4393 | /* Reject this request because invalid parameters */ |
| 4394 | stat.un.b.lsRjtRsvd0 = 0; |
| 4395 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4396 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 4397 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4398 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4399 | NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4400 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4401 | } |
| 4402 | |
| 4403 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4404 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4405 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4406 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4407 | } |
| 4408 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4409 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4410 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4411 | * @vport: pointer to a host virtual N_Port data structure. |
| 4412 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4413 | * @ndlp: pointer to a node-list data structure. |
| 4414 | * |
| 4415 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 4416 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 4417 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 4418 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 4419 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 4420 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 4421 | * |
| 4422 | * Return code |
| 4423 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 4424 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4425 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4426 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4427 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4428 | { |
| 4429 | struct lpfc_dmabuf *pcmd; |
| 4430 | uint32_t *lp; |
| 4431 | IOCB_t *icmd; |
| 4432 | RNID *rn; |
| 4433 | struct ls_rjt stat; |
| 4434 | uint32_t cmd, did; |
| 4435 | |
| 4436 | icmd = &cmdiocb->iocb; |
| 4437 | did = icmd->un.elsreq64.remoteID; |
| 4438 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4439 | lp = (uint32_t *) pcmd->virt; |
| 4440 | |
| 4441 | cmd = *lp++; |
| 4442 | rn = (RNID *) lp; |
| 4443 | |
| 4444 | /* RNID received */ |
| 4445 | |
| 4446 | switch (rn->Format) { |
| 4447 | case 0: |
| 4448 | case RNID_TOPOLOGY_DISC: |
| 4449 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4450 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4451 | break; |
| 4452 | default: |
| 4453 | /* Reject this request because format not supported */ |
| 4454 | stat.un.b.lsRjtRsvd0 = 0; |
| 4455 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4456 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4457 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4458 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4459 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4460 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4461 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4462 | } |
| 4463 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4464 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4465 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4466 | * @vport: pointer to a host virtual N_Port data structure. |
| 4467 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4468 | * @ndlp: pointer to a node-list data structure. |
| 4469 | * |
| 4470 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 4471 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 4472 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 4473 | * |
| 4474 | * Return code |
| 4475 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 4476 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4477 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4478 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4479 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4480 | { |
| 4481 | struct ls_rjt stat; |
| 4482 | |
| 4483 | /* For now, unconditionally reject this command */ |
| 4484 | stat.un.b.lsRjtRsvd0 = 0; |
| 4485 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4486 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4487 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4488 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4489 | return 0; |
| 4490 | } |
| 4491 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4492 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4493 | * 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] | 4494 | * @phba: pointer to lpfc hba data structure. |
| 4495 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4496 | * |
| 4497 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 4498 | * mailbox command. This callback function is to actually send the Accept |
| 4499 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 4500 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 4501 | * mailbox command, constructs the RPS response with the link statistics |
| 4502 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 4503 | * response to the RPS. |
| 4504 | * |
| 4505 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4506 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4507 | * will be stored into the context1 field of the IOCB for the completion |
| 4508 | * callback function to the RPS Accept Response ELS IOCB command. |
| 4509 | * |
| 4510 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4511 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4512 | 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] | 4513 | { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4514 | MAILBOX_t *mb; |
| 4515 | IOCB_t *icmd; |
| 4516 | RPS_RSP *rps_rsp; |
| 4517 | uint8_t *pcmd; |
| 4518 | struct lpfc_iocbq *elsiocb; |
| 4519 | struct lpfc_nodelist *ndlp; |
| 4520 | uint16_t xri, status; |
| 4521 | uint32_t cmdsize; |
| 4522 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4523 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4524 | |
| 4525 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4526 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 4527 | pmb->context1 = NULL; |
| 4528 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4529 | |
| 4530 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4531 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4532 | return; |
| 4533 | } |
| 4534 | |
| 4535 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4536 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4537 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 4538 | lpfc_max_els_tries, ndlp, |
| 4539 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4540 | |
| 4541 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4542 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4543 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4544 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4545 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4546 | |
| 4547 | icmd = &elsiocb->iocb; |
| 4548 | icmd->ulpContext = xri; |
| 4549 | |
| 4550 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4551 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4552 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4553 | rps_rsp = (RPS_RSP *)pcmd; |
| 4554 | |
| 4555 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| 4556 | status = 0x10; |
| 4557 | else |
| 4558 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4559 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4560 | status |= 0x4; |
| 4561 | |
| 4562 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4563 | rps_rsp->portStatus = cpu_to_be16(status); |
| 4564 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 4565 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 4566 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 4567 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 4568 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 4569 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4570 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4571 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 4572 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 4573 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4574 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4575 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4576 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4577 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4578 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4579 | 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] | 4580 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4581 | return; |
| 4582 | } |
| 4583 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4584 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4585 | * lpfc_els_rcv_rps - Process an unsolicited rps iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4586 | * @vport: pointer to a host virtual N_Port data structure. |
| 4587 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4588 | * @ndlp: pointer to a node-list data structure. |
| 4589 | * |
| 4590 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 4591 | * ELS unsolicited event. It first checks the remote port state. If the |
| 4592 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 4593 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 4594 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 4595 | * for reading the HBA link statistics. It is for the callback function, |
| 4596 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 4597 | * to actually sending out RPS Accept (ACC) response. |
| 4598 | * |
| 4599 | * Return codes |
| 4600 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 4601 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4602 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4603 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4604 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4605 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4606 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4607 | uint32_t *lp; |
| 4608 | uint8_t flag; |
| 4609 | LPFC_MBOXQ_t *mbox; |
| 4610 | struct lpfc_dmabuf *pcmd; |
| 4611 | RPS *rps; |
| 4612 | struct ls_rjt stat; |
| 4613 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4614 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4615 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 4616 | /* reject the unsolicited RPS request and done with it */ |
| 4617 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4618 | |
| 4619 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4620 | lp = (uint32_t *) pcmd->virt; |
| 4621 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 4622 | rps = (RPS *) lp; |
| 4623 | |
| 4624 | if ((flag == 0) || |
| 4625 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4626 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4627 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4628 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4629 | printk("Fix me....\n"); |
| 4630 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4631 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 4632 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4633 | lpfc_read_lnk_stat(phba, mbox); |
| 4634 | mbox->context1 = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4635 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4636 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4637 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4638 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4639 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4640 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4641 | /* Mbox completion will send ELS Response */ |
| 4642 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4643 | /* Decrement reference count used for the failed mbox |
| 4644 | * command. |
| 4645 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4646 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4647 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4648 | } |
| 4649 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4650 | |
| 4651 | reject_out: |
| 4652 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4653 | stat.un.b.lsRjtRsvd0 = 0; |
| 4654 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4655 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4656 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4657 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4658 | return 0; |
| 4659 | } |
| 4660 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4661 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4662 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4663 | * @vport: pointer to a host virtual N_Port data structure. |
| 4664 | * @cmdsize: size of the ELS command. |
| 4665 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4666 | * @ndlp: pointer to a node-list data structure. |
| 4667 | * |
| 4668 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 4669 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 4670 | * |
| 4671 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4672 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4673 | * will be stored into the context1 field of the IOCB for the completion |
| 4674 | * callback function to the RPL Accept Response ELS command. |
| 4675 | * |
| 4676 | * Return code |
| 4677 | * 0 - Successfully issued ACC RPL ELS command |
| 4678 | * 1 - Failed to issue ACC RPL ELS command |
| 4679 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4680 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4681 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 4682 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4683 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4684 | struct lpfc_hba *phba = vport->phba; |
| 4685 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4686 | RPL_RSP rpl_rsp; |
| 4687 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4688 | uint8_t *pcmd; |
| 4689 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4690 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4691 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4692 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4693 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4694 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4695 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4696 | icmd = &elsiocb->iocb; |
| 4697 | oldcmd = &oldiocb->iocb; |
| 4698 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 4699 | |
| 4700 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4701 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4702 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4703 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 4704 | pcmd += sizeof(uint16_t); |
| 4705 | |
| 4706 | /* Setup the RPL ACC payload */ |
| 4707 | rpl_rsp.listLen = be32_to_cpu(1); |
| 4708 | rpl_rsp.index = 0; |
| 4709 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4710 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 4711 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4712 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4713 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4714 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4715 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4716 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 4717 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 4718 | "rpi x%x\n", |
| 4719 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4720 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4721 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4722 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4723 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4724 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 4725 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4726 | lpfc_els_free_iocb(phba, elsiocb); |
| 4727 | return 1; |
| 4728 | } |
| 4729 | return 0; |
| 4730 | } |
| 4731 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4732 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4733 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4734 | * @vport: pointer to a host virtual N_Port data structure. |
| 4735 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4736 | * @ndlp: pointer to a node-list data structure. |
| 4737 | * |
| 4738 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 4739 | * unsolicited event. It first checks the remote port state. If the remote |
| 4740 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 4741 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 4742 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 4743 | * to accept the RPL. |
| 4744 | * |
| 4745 | * Return code |
| 4746 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 4747 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4748 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4749 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4750 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4751 | { |
| 4752 | struct lpfc_dmabuf *pcmd; |
| 4753 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4754 | uint32_t maxsize; |
| 4755 | uint16_t cmdsize; |
| 4756 | RPL *rpl; |
| 4757 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4758 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4759 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 4760 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4761 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4762 | stat.un.b.lsRjtRsvd0 = 0; |
| 4763 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4764 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4765 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4766 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4767 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4768 | /* rejected the unsolicited RPL request and done with it */ |
| 4769 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4770 | } |
| 4771 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4772 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4773 | lp = (uint32_t *) pcmd->virt; |
| 4774 | rpl = (RPL *) (lp + 1); |
| 4775 | |
| 4776 | maxsize = be32_to_cpu(rpl->maxsize); |
| 4777 | |
| 4778 | /* We support only one port */ |
| 4779 | if ((rpl->index == 0) && |
| 4780 | ((maxsize == 0) || |
| 4781 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 4782 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4783 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4784 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 4785 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4786 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4787 | |
| 4788 | return 0; |
| 4789 | } |
| 4790 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4791 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4792 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4793 | * @vport: pointer to a virtual N_Port data structure. |
| 4794 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4795 | * @ndlp: pointer to a node-list data structure. |
| 4796 | * |
| 4797 | * This routine processes Fibre Channel Address Resolution Protocol |
| 4798 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 4799 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 4800 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 4801 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 4802 | * remote PortName is compared against the FC PortName stored in the @vport |
| 4803 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 4804 | * compared against the FC NodeName stored in the @vport data structure. |
| 4805 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 4806 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 4807 | * invoked to send out FARP Response to the remote node. Before sending the |
| 4808 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 4809 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 4810 | * routine is invoked to log into the remote port first. |
| 4811 | * |
| 4812 | * Return code |
| 4813 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 4814 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4815 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4816 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4817 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4818 | { |
| 4819 | struct lpfc_dmabuf *pcmd; |
| 4820 | uint32_t *lp; |
| 4821 | IOCB_t *icmd; |
| 4822 | FARP *fp; |
| 4823 | uint32_t cmd, cnt, did; |
| 4824 | |
| 4825 | icmd = &cmdiocb->iocb; |
| 4826 | did = icmd->un.elsreq64.remoteID; |
| 4827 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4828 | lp = (uint32_t *) pcmd->virt; |
| 4829 | |
| 4830 | cmd = *lp++; |
| 4831 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4832 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4833 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4834 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4835 | /* We will only support match on WWPN or WWNN */ |
| 4836 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4837 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4838 | } |
| 4839 | |
| 4840 | cnt = 0; |
| 4841 | /* If this FARP command is searching for my portname */ |
| 4842 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4843 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4844 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4845 | cnt = 1; |
| 4846 | } |
| 4847 | |
| 4848 | /* If this FARP command is searching for my nodename */ |
| 4849 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4850 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4851 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4852 | cnt = 1; |
| 4853 | } |
| 4854 | |
| 4855 | if (cnt) { |
| 4856 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 4857 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 4858 | /* Log back into the node before sending the FARP. */ |
| 4859 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4860 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4861 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4862 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4863 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4864 | } |
| 4865 | |
| 4866 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4867 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 4868 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4869 | } |
| 4870 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4871 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4872 | } |
| 4873 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4874 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4875 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4876 | * @vport: pointer to a host virtual N_Port data structure. |
| 4877 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4878 | * @ndlp: pointer to a node-list data structure. |
| 4879 | * |
| 4880 | * This routine processes Fibre Channel Address Resolution Protocol |
| 4881 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 4882 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 4883 | * the FARP response request. |
| 4884 | * |
| 4885 | * Return code |
| 4886 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 4887 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4888 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4889 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4890 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4891 | { |
| 4892 | struct lpfc_dmabuf *pcmd; |
| 4893 | uint32_t *lp; |
| 4894 | IOCB_t *icmd; |
| 4895 | uint32_t cmd, did; |
| 4896 | |
| 4897 | icmd = &cmdiocb->iocb; |
| 4898 | did = icmd->un.elsreq64.remoteID; |
| 4899 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4900 | lp = (uint32_t *) pcmd->virt; |
| 4901 | |
| 4902 | cmd = *lp++; |
| 4903 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4904 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4905 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4906 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4907 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4908 | |
| 4909 | return 0; |
| 4910 | } |
| 4911 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4912 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4913 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4914 | * @vport: pointer to a host virtual N_Port data structure. |
| 4915 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4916 | * @fan_ndlp: pointer to a node-list data structure. |
| 4917 | * |
| 4918 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 4919 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 4920 | * only be processed on a physical port (i.e., the @vport represents the |
| 4921 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 4922 | * compared against those in the phba data structure. If any of those is |
| 4923 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 4924 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 4925 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 4926 | * is invoked to register login to the fabric. |
| 4927 | * |
| 4928 | * Return code |
| 4929 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 4930 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4931 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4932 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4933 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4934 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4935 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4936 | uint32_t *lp; |
| 4937 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4938 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4939 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 4940 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 4941 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4942 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4943 | if ((vport == phba->pport) && |
| 4944 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4945 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4946 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4947 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4948 | sizeof(struct lpfc_name)))) { |
| 4949 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4950 | lpfc_initial_flogi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4951 | } else { |
| 4952 | /* FAN verified - skip FLOGI */ |
| 4953 | vport->fc_myDID = vport->fc_prevDID; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4954 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 4955 | lpfc_issue_fabric_reglogin(vport); |
| 4956 | else |
| 4957 | lpfc_issue_reg_vfi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4958 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4959 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4960 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4961 | } |
| 4962 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4963 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4964 | * lpfc_els_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4965 | * @ptr: holder for the timer function associated data. |
| 4966 | * |
| 4967 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 4968 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 4969 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 4970 | * up the worker thread. It is for the worker thread to invoke the routine |
| 4971 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 4972 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4973 | void |
| 4974 | lpfc_els_timeout(unsigned long ptr) |
| 4975 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4976 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 4977 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4978 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4979 | unsigned long iflag; |
| 4980 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4981 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4982 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
| 4983 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4984 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4985 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4986 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4987 | if (!tmo_posted) |
| 4988 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4989 | return; |
| 4990 | } |
| 4991 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4992 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4993 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4994 | * @vport: pointer to a virtual N_Port data structure. |
| 4995 | * |
| 4996 | * This routine is the actual handler function that processes an ELS timeout |
| 4997 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 4998 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 4999 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5000 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5001 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5002 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5003 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5004 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5005 | struct lpfc_sli_ring *pring; |
| 5006 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5007 | IOCB_t *cmd = NULL; |
| 5008 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5009 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5010 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5011 | uint32_t remote_ID = 0xffffffff; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5012 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5013 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5014 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 5015 | |
| 5016 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5017 | |
| 5018 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5019 | cmd = &piocb->iocb; |
| 5020 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5021 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 5022 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 5023 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5024 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5025 | |
| 5026 | if (piocb->vport != vport) |
| 5027 | continue; |
| 5028 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5029 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5030 | if (pcmd) |
| 5031 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5032 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5033 | if (els_command == ELS_CMD_FARP || |
| 5034 | els_command == ELS_CMD_FARPR || |
| 5035 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5036 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5037 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5038 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5039 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5040 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5041 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5042 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5043 | continue; |
| 5044 | } |
| 5045 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5046 | remote_ID = 0xffffffff; |
| 5047 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5048 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5049 | else { |
| 5050 | struct lpfc_nodelist *ndlp; |
| 5051 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5052 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5053 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5054 | } |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5055 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5056 | "0127 ELS timeout Data: x%x x%x x%x " |
| 5057 | "x%x\n", els_command, |
| 5058 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5059 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5060 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5061 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 5062 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5063 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
| 5064 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5065 | } |
| 5066 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5067 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5068 | * 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] | 5069 | * @vport: pointer to a host virtual N_Port data structure. |
| 5070 | * |
| 5071 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5072 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 5073 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5074 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5075 | * the IOCBs with a non-NULL completion callback function, the callback |
| 5076 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5077 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 5078 | * callback function, the IOCB will simply be released. Finally, it walks |
| 5079 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 5080 | * completion queue IOCB that is associated with the @vport and is not |
| 5081 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 5082 | * part of the discovery state machine) out to HBA by invoking the |
| 5083 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 5084 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 5085 | * the IOCBs are aborted when this function returns. |
| 5086 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5087 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5088 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5089 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5090 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5091 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5092 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5093 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5094 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5095 | |
| 5096 | lpfc_fabric_abort_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5097 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5098 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5099 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5100 | cmd = &piocb->iocb; |
| 5101 | |
| 5102 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5103 | continue; |
| 5104 | } |
| 5105 | |
| 5106 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5107 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5108 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5109 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5110 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5111 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5112 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5113 | if (piocb->vport != vport) |
| 5114 | continue; |
| 5115 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5116 | list_move_tail(&piocb->list, &completions); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5117 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5118 | } |
| 5119 | |
| 5120 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5121 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5122 | continue; |
| 5123 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5124 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5125 | if (piocb->vport != vport) |
| 5126 | continue; |
| 5127 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5128 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5129 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5130 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5131 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5132 | /* Cancell all the IOCBs from the completions list */ |
| 5133 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5134 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5135 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5136 | return; |
| 5137 | } |
| 5138 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5139 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5140 | * 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] | 5141 | * @phba: pointer to lpfc hba data structure. |
| 5142 | * |
| 5143 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5144 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 5145 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5146 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5147 | * the IOCBs with the completion callback function associated, the callback |
| 5148 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5149 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 5150 | * callback function associated, the IOCB will simply be released. Finally, |
| 5151 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 5152 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 5153 | * management plane IOCBs that are not part of the discovery state machine) |
| 5154 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5155 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5156 | void |
| 5157 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 5158 | { |
| 5159 | LIST_HEAD(completions); |
| 5160 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 5161 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5162 | IOCB_t *cmd = NULL; |
| 5163 | |
| 5164 | lpfc_fabric_abort_hba(phba); |
| 5165 | spin_lock_irq(&phba->hbalock); |
| 5166 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5167 | cmd = &piocb->iocb; |
| 5168 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5169 | continue; |
| 5170 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
| 5171 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5172 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5173 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5174 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| 5175 | continue; |
| 5176 | list_move_tail(&piocb->list, &completions); |
| 5177 | pring->txq_cnt--; |
| 5178 | } |
| 5179 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5180 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5181 | continue; |
| 5182 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5183 | } |
| 5184 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5185 | |
| 5186 | /* Cancel all the IOCBs from the completions list */ |
| 5187 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5188 | IOERR_SLI_ABORTED); |
| 5189 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5190 | return; |
| 5191 | } |
| 5192 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5193 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5194 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5195 | * @phba: Pointer to hba context object. |
| 5196 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 5197 | * @rspiocbp: Pointer to response iocb which reported error. |
| 5198 | * |
| 5199 | * This function sends an event when there is an ELS command |
| 5200 | * failure. |
| 5201 | **/ |
| 5202 | void |
| 5203 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 5204 | struct lpfc_iocbq *cmdiocbp, |
| 5205 | struct lpfc_iocbq *rspiocbp) |
| 5206 | { |
| 5207 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 5208 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5209 | struct lpfc_lsrjt_event lsrjt_event; |
| 5210 | struct lpfc_fabric_event_header fabric_event; |
| 5211 | struct ls_rjt stat; |
| 5212 | struct lpfc_nodelist *ndlp; |
| 5213 | uint32_t *pcmd; |
| 5214 | |
| 5215 | ndlp = cmdiocbp->context1; |
| 5216 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 5217 | return; |
| 5218 | |
| 5219 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 5220 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 5221 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 5222 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 5223 | sizeof(struct lpfc_name)); |
| 5224 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 5225 | sizeof(struct lpfc_name)); |
| 5226 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 5227 | cmdiocbp->context2)->virt); |
| 5228 | lsrjt_event.command = *pcmd; |
| 5229 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 5230 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 5231 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 5232 | fc_host_post_vendor_event(shost, |
| 5233 | fc_get_event_number(), |
| 5234 | sizeof(lsrjt_event), |
| 5235 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5236 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5237 | return; |
| 5238 | } |
| 5239 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 5240 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 5241 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 5242 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 5243 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 5244 | else |
| 5245 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 5246 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 5247 | sizeof(struct lpfc_name)); |
| 5248 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 5249 | sizeof(struct lpfc_name)); |
| 5250 | fc_host_post_vendor_event(shost, |
| 5251 | fc_get_event_number(), |
| 5252 | sizeof(fabric_event), |
| 5253 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5254 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5255 | return; |
| 5256 | } |
| 5257 | |
| 5258 | } |
| 5259 | |
| 5260 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5261 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5262 | * @vport: Pointer to vport object. |
| 5263 | * @ndlp: Pointer FC node object. |
| 5264 | * @cmd: ELS command code. |
| 5265 | * |
| 5266 | * This function posts an event when there is an incoming |
| 5267 | * unsolicited ELS command. |
| 5268 | **/ |
| 5269 | static void |
| 5270 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 5271 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5272 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5273 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5274 | struct lpfc_els_event_header *els_data = NULL; |
| 5275 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5276 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5277 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5278 | if (*payload == ELS_CMD_LOGO) { |
| 5279 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 5280 | if (!logo_data) { |
| 5281 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5282 | "0148 Failed to allocate memory " |
| 5283 | "for LOGO event\n"); |
| 5284 | return; |
| 5285 | } |
| 5286 | els_data = &logo_data->header; |
| 5287 | } else { |
| 5288 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 5289 | GFP_KERNEL); |
| 5290 | if (!els_data) { |
| 5291 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5292 | "0149 Failed to allocate memory " |
| 5293 | "for ELS event\n"); |
| 5294 | return; |
| 5295 | } |
| 5296 | } |
| 5297 | els_data->event_type = FC_REG_ELS_EVENT; |
| 5298 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5299 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5300 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5301 | break; |
| 5302 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5303 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5304 | break; |
| 5305 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5306 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 5307 | break; |
| 5308 | case ELS_CMD_LOGO: |
| 5309 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 5310 | /* Copy the WWPN in the LOGO payload */ |
| 5311 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 5312 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5313 | break; |
| 5314 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 5315 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5316 | return; |
| 5317 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5318 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 5319 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 5320 | if (*payload == ELS_CMD_LOGO) { |
| 5321 | fc_host_post_vendor_event(shost, |
| 5322 | fc_get_event_number(), |
| 5323 | sizeof(struct lpfc_logo_event), |
| 5324 | (char *)logo_data, |
| 5325 | LPFC_NL_VENDOR_ID); |
| 5326 | kfree(logo_data); |
| 5327 | } else { |
| 5328 | fc_host_post_vendor_event(shost, |
| 5329 | fc_get_event_number(), |
| 5330 | sizeof(struct lpfc_els_event_header), |
| 5331 | (char *)els_data, |
| 5332 | LPFC_NL_VENDOR_ID); |
| 5333 | kfree(els_data); |
| 5334 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5335 | |
| 5336 | return; |
| 5337 | } |
| 5338 | |
| 5339 | |
| 5340 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5341 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5342 | * @phba: pointer to lpfc hba data structure. |
| 5343 | * @pring: pointer to a SLI ring. |
| 5344 | * @vport: pointer to a host virtual N_Port data structure. |
| 5345 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 5346 | * |
| 5347 | * This routine is used for processing the IOCB associated with a unsolicited |
| 5348 | * event. It first determines whether there is an existing ndlp that matches |
| 5349 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 5350 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 5351 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 5352 | * of the discovery state machine. |
| 5353 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5354 | static void |
| 5355 | 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] | 5356 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5357 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5358 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5359 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5360 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5361 | uint32_t *payload; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5362 | uint32_t cmd, did, newnode, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5363 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5364 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5365 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5366 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5367 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5368 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5369 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 5370 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5371 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5372 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5373 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5374 | did = icmd->un.rcvels.remoteID; |
| 5375 | if (icmd->ulpStatus) { |
| 5376 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5377 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 5378 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5379 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5380 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5381 | |
| 5382 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5383 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5384 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5385 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5386 | /* Ignore traffic recevied during vport shutdown. */ |
| 5387 | if (vport->load_flag & FC_UNLOADING) |
| 5388 | goto dropit; |
| 5389 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5390 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5391 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5392 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5393 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5394 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5395 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5396 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5397 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5398 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5399 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5400 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5401 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5402 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5403 | ndlp = lpfc_enable_node(vport, ndlp, |
| 5404 | NLP_STE_UNUSED_NODE); |
| 5405 | if (!ndlp) |
| 5406 | goto dropit; |
| 5407 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5408 | newnode = 1; |
| 5409 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 5410 | ndlp->nlp_type |= NLP_FABRIC; |
| 5411 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 5412 | /* This is similar to the new node path */ |
| 5413 | ndlp = lpfc_nlp_get(ndlp); |
| 5414 | if (!ndlp) |
| 5415 | goto dropit; |
| 5416 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5417 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5418 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5419 | |
| 5420 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5421 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5422 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5423 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5424 | |
| 5425 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 5426 | cmd &= ELS_CMD_MASK; |
| 5427 | } |
| 5428 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5429 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5430 | "0112 ELS command x%x received from NPORT x%x " |
| 5431 | "Data: x%x\n", cmd, did, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5432 | switch (cmd) { |
| 5433 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5434 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5435 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 5436 | did, vport->port_state, ndlp->nlp_flag); |
| 5437 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5438 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5439 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
| 5440 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5441 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5442 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5443 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 5444 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 5445 | rjt_err = LSRJT_UNABLE_TPC; |
| 5446 | break; |
| 5447 | } |
| 5448 | /* We get here, and drop thru, if we are PT2PT with |
| 5449 | * another NPort and the other side has initiated |
| 5450 | * the PLOGI before responding to our FLOGI. |
| 5451 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5452 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5453 | |
| 5454 | shost = lpfc_shost_from_vport(vport); |
| 5455 | spin_lock_irq(shost->host_lock); |
| 5456 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 5457 | spin_unlock_irq(shost->host_lock); |
| 5458 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5459 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5460 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5461 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5462 | break; |
| 5463 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5464 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5465 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 5466 | did, vport->port_state, ndlp->nlp_flag); |
| 5467 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5468 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5469 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5470 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5471 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5472 | break; |
| 5473 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5474 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5475 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 5476 | did, vport->port_state, ndlp->nlp_flag); |
| 5477 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5478 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5479 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5480 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5481 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5482 | break; |
| 5483 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5484 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5485 | break; |
| 5486 | case ELS_CMD_PRLO: |
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 PRLO: 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.elsRcvPRLO++; |
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_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5498 | break; |
| 5499 | case ELS_CMD_RSCN: |
| 5500 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5501 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5502 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5503 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5504 | break; |
| 5505 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5506 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5507 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 5508 | did, vport->port_state, ndlp->nlp_flag); |
| 5509 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5510 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5511 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5512 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5513 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5514 | break; |
| 5515 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5516 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5517 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5518 | break; |
| 5519 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5520 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5521 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 5522 | did, vport->port_state, ndlp->nlp_flag); |
| 5523 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5524 | phba->fc_stat.elsRcvPDISC++; |
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_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5531 | break; |
| 5532 | case ELS_CMD_FARPR: |
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 FARPR: 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.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5538 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5539 | break; |
| 5540 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5541 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5542 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 5543 | did, vport->port_state, ndlp->nlp_flag); |
| 5544 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5545 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5546 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5547 | break; |
| 5548 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5549 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5550 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 5551 | did, vport->port_state, ndlp->nlp_flag); |
| 5552 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5553 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5554 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5555 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5556 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5557 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5558 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 5559 | did, vport->port_state, ndlp->nlp_flag); |
| 5560 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5561 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5562 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5563 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5564 | break; |
| 5565 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5566 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5567 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5568 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5569 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5570 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 5571 | did, vport->port_state, ndlp->nlp_flag); |
| 5572 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5573 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5574 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5575 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5576 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5577 | break; |
| 5578 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5579 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5580 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 5581 | did, vport->port_state, ndlp->nlp_flag); |
| 5582 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5583 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5584 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5585 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5586 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5587 | break; |
| 5588 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5589 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5590 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 5591 | did, vport->port_state, ndlp->nlp_flag); |
| 5592 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5593 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5594 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5595 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5596 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5597 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5598 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5599 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5600 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 5601 | did, vport->port_state, ndlp->nlp_flag); |
| 5602 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5603 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5604 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5605 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5606 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5607 | break; |
| 5608 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5609 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5610 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 5611 | cmd, did, vport->port_state); |
| 5612 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5613 | /* Unsupported ELS command, reject */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5614 | rjt_err = LSRJT_INVALID_CMD; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5615 | |
| 5616 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5617 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5618 | "0115 Unknown ELS command x%x " |
| 5619 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5620 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5621 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5622 | break; |
| 5623 | } |
| 5624 | |
| 5625 | /* check if need to LS_RJT received ELS cmd */ |
| 5626 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5627 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5628 | stat.un.b.lsRjtRsnCode = rjt_err; |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 5629 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5630 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 5631 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5632 | } |
| 5633 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5634 | lpfc_nlp_put(elsiocb->context1); |
| 5635 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5636 | return; |
| 5637 | |
| 5638 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5639 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5640 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5641 | "0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5642 | "Data: x%x x%x x%x\n", |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5643 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5644 | phba->fc_stat.elsRcvDrop++; |
| 5645 | } |
| 5646 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5647 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5648 | * 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] | 5649 | * @phba: pointer to lpfc hba data structure. |
| 5650 | * @vpi: host virtual N_Port identifier. |
| 5651 | * |
| 5652 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 5653 | * @vpi. The function walks the HBA's vport list and returns the address |
| 5654 | * of the vport with the matching @vpi. |
| 5655 | * |
| 5656 | * Return code |
| 5657 | * NULL - No vport with the matching @vpi found |
| 5658 | * Otherwise - Address to the vport with the matching @vpi. |
| 5659 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5660 | static struct lpfc_vport * |
| 5661 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 5662 | { |
| 5663 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5664 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5665 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5666 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5667 | list_for_each_entry(vport, &phba->port_list, listentry) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5668 | if (vport->vpi == vpi) { |
| 5669 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5670 | return vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5671 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5672 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5673 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5674 | return NULL; |
| 5675 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5676 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5677 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5678 | * 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] | 5679 | * @phba: pointer to lpfc hba data structure. |
| 5680 | * @pring: pointer to a SLI ring. |
| 5681 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 5682 | * |
| 5683 | * This routine is used to process an unsolicited event received from a SLI |
| 5684 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 5685 | * associated with the unsolicited event is done by invoking the routine |
| 5686 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 5687 | * SLI ring on which the unsolicited event was received. |
| 5688 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5689 | void |
| 5690 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 5691 | struct lpfc_iocbq *elsiocb) |
| 5692 | { |
| 5693 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5694 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5695 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5696 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 5697 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5698 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5699 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5700 | elsiocb->context2 = NULL; |
| 5701 | elsiocb->context3 = NULL; |
| 5702 | |
| 5703 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 5704 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 5705 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 5706 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5707 | phba->fc_stat.NoRcvBuf++; |
| 5708 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5709 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5710 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5711 | return; |
| 5712 | } |
| 5713 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5714 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 5715 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 5716 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 5717 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 5718 | vport = phba->pport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5719 | else |
| 5720 | vport = lpfc_find_vport_by_vpid(phba, |
| 5721 | icmd->unsli3.rcvsli3.vpi - phba->vpi_base); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5722 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5723 | /* If there are no BDEs associated |
| 5724 | * with this IOCB, there is nothing to do. |
| 5725 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5726 | if (icmd->ulpBdeCount == 0) |
| 5727 | return; |
| 5728 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5729 | /* type of ELS cmd is first 32bit word |
| 5730 | * in packet |
| 5731 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5732 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5733 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5734 | } else { |
| 5735 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 5736 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5737 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 5738 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5739 | } |
| 5740 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5741 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 5742 | /* |
| 5743 | * The different unsolicited event handlers would tell us |
| 5744 | * if they are done with "mp" by setting context2 to NULL. |
| 5745 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5746 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5747 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 5748 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5749 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5750 | |
| 5751 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5752 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5753 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5754 | elsiocb->context2 = bdeBuf2; |
| 5755 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5756 | /* free mp if we are done with it */ |
| 5757 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5758 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 5759 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5760 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5761 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5762 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5763 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5764 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5765 | * 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] | 5766 | * @phba: pointer to lpfc hba data structure. |
| 5767 | * @vport: pointer to a virtual N_Port data structure. |
| 5768 | * |
| 5769 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 5770 | * State Change Request (SCR) for a @vport. This routine will create an |
| 5771 | * ndlp for the Name Server associated to the @vport if such node does |
| 5772 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 5773 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 5774 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 5775 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 5776 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5777 | void |
| 5778 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 5779 | { |
| 5780 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
| 5781 | |
| 5782 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 5783 | if (!ndlp) { |
| 5784 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 5785 | if (!ndlp) { |
| 5786 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5787 | lpfc_disc_start(vport); |
| 5788 | return; |
| 5789 | } |
| 5790 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5791 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5792 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5793 | return; |
| 5794 | } |
| 5795 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5796 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5797 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 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); |
| 5804 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5805 | "0348 NameServer login: node freed\n"); |
| 5806 | return; |
| 5807 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5808 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5809 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5810 | |
| 5811 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 5812 | |
| 5813 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 5814 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5815 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5816 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5817 | return; |
| 5818 | } |
| 5819 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5820 | if (vport->cfg_fdmi_on) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5821 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 5822 | GFP_KERNEL); |
| 5823 | if (ndlp_fdmi) { |
| 5824 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 5825 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5826 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
| 5827 | NLP_STE_PLOGI_ISSUE); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5828 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, |
| 5829 | 0); |
| 5830 | } |
| 5831 | } |
| 5832 | return; |
| 5833 | } |
| 5834 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5835 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5836 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5837 | * @phba: pointer to lpfc hba data structure. |
| 5838 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 5839 | * |
| 5840 | * This routine is the completion callback function to register new vport |
| 5841 | * mailbox command. If the new vport mailbox command completes successfully, |
| 5842 | * the fabric registration login shall be performed on physical port (the |
| 5843 | * new vport created is actually a physical port, with VPI 0) or the port |
| 5844 | * login to Name Server for State Change Request (SCR) will be performed |
| 5845 | * on virtual port (real virtual port, with VPI greater than 0). |
| 5846 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5847 | static void |
| 5848 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 5849 | { |
| 5850 | struct lpfc_vport *vport = pmb->vport; |
| 5851 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5852 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5853 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5854 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5855 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5856 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5857 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5858 | |
| 5859 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5860 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 5861 | "0915 Register VPI failed: 0x%x\n", |
| 5862 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5863 | |
| 5864 | switch (mb->mbxStatus) { |
| 5865 | case 0x11: /* unsupported feature */ |
| 5866 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5867 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5868 | /* giving up on vport registration */ |
| 5869 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5870 | spin_lock_irq(shost->host_lock); |
| 5871 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 5872 | spin_unlock_irq(shost->host_lock); |
| 5873 | lpfc_can_disctmo(vport); |
| 5874 | break; |
| 5875 | default: |
| 5876 | /* Try to recover from this error */ |
| 5877 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5878 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5879 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5880 | spin_unlock_irq(shost->host_lock); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5881 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 5882 | lpfc_initial_flogi(vport); |
| 5883 | else |
| 5884 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5885 | break; |
| 5886 | } |
| 5887 | |
| 5888 | } else { |
| 5889 | if (vport == phba->pport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5890 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 5891 | lpfc_issue_fabric_reglogin(vport); |
| 5892 | else |
| 5893 | lpfc_issue_reg_vfi(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5894 | else |
| 5895 | lpfc_do_scr_ns_plogi(phba, vport); |
| 5896 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5897 | |
| 5898 | /* Now, we decrement the ndlp reference count held for this |
| 5899 | * callback function |
| 5900 | */ |
| 5901 | lpfc_nlp_put(ndlp); |
| 5902 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5903 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5904 | return; |
| 5905 | } |
| 5906 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5907 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5908 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5909 | * @phba: pointer to lpfc hba data structure. |
| 5910 | * @vport: pointer to a host virtual N_Port data structure. |
| 5911 | * @ndlp: pointer to a node-list data structure. |
| 5912 | * |
| 5913 | * This routine registers the @vport as a new virtual port with a HBA. |
| 5914 | * It is done through a registering vpi mailbox command. |
| 5915 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5916 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5917 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 5918 | struct lpfc_nodelist *ndlp) |
| 5919 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5920 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5921 | LPFC_MBOXQ_t *mbox; |
| 5922 | |
| 5923 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5924 | if (mbox) { |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5925 | lpfc_reg_vpi(vport, mbox); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5926 | mbox->vport = vport; |
| 5927 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 5928 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5929 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5930 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5931 | /* mailbox command not success, decrement ndlp |
| 5932 | * reference count for this command |
| 5933 | */ |
| 5934 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5935 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5936 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5937 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 5938 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5939 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5940 | } |
| 5941 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5942 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 5943 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5944 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5945 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5946 | return; |
| 5947 | |
| 5948 | mbox_err_exit: |
| 5949 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5950 | spin_lock_irq(shost->host_lock); |
| 5951 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 5952 | spin_unlock_irq(shost->host_lock); |
| 5953 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5954 | } |
| 5955 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5956 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5957 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5958 | * @phba: pointer to lpfc hba data structure. |
| 5959 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5960 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 5961 | * |
| 5962 | * This routine is the completion callback function to a Fabric Discover |
| 5963 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 5964 | * single threaded, each FDISC completion callback function will reset |
| 5965 | * the discovery timer for all vports such that the timers will not get |
| 5966 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 5967 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 5968 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 5969 | * assigned to the vport has been changed with the completion of the FDISC |
| 5970 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 5971 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 5972 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 5973 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 5974 | * Server for State Change Request (SCR). |
| 5975 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5976 | static void |
| 5977 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 5978 | struct lpfc_iocbq *rspiocb) |
| 5979 | { |
| 5980 | struct lpfc_vport *vport = cmdiocb->vport; |
| 5981 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5982 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 5983 | struct lpfc_nodelist *np; |
| 5984 | struct lpfc_nodelist *next_np; |
| 5985 | IOCB_t *irsp = &rspiocb->iocb; |
| 5986 | struct lpfc_iocbq *piocb; |
| 5987 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5988 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5989 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 5990 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 5991 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5992 | /* Since all FDISCs are being single threaded, we |
| 5993 | * must reset the discovery timer for ALL vports |
| 5994 | * waiting to send FDISC when one completes. |
| 5995 | */ |
| 5996 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 5997 | lpfc_set_disctmo(piocb->vport); |
| 5998 | } |
| 5999 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6000 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6001 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 6002 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 6003 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6004 | if (irsp->ulpStatus) { |
| 6005 | /* Check for retry */ |
| 6006 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 6007 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6008 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6009 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6010 | "0126 FDISC failed. (%d/%d)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6011 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6012 | goto fdisc_failed; |
| 6013 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6014 | if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING) |
| 6015 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6016 | lpfc_nlp_put(ndlp); |
| 6017 | /* giving up on FDISC. Cancel discovery timer */ |
| 6018 | lpfc_can_disctmo(vport); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6019 | spin_lock_irq(shost->host_lock); |
| 6020 | vport->fc_flag |= FC_FABRIC; |
| 6021 | if (vport->phba->fc_topology == TOPOLOGY_LOOP) |
| 6022 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 6023 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6024 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6025 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 6026 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
| 6027 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 6028 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 6029 | /* If our NportID changed, we need to ensure all |
| 6030 | * remaining NPORTs get unreg_login'ed so we can |
| 6031 | * issue unreg_vpi. |
| 6032 | */ |
| 6033 | list_for_each_entry_safe(np, next_np, |
| 6034 | &vport->fc_nodes, nlp_listp) { |
| 6035 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 6036 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 6037 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 6038 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6039 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6040 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6041 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6042 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6043 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6044 | lpfc_mbx_unreg_vpi(vport); |
| 6045 | spin_lock_irq(shost->host_lock); |
| 6046 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 6047 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6048 | } |
| 6049 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6050 | if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 6051 | lpfc_register_new_vport(phba, vport, ndlp); |
| 6052 | else |
| 6053 | lpfc_do_scr_ns_plogi(phba, vport); |
| 6054 | goto out; |
| 6055 | fdisc_failed: |
| 6056 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6057 | /* Cancel discovery timer */ |
| 6058 | lpfc_can_disctmo(vport); |
| 6059 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6060 | out: |
| 6061 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6062 | } |
| 6063 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6064 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6065 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6066 | * @vport: pointer to a virtual N_Port data structure. |
| 6067 | * @ndlp: pointer to a node-list data structure. |
| 6068 | * @retry: number of retries to the command IOCB. |
| 6069 | * |
| 6070 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 6071 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 6072 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 6073 | * IOCB will be sent off HBA at any given time. |
| 6074 | * |
| 6075 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6076 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6077 | * will be stored into the context1 field of the IOCB for the completion |
| 6078 | * callback function to the FDISC ELS command. |
| 6079 | * |
| 6080 | * Return code |
| 6081 | * 0 - Successfully issued fdisc iocb command |
| 6082 | * 1 - Failed to issue fdisc iocb command |
| 6083 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6084 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6085 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 6086 | uint8_t retry) |
| 6087 | { |
| 6088 | struct lpfc_hba *phba = vport->phba; |
| 6089 | IOCB_t *icmd; |
| 6090 | struct lpfc_iocbq *elsiocb; |
| 6091 | struct serv_parm *sp; |
| 6092 | uint8_t *pcmd; |
| 6093 | uint16_t cmdsize; |
| 6094 | int did = ndlp->nlp_DID; |
| 6095 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6096 | |
| 6097 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 6098 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 6099 | ELS_CMD_FDISC); |
| 6100 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6101 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6102 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6103 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6104 | return 1; |
| 6105 | } |
| 6106 | |
| 6107 | icmd = &elsiocb->iocb; |
| 6108 | icmd->un.elsreq64.myID = 0; |
| 6109 | icmd->un.elsreq64.fl = 1; |
| 6110 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame^] | 6111 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 6112 | /* FDISC needs to be 1 for WQE VPI */ |
| 6113 | elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1; |
| 6114 | elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ; |
| 6115 | /* Set the ulpContext to the vpi */ |
| 6116 | elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base; |
| 6117 | } else { |
| 6118 | /* For FDISC, Let FDISC rsp set the NPortID for this VPI */ |
| 6119 | icmd->ulpCt_h = 1; |
| 6120 | icmd->ulpCt_l = 0; |
| 6121 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6122 | |
| 6123 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6124 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 6125 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 6126 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 6127 | sp = (struct serv_parm *) pcmd; |
| 6128 | /* Setup CSPs accordingly for Fabric */ |
| 6129 | sp->cmn.e_d_tov = 0; |
| 6130 | sp->cmn.w2.r_a_tov = 0; |
| 6131 | sp->cls1.classValid = 0; |
| 6132 | sp->cls2.seqDelivery = 1; |
| 6133 | sp->cls3.seqDelivery = 1; |
| 6134 | |
| 6135 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 6136 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 6137 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 6138 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 6139 | memcpy(pcmd, &vport->fc_portname, 8); |
| 6140 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6141 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6142 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 6143 | |
| 6144 | lpfc_set_disctmo(vport); |
| 6145 | |
| 6146 | phba->fc_stat.elsXmitFDISC++; |
| 6147 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 6148 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6149 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6150 | "Issue FDISC: did:x%x", |
| 6151 | did, 0, 0); |
| 6152 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6153 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 6154 | if (rc == IOCB_ERROR) { |
| 6155 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6156 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6157 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6158 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6159 | return 1; |
| 6160 | } |
| 6161 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
| 6162 | vport->port_state = LPFC_FDISC; |
| 6163 | return 0; |
| 6164 | } |
| 6165 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6166 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6167 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6168 | * @phba: pointer to lpfc hba data structure. |
| 6169 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6170 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6171 | * |
| 6172 | * This routine is the completion callback function to the issuing of a LOGO |
| 6173 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 6174 | * reference count held on ndlp for this completion function, indicating that |
| 6175 | * the reference to the ndlp is no long needed. Note that the |
| 6176 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 6177 | * callback function and an additional explicit ndlp reference decrementation |
| 6178 | * will trigger the actual release of the ndlp. |
| 6179 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6180 | static void |
| 6181 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6182 | struct lpfc_iocbq *rspiocb) |
| 6183 | { |
| 6184 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6185 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6186 | struct lpfc_nodelist *ndlp; |
| 6187 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6188 | |
| 6189 | irsp = &rspiocb->iocb; |
| 6190 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6191 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 6192 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6193 | |
| 6194 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6195 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6196 | |
| 6197 | /* Trigger the release of the ndlp after logo */ |
| 6198 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6199 | } |
| 6200 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6201 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6202 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6203 | * @vport: pointer to a virtual N_Port data structure. |
| 6204 | * @ndlp: pointer to a node-list data structure. |
| 6205 | * |
| 6206 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 6207 | * |
| 6208 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6209 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6210 | * will be stored into the context1 field of the IOCB for the completion |
| 6211 | * callback function to the LOGO ELS command. |
| 6212 | * |
| 6213 | * Return codes |
| 6214 | * 0 - Successfully issued logo off the @vport |
| 6215 | * 1 - Failed to issue logo off the @vport |
| 6216 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6217 | int |
| 6218 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 6219 | { |
| 6220 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6221 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6222 | IOCB_t *icmd; |
| 6223 | struct lpfc_iocbq *elsiocb; |
| 6224 | uint8_t *pcmd; |
| 6225 | uint16_t cmdsize; |
| 6226 | |
| 6227 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 6228 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 6229 | ELS_CMD_LOGO); |
| 6230 | if (!elsiocb) |
| 6231 | return 1; |
| 6232 | |
| 6233 | icmd = &elsiocb->iocb; |
| 6234 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6235 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 6236 | pcmd += sizeof(uint32_t); |
| 6237 | |
| 6238 | /* Fill in LOGO payload */ |
| 6239 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 6240 | pcmd += sizeof(uint32_t); |
| 6241 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 6242 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6243 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6244 | "Issue LOGO npiv did:x%x flg:x%x", |
| 6245 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 6246 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6247 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 6248 | spin_lock_irq(shost->host_lock); |
| 6249 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 6250 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6251 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 6252 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6253 | spin_lock_irq(shost->host_lock); |
| 6254 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 6255 | spin_unlock_irq(shost->host_lock); |
| 6256 | lpfc_els_free_iocb(phba, elsiocb); |
| 6257 | return 1; |
| 6258 | } |
| 6259 | return 0; |
| 6260 | } |
| 6261 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6262 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6263 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6264 | * @ptr: holder for the timer function associated data. |
| 6265 | * |
| 6266 | * This routine is invoked by the fabric iocb block timer after |
| 6267 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 6268 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 6269 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 6270 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 6271 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 6272 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6273 | void |
| 6274 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 6275 | { |
| 6276 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 6277 | unsigned long iflags; |
| 6278 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6279 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6280 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 6281 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 6282 | if (!tmo_posted) |
| 6283 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 6284 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 6285 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6286 | if (!tmo_posted) |
| 6287 | lpfc_worker_wake_up(phba); |
| 6288 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6289 | } |
| 6290 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6291 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6292 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6293 | * @phba: pointer to lpfc hba data structure. |
| 6294 | * |
| 6295 | * This routine issues one fabric iocb from the driver internal list to |
| 6296 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 6297 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 6298 | * remove one pending fabric iocb from the driver internal list and invokes |
| 6299 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 6300 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6301 | static void |
| 6302 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 6303 | { |
| 6304 | struct lpfc_iocbq *iocb; |
| 6305 | unsigned long iflags; |
| 6306 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6307 | IOCB_t *cmd; |
| 6308 | |
| 6309 | repeat: |
| 6310 | iocb = NULL; |
| 6311 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6312 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6313 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 6314 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 6315 | list); |
| 6316 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6317 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6318 | atomic_inc(&phba->fabric_iocb_count); |
| 6319 | } |
| 6320 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6321 | if (iocb) { |
| 6322 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6323 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6324 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6325 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6326 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6327 | "Fabric sched1: ste:x%x", |
| 6328 | iocb->vport->port_state, 0, 0); |
| 6329 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6330 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6331 | |
| 6332 | if (ret == IOCB_ERROR) { |
| 6333 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6334 | iocb->fabric_iocb_cmpl = NULL; |
| 6335 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6336 | cmd = &iocb->iocb; |
| 6337 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6338 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6339 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 6340 | |
| 6341 | atomic_dec(&phba->fabric_iocb_count); |
| 6342 | goto repeat; |
| 6343 | } |
| 6344 | } |
| 6345 | |
| 6346 | return; |
| 6347 | } |
| 6348 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6349 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6350 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6351 | * @phba: pointer to lpfc hba data structure. |
| 6352 | * |
| 6353 | * This routine unblocks the issuing fabric iocb command. The function |
| 6354 | * will clear the fabric iocb block bit and then invoke the routine |
| 6355 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 6356 | * from the driver internal fabric iocb list. |
| 6357 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6358 | void |
| 6359 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 6360 | { |
| 6361 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6362 | |
| 6363 | lpfc_resume_fabric_iocbs(phba); |
| 6364 | return; |
| 6365 | } |
| 6366 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6367 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6368 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6369 | * @phba: pointer to lpfc hba data structure. |
| 6370 | * |
| 6371 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 6372 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 6373 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 6374 | * fabric iocb will be issued out of the HBA. |
| 6375 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6376 | static void |
| 6377 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 6378 | { |
| 6379 | int blocked; |
| 6380 | |
| 6381 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6382 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6383 | if (!blocked) |
| 6384 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); |
| 6385 | |
| 6386 | return; |
| 6387 | } |
| 6388 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6389 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6390 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6391 | * @phba: pointer to lpfc hba data structure. |
| 6392 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6393 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6394 | * |
| 6395 | * This routine is the callback function that is put to the fabric iocb's |
| 6396 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 6397 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 6398 | * function first restores and invokes the original iocb's callback function |
| 6399 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 6400 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 6401 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6402 | static void |
| 6403 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6404 | struct lpfc_iocbq *rspiocb) |
| 6405 | { |
| 6406 | struct ls_rjt stat; |
| 6407 | |
| 6408 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 6409 | BUG(); |
| 6410 | |
| 6411 | switch (rspiocb->iocb.ulpStatus) { |
| 6412 | case IOSTAT_NPORT_RJT: |
| 6413 | case IOSTAT_FABRIC_RJT: |
| 6414 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 6415 | lpfc_block_fabric_iocbs(phba); |
| 6416 | } |
| 6417 | break; |
| 6418 | |
| 6419 | case IOSTAT_NPORT_BSY: |
| 6420 | case IOSTAT_FABRIC_BSY: |
| 6421 | lpfc_block_fabric_iocbs(phba); |
| 6422 | break; |
| 6423 | |
| 6424 | case IOSTAT_LS_RJT: |
| 6425 | stat.un.lsRjtError = |
| 6426 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 6427 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 6428 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 6429 | lpfc_block_fabric_iocbs(phba); |
| 6430 | break; |
| 6431 | } |
| 6432 | |
| 6433 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 6434 | BUG(); |
| 6435 | |
| 6436 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 6437 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 6438 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6439 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 6440 | |
| 6441 | atomic_dec(&phba->fabric_iocb_count); |
| 6442 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6443 | /* Post any pending iocbs to HBA */ |
| 6444 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6445 | } |
| 6446 | } |
| 6447 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6448 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6449 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6450 | * @phba: pointer to lpfc hba data structure. |
| 6451 | * @iocb: pointer to lpfc command iocb data structure. |
| 6452 | * |
| 6453 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 6454 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 6455 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 6456 | * any given time. As such, this function will first check to see whether there |
| 6457 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 6458 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 6459 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 6460 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 6461 | * |
| 6462 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 6463 | * order. The problem is caused by the construction of the "ready" boolen does |
| 6464 | * not include the condition that the internal fabric IOCB list is empty. As |
| 6465 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 6466 | * ahead of the fabric IOCBs in the internal list. |
| 6467 | * |
| 6468 | * Return code |
| 6469 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 6470 | * IOCB_ERROR - failed to issue fabric iocb |
| 6471 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6472 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6473 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 6474 | { |
| 6475 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6476 | int ready; |
| 6477 | int ret; |
| 6478 | |
| 6479 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 6480 | BUG(); |
| 6481 | |
| 6482 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6483 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 6484 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6485 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6486 | if (ready) |
| 6487 | /* Increment fabric iocb count to hold the position */ |
| 6488 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6489 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6490 | if (ready) { |
| 6491 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6492 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6493 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6494 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6495 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6496 | "Fabric sched2: ste:x%x", |
| 6497 | iocb->vport->port_state, 0, 0); |
| 6498 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6499 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6500 | |
| 6501 | if (ret == IOCB_ERROR) { |
| 6502 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6503 | iocb->fabric_iocb_cmpl = NULL; |
| 6504 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6505 | atomic_dec(&phba->fabric_iocb_count); |
| 6506 | } |
| 6507 | } else { |
| 6508 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6509 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 6510 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6511 | ret = IOCB_SUCCESS; |
| 6512 | } |
| 6513 | return ret; |
| 6514 | } |
| 6515 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6516 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6517 | * 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] | 6518 | * @vport: pointer to a virtual N_Port data structure. |
| 6519 | * |
| 6520 | * This routine aborts all the IOCBs associated with a @vport from the |
| 6521 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6522 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6523 | * list, removes each IOCB associated with the @vport off the list, set the |
| 6524 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6525 | * associated with the IOCB. |
| 6526 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6527 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6528 | { |
| 6529 | LIST_HEAD(completions); |
| 6530 | struct lpfc_hba *phba = vport->phba; |
| 6531 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6532 | |
| 6533 | spin_lock_irq(&phba->hbalock); |
| 6534 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6535 | list) { |
| 6536 | |
| 6537 | if (piocb->vport != vport) |
| 6538 | continue; |
| 6539 | |
| 6540 | list_move_tail(&piocb->list, &completions); |
| 6541 | } |
| 6542 | spin_unlock_irq(&phba->hbalock); |
| 6543 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6544 | /* Cancel all the IOCBs from the completions list */ |
| 6545 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6546 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6547 | } |
| 6548 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6549 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6550 | * 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] | 6551 | * @ndlp: pointer to a node-list data structure. |
| 6552 | * |
| 6553 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 6554 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6555 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6556 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 6557 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6558 | * associated with the IOCB. |
| 6559 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6560 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 6561 | { |
| 6562 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6563 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6564 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6565 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6566 | |
| 6567 | spin_lock_irq(&phba->hbalock); |
| 6568 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6569 | list) { |
| 6570 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 6571 | |
| 6572 | list_move_tail(&piocb->list, &completions); |
| 6573 | } |
| 6574 | } |
| 6575 | spin_unlock_irq(&phba->hbalock); |
| 6576 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6577 | /* Cancel all the IOCBs from the completions list */ |
| 6578 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6579 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6580 | } |
| 6581 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6582 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6583 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6584 | * @phba: pointer to lpfc hba data structure. |
| 6585 | * |
| 6586 | * This routine aborts all the IOCBs currently on the driver internal |
| 6587 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 6588 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 6589 | * list, removes IOCBs off the list, set the status feild to |
| 6590 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 6591 | * the IOCB. |
| 6592 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6593 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 6594 | { |
| 6595 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6596 | |
| 6597 | spin_lock_irq(&phba->hbalock); |
| 6598 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 6599 | spin_unlock_irq(&phba->hbalock); |
| 6600 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6601 | /* Cancel all the IOCBs from the completions list */ |
| 6602 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6603 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6604 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6605 | |
| 6606 | /** |
| 6607 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort |
| 6608 | * @phba: pointer to lpfc hba data structure. |
| 6609 | * @axri: pointer to the els xri abort wcqe structure. |
| 6610 | * |
| 6611 | * This routine is invoked by the worker thread to process a SLI4 slow-path |
| 6612 | * ELS aborted xri. |
| 6613 | **/ |
| 6614 | void |
| 6615 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, |
| 6616 | struct sli4_wcqe_xri_aborted *axri) |
| 6617 | { |
| 6618 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); |
| 6619 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 6620 | unsigned long iflag = 0; |
| 6621 | |
| 6622 | spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, iflag); |
| 6623 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 6624 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { |
| 6625 | if (sglq_entry->sli4_xritag == xri) { |
| 6626 | list_del(&sglq_entry->list); |
| 6627 | spin_unlock_irqrestore( |
| 6628 | &phba->sli4_hba.abts_sgl_list_lock, |
| 6629 | iflag); |
| 6630 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 6631 | |
| 6632 | list_add_tail(&sglq_entry->list, |
| 6633 | &phba->sli4_hba.lpfc_sgl_list); |
| 6634 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 6635 | return; |
| 6636 | } |
| 6637 | } |
| 6638 | spin_unlock_irqrestore(&phba->sli4_hba.abts_sgl_list_lock, iflag); |
| 6639 | } |