| 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 | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4 | * Copyright (C) 2004-2008 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 | |
| 31 | #include "lpfc_hw.h" |
| 32 | #include "lpfc_sli.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 33 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 34 | #include "lpfc_disc.h" |
| 35 | #include "lpfc_scsi.h" |
| 36 | #include "lpfc.h" |
| 37 | #include "lpfc_logmsg.h" |
| 38 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 39 | #include "lpfc_vport.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 40 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 41 | |
| 42 | static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *, |
| 43 | struct lpfc_iocbq *); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 44 | static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *, |
| 45 | struct lpfc_iocbq *); |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 46 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport); |
| 47 | static int lpfc_issue_els_fdisc(struct lpfc_vport *vport, |
| 48 | struct lpfc_nodelist *ndlp, uint8_t retry); |
| 49 | static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba, |
| 50 | struct lpfc_iocbq *iocb); |
| 51 | static void lpfc_register_new_vport(struct lpfc_hba *phba, |
| 52 | struct lpfc_vport *vport, |
| 53 | struct lpfc_nodelist *ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 54 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 55 | static int lpfc_max_els_tries = 3; |
| 56 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 57 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 58 | * lpfc_els_chk_latt - Check host link attention event for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 59 | * @vport: pointer to a host virtual N_Port data structure. |
| 60 | * |
| 61 | * This routine checks whether there is an outstanding host link |
| 62 | * attention event during the discovery process with the @vport. It is done |
| 63 | * by reading the HBA's Host Attention (HA) register. If there is any host |
| 64 | * link attention events during this @vport's discovery process, the @vport |
| 65 | * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall |
| 66 | * be issued if the link state is not already in host link cleared state, |
| 67 | * and a return code shall indicate whether the host link attention event |
| 68 | * had happened. |
| 69 | * |
| 70 | * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport |
| 71 | * state in LPFC_VPORT_READY, the request for checking host link attention |
| 72 | * event will be ignored and a return code shall indicate no host link |
| 73 | * attention event had happened. |
| 74 | * |
| 75 | * Return codes |
| 76 | * 0 - no host link attention event happened |
| 77 | * 1 - host link attention event happened |
| 78 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 79 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 80 | lpfc_els_chk_latt(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 81 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 82 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 83 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 84 | uint32_t ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 85 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 86 | if (vport->port_state >= LPFC_VPORT_READY || |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 87 | phba->link_state == LPFC_LINK_DOWN || |
| 88 | phba->sli_rev > LPFC_SLI_REV3) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 89 | return 0; |
| 90 | |
| 91 | /* Read the HBA Host Attention Register */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 92 | ha_copy = readl(phba->HAregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 93 | |
| 94 | if (!(ha_copy & HA_LATT)) |
| 95 | return 0; |
| 96 | |
| 97 | /* Pending Link Event during Discovery */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 98 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 99 | "0237 Pending Link Event during " |
| 100 | "Discovery: State x%x\n", |
| 101 | phba->pport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 102 | |
| 103 | /* CLEAR_LA should re-enable link attention events and |
| 104 | * we should then imediately take a LATT event. The |
| 105 | * LATT processing should call lpfc_linkdown() which |
| 106 | * will cleanup any left over in-progress discovery |
| 107 | * events. |
| 108 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 109 | spin_lock_irq(shost->host_lock); |
| 110 | vport->fc_flag |= FC_ABORT_DISCOVERY; |
| 111 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 112 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 113 | if (phba->link_state != LPFC_CLEAR_LA) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 114 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 115 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 116 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 117 | } |
| 118 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 119 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 120 | * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 121 | * @vport: pointer to a host virtual N_Port data structure. |
| 122 | * @expectRsp: flag indicating whether response is expected. |
| 123 | * @cmdSize: size of the ELS command. |
| 124 | * @retry: number of retries to the command IOCB when it fails. |
| 125 | * @ndlp: pointer to a node-list data structure. |
| 126 | * @did: destination identifier. |
| 127 | * @elscmd: the ELS command code. |
| 128 | * |
| 129 | * This routine is used for allocating a lpfc-IOCB data structure from |
| 130 | * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters |
| 131 | * passed into the routine for discovery state machine to issue an Extended |
| 132 | * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation |
| 133 | * and preparation routine that is used by all the discovery state machine |
| 134 | * routines and the ELS command-specific fields will be later set up by |
| 135 | * the individual discovery machine routines after calling this routine |
| 136 | * allocating and preparing a generic IOCB data structure. It fills in the |
| 137 | * Buffer Descriptor Entries (BDEs), allocates buffers for both command |
| 138 | * payload and response payload (if expected). The reference count on the |
| 139 | * ndlp is incremented by 1 and the reference to the ndlp is put into |
| 140 | * context1 of the IOCB data structure for this IOCB to hold the ndlp |
| 141 | * reference for the command's callback function to access later. |
| 142 | * |
| 143 | * Return code |
| 144 | * Pointer to the newly allocated/prepared els iocb data structure |
| 145 | * NULL - when els iocb data structure allocation/preparation failed |
| 146 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 147 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 148 | lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, |
| 149 | uint16_t cmdSize, uint8_t retry, |
| 150 | struct lpfc_nodelist *ndlp, uint32_t did, |
| 151 | uint32_t elscmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 152 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 153 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 154 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 155 | struct lpfc_dmabuf *pcmd, *prsp, *pbuflist; |
| 156 | struct ulp_bde64 *bpl; |
| 157 | IOCB_t *icmd; |
| 158 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 159 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 160 | if (!lpfc_is_link_up(phba)) |
| 161 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 162 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 163 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 164 | elsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 165 | |
| 166 | if (elsiocb == NULL) |
| 167 | return NULL; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 168 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 169 | icmd = &elsiocb->iocb; |
| 170 | |
| 171 | /* fill in BDEs for command */ |
| 172 | /* Allocate buffer for command payload */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 173 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 174 | if (pcmd) |
| 175 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 176 | if (!pcmd || !pcmd->virt) |
| 177 | goto els_iocb_free_pcmb_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 178 | |
| 179 | INIT_LIST_HEAD(&pcmd->list); |
| 180 | |
| 181 | /* Allocate buffer for response payload */ |
| 182 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 183 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 184 | if (prsp) |
| 185 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 186 | &prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 187 | if (!prsp || !prsp->virt) |
| 188 | goto els_iocb_free_prsp_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 189 | INIT_LIST_HEAD(&prsp->list); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 190 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 191 | prsp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 192 | |
| 193 | /* Allocate buffer for Buffer ptr list */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 194 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 195 | if (pbuflist) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 196 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 197 | &pbuflist->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 198 | if (!pbuflist || !pbuflist->virt) |
| 199 | goto els_iocb_free_pbuf_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 200 | |
| 201 | INIT_LIST_HEAD(&pbuflist->list); |
| 202 | |
| 203 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 204 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 205 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 206 | icmd->un.elsreq64.remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 207 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 208 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 209 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 210 | icmd->ulpTimeout = phba->fc_ratov * 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 211 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 212 | icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 213 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; |
| 214 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 215 | icmd->ulpBdeCount = 1; |
| 216 | icmd->ulpLe = 1; |
| 217 | icmd->ulpClass = CLASS3; |
| 218 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 219 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 220 | icmd->un.elsreq64.myID = vport->fc_myDID; |
| 221 | |
| 222 | /* For ELS_REQUEST64_CR, use the VPI by default */ |
| 223 | icmd->ulpContext = vport->vpi; |
| 224 | icmd->ulpCt_h = 0; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 225 | /* The CT field must be 0=INVALID_RPI for the ECHO cmd */ |
| 226 | if (elscmd == ELS_CMD_ECHO) |
| 227 | icmd->ulpCt_l = 0; /* context = invalid RPI */ |
| 228 | else |
| 229 | icmd->ulpCt_l = 1; /* context = VPI */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 230 | } |
| 231 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 232 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
| 233 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); |
| 234 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); |
| 235 | bpl->tus.f.bdeSize = cmdSize; |
| 236 | bpl->tus.f.bdeFlags = 0; |
| 237 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 238 | |
| 239 | if (expectRsp) { |
| 240 | bpl++; |
| 241 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); |
| 242 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); |
| 243 | bpl->tus.f.bdeSize = FCELSSIZE; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 244 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 245 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 246 | } |
| 247 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 248 | /* prevent preparing iocb with NULL ndlp reference */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 249 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 250 | if (!elsiocb->context1) |
| 251 | goto els_iocb_free_pbuf_exit; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 252 | elsiocb->context2 = pcmd; |
| 253 | elsiocb->context3 = pbuflist; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 254 | elsiocb->retry = retry; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 255 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 256 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
| 257 | |
| 258 | if (prsp) { |
| 259 | list_add(&prsp->list, &pcmd->list); |
| 260 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 261 | if (expectRsp) { |
| 262 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 263 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 264 | "0116 Xmit ELS command x%x to remote " |
| 265 | "NPORT x%x I/O tag: x%x, port state: x%x\n", |
| 266 | elscmd, did, elsiocb->iotag, |
| 267 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 268 | } else { |
| 269 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 270 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 271 | "0117 Xmit ELS response x%x to remote " |
| 272 | "NPORT x%x I/O tag: x%x, size: x%x\n", |
| 273 | elscmd, ndlp->nlp_DID, elsiocb->iotag, |
| 274 | cmdSize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 275 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 276 | return elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 277 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 278 | els_iocb_free_pbuf_exit: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 279 | if (expectRsp) |
| 280 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 281 | kfree(pbuflist); |
| 282 | |
| 283 | els_iocb_free_prsp_exit: |
| 284 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 285 | kfree(prsp); |
| 286 | |
| 287 | els_iocb_free_pcmb_exit: |
| 288 | kfree(pcmd); |
| 289 | lpfc_sli_release_iocbq(phba, elsiocb); |
| 290 | return NULL; |
| 291 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 292 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 293 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 294 | * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 295 | * @vport: pointer to a host virtual N_Port data structure. |
| 296 | * |
| 297 | * This routine issues a fabric registration login for a @vport. An |
| 298 | * active ndlp node with Fabric_DID must already exist for this @vport. |
| 299 | * The routine invokes two mailbox commands to carry out fabric registration |
| 300 | * login through the HBA firmware: the first mailbox command requests the |
| 301 | * HBA to perform link configuration for the @vport; and the second mailbox |
| 302 | * command requests the HBA to perform the actual fabric registration login |
| 303 | * with the @vport. |
| 304 | * |
| 305 | * Return code |
| 306 | * 0 - successfully issued fabric registration login for @vport |
| 307 | * -ENXIO -- failed to issue fabric registration login for @vport |
| 308 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 309 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 310 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
| 311 | { |
| 312 | struct lpfc_hba *phba = vport->phba; |
| 313 | LPFC_MBOXQ_t *mbox; |
| 314 | struct lpfc_dmabuf *mp; |
| 315 | struct lpfc_nodelist *ndlp; |
| 316 | struct serv_parm *sp; |
| 317 | int rc; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 318 | int err = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 319 | |
| 320 | sp = &phba->fc_fabparam; |
| 321 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 322 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 323 | err = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 324 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 325 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 326 | |
| 327 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 328 | if (!mbox) { |
| 329 | err = 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 330 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 331 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 332 | |
| 333 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 334 | lpfc_config_link(phba, mbox); |
| 335 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 336 | mbox->vport = vport; |
| 337 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 338 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 339 | if (rc == MBX_NOT_FINISHED) { |
| 340 | err = 3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 341 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 342 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 343 | |
| 344 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 345 | if (!mbox) { |
| 346 | err = 4; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 347 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 348 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 349 | 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] | 350 | if (rc) { |
| 351 | err = 5; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 352 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 353 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 354 | |
| 355 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; |
| 356 | mbox->vport = vport; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 357 | /* increment the reference count on ndlp to hold reference |
| 358 | * for the callback routine. |
| 359 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 360 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 361 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 362 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 363 | if (rc == MBX_NOT_FINISHED) { |
| 364 | err = 6; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 365 | goto fail_issue_reg_login; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 366 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 367 | |
| 368 | return 0; |
| 369 | |
| 370 | fail_issue_reg_login: |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 371 | /* decrement the reference count on ndlp just incremented |
| 372 | * for the failed mbox command. |
| 373 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 374 | lpfc_nlp_put(ndlp); |
| 375 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 376 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 377 | kfree(mp); |
| 378 | fail_free_mbox: |
| 379 | mempool_free(mbox, phba->mbox_mem_pool); |
| 380 | |
| 381 | fail: |
| 382 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 383 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 384 | "0249 Cannot issue Register Fabric login: Err %d\n", err); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 385 | return -ENXIO; |
| 386 | } |
| 387 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 388 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 389 | * 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] | 390 | * @vport: pointer to a host virtual N_Port data structure. |
| 391 | * @ndlp: pointer to a node-list data structure. |
| 392 | * @sp: pointer to service parameter data structure. |
| 393 | * @irsp: pointer to the IOCB within the lpfc response IOCB. |
| 394 | * |
| 395 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 396 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric |
| 397 | * port in a fabric topology. It properly sets up the parameters to the @ndlp |
| 398 | * from the IOCB response. It also check the newly assigned N_Port ID to the |
| 399 | * @vport against the previously assigned N_Port ID. If it is different from |
| 400 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine |
| 401 | * is invoked on all the remaining nodes with the @vport to unregister the |
| 402 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() |
| 403 | * is invoked to register login to the fabric. |
| 404 | * |
| 405 | * Return code |
| 406 | * 0 - Success (currently, always return 0) |
| 407 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 408 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 409 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 410 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 411 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 412 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 413 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 414 | struct lpfc_nodelist *np; |
| 415 | struct lpfc_nodelist *next_np; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 416 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 417 | spin_lock_irq(shost->host_lock); |
| 418 | vport->fc_flag |= FC_FABRIC; |
| 419 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 420 | |
| 421 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 422 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 423 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 424 | |
| 425 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 426 | |
| 427 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 428 | spin_lock_irq(shost->host_lock); |
| 429 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 430 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 431 | } else { |
| 432 | /* |
| 433 | * If we are a N-port connected to a Fabric, fixup sparam's so |
| 434 | * logins to devices on remote loops work. |
| 435 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 436 | vport->fc_sparam.cmn.altBbCredit = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 437 | } |
| 438 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 439 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 440 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 441 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 442 | ndlp->nlp_class_sup = 0; |
| 443 | if (sp->cls1.classValid) |
| 444 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 445 | if (sp->cls2.classValid) |
| 446 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 447 | if (sp->cls3.classValid) |
| 448 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 449 | if (sp->cls4.classValid) |
| 450 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 451 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 452 | sp->cmn.bbRcvSizeLsb; |
| 453 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 454 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 455 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 456 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 457 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 458 | LOG_ELS | LOG_VPORT, |
| 459 | "1816 FLOGI NPIV supported, " |
| 460 | "response data 0x%x\n", |
| 461 | sp->cmn.response_multiple_NPort); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 462 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 463 | } else { |
| 464 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 465 | to call reg_vnpid atleast for the physcial host */ |
| 466 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 467 | LOG_ELS | LOG_VPORT, |
| 468 | "1817 Fabric does not support NPIV " |
| 469 | "- configuring single port mode.\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 470 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 475 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 476 | |
| 477 | /* If our NportID changed, we need to ensure all |
| 478 | * remaining NPORTs get unreg_login'ed. |
| 479 | */ |
| 480 | list_for_each_entry_safe(np, next_np, |
| 481 | &vport->fc_nodes, nlp_listp) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 482 | if (!NLP_CHK_NODE_ACT(np)) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 483 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 484 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 485 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 486 | continue; |
| 487 | spin_lock_irq(shost->host_lock); |
| 488 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 489 | spin_unlock_irq(shost->host_lock); |
| 490 | lpfc_unreg_rpi(vport, np); |
| 491 | } |
| 492 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 493 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 494 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 495 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 496 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 500 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 501 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 502 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 503 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) { |
| 504 | lpfc_register_new_vport(phba, vport, ndlp); |
| 505 | return 0; |
| 506 | } |
| 507 | lpfc_issue_fabric_reglogin(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 508 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 509 | } |
| 510 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 511 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 512 | * 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] | 513 | * @vport: pointer to a host virtual N_Port data structure. |
| 514 | * @ndlp: pointer to a node-list data structure. |
| 515 | * @sp: pointer to service parameter data structure. |
| 516 | * |
| 517 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 518 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 519 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 520 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 521 | * the received N_Port Name lexicographically, this node shall assign local |
| 522 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 523 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 524 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 525 | * N_Port IDs. |
| 526 | * |
| 527 | * Return code |
| 528 | * 0 - Success |
| 529 | * -ENXIO - Fail |
| 530 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 531 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 532 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 533 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 534 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 535 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 536 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 537 | LPFC_MBOXQ_t *mbox; |
| 538 | int rc; |
| 539 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 540 | spin_lock_irq(shost->host_lock); |
| 541 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 542 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 543 | |
| 544 | phba->fc_edtov = FF_DEF_EDTOV; |
| 545 | phba->fc_ratov = FF_DEF_RATOV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 546 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 547 | sizeof(vport->fc_portname)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 548 | if (rc >= 0) { |
| 549 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 550 | spin_lock_irq(shost->host_lock); |
| 551 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 552 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 553 | |
| 554 | /* |
| 555 | * N_Port ID cannot be 0, set our to LocalID the other |
| 556 | * side will be RemoteID. |
| 557 | */ |
| 558 | |
| 559 | /* not equal */ |
| 560 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 561 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 562 | |
| 563 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 564 | if (!mbox) |
| 565 | goto fail; |
| 566 | |
| 567 | lpfc_config_link(phba, mbox); |
| 568 | |
| 569 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 570 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 571 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 572 | if (rc == MBX_NOT_FINISHED) { |
| 573 | mempool_free(mbox, phba->mbox_mem_pool); |
| 574 | goto fail; |
| 575 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 576 | /* Decrement ndlp reference count indicating that ndlp can be |
| 577 | * safely released when other references to it are done. |
| 578 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 579 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 580 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 581 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 582 | if (!ndlp) { |
| 583 | /* |
| 584 | * Cannot find existing Fabric ndlp, so allocate a |
| 585 | * new one |
| 586 | */ |
| 587 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 588 | if (!ndlp) |
| 589 | goto fail; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 590 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 591 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 592 | ndlp = lpfc_enable_node(vport, ndlp, |
| 593 | NLP_STE_UNUSED_NODE); |
| 594 | if(!ndlp) |
| 595 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 599 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 600 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 601 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 602 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 603 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 604 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 605 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 606 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 607 | } else |
| 608 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 609 | * count indicating that ndlp can be released when other |
| 610 | * references to it are done. |
| 611 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 612 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 613 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 614 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 615 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 616 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 617 | spin_lock_irq(shost->host_lock); |
| 618 | vport->fc_flag |= FC_PT2PT; |
| 619 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 620 | |
| 621 | /* Start discovery - this should just do CLEAR_LA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 622 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 623 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 624 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 625 | return -ENXIO; |
| 626 | } |
| 627 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 628 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 629 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 630 | * @phba: pointer to lpfc hba data structure. |
| 631 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 632 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 633 | * |
| 634 | * This routine is the top-level completion callback function for issuing |
| 635 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 636 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 637 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 638 | * returning 1), the command IOCB will be released and function returned. |
| 639 | * If the retry attempt has been given up (possibly reach the maximum |
| 640 | * number of retries), one additional decrement of ndlp reference shall be |
| 641 | * invoked before going out after releasing the command IOCB. This will |
| 642 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 643 | * invoke one decrement of ndlp reference count). If no error reported in |
| 644 | * the IOCB status, the command Port ID field is used to determine whether |
| 645 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 646 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 647 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 648 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 649 | * specific topology completion conditions. |
| 650 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 651 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 652 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 653 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 654 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 655 | struct lpfc_vport *vport = cmdiocb->vport; |
| 656 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 657 | IOCB_t *irsp = &rspiocb->iocb; |
| 658 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 659 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 660 | struct serv_parm *sp; |
| 661 | int rc; |
| 662 | |
| 663 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 664 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 665 | /* One additional decrement on node reference count to |
| 666 | * trigger the release of the node |
| 667 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 668 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 669 | goto out; |
| 670 | } |
| 671 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 672 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 673 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 674 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 675 | vport->port_state); |
| 676 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 677 | if (irsp->ulpStatus) { |
| 678 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 679 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 680 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 681 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 682 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 683 | spin_lock_irq(shost->host_lock); |
| 684 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 685 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 686 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 687 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 688 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 689 | * alpa map would take too long otherwise. |
| 690 | */ |
| 691 | if (phba->alpa_map[0] == 0) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 692 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | /* FLOGI failure */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 696 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 697 | "0100 FLOGI failure Data: x%x x%x " |
| 698 | "x%x\n", |
| 699 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 700 | irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 701 | goto flogifail; |
| 702 | } |
| 703 | |
| 704 | /* |
| 705 | * The FLogI succeeded. Sync the data for the CPU before |
| 706 | * accessing it. |
| 707 | */ |
| 708 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 709 | |
| 710 | sp = prsp->virt + sizeof(uint32_t); |
| 711 | |
| 712 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 713 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 714 | "0101 FLOGI completes sucessfully " |
| 715 | "Data: x%x x%x x%x x%x\n", |
| 716 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
| 717 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 718 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 719 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 720 | /* |
| 721 | * If Common Service Parameters indicate Nport |
| 722 | * we are point to point, if Fport we are Fabric. |
| 723 | */ |
| 724 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 725 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 726 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 727 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 728 | |
| 729 | if (!rc) |
| 730 | goto out; |
| 731 | } |
| 732 | |
| 733 | flogifail: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 734 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 735 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 736 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 737 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 738 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 739 | |
| 740 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 741 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 742 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 743 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && |
| 744 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) && |
| 745 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 746 | /* If FLOGI failed enable link interrupt. */ |
| 747 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 748 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 749 | out: |
| 750 | lpfc_els_free_iocb(phba, cmdiocb); |
| 751 | } |
| 752 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 753 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 754 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 755 | * @vport: pointer to a host virtual N_Port data structure. |
| 756 | * @ndlp: pointer to a node-list data structure. |
| 757 | * @retry: number of retries to the command IOCB. |
| 758 | * |
| 759 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 760 | * for a @vport. The initiator service parameters are put into the payload |
| 761 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 762 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 763 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 764 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 765 | * |
| 766 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 767 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 768 | * will be stored into the context1 field of the IOCB for the completion |
| 769 | * callback function to the FLOGI ELS command. |
| 770 | * |
| 771 | * Return code |
| 772 | * 0 - successfully issued flogi iocb for @vport |
| 773 | * 1 - failed to issue flogi iocb for @vport |
| 774 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 775 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 776 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 777 | uint8_t retry) |
| 778 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 779 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 780 | struct serv_parm *sp; |
| 781 | IOCB_t *icmd; |
| 782 | struct lpfc_iocbq *elsiocb; |
| 783 | struct lpfc_sli_ring *pring; |
| 784 | uint8_t *pcmd; |
| 785 | uint16_t cmdsize; |
| 786 | uint32_t tmo; |
| 787 | int rc; |
| 788 | |
| 789 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 790 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 791 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 792 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 793 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 794 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 795 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 796 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 797 | |
| 798 | icmd = &elsiocb->iocb; |
| 799 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 800 | |
| 801 | /* For FLOGI request, remainder of payload is service parameters */ |
| 802 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 803 | pcmd += sizeof(uint32_t); |
| 804 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 805 | sp = (struct serv_parm *) pcmd; |
| 806 | |
| 807 | /* Setup CSPs accordingly for Fabric */ |
| 808 | sp->cmn.e_d_tov = 0; |
| 809 | sp->cmn.w2.r_a_tov = 0; |
| 810 | sp->cls1.classValid = 0; |
| 811 | sp->cls2.seqDelivery = 1; |
| 812 | sp->cls3.seqDelivery = 1; |
| 813 | if (sp->cmn.fcphLow < FC_PH3) |
| 814 | sp->cmn.fcphLow = FC_PH3; |
| 815 | if (sp->cmn.fcphHigh < FC_PH3) |
| 816 | sp->cmn.fcphHigh = FC_PH3; |
| 817 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 818 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 819 | sp->cmn.request_multiple_Nport = 1; |
| 820 | |
| 821 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 822 | icmd->ulpCt_h = 1; |
| 823 | icmd->ulpCt_l = 0; |
| 824 | } |
| 825 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 826 | if (phba->fc_topology != TOPOLOGY_LOOP) { |
| 827 | icmd->un.elsreq64.myID = 0; |
| 828 | icmd->un.elsreq64.fl = 1; |
| 829 | } |
| 830 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 831 | tmo = phba->fc_ratov; |
| 832 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 833 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 834 | phba->fc_ratov = tmo; |
| 835 | |
| 836 | phba->fc_stat.elsXmitFLOGI++; |
| 837 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 838 | |
| 839 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 840 | "Issue FLOGI: opt:x%x", |
| 841 | phba->sli3_options, 0, 0); |
| 842 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 843 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 844 | if (rc == IOCB_ERROR) { |
| 845 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 846 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 847 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 848 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 849 | } |
| 850 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 851 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 852 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 853 | * @phba: pointer to lpfc hba data structure. |
| 854 | * |
| 855 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 856 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 857 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 858 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 859 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 860 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 861 | * |
| 862 | * Return code |
| 863 | * 0 - Sucessfully issued abort iocb on all outstanding flogis (Always 0) |
| 864 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 865 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 866 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 867 | { |
| 868 | struct lpfc_sli_ring *pring; |
| 869 | struct lpfc_iocbq *iocb, *next_iocb; |
| 870 | struct lpfc_nodelist *ndlp; |
| 871 | IOCB_t *icmd; |
| 872 | |
| 873 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 874 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 875 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 876 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 877 | |
| 878 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 879 | |
| 880 | /* |
| 881 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 882 | * searching for. |
| 883 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 884 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 885 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 886 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 887 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR && |
| 888 | icmd->un.elsreq64.bdl.ulpIoTag32) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 889 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 890 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 891 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 892 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 893 | } |
| 894 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 895 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 896 | |
| 897 | return 0; |
| 898 | } |
| 899 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 900 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 901 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 902 | * @vport: pointer to a host virtual N_Port data structure. |
| 903 | * |
| 904 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 905 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 906 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 907 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 908 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 909 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 910 | * @vport. |
| 911 | * |
| 912 | * Return code |
| 913 | * 0 - failed to issue initial flogi for @vport |
| 914 | * 1 - successfully issued initial flogi for @vport |
| 915 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 916 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 917 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 918 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 919 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 920 | struct lpfc_nodelist *ndlp; |
| 921 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 922 | vport->port_state = LPFC_FLOGI; |
| 923 | lpfc_set_disctmo(vport); |
| 924 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 925 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 926 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 927 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 928 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 929 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 930 | if (!ndlp) |
| 931 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 932 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 933 | /* Put ndlp onto node list */ |
| 934 | lpfc_enqueue_node(vport, ndlp); |
| 935 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 936 | /* re-setup ndlp without removing from node list */ |
| 937 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 938 | if (!ndlp) |
| 939 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 940 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 941 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 942 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 943 | /* This decrement of reference count to node shall kick off |
| 944 | * the release of the node. |
| 945 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 946 | lpfc_nlp_put(ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 947 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 948 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 949 | } |
| 950 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 951 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 952 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 953 | * @vport: pointer to a host virtual N_Port data structure. |
| 954 | * |
| 955 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 956 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 957 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 958 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 959 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 960 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 961 | * @vport. |
| 962 | * |
| 963 | * Return code |
| 964 | * 0 - failed to issue initial fdisc for @vport |
| 965 | * 1 - successfully issued initial fdisc for @vport |
| 966 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 967 | int |
| 968 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 969 | { |
| 970 | struct lpfc_hba *phba = vport->phba; |
| 971 | struct lpfc_nodelist *ndlp; |
| 972 | |
| 973 | /* First look for the Fabric ndlp */ |
| 974 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 975 | if (!ndlp) { |
| 976 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 977 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 978 | if (!ndlp) |
| 979 | return 0; |
| 980 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 981 | /* Put ndlp onto node list */ |
| 982 | lpfc_enqueue_node(vport, ndlp); |
| 983 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 984 | /* re-setup ndlp without removing from node list */ |
| 985 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 986 | if (!ndlp) |
| 987 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 988 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 989 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 990 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 991 | /* decrement node reference count to trigger the release of |
| 992 | * the node. |
| 993 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 994 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 995 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 996 | } |
| 997 | return 1; |
| 998 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 999 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1000 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1001 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1002 | * @vport: pointer to a host virtual N_Port data structure. |
| 1003 | * |
| 1004 | * This routine checks whether there are more remaining Port Logins |
| 1005 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1006 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1007 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1008 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1009 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1010 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1011 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1012 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1013 | { |
| 1014 | int sentplogi; |
| 1015 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1016 | if (vport->num_disc_nodes) |
| 1017 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1018 | |
| 1019 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1020 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1021 | "0232 Continue discovery with %d PLOGIs to go " |
| 1022 | "Data: x%x x%x x%x\n", |
| 1023 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1024 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1025 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1026 | if (vport->fc_flag & FC_NLP_MORE) |
| 1027 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 1028 | sentplogi = lpfc_els_disc_plogi(vport); |
| 1029 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1030 | return; |
| 1031 | } |
| 1032 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1033 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1034 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1035 | * @phba: pointer to lpfc hba data structure. |
| 1036 | * @prsp: pointer to response IOCB payload. |
| 1037 | * @ndlp: pointer to a node-list data structure. |
| 1038 | * |
| 1039 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1040 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1041 | * The following cases are considered N_Port confirmed: |
| 1042 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1043 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1044 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1045 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1046 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1047 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1048 | * on that node to release the RPI associated with the node; 2) if there is |
| 1049 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1050 | * into, a new node shall be allocated (or activated). In either case, the |
| 1051 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1052 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1053 | * its pointer returned as the confirmed node. |
| 1054 | * |
| 1055 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1056 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1057 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1058 | * into an inactive state on the vport node list and the vport node list |
| 1059 | * management algorithm does not allow two node with a same DID. |
| 1060 | * |
| 1061 | * Return code |
| 1062 | * pointer to the PLOGI N_Port @ndlp |
| 1063 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1064 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1065 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1066 | struct lpfc_nodelist *ndlp) |
| 1067 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1068 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1069 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1070 | struct lpfc_rport_data *rdata; |
| 1071 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1072 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1073 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1074 | uint32_t rc, keepDID = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1075 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1076 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1077 | * by WWPN. Just return the ndlp that was given to us. |
| 1078 | */ |
| 1079 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1080 | return ndlp; |
| 1081 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1082 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1083 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1084 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1085 | /* 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] | 1086 | * we have for that ndlp. If not, we have some work to do. |
| 1087 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1088 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1089 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1090 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1091 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1092 | |
| 1093 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1094 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1095 | sizeof(struct lpfc_name)); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1096 | if (!rc) |
| 1097 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1098 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
| 1099 | if (!new_ndlp) |
| 1100 | return ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1101 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1102 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1103 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1104 | sizeof(struct lpfc_name)); |
| 1105 | if (!rc) |
| 1106 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1107 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1108 | NLP_STE_UNUSED_NODE); |
| 1109 | if (!new_ndlp) |
| 1110 | return ndlp; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1111 | keepDID = new_ndlp->nlp_DID; |
| 1112 | } else |
| 1113 | keepDID = new_ndlp->nlp_DID; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1114 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1115 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1116 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1117 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1118 | |
| 1119 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) |
| 1120 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 1121 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 1122 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1123 | /* 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] | 1124 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1125 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1126 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1127 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1128 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1129 | * to put ndlp on UNUSED list and try to free it. |
| 1130 | */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1131 | |
| 1132 | /* Fix up the rport accordingly */ |
| 1133 | rport = ndlp->rport; |
| 1134 | if (rport) { |
| 1135 | rdata = rport->dd_data; |
| 1136 | if (rdata->pnode == ndlp) { |
| 1137 | lpfc_nlp_put(ndlp); |
| 1138 | ndlp->rport = NULL; |
| 1139 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1140 | new_ndlp->rport = rport; |
| 1141 | } |
| 1142 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1143 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1144 | /* We shall actually free the ndlp with both nlp_DID and |
| 1145 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1146 | * nodelist never to be used. |
| 1147 | */ |
| 1148 | if (ndlp->nlp_DID == 0) { |
| 1149 | spin_lock_irq(&phba->ndlp_lock); |
| 1150 | NLP_SET_FREE_REQ(ndlp); |
| 1151 | spin_unlock_irq(&phba->ndlp_lock); |
| 1152 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1153 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1154 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1155 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1156 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1157 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1158 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1159 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1160 | /* Two ndlps cannot have the same did */ |
| 1161 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1162 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1163 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1164 | return new_ndlp; |
| 1165 | } |
| 1166 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1167 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1168 | * lpfc_end_rscn - Check and handle more rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1169 | * @vport: pointer to a host virtual N_Port data structure. |
| 1170 | * |
| 1171 | * This routine checks whether more Registration State Change |
| 1172 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1173 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1174 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1175 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1176 | * handling the RSCNs. |
| 1177 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1178 | void |
| 1179 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1180 | { |
| 1181 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1182 | |
| 1183 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1184 | /* |
| 1185 | * Check to see if more RSCNs came in while we were |
| 1186 | * processing this one. |
| 1187 | */ |
| 1188 | if (vport->fc_rscn_id_cnt || |
| 1189 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1190 | lpfc_els_handle_rscn(vport); |
| 1191 | else { |
| 1192 | spin_lock_irq(shost->host_lock); |
| 1193 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1194 | spin_unlock_irq(shost->host_lock); |
| 1195 | } |
| 1196 | } |
| 1197 | } |
| 1198 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1199 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1200 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1201 | * @phba: pointer to lpfc hba data structure. |
| 1202 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1203 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1204 | * |
| 1205 | * This routine is the completion callback function for issuing the Port |
| 1206 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1207 | * ndlp on the vport node list that matches the remote node ID from the |
| 1208 | * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply |
| 1209 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1210 | * checked for error conditons. If there is error status reported, PLOGI |
| 1211 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1212 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1213 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1214 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1215 | * there are additional N_Port nodes with the vport that need to perform |
| 1216 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1217 | * PLOGIs. |
| 1218 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1219 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1220 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1221 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1222 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1223 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1224 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1225 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1226 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1227 | struct lpfc_dmabuf *prsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1228 | int disc, rc, did, type; |
| 1229 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1230 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1231 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1232 | |
| 1233 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1234 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1235 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1236 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1237 | irsp->un.elsreq64.remoteID); |
| 1238 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1239 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1240 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1241 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1242 | "0136 PLOGI completes to NPort x%x " |
| 1243 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1244 | irsp->un.elsreq64.remoteID, |
| 1245 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1246 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1247 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1248 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1249 | |
| 1250 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1251 | * is being used during discovery. |
| 1252 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1253 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1254 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1255 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1256 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1257 | rc = 0; |
| 1258 | |
| 1259 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1260 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1261 | "0102 PLOGI completes to NPort x%x " |
| 1262 | "Data: x%x x%x x%x x%x x%x\n", |
| 1263 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1264 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1265 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1266 | if (lpfc_els_chk_latt(vport)) { |
| 1267 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1268 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1269 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1270 | goto out; |
| 1271 | } |
| 1272 | |
| 1273 | /* ndlp could be freed in DSM, save these values now */ |
| 1274 | type = ndlp->nlp_type; |
| 1275 | did = ndlp->nlp_DID; |
| 1276 | |
| 1277 | if (irsp->ulpStatus) { |
| 1278 | /* Check for retry */ |
| 1279 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1280 | /* ELS command is being retried */ |
| 1281 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1282 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1283 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1284 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1285 | } |
| 1286 | goto out; |
| 1287 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1288 | /* PLOGI failed */ |
| 1289 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1290 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1291 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1292 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1293 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1294 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1295 | } else { |
| 1296 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1297 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1298 | cmdiocb->context2)->list.next, |
| 1299 | struct lpfc_dmabuf, list); |
| 1300 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1301 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1302 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1303 | } |
| 1304 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1305 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1306 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1307 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1308 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1309 | if (vport->num_disc_nodes == 0) { |
| 1310 | spin_lock_irq(shost->host_lock); |
| 1311 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1312 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1313 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1314 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1315 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1316 | } |
| 1317 | } |
| 1318 | |
| 1319 | out: |
| 1320 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1321 | return; |
| 1322 | } |
| 1323 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1324 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1325 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1326 | * @vport: pointer to a host virtual N_Port data structure. |
| 1327 | * @did: destination port identifier. |
| 1328 | * @retry: number of retries to the command IOCB. |
| 1329 | * |
| 1330 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1331 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1332 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1333 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1334 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1335 | * |
| 1336 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1337 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1338 | * will be stored into the context1 field of the IOCB for the completion |
| 1339 | * callback function to the PLOGI ELS command. |
| 1340 | * |
| 1341 | * Return code |
| 1342 | * 0 - Successfully issued a plogi for @vport |
| 1343 | * 1 - failed to issue a plogi for @vport |
| 1344 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1345 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1346 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1347 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1348 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1349 | struct serv_parm *sp; |
| 1350 | IOCB_t *icmd; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1351 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1352 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1353 | struct lpfc_sli *psli; |
| 1354 | uint8_t *pcmd; |
| 1355 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1356 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1357 | |
| 1358 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1359 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1360 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1361 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1362 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1363 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1364 | /* 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] | 1365 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1366 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1367 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1368 | if (!elsiocb) |
| 1369 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1370 | |
| 1371 | icmd = &elsiocb->iocb; |
| 1372 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1373 | |
| 1374 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1375 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1376 | pcmd += sizeof(uint32_t); |
| 1377 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1378 | sp = (struct serv_parm *) pcmd; |
| 1379 | |
| 1380 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1381 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1382 | |
| 1383 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1384 | sp->cmn.fcphHigh = FC_PH3; |
| 1385 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1386 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1387 | "Issue PLOGI: did:x%x", |
| 1388 | did, 0, 0); |
| 1389 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1390 | phba->fc_stat.elsXmitPLOGI++; |
| 1391 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 1392 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1393 | |
| 1394 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1395 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1396 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1397 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1398 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1399 | } |
| 1400 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1401 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1402 | * lpfc_cmpl_els_prli - Completion callback function for prli |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1403 | * @phba: pointer to lpfc hba data structure. |
| 1404 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1405 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1406 | * |
| 1407 | * This routine is the completion callback function for a Process Login |
| 1408 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 1409 | * status. If there is error status reported, PRLI retry shall be attempted |
| 1410 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 1411 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 1412 | * ndlp to mark the PRLI completion. |
| 1413 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1414 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1415 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1416 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1417 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1418 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1419 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1420 | IOCB_t *irsp; |
| 1421 | struct lpfc_sli *psli; |
| 1422 | struct lpfc_nodelist *ndlp; |
| 1423 | |
| 1424 | psli = &phba->sli; |
| 1425 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1426 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1427 | |
| 1428 | irsp = &(rspiocb->iocb); |
| 1429 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1430 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1431 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1432 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1433 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1434 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1435 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 1436 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1437 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1438 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1439 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1440 | "0103 PRLI completes to NPort x%x " |
| 1441 | "Data: x%x x%x x%x x%x\n", |
| 1442 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1443 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1444 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1445 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1446 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1447 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1448 | goto out; |
| 1449 | |
| 1450 | if (irsp->ulpStatus) { |
| 1451 | /* Check for retry */ |
| 1452 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1453 | /* ELS command is being retried */ |
| 1454 | goto out; |
| 1455 | } |
| 1456 | /* PRLI failed */ |
| 1457 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1458 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1459 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1460 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1461 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1462 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1463 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1464 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1465 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1466 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1467 | out: |
| 1468 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1469 | return; |
| 1470 | } |
| 1471 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1472 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1473 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1474 | * @vport: pointer to a host virtual N_Port data structure. |
| 1475 | * @ndlp: pointer to a node-list data structure. |
| 1476 | * @retry: number of retries to the command IOCB. |
| 1477 | * |
| 1478 | * This routine issues a Process Login (PRLI) ELS command for the |
| 1479 | * @vport. The PRLI service parameters are set up in the payload of the |
| 1480 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 1481 | * is put to the IOCB completion callback func field before invoking the |
| 1482 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 1483 | * |
| 1484 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1485 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1486 | * will be stored into the context1 field of the IOCB for the completion |
| 1487 | * callback function to the PRLI ELS command. |
| 1488 | * |
| 1489 | * Return code |
| 1490 | * 0 - successfully issued prli iocb command for @vport |
| 1491 | * 1 - failed to issue prli iocb command for @vport |
| 1492 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1493 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1494 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1495 | uint8_t retry) |
| 1496 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1497 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1498 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1499 | PRLI *npr; |
| 1500 | IOCB_t *icmd; |
| 1501 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1502 | uint8_t *pcmd; |
| 1503 | uint16_t cmdsize; |
| 1504 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1505 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1506 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1507 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1508 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1509 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1510 | |
| 1511 | icmd = &elsiocb->iocb; |
| 1512 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1513 | |
| 1514 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1515 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1516 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1517 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1518 | |
| 1519 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 1520 | npr = (PRLI *) pcmd; |
| 1521 | /* |
| 1522 | * If our firmware version is 3.20 or later, |
| 1523 | * set the following bits for FC-TAPE support. |
| 1524 | */ |
| 1525 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 1526 | npr->ConfmComplAllowed = 1; |
| 1527 | npr->Retry = 1; |
| 1528 | npr->TaskRetryIdReq = 1; |
| 1529 | } |
| 1530 | npr->estabImagePair = 1; |
| 1531 | npr->readXferRdyDis = 1; |
| 1532 | |
| 1533 | /* For FCP support */ |
| 1534 | npr->prliType = PRLI_FCP_TYPE; |
| 1535 | npr->initiatorFunc = 1; |
| 1536 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1537 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1538 | "Issue PRLI: did:x%x", |
| 1539 | ndlp->nlp_DID, 0, 0); |
| 1540 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1541 | phba->fc_stat.elsXmitPRLI++; |
| 1542 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1543 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1544 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1545 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 1546 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 1547 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1548 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1549 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1550 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1551 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1552 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1553 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1554 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1555 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1556 | } |
| 1557 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1558 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1559 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1560 | * @vport: pointer to a host virtual N_Port data structure. |
| 1561 | * |
| 1562 | * This routine performs Registration State Change Notification (RSCN) |
| 1563 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 1564 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 1565 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 1566 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 1567 | * invoked to check and handle possible more RSCN came in during the period |
| 1568 | * of processing the current ones. |
| 1569 | **/ |
| 1570 | static void |
| 1571 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 1572 | { |
| 1573 | lpfc_can_disctmo(vport); |
| 1574 | |
| 1575 | /* RSCN discovery */ |
| 1576 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 1577 | if (vport->fc_npr_cnt) |
| 1578 | if (lpfc_els_disc_plogi(vport)) |
| 1579 | return; |
| 1580 | |
| 1581 | lpfc_end_rscn(vport); |
| 1582 | } |
| 1583 | |
| 1584 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1585 | * lpfc_adisc_done - Complete the adisc phase of discovery |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1586 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 1587 | * |
| 1588 | * This function is called when the final ADISC is completed during discovery. |
| 1589 | * This function handles clearing link attention or issuing reg_vpi depending |
| 1590 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 1591 | * discovery. |
| 1592 | * This function is called with no locks held. |
| 1593 | **/ |
| 1594 | static void |
| 1595 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 1596 | { |
| 1597 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1598 | struct lpfc_hba *phba = vport->phba; |
| 1599 | |
| 1600 | /* |
| 1601 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 1602 | * and continue discovery. |
| 1603 | */ |
| 1604 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 1605 | !(vport->fc_flag & FC_RSCN_MODE)) { |
| 1606 | lpfc_issue_reg_vpi(phba, vport); |
| 1607 | return; |
| 1608 | } |
| 1609 | /* |
| 1610 | * For SLI2, we need to set port_state to READY |
| 1611 | * and continue discovery. |
| 1612 | */ |
| 1613 | if (vport->port_state < LPFC_VPORT_READY) { |
| 1614 | /* If we get here, there is nothing to ADISC */ |
| 1615 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1616 | lpfc_issue_clear_la(phba, vport); |
| 1617 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 1618 | vport->num_disc_nodes = 0; |
| 1619 | /* go thru NPR list, issue ELS PLOGIs */ |
| 1620 | if (vport->fc_npr_cnt) |
| 1621 | lpfc_els_disc_plogi(vport); |
| 1622 | if (!vport->num_disc_nodes) { |
| 1623 | spin_lock_irq(shost->host_lock); |
| 1624 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1625 | spin_unlock_irq(shost->host_lock); |
| 1626 | lpfc_can_disctmo(vport); |
| 1627 | lpfc_end_rscn(vport); |
| 1628 | } |
| 1629 | } |
| 1630 | vport->port_state = LPFC_VPORT_READY; |
| 1631 | } else |
| 1632 | lpfc_rscn_disc(vport); |
| 1633 | } |
| 1634 | |
| 1635 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1636 | * lpfc_more_adisc - Issue more adisc as needed |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1637 | * @vport: pointer to a host virtual N_Port data structure. |
| 1638 | * |
| 1639 | * This routine determines whether there are more ndlps on a @vport |
| 1640 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 1641 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 1642 | * remaining nodes which need to have ADISC sent. |
| 1643 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1644 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1645 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1646 | { |
| 1647 | int sentadisc; |
| 1648 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1649 | if (vport->num_disc_nodes) |
| 1650 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1651 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1652 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1653 | "0210 Continue discovery with %d ADISCs to go " |
| 1654 | "Data: x%x x%x x%x\n", |
| 1655 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 1656 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1657 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1658 | if (vport->fc_flag & FC_NLP_MORE) { |
| 1659 | lpfc_set_disctmo(vport); |
| 1660 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 1661 | sentadisc = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1662 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1663 | if (!vport->num_disc_nodes) |
| 1664 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1665 | return; |
| 1666 | } |
| 1667 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1668 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1669 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1670 | * @phba: pointer to lpfc hba data structure. |
| 1671 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1672 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1673 | * |
| 1674 | * This routine is the completion function for issuing the Address Discover |
| 1675 | * (ADISC) command. It first checks to see whether link went down during |
| 1676 | * the discovery process. If so, the node will be marked as node port |
| 1677 | * recovery for issuing discover IOCB by the link attention handler and |
| 1678 | * exit. Otherwise, the response status is checked. If error was reported |
| 1679 | * in the response status, the ADISC command shall be retried by invoking |
| 1680 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 1681 | * the response status, the state machine is invoked to set transition |
| 1682 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 1683 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1684 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1685 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1686 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1687 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1688 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1689 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1690 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1691 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1692 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1693 | |
| 1694 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1695 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1696 | |
| 1697 | irsp = &(rspiocb->iocb); |
| 1698 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1699 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1700 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1701 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 1702 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1703 | ndlp->nlp_DID); |
| 1704 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1705 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1706 | * is being used during discovery. |
| 1707 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1708 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1709 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1710 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1711 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1712 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1713 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1714 | "0104 ADISC completes to NPort x%x " |
| 1715 | "Data: x%x x%x x%x x%x x%x\n", |
| 1716 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1717 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1718 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1719 | if (lpfc_els_chk_latt(vport)) { |
| 1720 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1721 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1722 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1723 | goto out; |
| 1724 | } |
| 1725 | |
| 1726 | if (irsp->ulpStatus) { |
| 1727 | /* Check for retry */ |
| 1728 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1729 | /* ELS command is being retried */ |
| 1730 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1731 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1732 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1733 | spin_unlock_irq(shost->host_lock); |
| 1734 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1735 | } |
| 1736 | goto out; |
| 1737 | } |
| 1738 | /* ADISC failed */ |
| 1739 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1740 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1741 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1742 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1743 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1744 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1745 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1746 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1747 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1748 | /* Check to see if there are more ADISCs to be sent */ |
| 1749 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1750 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1751 | out: |
| 1752 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1753 | return; |
| 1754 | } |
| 1755 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1756 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1757 | * 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] | 1758 | * @vport: pointer to a virtual N_Port data structure. |
| 1759 | * @ndlp: pointer to a node-list data structure. |
| 1760 | * @retry: number of retries to the command IOCB. |
| 1761 | * |
| 1762 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 1763 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 1764 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 1765 | * to issue the ADISC ELS command. |
| 1766 | * |
| 1767 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1768 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1769 | * will be stored into the context1 field of the IOCB for the completion |
| 1770 | * callback function to the ADISC ELS command. |
| 1771 | * |
| 1772 | * Return code |
| 1773 | * 0 - successfully issued adisc |
| 1774 | * 1 - failed to issue adisc |
| 1775 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1776 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1777 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1778 | uint8_t retry) |
| 1779 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1780 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1781 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1782 | ADISC *ap; |
| 1783 | IOCB_t *icmd; |
| 1784 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1785 | uint8_t *pcmd; |
| 1786 | uint16_t cmdsize; |
| 1787 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1788 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1789 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1790 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1791 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1792 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1793 | |
| 1794 | icmd = &elsiocb->iocb; |
| 1795 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1796 | |
| 1797 | /* For ADISC request, remainder of payload is service parameters */ |
| 1798 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1799 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1800 | |
| 1801 | /* Fill in ADISC payload */ |
| 1802 | ap = (ADISC *) pcmd; |
| 1803 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1804 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 1805 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1806 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1807 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1808 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1809 | "Issue ADISC: did:x%x", |
| 1810 | ndlp->nlp_DID, 0, 0); |
| 1811 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1812 | phba->fc_stat.elsXmitADISC++; |
| 1813 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1814 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1815 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1816 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 1817 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 1818 | IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1819 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1820 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1821 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1822 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1823 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1824 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1825 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1826 | } |
| 1827 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1828 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1829 | * lpfc_cmpl_els_logo - Completion callback function for logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1830 | * @phba: pointer to lpfc hba data structure. |
| 1831 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1832 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1833 | * |
| 1834 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 1835 | * command. If no error status was reported from the LOGO response, the |
| 1836 | * state machine of the associated ndlp shall be invoked for transition with |
| 1837 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 1838 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 1839 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1840 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1841 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1842 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1843 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1844 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 1845 | struct lpfc_vport *vport = ndlp->vport; |
| 1846 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1847 | IOCB_t *irsp; |
| 1848 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1849 | |
| 1850 | psli = &phba->sli; |
| 1851 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1852 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1853 | |
| 1854 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1855 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1856 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1857 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1858 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1859 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1860 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 1861 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1862 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1863 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1864 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1865 | "0105 LOGO completes to NPort x%x " |
| 1866 | "Data: x%x x%x x%x x%x\n", |
| 1867 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1868 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1869 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1870 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1871 | goto out; |
| 1872 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1873 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 1874 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 1875 | * which should abort all outstanding IOs. |
| 1876 | */ |
| 1877 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 1878 | NLP_EVT_DEVICE_RM); |
| 1879 | goto out; |
| 1880 | } |
| 1881 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1882 | if (irsp->ulpStatus) { |
| 1883 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1884 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1885 | /* ELS command is being retried */ |
| 1886 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1887 | /* LOGO failed */ |
| 1888 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1889 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1890 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1891 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1892 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1893 | NLP_EVT_CMPL_LOGO); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1894 | } else |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1895 | /* Good status, call state machine. |
| 1896 | * This will unregister the rpi if needed. |
| 1897 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1898 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1899 | NLP_EVT_CMPL_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1900 | out: |
| 1901 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1902 | return; |
| 1903 | } |
| 1904 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1905 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1906 | * 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] | 1907 | * @vport: pointer to a virtual N_Port data structure. |
| 1908 | * @ndlp: pointer to a node-list data structure. |
| 1909 | * @retry: number of retries to the command IOCB. |
| 1910 | * |
| 1911 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 1912 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 1913 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 1914 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 1915 | * |
| 1916 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1917 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1918 | * will be stored into the context1 field of the IOCB for the completion |
| 1919 | * callback function to the LOGO ELS command. |
| 1920 | * |
| 1921 | * Return code |
| 1922 | * 0 - successfully issued logo |
| 1923 | * 1 - failed to issue logo |
| 1924 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1925 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1926 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1927 | uint8_t retry) |
| 1928 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1929 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1930 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1931 | IOCB_t *icmd; |
| 1932 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1933 | uint8_t *pcmd; |
| 1934 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1935 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1936 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1937 | spin_lock_irq(shost->host_lock); |
| 1938 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 1939 | spin_unlock_irq(shost->host_lock); |
| 1940 | return 0; |
| 1941 | } |
| 1942 | spin_unlock_irq(shost->host_lock); |
| 1943 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1944 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1945 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1946 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1947 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1948 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1949 | |
| 1950 | icmd = &elsiocb->iocb; |
| 1951 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1952 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1953 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1954 | |
| 1955 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1956 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1957 | pcmd += sizeof(uint32_t); |
| 1958 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1959 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1960 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1961 | "Issue LOGO: did:x%x", |
| 1962 | ndlp->nlp_DID, 0, 0); |
| 1963 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1964 | phba->fc_stat.elsXmitLOGO++; |
| 1965 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1966 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1967 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1968 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 1969 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1970 | |
| 1971 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1972 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1973 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1974 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1975 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1976 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1977 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1978 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1979 | } |
| 1980 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1981 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1982 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1983 | * @phba: pointer to lpfc hba data structure. |
| 1984 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1985 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1986 | * |
| 1987 | * This routine is a generic completion callback function for ELS commands. |
| 1988 | * Specifically, it is the callback function which does not need to perform |
| 1989 | * any command specific operations. It is currently used by the ELS command |
| 1990 | * issuing routines for the ELS State Change Request (SCR), |
| 1991 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 1992 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 1993 | * certain debug loggings, this callback function simply invokes the |
| 1994 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 1995 | * discovery process. |
| 1996 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1997 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1998 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1999 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2000 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2001 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2002 | IOCB_t *irsp; |
| 2003 | |
| 2004 | irsp = &rspiocb->iocb; |
| 2005 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2006 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2007 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2008 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2009 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2010 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2011 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2012 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2013 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2014 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2015 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2016 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2017 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2018 | return; |
| 2019 | } |
| 2020 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2021 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2022 | * 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] | 2023 | * @vport: pointer to a host virtual N_Port data structure. |
| 2024 | * @nportid: N_Port identifier to the remote node. |
| 2025 | * @retry: number of retries to the command IOCB. |
| 2026 | * |
| 2027 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2028 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2029 | * first search the @vport node list to find the matching ndlp. If no such |
| 2030 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2031 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2032 | * routine is invoked to send the SCR IOCB. |
| 2033 | * |
| 2034 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2035 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2036 | * will be stored into the context1 field of the IOCB for the completion |
| 2037 | * callback function to the SCR ELS command. |
| 2038 | * |
| 2039 | * Return code |
| 2040 | * 0 - Successfully issued scr command |
| 2041 | * 1 - Failed to issue scr command |
| 2042 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2043 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2044 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2045 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2046 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2047 | IOCB_t *icmd; |
| 2048 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2049 | struct lpfc_sli *psli; |
| 2050 | uint8_t *pcmd; |
| 2051 | uint16_t cmdsize; |
| 2052 | struct lpfc_nodelist *ndlp; |
| 2053 | |
| 2054 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2055 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2056 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2057 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2058 | if (!ndlp) { |
| 2059 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2060 | if (!ndlp) |
| 2061 | return 1; |
| 2062 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2063 | lpfc_enqueue_node(vport, ndlp); |
| 2064 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2065 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2066 | if (!ndlp) |
| 2067 | return 1; |
| 2068 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2069 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2070 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2071 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2072 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2073 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2074 | /* This will trigger the release of the node just |
| 2075 | * allocated |
| 2076 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2077 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2078 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2079 | } |
| 2080 | |
| 2081 | icmd = &elsiocb->iocb; |
| 2082 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2083 | |
| 2084 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2085 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2086 | |
| 2087 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2088 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2089 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2090 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2091 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2092 | "Issue SCR: did:x%x", |
| 2093 | ndlp->nlp_DID, 0, 0); |
| 2094 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2095 | phba->fc_stat.elsXmitSCR++; |
| 2096 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 2097 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2098 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2099 | /* The additional lpfc_nlp_put will cause the following |
| 2100 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2101 | * the node. |
| 2102 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2103 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2104 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2105 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2106 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2107 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2108 | * trigger the release of node. |
| 2109 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2110 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2111 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2112 | } |
| 2113 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2114 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2115 | * 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] | 2116 | * @vport: pointer to a host virtual N_Port data structure. |
| 2117 | * @nportid: N_Port identifier to the remote node. |
| 2118 | * @retry: number of retries to the command IOCB. |
| 2119 | * |
| 2120 | * This routine issues a Fibre Channel Address Resolution Response |
| 2121 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2122 | * is passed into the function. It first search the @vport node list to find |
| 2123 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2124 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2125 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2126 | * |
| 2127 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2128 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2129 | * will be stored into the context1 field of the IOCB for the completion |
| 2130 | * callback function to the PARPR ELS command. |
| 2131 | * |
| 2132 | * Return code |
| 2133 | * 0 - Successfully issued farpr command |
| 2134 | * 1 - Failed to issue farpr command |
| 2135 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2136 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2137 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2138 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2139 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2140 | IOCB_t *icmd; |
| 2141 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2142 | struct lpfc_sli *psli; |
| 2143 | FARP *fp; |
| 2144 | uint8_t *pcmd; |
| 2145 | uint32_t *lp; |
| 2146 | uint16_t cmdsize; |
| 2147 | struct lpfc_nodelist *ondlp; |
| 2148 | struct lpfc_nodelist *ndlp; |
| 2149 | |
| 2150 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2151 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2152 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2153 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2154 | if (!ndlp) { |
| 2155 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2156 | if (!ndlp) |
| 2157 | return 1; |
| 2158 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2159 | lpfc_enqueue_node(vport, ndlp); |
| 2160 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2161 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2162 | if (!ndlp) |
| 2163 | return 1; |
| 2164 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2165 | |
| 2166 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2167 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2168 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2169 | /* This will trigger the release of the node just |
| 2170 | * allocated |
| 2171 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2172 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2173 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2174 | } |
| 2175 | |
| 2176 | icmd = &elsiocb->iocb; |
| 2177 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2178 | |
| 2179 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2180 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2181 | |
| 2182 | /* Fill in FARPR payload */ |
| 2183 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2184 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2185 | lp = (uint32_t *) pcmd; |
| 2186 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2187 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2188 | fp->Rflags = 0; |
| 2189 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2190 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2191 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2192 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2193 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2194 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2195 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2196 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2197 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2198 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2199 | } |
| 2200 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2201 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2202 | "Issue FARPR: did:x%x", |
| 2203 | ndlp->nlp_DID, 0, 0); |
| 2204 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2205 | phba->fc_stat.elsXmitFARPR++; |
| 2206 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 2207 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 2208 | IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2209 | /* The additional lpfc_nlp_put will cause the following |
| 2210 | * lpfc_els_free_iocb routine to trigger the release of |
| 2211 | * the node. |
| 2212 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2213 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2214 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2215 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2216 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2217 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2218 | * trigger the release of the node. |
| 2219 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2220 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2221 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2222 | } |
| 2223 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2224 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2225 | * 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] | 2226 | * @vport: pointer to a host virtual N_Port data structure. |
| 2227 | * @nlp: pointer to a node-list data structure. |
| 2228 | * |
| 2229 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2230 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2231 | * removes the ELS retry event if it presents. In addition, if the |
| 2232 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2233 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2234 | * ADISC. |
| 2235 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2236 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2237 | 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] | 2238 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2239 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2240 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2241 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2242 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2243 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2244 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2245 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2246 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2247 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2248 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2249 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2250 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2251 | /* Decrement nlp reference count held for the delayed retry */ |
| 2252 | evtp = &nlp->els_retry_evt; |
| 2253 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2254 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2255 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2256 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2257 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2258 | spin_unlock_irq(shost->host_lock); |
| 2259 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2260 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2261 | /* Check if there are more ADISCs to be sent */ |
| 2262 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2263 | } else { |
| 2264 | /* Check if there are more PLOGIs to be sent */ |
| 2265 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2266 | if (vport->num_disc_nodes == 0) { |
| 2267 | spin_lock_irq(shost->host_lock); |
| 2268 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2269 | spin_unlock_irq(shost->host_lock); |
| 2270 | lpfc_can_disctmo(vport); |
| 2271 | lpfc_end_rscn(vport); |
| 2272 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2273 | } |
| 2274 | } |
| 2275 | } |
| 2276 | return; |
| 2277 | } |
| 2278 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2279 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2280 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2281 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2282 | * |
| 2283 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2284 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2285 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2286 | * adds the delayed events to the HBA work list and invokes the |
| 2287 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2288 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2289 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2290 | * reference to ndlp will still be available when the worker thread gets |
| 2291 | * to the event associated with the ndlp. |
| 2292 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2293 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2294 | lpfc_els_retry_delay(unsigned long ptr) |
| 2295 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2296 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2297 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2298 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2299 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2300 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2301 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2302 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2303 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2304 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2305 | return; |
| 2306 | } |
| 2307 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2308 | /* We need to hold the node by incrementing the reference |
| 2309 | * count until the queued work is done |
| 2310 | */ |
| 2311 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2312 | if (evtp->evt_arg1) { |
| 2313 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2314 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2315 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2316 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2317 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2318 | return; |
| 2319 | } |
| 2320 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2321 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2322 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2323 | * @ndlp: pointer to a node-list data structure. |
| 2324 | * |
| 2325 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 2326 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 2327 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 2328 | * function according to the delayed ELS command to retry the command. |
| 2329 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2330 | void |
| 2331 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 2332 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2333 | struct lpfc_vport *vport = ndlp->vport; |
| 2334 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2335 | uint32_t cmd, did, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2336 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2337 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2338 | did = ndlp->nlp_DID; |
| 2339 | cmd = ndlp->nlp_last_elscmd; |
| 2340 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2341 | |
| 2342 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2343 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2344 | return; |
| 2345 | } |
| 2346 | |
| 2347 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2348 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 2349 | /* |
| 2350 | * If a discovery event readded nlp_delayfunc after timer |
| 2351 | * firing and before processing the timer, cancel the |
| 2352 | * nlp_delayfunc. |
| 2353 | */ |
| 2354 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2355 | retry = ndlp->nlp_retry; |
| 2356 | |
| 2357 | switch (cmd) { |
| 2358 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2359 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2360 | break; |
| 2361 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2362 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2363 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2364 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2365 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2366 | break; |
| 2367 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2368 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2369 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2370 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2371 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2372 | break; |
| 2373 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2374 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2375 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2376 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2377 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2378 | break; |
| 2379 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2380 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2381 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2382 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2383 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2384 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2385 | case ELS_CMD_FDISC: |
| 2386 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
| 2387 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2388 | } |
| 2389 | return; |
| 2390 | } |
| 2391 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2392 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2393 | * lpfc_els_retry - Make retry decision on an els command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2394 | * @phba: pointer to lpfc hba data structure. |
| 2395 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2396 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2397 | * |
| 2398 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 2399 | * failed. The following ELS IOCBs use this function for retrying the command |
| 2400 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 2401 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 2402 | * returned error status, it makes the decision whether a retry shall be |
| 2403 | * issued for the command, and whether a retry shall be made immediately or |
| 2404 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 2405 | * is called to retry the command. In the later case, the ELS command shall |
| 2406 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 2407 | * ndlp for the delayed command issusing. |
| 2408 | * |
| 2409 | * Return code |
| 2410 | * 0 - No retry of els command is made |
| 2411 | * 1 - Immediate or delayed retry of els command is made |
| 2412 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2413 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2414 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2415 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2416 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2417 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2418 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2419 | IOCB_t *irsp = &rspiocb->iocb; |
| 2420 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2421 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2422 | uint32_t *elscmd; |
| 2423 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2424 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2425 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2426 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2427 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2428 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2429 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2430 | /* Note: context2 may be 0 for internal driver abort |
| 2431 | * of delays ELS command. |
| 2432 | */ |
| 2433 | |
| 2434 | if (pcmd && pcmd->virt) { |
| 2435 | elscmd = (uint32_t *) (pcmd->virt); |
| 2436 | cmd = *elscmd++; |
| 2437 | } |
| 2438 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2439 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2440 | did = ndlp->nlp_DID; |
| 2441 | else { |
| 2442 | /* We should only hit this case for retrying PLOGI */ |
| 2443 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2444 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2445 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 2446 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2447 | return 1; |
| 2448 | } |
| 2449 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2450 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2451 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 2452 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 2453 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2454 | switch (irsp->ulpStatus) { |
| 2455 | case IOSTAT_FCP_RSP_ERROR: |
| 2456 | case IOSTAT_REMOTE_STOP: |
| 2457 | break; |
| 2458 | |
| 2459 | case IOSTAT_LOCAL_REJECT: |
| 2460 | switch ((irsp->un.ulpWord[4] & 0xff)) { |
| 2461 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2462 | if (cmd == ELS_CMD_FLOGI) { |
| 2463 | if (PCI_DEVICE_ID_HORNET == |
| 2464 | phba->pcidev->device) { |
| 2465 | phba->fc_topology = TOPOLOGY_LOOP; |
| 2466 | phba->pport->fc_myDID = 0; |
| 2467 | phba->alpa_map[0] = 0; |
| 2468 | phba->alpa_map[1] = 0; |
| 2469 | } |
| 2470 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2471 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2472 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2473 | retry = 1; |
| 2474 | break; |
| 2475 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2476 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2477 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2478 | "0124 Retry illegal cmd x%x " |
| 2479 | "retry:x%x delay:x%x\n", |
| 2480 | cmd, cmdiocb->retry, delay); |
| 2481 | retry = 1; |
| 2482 | /* All command's retry policy */ |
| 2483 | maxretry = 8; |
| 2484 | if (cmdiocb->retry > 2) |
| 2485 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2486 | break; |
| 2487 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2488 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2489 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2490 | retry = 1; |
| 2491 | if (cmdiocb->retry > 100) |
| 2492 | delay = 100; |
| 2493 | maxretry = 250; |
| 2494 | break; |
| 2495 | |
| 2496 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2497 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2498 | retry = 1; |
| 2499 | break; |
| 2500 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2501 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2502 | case IOERR_INVALID_RPI: |
| 2503 | retry = 1; |
| 2504 | break; |
| 2505 | } |
| 2506 | break; |
| 2507 | |
| 2508 | case IOSTAT_NPORT_RJT: |
| 2509 | case IOSTAT_FABRIC_RJT: |
| 2510 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 2511 | retry = 1; |
| 2512 | break; |
| 2513 | } |
| 2514 | break; |
| 2515 | |
| 2516 | case IOSTAT_NPORT_BSY: |
| 2517 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2518 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2519 | retry = 1; |
| 2520 | break; |
| 2521 | |
| 2522 | case IOSTAT_LS_RJT: |
| 2523 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 2524 | /* Added for Vendor specifc support |
| 2525 | * Just keep retrying for these Rsn / Exp codes |
| 2526 | */ |
| 2527 | switch (stat.un.b.lsRjtRsnCode) { |
| 2528 | case LSRJT_UNABLE_TPC: |
| 2529 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2530 | LSEXP_CMD_IN_PROGRESS) { |
| 2531 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2532 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2533 | maxretry = 48; |
| 2534 | } |
| 2535 | retry = 1; |
| 2536 | break; |
| 2537 | } |
| 2538 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2539 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2540 | maxretry = lpfc_max_els_tries + 1; |
| 2541 | retry = 1; |
| 2542 | break; |
| 2543 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2544 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2545 | (cmd == ELS_CMD_FDISC) && |
| 2546 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2547 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2548 | "0125 FDISC Failed (x%x). " |
| 2549 | "Fabric out of resources\n", |
| 2550 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2551 | lpfc_vport_set_state(vport, |
| 2552 | FC_VPORT_NO_FABRIC_RSCS); |
| 2553 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2554 | break; |
| 2555 | |
| 2556 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2557 | if ((cmd == ELS_CMD_PLOGI) || |
| 2558 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2559 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2560 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2561 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2562 | /* FDISC retry policy */ |
| 2563 | maxretry = 48; |
| 2564 | if (cmdiocb->retry >= 32) |
| 2565 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2566 | } |
| 2567 | retry = 1; |
| 2568 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2569 | |
| 2570 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2571 | /* There are some cases where switches return this |
| 2572 | * error when they are not ready and should be returning |
| 2573 | * Logical Busy. We should delay every time. |
| 2574 | */ |
| 2575 | if (cmd == ELS_CMD_FDISC && |
| 2576 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 2577 | maxretry = 3; |
| 2578 | delay = 1000; |
| 2579 | retry = 1; |
| 2580 | break; |
| 2581 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2582 | case LSRJT_PROTOCOL_ERR: |
| 2583 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2584 | (cmd == ELS_CMD_FDISC) && |
| 2585 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 2586 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 2587 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2588 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2589 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2590 | "Fabric Detected Bad WWN\n", |
| 2591 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2592 | lpfc_vport_set_state(vport, |
| 2593 | FC_VPORT_FABRIC_REJ_WWN); |
| 2594 | } |
| 2595 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2596 | } |
| 2597 | break; |
| 2598 | |
| 2599 | case IOSTAT_INTERMED_RSP: |
| 2600 | case IOSTAT_BA_RJT: |
| 2601 | break; |
| 2602 | |
| 2603 | default: |
| 2604 | break; |
| 2605 | } |
| 2606 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2607 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2608 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2609 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2610 | if ((cmd == ELS_CMD_FLOGI) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 2611 | (phba->fc_topology != TOPOLOGY_LOOP) && |
| 2612 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2613 | /* FLOGI retry policy */ |
| 2614 | retry = 1; |
| 2615 | maxretry = 48; |
| 2616 | if (cmdiocb->retry >= 32) |
| 2617 | delay = 1000; |
| 2618 | } |
| 2619 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2620 | if ((++cmdiocb->retry) >= maxretry) { |
| 2621 | phba->fc_stat.elsRetryExceeded++; |
| 2622 | retry = 0; |
| 2623 | } |
| 2624 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2625 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 2626 | retry = 0; |
| 2627 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2628 | if (retry) { |
| 2629 | |
| 2630 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2631 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2632 | "0107 Retry ELS command x%x to remote " |
| 2633 | "NPORT x%x Data: x%x x%x\n", |
| 2634 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2635 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2636 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 2637 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 2638 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { |
| 2639 | /* Don't reset timer for no resources */ |
| 2640 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2641 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2642 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2643 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2644 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2645 | } |
| 2646 | |
| 2647 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2648 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2649 | phba->fc_stat.elsDelayRetry++; |
| 2650 | ndlp->nlp_retry = cmdiocb->retry; |
| 2651 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2652 | /* delay is specified in milliseconds */ |
| 2653 | mod_timer(&ndlp->nlp_delayfunc, |
| 2654 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2655 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2656 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2657 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2658 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2659 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2660 | if (cmd == ELS_CMD_PRLI) |
| 2661 | lpfc_nlp_set_state(vport, ndlp, |
| 2662 | NLP_STE_REG_LOGIN_ISSUE); |
| 2663 | else |
| 2664 | lpfc_nlp_set_state(vport, ndlp, |
| 2665 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2666 | ndlp->nlp_last_elscmd = cmd; |
| 2667 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2668 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2669 | } |
| 2670 | switch (cmd) { |
| 2671 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2672 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2673 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2674 | case ELS_CMD_FDISC: |
| 2675 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 2676 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2677 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2678 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2679 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2680 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2681 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2682 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2683 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2684 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2685 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2686 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2687 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 2688 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2689 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2690 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2691 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2692 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 2693 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2694 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2695 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2696 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2697 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 2698 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2699 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2700 | } |
| 2701 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2702 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2703 | if (logerr) { |
| 2704 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2705 | "0137 No retry ELS command x%x to remote " |
| 2706 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 2707 | cmd, did, irsp->ulpStatus, |
| 2708 | irsp->un.ulpWord[4]); |
| 2709 | } |
| 2710 | else { |
| 2711 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2712 | "0108 No retry ELS command x%x to remote " |
| 2713 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 2714 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 2715 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2716 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2717 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2718 | } |
| 2719 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2720 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2721 | * 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] | 2722 | * @phba: pointer to lpfc hba data structure. |
| 2723 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 2724 | * |
| 2725 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 2726 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 2727 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 2728 | * response of the command IOCB. If so, it will be released before releasing |
| 2729 | * the lpfc DMA buffer associated with the IOCB itself. |
| 2730 | * |
| 2731 | * Return code |
| 2732 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2733 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2734 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2735 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 2736 | { |
| 2737 | struct lpfc_dmabuf *buf_ptr; |
| 2738 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2739 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2740 | if (!list_empty(&buf_ptr1->list)) { |
| 2741 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 2742 | struct lpfc_dmabuf, |
| 2743 | list); |
| 2744 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2745 | kfree(buf_ptr); |
| 2746 | } |
| 2747 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 2748 | kfree(buf_ptr1); |
| 2749 | return 0; |
| 2750 | } |
| 2751 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2752 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2753 | * 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] | 2754 | * @phba: pointer to lpfc hba data structure. |
| 2755 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 2756 | * |
| 2757 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 2758 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 2759 | * pool. |
| 2760 | * |
| 2761 | * Return code |
| 2762 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2763 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2764 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2765 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 2766 | { |
| 2767 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2768 | kfree(buf_ptr); |
| 2769 | return 0; |
| 2770 | } |
| 2771 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2772 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2773 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2774 | * @phba: pointer to lpfc hba data structure. |
| 2775 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 2776 | * |
| 2777 | * This routine frees a command IOCB and its associated resources. The |
| 2778 | * command IOCB data structure contains the reference to various associated |
| 2779 | * resources, these fields must be set to NULL if the associated reference |
| 2780 | * not present: |
| 2781 | * context1 - reference to ndlp |
| 2782 | * context2 - reference to cmd |
| 2783 | * context2->next - reference to rsp |
| 2784 | * context3 - reference to bpl |
| 2785 | * |
| 2786 | * It first properly decrements the reference count held on ndlp for the |
| 2787 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 2788 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 2789 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 2790 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 2791 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 2792 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 2793 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 2794 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 2795 | * |
| 2796 | * Return code |
| 2797 | * 0 - Success (currently, always return 0) |
| 2798 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2799 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2800 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2801 | { |
| 2802 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2803 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2804 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2805 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 2806 | if (ndlp) { |
| 2807 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 2808 | lpfc_nlp_put(ndlp); |
| 2809 | |
| 2810 | /* If the ndlp is not being used by another discovery |
| 2811 | * thread, free it. |
| 2812 | */ |
| 2813 | if (!lpfc_nlp_not_used(ndlp)) { |
| 2814 | /* If ndlp is being used by another discovery |
| 2815 | * thread, just clear NLP_DEFER_RM |
| 2816 | */ |
| 2817 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 2818 | } |
| 2819 | } |
| 2820 | else |
| 2821 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2822 | elsiocb->context1 = NULL; |
| 2823 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2824 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 2825 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2826 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 2827 | /* Firmware could still be in progress of DMAing |
| 2828 | * payload, so don't free data buffer till after |
| 2829 | * a hbeat. |
| 2830 | */ |
| 2831 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 2832 | buf_ptr = elsiocb->context2; |
| 2833 | elsiocb->context2 = NULL; |
| 2834 | if (buf_ptr) { |
| 2835 | buf_ptr1 = NULL; |
| 2836 | spin_lock_irq(&phba->hbalock); |
| 2837 | if (!list_empty(&buf_ptr->list)) { |
| 2838 | list_remove_head(&buf_ptr->list, |
| 2839 | buf_ptr1, struct lpfc_dmabuf, |
| 2840 | list); |
| 2841 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 2842 | list_add_tail(&buf_ptr1->list, |
| 2843 | &phba->elsbuf); |
| 2844 | phba->elsbuf_cnt++; |
| 2845 | } |
| 2846 | INIT_LIST_HEAD(&buf_ptr->list); |
| 2847 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 2848 | phba->elsbuf_cnt++; |
| 2849 | spin_unlock_irq(&phba->hbalock); |
| 2850 | } |
| 2851 | } else { |
| 2852 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 2853 | lpfc_els_free_data(phba, buf_ptr1); |
| 2854 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2855 | } |
| 2856 | |
| 2857 | if (elsiocb->context3) { |
| 2858 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2859 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2860 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2861 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2862 | return 0; |
| 2863 | } |
| 2864 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2865 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2866 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2867 | * @phba: pointer to lpfc hba data structure. |
| 2868 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2869 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2870 | * |
| 2871 | * This routine is the completion callback function to the Logout (LOGO) |
| 2872 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 2873 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 2874 | * release the ndlp if it has the last reference remaining (reference count |
| 2875 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 2876 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 2877 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 2878 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 2879 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 2880 | * IOCB data structure. |
| 2881 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2882 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2883 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2884 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2885 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2886 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2887 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2888 | IOCB_t *irsp; |
| 2889 | |
| 2890 | irsp = &rspiocb->iocb; |
| 2891 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 2892 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 2893 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2894 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2895 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2896 | "0109 ACC to LOGO completes to NPort x%x " |
| 2897 | "Data: x%x x%x x%x\n", |
| 2898 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 2899 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2900 | |
| 2901 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 2902 | /* NPort Recovery mode or node is just allocated */ |
| 2903 | if (!lpfc_nlp_not_used(ndlp)) { |
| 2904 | /* If the ndlp is being used by another discovery |
| 2905 | * thread, just unregister the RPI. |
| 2906 | */ |
| 2907 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2908 | } else { |
| 2909 | /* Indicate the node has already released, should |
| 2910 | * not reference to it from within lpfc_els_free_iocb. |
| 2911 | */ |
| 2912 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2913 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2914 | } |
| 2915 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2916 | return; |
| 2917 | } |
| 2918 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2919 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2920 | * 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] | 2921 | * @phba: pointer to lpfc hba data structure. |
| 2922 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 2923 | * |
| 2924 | * This routine is the completion callback function for unregister default |
| 2925 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 2926 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 2927 | * decrements the ndlp reference count held for this completion callback |
| 2928 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 2929 | * whether there is only one reference left on the ndlp. If so, it will |
| 2930 | * perform one more decrement and trigger the release of the ndlp. |
| 2931 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2932 | void |
| 2933 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2934 | { |
| 2935 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 2936 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 2937 | |
| 2938 | pmb->context1 = NULL; |
| 2939 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2940 | kfree(mp); |
| 2941 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2942 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2943 | lpfc_nlp_put(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2944 | /* This is the end of the default RPI cleanup logic for this |
| 2945 | * ndlp. If no other discovery threads are using this ndlp. |
| 2946 | * we should free all resources associated with it. |
| 2947 | */ |
| 2948 | lpfc_nlp_not_used(ndlp); |
| 2949 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 2950 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2951 | return; |
| 2952 | } |
| 2953 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2954 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2955 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2956 | * @phba: pointer to lpfc hba data structure. |
| 2957 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2958 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2959 | * |
| 2960 | * This routine is the completion callback function for ELS Response IOCB |
| 2961 | * command. In normal case, this callback function just properly sets the |
| 2962 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 2963 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 2964 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 2965 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 2966 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 2967 | * routine shall be invoked trying to release the ndlp if no other threads |
| 2968 | * are currently referring it. |
| 2969 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2970 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2971 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2972 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2973 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2974 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2975 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 2976 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2977 | IOCB_t *irsp; |
| 2978 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2979 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2980 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2981 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2982 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 2983 | irsp = &rspiocb->iocb; |
| 2984 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2985 | if (cmdiocb->context_un.mbox) |
| 2986 | mbox = cmdiocb->context_un.mbox; |
| 2987 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2988 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 2989 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 2990 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2991 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2992 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 2993 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2994 | /* A LS_RJT associated with Default RPI cleanup has its own |
| 2995 | * seperate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2996 | */ |
| 2997 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 2998 | ls_rjt = 1; |
| 2999 | } |
| 3000 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3001 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3002 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3003 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3004 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3005 | if (mp) { |
| 3006 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3007 | kfree(mp); |
| 3008 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3009 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3010 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3011 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3012 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3013 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3014 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3015 | /* Indicate the node has already released, |
| 3016 | * should not reference to it from within |
| 3017 | * the routine lpfc_els_free_iocb. |
| 3018 | */ |
| 3019 | cmdiocb->context1 = NULL; |
| 3020 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3021 | goto out; |
| 3022 | } |
| 3023 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3024 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3025 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3026 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3027 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3028 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3029 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3030 | "0110 ELS response tag x%x completes " |
| 3031 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3032 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3033 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3034 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3035 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3036 | if (mbox) { |
| 3037 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3038 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3039 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3040 | /* Increment reference count to ndlp to hold the |
| 3041 | * reference to ndlp for the callback function. |
| 3042 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3043 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3044 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3045 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3046 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3047 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3048 | } |
| 3049 | else { |
| 3050 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3051 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3052 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3053 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3054 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3055 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3056 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3057 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3058 | else |
| 3059 | /* Decrement the ndlp reference count we |
| 3060 | * set for this failed mailbox command. |
| 3061 | */ |
| 3062 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3063 | |
| 3064 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3065 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3066 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3067 | "Data: x%x x%x x%x\n", |
| 3068 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3069 | ndlp->nlp_rpi); |
| 3070 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3071 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3072 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3073 | /* Indicate node has already been released, |
| 3074 | * should not reference to it from within |
| 3075 | * the routine lpfc_els_free_iocb. |
| 3076 | */ |
| 3077 | cmdiocb->context1 = NULL; |
| 3078 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3079 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3080 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3081 | if (!lpfc_error_lost_link(irsp) && |
| 3082 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3083 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3084 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3085 | /* Indicate node has already been |
| 3086 | * released, should not reference |
| 3087 | * to it from within the routine |
| 3088 | * lpfc_els_free_iocb. |
| 3089 | */ |
| 3090 | cmdiocb->context1 = NULL; |
| 3091 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3092 | } |
| 3093 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3094 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3095 | if (mp) { |
| 3096 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3097 | kfree(mp); |
| 3098 | } |
| 3099 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3100 | } |
| 3101 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3102 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3103 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3104 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3105 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3106 | |
| 3107 | /* If the node is not being used by another discovery thread, |
| 3108 | * and we are sending a reject, we are done with it. |
| 3109 | * Release driver reference count here and free associated |
| 3110 | * resources. |
| 3111 | */ |
| 3112 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3113 | if (lpfc_nlp_not_used(ndlp)) |
| 3114 | /* Indicate node has already been released, |
| 3115 | * should not reference to it from within |
| 3116 | * the routine lpfc_els_free_iocb. |
| 3117 | */ |
| 3118 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3119 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3120 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3121 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3122 | return; |
| 3123 | } |
| 3124 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3125 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3126 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3127 | * @vport: pointer to a host virtual N_Port data structure. |
| 3128 | * @flag: the els command code to be accepted. |
| 3129 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3130 | * @ndlp: pointer to a node-list data structure. |
| 3131 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3132 | * |
| 3133 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3134 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3135 | * specific ACC response command to be issued and invokes the |
| 3136 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3137 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3138 | * field of the IOCB for the completion callback function to issue the |
| 3139 | * mailbox command to the HBA later when callback is invoked. |
| 3140 | * |
| 3141 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3142 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3143 | * will be stored into the context1 field of the IOCB for the completion |
| 3144 | * callback function to the corresponding response ELS IOCB command. |
| 3145 | * |
| 3146 | * Return code |
| 3147 | * 0 - Successfully issued acc response |
| 3148 | * 1 - Failed to issue acc response |
| 3149 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3150 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3151 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3152 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3153 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3154 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3155 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3156 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3157 | IOCB_t *icmd; |
| 3158 | IOCB_t *oldcmd; |
| 3159 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3160 | struct lpfc_sli *psli; |
| 3161 | uint8_t *pcmd; |
| 3162 | uint16_t cmdsize; |
| 3163 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3164 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3165 | |
| 3166 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3167 | oldcmd = &oldiocb->iocb; |
| 3168 | |
| 3169 | switch (flag) { |
| 3170 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3171 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3172 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3173 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3174 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3175 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3176 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3177 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3178 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3179 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3180 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3181 | icmd = &elsiocb->iocb; |
| 3182 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3183 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3184 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3185 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3186 | |
| 3187 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3188 | "Issue ACC: did:x%x flg:x%x", |
| 3189 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3190 | break; |
| 3191 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3192 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3193 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3194 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3195 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3196 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3197 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3198 | icmd = &elsiocb->iocb; |
| 3199 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3200 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3201 | |
| 3202 | if (mbox) |
| 3203 | elsiocb->context_un.mbox = mbox; |
| 3204 | |
| 3205 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3206 | pcmd += sizeof(uint32_t); |
| 3207 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3208 | |
| 3209 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3210 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 3211 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3212 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3213 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3214 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3215 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3216 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3217 | if (!elsiocb) |
| 3218 | return 1; |
| 3219 | |
| 3220 | icmd = &elsiocb->iocb; |
| 3221 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3222 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3223 | |
| 3224 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3225 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3226 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 3227 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 3228 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3229 | |
| 3230 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3231 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 3232 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3233 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3234 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3235 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3236 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3237 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3238 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3239 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
| 3240 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", |
| 3241 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3242 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3243 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3244 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3245 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3246 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3247 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3248 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 3249 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3250 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3254 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3255 | if (rc == IOCB_ERROR) { |
| 3256 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3257 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3258 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3259 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3260 | } |
| 3261 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3262 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3263 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3264 | * @vport: pointer to a virtual N_Port data structure. |
| 3265 | * @rejectError: |
| 3266 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3267 | * @ndlp: pointer to a node-list data structure. |
| 3268 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3269 | * |
| 3270 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 3271 | * command. If a @mbox pointer is passed in, it will be put into the |
| 3272 | * context_un.mbox field of the IOCB for the completion callback function |
| 3273 | * to issue to the HBA later. |
| 3274 | * |
| 3275 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3276 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3277 | * will be stored into the context1 field of the IOCB for the completion |
| 3278 | * callback function to the reject response ELS IOCB command. |
| 3279 | * |
| 3280 | * Return code |
| 3281 | * 0 - Successfully issued reject response |
| 3282 | * 1 - Failed to issue reject response |
| 3283 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3284 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3285 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3286 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 3287 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3288 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3289 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3290 | IOCB_t *icmd; |
| 3291 | IOCB_t *oldcmd; |
| 3292 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3293 | struct lpfc_sli *psli; |
| 3294 | uint8_t *pcmd; |
| 3295 | uint16_t cmdsize; |
| 3296 | int rc; |
| 3297 | |
| 3298 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3299 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3300 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3301 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3302 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3303 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3304 | |
| 3305 | icmd = &elsiocb->iocb; |
| 3306 | oldcmd = &oldiocb->iocb; |
| 3307 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3308 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3309 | |
| 3310 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3311 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3312 | *((uint32_t *) (pcmd)) = rejectError; |
| 3313 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3314 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3315 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3316 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3317 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3318 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3319 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 3320 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 3321 | "rpi x%x\n", |
| 3322 | rejectError, elsiocb->iotag, |
| 3323 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 3324 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3325 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3326 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 3327 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 3328 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3329 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3330 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3331 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3332 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3333 | if (rc == IOCB_ERROR) { |
| 3334 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3335 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3336 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3337 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3338 | } |
| 3339 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3340 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3341 | * 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] | 3342 | * @vport: pointer to a virtual N_Port data structure. |
| 3343 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3344 | * @ndlp: pointer to a node-list data structure. |
| 3345 | * |
| 3346 | * This routine prepares and issues an Accept (ACC) response to Address |
| 3347 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 3348 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3349 | * |
| 3350 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3351 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3352 | * will be stored into the context1 field of the IOCB for the completion |
| 3353 | * callback function to the ADISC Accept response ELS IOCB command. |
| 3354 | * |
| 3355 | * Return code |
| 3356 | * 0 - Successfully issued acc adisc response |
| 3357 | * 1 - Failed to issue adisc acc response |
| 3358 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3359 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3360 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 3361 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3362 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3363 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3364 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3365 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3366 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3367 | uint8_t *pcmd; |
| 3368 | uint16_t cmdsize; |
| 3369 | int rc; |
| 3370 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3371 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3372 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3373 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3374 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3375 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3376 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3377 | icmd = &elsiocb->iocb; |
| 3378 | oldcmd = &oldiocb->iocb; |
| 3379 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3380 | |
| 3381 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3382 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3383 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 3384 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 3385 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3386 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3387 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3388 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3389 | |
| 3390 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3391 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3392 | |
| 3393 | ap = (ADISC *) (pcmd); |
| 3394 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3395 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3396 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3397 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3398 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3399 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3400 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 3401 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3402 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3403 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3404 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3405 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3406 | if (rc == IOCB_ERROR) { |
| 3407 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3408 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3409 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3410 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3411 | } |
| 3412 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3413 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3414 | * 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] | 3415 | * @vport: pointer to a virtual N_Port data structure. |
| 3416 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3417 | * @ndlp: pointer to a node-list data structure. |
| 3418 | * |
| 3419 | * This routine prepares and issues an Accept (ACC) response to Process |
| 3420 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 3421 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3422 | * |
| 3423 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3424 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3425 | * will be stored into the context1 field of the IOCB for the completion |
| 3426 | * callback function to the PRLI Accept response ELS IOCB command. |
| 3427 | * |
| 3428 | * Return code |
| 3429 | * 0 - Successfully issued acc prli response |
| 3430 | * 1 - Failed to issue acc prli response |
| 3431 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3432 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3433 | 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] | 3434 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3435 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3436 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3437 | PRLI *npr; |
| 3438 | lpfc_vpd_t *vpd; |
| 3439 | IOCB_t *icmd; |
| 3440 | IOCB_t *oldcmd; |
| 3441 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3442 | struct lpfc_sli *psli; |
| 3443 | uint8_t *pcmd; |
| 3444 | uint16_t cmdsize; |
| 3445 | int rc; |
| 3446 | |
| 3447 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3448 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3449 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3450 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3451 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3452 | if (!elsiocb) |
| 3453 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3454 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3455 | icmd = &elsiocb->iocb; |
| 3456 | oldcmd = &oldiocb->iocb; |
| 3457 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3458 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3459 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3460 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 3461 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 3462 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3463 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3464 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3465 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3466 | |
| 3467 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3468 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3469 | |
| 3470 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3471 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3472 | |
| 3473 | npr = (PRLI *) pcmd; |
| 3474 | vpd = &phba->vpd; |
| 3475 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3476 | * If the remote port is a target and our firmware version is 3.20 or |
| 3477 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3478 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3479 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 3480 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3481 | npr->ConfmComplAllowed = 1; |
| 3482 | npr->Retry = 1; |
| 3483 | npr->TaskRetryIdReq = 1; |
| 3484 | } |
| 3485 | |
| 3486 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 3487 | npr->estabImagePair = 1; |
| 3488 | npr->readXferRdyDis = 1; |
| 3489 | npr->ConfmComplAllowed = 1; |
| 3490 | |
| 3491 | npr->prliType = PRLI_FCP_TYPE; |
| 3492 | npr->initiatorFunc = 1; |
| 3493 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3494 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3495 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 3496 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3497 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3498 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3499 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3500 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3501 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3502 | if (rc == IOCB_ERROR) { |
| 3503 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3504 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3505 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3506 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3507 | } |
| 3508 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3509 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3510 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3511 | * @vport: pointer to a virtual N_Port data structure. |
| 3512 | * @format: rnid command format. |
| 3513 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3514 | * @ndlp: pointer to a node-list data structure. |
| 3515 | * |
| 3516 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 3517 | * (ACC) response. It constructs the RNID ACC response command according to |
| 3518 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 3519 | * issue the response. Note that this command does not need to hold the ndlp |
| 3520 | * reference count for the callback. So, the ndlp reference count taken by |
| 3521 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 3522 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 3523 | * there is no ndlp reference available. |
| 3524 | * |
| 3525 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3526 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3527 | * will be stored into the context1 field of the IOCB for the completion |
| 3528 | * callback function. However, for the RNID Accept Response ELS command, |
| 3529 | * this is undone later by this routine after the IOCB is allocated. |
| 3530 | * |
| 3531 | * Return code |
| 3532 | * 0 - Successfully issued acc rnid response |
| 3533 | * 1 - Failed to issue acc rnid response |
| 3534 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3535 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3536 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3537 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3538 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3539 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3540 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3541 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3542 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3543 | struct lpfc_sli *psli; |
| 3544 | uint8_t *pcmd; |
| 3545 | uint16_t cmdsize; |
| 3546 | int rc; |
| 3547 | |
| 3548 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3549 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 3550 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3551 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3552 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3553 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3554 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3555 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3556 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3557 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3558 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3559 | icmd = &elsiocb->iocb; |
| 3560 | oldcmd = &oldiocb->iocb; |
| 3561 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3562 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3563 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3564 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 3565 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3566 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3567 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3568 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3569 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3570 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3571 | rn = (RNID *) (pcmd); |
| 3572 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3573 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 3574 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3575 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3576 | switch (format) { |
| 3577 | case 0: |
| 3578 | rn->SpecificLen = 0; |
| 3579 | break; |
| 3580 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3581 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3582 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3583 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3584 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 3585 | rn->un.topologyDisc.physPort = 0; |
| 3586 | rn->un.topologyDisc.attachedNodes = 0; |
| 3587 | break; |
| 3588 | default: |
| 3589 | rn->CommonLen = 0; |
| 3590 | rn->SpecificLen = 0; |
| 3591 | break; |
| 3592 | } |
| 3593 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3594 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3595 | "Issue ACC RNID: did:x%x flg:x%x", |
| 3596 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3597 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3598 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3599 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3600 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3601 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 3602 | * it could be freed */ |
| 3603 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3604 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3605 | if (rc == IOCB_ERROR) { |
| 3606 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3607 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3608 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3609 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3610 | } |
| 3611 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3612 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3613 | * 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] | 3614 | * @vport: pointer to a host virtual N_Port data structure. |
| 3615 | * |
| 3616 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 3617 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 3618 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 3619 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 3620 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 3621 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 3622 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 3623 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 3624 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 3625 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 3626 | * no more ADISC need to be sent. |
| 3627 | * |
| 3628 | * Return code |
| 3629 | * The number of N_Ports with adisc issued. |
| 3630 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3631 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3632 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3633 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3634 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3635 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3636 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3637 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3638 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3639 | 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] | 3640 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3641 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3642 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3643 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3644 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3645 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3646 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3647 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3648 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3649 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 3650 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3651 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3652 | vport->num_disc_nodes++; |
| 3653 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3654 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3655 | spin_lock_irq(shost->host_lock); |
| 3656 | vport->fc_flag |= FC_NLP_MORE; |
| 3657 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3658 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3659 | } |
| 3660 | } |
| 3661 | } |
| 3662 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3663 | spin_lock_irq(shost->host_lock); |
| 3664 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3665 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3666 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3667 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3668 | } |
| 3669 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3670 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3671 | * 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] | 3672 | * @vport: pointer to a host virtual N_Port data structure. |
| 3673 | * |
| 3674 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 3675 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 3676 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 3677 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 3678 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 3679 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 3680 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 3681 | * later pick up. On the other hand, after walking through all the ndlps with |
| 3682 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 3683 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 3684 | * PLOGI need to be sent. |
| 3685 | * |
| 3686 | * Return code |
| 3687 | * The number of N_Ports with plogi issued. |
| 3688 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3689 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3690 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3691 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3692 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3693 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3694 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3695 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3696 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 3697 | 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] | 3698 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3699 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3700 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3701 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3702 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 3703 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 3704 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3705 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 3706 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3707 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3708 | vport->num_disc_nodes++; |
| 3709 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3710 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3711 | spin_lock_irq(shost->host_lock); |
| 3712 | vport->fc_flag |= FC_NLP_MORE; |
| 3713 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3714 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3715 | } |
| 3716 | } |
| 3717 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3718 | if (sentplogi) { |
| 3719 | lpfc_set_disctmo(vport); |
| 3720 | } |
| 3721 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3722 | spin_lock_irq(shost->host_lock); |
| 3723 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3724 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3725 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3726 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3727 | } |
| 3728 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3729 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3730 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3731 | * @vport: pointer to a host virtual N_Port data structure. |
| 3732 | * |
| 3733 | * This routine cleans up any Registration State Change Notification |
| 3734 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 3735 | * @vport together with the host_lock is used to prevent multiple thread |
| 3736 | * trying to access the RSCN array on a same @vport at the same time. |
| 3737 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3738 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3739 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3740 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3741 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3742 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3743 | int i; |
| 3744 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3745 | spin_lock_irq(shost->host_lock); |
| 3746 | if (vport->fc_rscn_flush) { |
| 3747 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3748 | spin_unlock_irq(shost->host_lock); |
| 3749 | return; |
| 3750 | } |
| 3751 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 3752 | vport->fc_rscn_flush = 1; |
| 3753 | spin_unlock_irq(shost->host_lock); |
| 3754 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3755 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3756 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3757 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3758 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3759 | spin_lock_irq(shost->host_lock); |
| 3760 | vport->fc_rscn_id_cnt = 0; |
| 3761 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 3762 | spin_unlock_irq(shost->host_lock); |
| 3763 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3764 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 3765 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3766 | } |
| 3767 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3768 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3769 | * 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] | 3770 | * @vport: pointer to a host virtual N_Port data structure. |
| 3771 | * @did: remote destination port identifier. |
| 3772 | * |
| 3773 | * This routine checks whether there is any pending Registration State |
| 3774 | * Configuration Notification (RSCN) to a @did on @vport. |
| 3775 | * |
| 3776 | * Return code |
| 3777 | * None zero - The @did matched with a pending rscn |
| 3778 | * 0 - not able to match @did with a pending rscn |
| 3779 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3780 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3781 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3782 | { |
| 3783 | D_ID ns_did; |
| 3784 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3785 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3786 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3787 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3788 | |
| 3789 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3790 | |
| 3791 | /* Never match fabric nodes for RSCNs */ |
| 3792 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3793 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3794 | |
| 3795 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3796 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3797 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3798 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3799 | spin_lock_irq(shost->host_lock); |
| 3800 | if (vport->fc_rscn_flush) { |
| 3801 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3802 | spin_unlock_irq(shost->host_lock); |
| 3803 | return 0; |
| 3804 | } |
| 3805 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 3806 | vport->fc_rscn_flush = 1; |
| 3807 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3808 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3809 | lp = vport->fc_rscn_id_list[i]->virt; |
| 3810 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 3811 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3812 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3813 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 3814 | payload_len -= sizeof(uint32_t); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3815 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
| 3816 | case RSCN_ADDRESS_FORMAT_PORT: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3817 | if (ns_did.un.word == rscn_did.un.word) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3818 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3819 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3820 | case RSCN_ADDRESS_FORMAT_AREA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3821 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 3822 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3823 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3824 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3825 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3826 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3827 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3828 | break; |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3829 | case RSCN_ADDRESS_FORMAT_FABRIC: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3830 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3831 | } |
| 3832 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3833 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3834 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 3835 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3836 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3837 | return_did_out: |
| 3838 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 3839 | vport->fc_rscn_flush = 0; |
| 3840 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3841 | } |
| 3842 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3843 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3844 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3845 | * @vport: pointer to a host virtual N_Port data structure. |
| 3846 | * |
| 3847 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 3848 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 3849 | * State Change Notification). |
| 3850 | * |
| 3851 | * Return code |
| 3852 | * 0 - Successful (currently alway return 0) |
| 3853 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3854 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3855 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3856 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3857 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3858 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3859 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3860 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3861 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3862 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 3863 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3864 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3865 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3866 | NLP_EVT_DEVICE_RECOVERY); |
| 3867 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3868 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3869 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3870 | } |
| 3871 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3872 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3873 | * lpfc_send_rscn_event - Send an RSCN event to management application |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 3874 | * @vport: pointer to a host virtual N_Port data structure. |
| 3875 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3876 | * |
| 3877 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 3878 | * applications. |
| 3879 | */ |
| 3880 | static void |
| 3881 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 3882 | struct lpfc_iocbq *cmdiocb) |
| 3883 | { |
| 3884 | struct lpfc_dmabuf *pcmd; |
| 3885 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3886 | uint32_t *payload_ptr; |
| 3887 | uint32_t payload_len; |
| 3888 | struct lpfc_rscn_event_header *rscn_event_data; |
| 3889 | |
| 3890 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 3891 | payload_ptr = (uint32_t *) pcmd->virt; |
| 3892 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 3893 | |
| 3894 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 3895 | payload_len, GFP_KERNEL); |
| 3896 | if (!rscn_event_data) { |
| 3897 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3898 | "0147 Failed to allocate memory for RSCN event\n"); |
| 3899 | return; |
| 3900 | } |
| 3901 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 3902 | rscn_event_data->payload_length = payload_len; |
| 3903 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 3904 | payload_len); |
| 3905 | |
| 3906 | fc_host_post_vendor_event(shost, |
| 3907 | fc_get_event_number(), |
| 3908 | sizeof(struct lpfc_els_event_header) + payload_len, |
| 3909 | (char *)rscn_event_data, |
| 3910 | LPFC_NL_VENDOR_ID); |
| 3911 | |
| 3912 | kfree(rscn_event_data); |
| 3913 | } |
| 3914 | |
| 3915 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3916 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3917 | * @vport: pointer to a host virtual N_Port data structure. |
| 3918 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3919 | * @ndlp: pointer to a node-list data structure. |
| 3920 | * |
| 3921 | * This routine processes an unsolicited RSCN (Registration State Change |
| 3922 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 3923 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 3924 | * discover state machine is about to begin discovery, it just accepts the |
| 3925 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 3926 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 3927 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 3928 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 3929 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 3930 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 3931 | * routine is invoked to handle the RSCN event. |
| 3932 | * |
| 3933 | * Return code |
| 3934 | * 0 - Just sent the acc response |
| 3935 | * 1 - Sent the acc response and waited for name server completion |
| 3936 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3937 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3938 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3939 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3940 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3941 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3942 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3943 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3944 | uint32_t *lp, *datap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3945 | IOCB_t *icmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3946 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3947 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3948 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 3949 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3950 | |
| 3951 | icmd = &cmdiocb->iocb; |
| 3952 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 3953 | lp = (uint32_t *) pcmd->virt; |
| 3954 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3955 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 3956 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3957 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3958 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 3959 | "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] | 3960 | vport->fc_flag, payload_len, *lp, |
| 3961 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 3962 | |
| 3963 | /* Send an RSCN event to the management application */ |
| 3964 | lpfc_send_rscn_event(vport, cmdiocb); |
| 3965 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 3966 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3967 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 3968 | FCH_EVT_RSCN, lp[i]); |
| 3969 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3970 | /* If we are about to begin discovery, just ACC the RSCN. |
| 3971 | * Discovery processing will satisfy it. |
| 3972 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3973 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3974 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 3975 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 3976 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 3977 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3978 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3979 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3980 | } |
| 3981 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3982 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 3983 | * just ACC and ignore it. |
| 3984 | */ |
| 3985 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3986 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3987 | i = payload_len; |
| 3988 | datap = lp; |
| 3989 | while (i > 0) { |
| 3990 | nportid = *datap++; |
| 3991 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 3992 | i -= sizeof(uint32_t); |
| 3993 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3994 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 3995 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3996 | } |
| 3997 | if (rscn_id == hba_id) { |
| 3998 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3999 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4000 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4001 | "Data: x%x x%x x%x x%x\n", |
| 4002 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4003 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4004 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4005 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 4006 | ndlp->nlp_DID, vport->port_state, |
| 4007 | ndlp->nlp_flag); |
| 4008 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4009 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4010 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4011 | return 0; |
| 4012 | } |
| 4013 | } |
| 4014 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4015 | spin_lock_irq(shost->host_lock); |
| 4016 | if (vport->fc_rscn_flush) { |
| 4017 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4018 | spin_unlock_irq(shost->host_lock); |
| 4019 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4020 | /* Send back ACC */ |
| 4021 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4022 | return 0; |
| 4023 | } |
| 4024 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4025 | vport->fc_rscn_flush = 1; |
| 4026 | spin_unlock_irq(shost->host_lock); |
| 4027 | /* Get the array count after sucessfully have the token */ |
| 4028 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4029 | /* If we are already processing an RSCN, save the received |
| 4030 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 4031 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4032 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4033 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4034 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 4035 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4036 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4037 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4038 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 4039 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4040 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4041 | vport->fc_flag |= FC_RSCN_MODE; |
| 4042 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4043 | if (rscn_cnt) { |
| 4044 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 4045 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 4046 | } |
| 4047 | if ((rscn_cnt) && |
| 4048 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 4049 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4050 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4051 | memcpy(((uint8_t *)cmd) + length, lp, |
| 4052 | payload_len); |
| 4053 | } else { |
| 4054 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 4055 | vport->fc_rscn_id_cnt++; |
| 4056 | /* If we zero, cmdiocb->context2, the calling |
| 4057 | * routine will not try to free it. |
| 4058 | */ |
| 4059 | cmdiocb->context2 = NULL; |
| 4060 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4061 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4062 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4063 | "0235 Deferred RSCN " |
| 4064 | "Data: x%x x%x x%x\n", |
| 4065 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4066 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4067 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4068 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 4069 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4070 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4071 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4072 | "0234 ReDiscovery RSCN " |
| 4073 | "Data: x%x x%x x%x\n", |
| 4074 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4075 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4076 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4077 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4078 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4079 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4080 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4081 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4082 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4083 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4084 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4085 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4086 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4087 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4088 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4089 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 4090 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4091 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4092 | spin_lock_irq(shost->host_lock); |
| 4093 | vport->fc_flag |= FC_RSCN_MODE; |
| 4094 | spin_unlock_irq(shost->host_lock); |
| 4095 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4096 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4097 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4098 | /* |
| 4099 | * If we zero, cmdiocb->context2, the calling routine will |
| 4100 | * not try to free it. |
| 4101 | */ |
| 4102 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4103 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4104 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4105 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4106 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4107 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4108 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4109 | } |
| 4110 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4111 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4112 | * lpfc_els_handle_rscn - Handle rscn for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4113 | * @vport: pointer to a host virtual N_Port data structure. |
| 4114 | * |
| 4115 | * This routine handles the Registration State Configuration Notification |
| 4116 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 4117 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 4118 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 4119 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 4120 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 4121 | * RSCN activities with the @vport. |
| 4122 | * |
| 4123 | * Return code |
| 4124 | * 0 - Cleaned up rscn on the @vport |
| 4125 | * 1 - Wait for plogi to name server before proceed |
| 4126 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4127 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4128 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4129 | { |
| 4130 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4131 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4132 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4133 | /* Ignore RSCN if the port is being torn down. */ |
| 4134 | if (vport->load_flag & FC_UNLOADING) { |
| 4135 | lpfc_els_flush_rscn(vport); |
| 4136 | return 0; |
| 4137 | } |
| 4138 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4139 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4140 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4141 | |
| 4142 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4143 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4144 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 4145 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 4146 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4147 | |
| 4148 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4149 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4150 | vport->num_disc_nodes = 0; |
| 4151 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4152 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4153 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 4154 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4155 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4156 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4157 | /* Wait for NameServer query cmpl before we can |
| 4158 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4159 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4160 | } else { |
| 4161 | /* If login to NameServer does not exist, issue one */ |
| 4162 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4163 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4164 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4165 | /* Wait for NameServer login cmpl before we can |
| 4166 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4167 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4168 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4169 | if (ndlp) { |
| 4170 | ndlp = lpfc_enable_node(vport, ndlp, |
| 4171 | NLP_STE_PLOGI_ISSUE); |
| 4172 | if (!ndlp) { |
| 4173 | lpfc_els_flush_rscn(vport); |
| 4174 | return 0; |
| 4175 | } |
| 4176 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4177 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4178 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4179 | if (!ndlp) { |
| 4180 | lpfc_els_flush_rscn(vport); |
| 4181 | return 0; |
| 4182 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4183 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4184 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4185 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4186 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4187 | ndlp->nlp_type |= NLP_FABRIC; |
| 4188 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 4189 | /* Wait for NameServer login cmpl before we can |
| 4190 | * continue |
| 4191 | */ |
| 4192 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4193 | } |
| 4194 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4195 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4196 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4197 | } |
| 4198 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4199 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4200 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4201 | * @vport: pointer to a host virtual N_Port data structure. |
| 4202 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4203 | * @ndlp: pointer to a node-list data structure. |
| 4204 | * |
| 4205 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 4206 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 4207 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 4208 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 4209 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 4210 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 4211 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 4212 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 4213 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 4214 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 4215 | * higher priority (as the winning port) and will initiate PLOGI and |
| 4216 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 4217 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 4218 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 4219 | * |
| 4220 | * Return code |
| 4221 | * 0 - Successfully processed the unsolicited flogi |
| 4222 | * 1 - Failed to process the unsolicited flogi |
| 4223 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4224 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4225 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4226 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4227 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4228 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4229 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4230 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4231 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 4232 | IOCB_t *icmd = &cmdiocb->iocb; |
| 4233 | struct serv_parm *sp; |
| 4234 | LPFC_MBOXQ_t *mbox; |
| 4235 | struct ls_rjt stat; |
| 4236 | uint32_t cmd, did; |
| 4237 | int rc; |
| 4238 | |
| 4239 | cmd = *lp++; |
| 4240 | sp = (struct serv_parm *) lp; |
| 4241 | |
| 4242 | /* FLOGI received */ |
| 4243 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4244 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4245 | |
| 4246 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 4247 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 4248 | did = icmd->un.elsreq64.remoteID; |
| 4249 | |
| 4250 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 4251 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4252 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4253 | "0113 An FLOGI ELS command x%x was " |
| 4254 | "received from DID x%x in Loop Mode\n", |
| 4255 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4256 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4257 | } |
| 4258 | |
| 4259 | did = Fabric_DID; |
| 4260 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4261 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4262 | /* For a FLOGI we accept, then if our portname is greater |
| 4263 | * then the remote portname we initiate Nport login. |
| 4264 | */ |
| 4265 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4266 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4267 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4268 | |
| 4269 | if (!rc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4270 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4271 | if (!mbox) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4272 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4273 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4274 | lpfc_linkdown(phba); |
| 4275 | lpfc_init_link(phba, mbox, |
| 4276 | phba->cfg_topology, |
| 4277 | phba->cfg_link_speed); |
| 4278 | mbox->mb.un.varInitLnk.lipsr_AL_PA = 0; |
| 4279 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4280 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4281 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4282 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4283 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4284 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4285 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4286 | return 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4287 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4288 | spin_lock_irq(shost->host_lock); |
| 4289 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 4290 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4291 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4292 | spin_lock_irq(shost->host_lock); |
| 4293 | vport->fc_flag |= FC_PT2PT; |
| 4294 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 4295 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4296 | } else { |
| 4297 | /* Reject this request because invalid parameters */ |
| 4298 | stat.un.b.lsRjtRsvd0 = 0; |
| 4299 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4300 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 4301 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4302 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4303 | NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4304 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4305 | } |
| 4306 | |
| 4307 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4308 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4309 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4310 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4311 | } |
| 4312 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4313 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4314 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4315 | * @vport: pointer to a host virtual N_Port data structure. |
| 4316 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4317 | * @ndlp: pointer to a node-list data structure. |
| 4318 | * |
| 4319 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 4320 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 4321 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 4322 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 4323 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 4324 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 4325 | * |
| 4326 | * Return code |
| 4327 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 4328 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4329 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4330 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4331 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4332 | { |
| 4333 | struct lpfc_dmabuf *pcmd; |
| 4334 | uint32_t *lp; |
| 4335 | IOCB_t *icmd; |
| 4336 | RNID *rn; |
| 4337 | struct ls_rjt stat; |
| 4338 | uint32_t cmd, did; |
| 4339 | |
| 4340 | icmd = &cmdiocb->iocb; |
| 4341 | did = icmd->un.elsreq64.remoteID; |
| 4342 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4343 | lp = (uint32_t *) pcmd->virt; |
| 4344 | |
| 4345 | cmd = *lp++; |
| 4346 | rn = (RNID *) lp; |
| 4347 | |
| 4348 | /* RNID received */ |
| 4349 | |
| 4350 | switch (rn->Format) { |
| 4351 | case 0: |
| 4352 | case RNID_TOPOLOGY_DISC: |
| 4353 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4354 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4355 | break; |
| 4356 | default: |
| 4357 | /* Reject this request because format not supported */ |
| 4358 | stat.un.b.lsRjtRsvd0 = 0; |
| 4359 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4360 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4361 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4362 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4363 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4364 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4365 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4366 | } |
| 4367 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4368 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4369 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4370 | * @vport: pointer to a host virtual N_Port data structure. |
| 4371 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4372 | * @ndlp: pointer to a node-list data structure. |
| 4373 | * |
| 4374 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 4375 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 4376 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 4377 | * |
| 4378 | * Return code |
| 4379 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 4380 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4381 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4382 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4383 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4384 | { |
| 4385 | struct ls_rjt stat; |
| 4386 | |
| 4387 | /* For now, unconditionally reject this command */ |
| 4388 | stat.un.b.lsRjtRsvd0 = 0; |
| 4389 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4390 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4391 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4392 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4393 | return 0; |
| 4394 | } |
| 4395 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4396 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4397 | * 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] | 4398 | * @phba: pointer to lpfc hba data structure. |
| 4399 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4400 | * |
| 4401 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 4402 | * mailbox command. This callback function is to actually send the Accept |
| 4403 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 4404 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 4405 | * mailbox command, constructs the RPS response with the link statistics |
| 4406 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 4407 | * response to the RPS. |
| 4408 | * |
| 4409 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4410 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4411 | * will be stored into the context1 field of the IOCB for the completion |
| 4412 | * callback function to the RPS Accept Response ELS IOCB command. |
| 4413 | * |
| 4414 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4415 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4416 | 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] | 4417 | { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4418 | MAILBOX_t *mb; |
| 4419 | IOCB_t *icmd; |
| 4420 | RPS_RSP *rps_rsp; |
| 4421 | uint8_t *pcmd; |
| 4422 | struct lpfc_iocbq *elsiocb; |
| 4423 | struct lpfc_nodelist *ndlp; |
| 4424 | uint16_t xri, status; |
| 4425 | uint32_t cmdsize; |
| 4426 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4427 | mb = &pmb->mb; |
| 4428 | |
| 4429 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4430 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 4431 | pmb->context1 = NULL; |
| 4432 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4433 | |
| 4434 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4435 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4436 | return; |
| 4437 | } |
| 4438 | |
| 4439 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4440 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4441 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 4442 | lpfc_max_els_tries, ndlp, |
| 4443 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4444 | |
| 4445 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4446 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4447 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4448 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4449 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4450 | |
| 4451 | icmd = &elsiocb->iocb; |
| 4452 | icmd->ulpContext = xri; |
| 4453 | |
| 4454 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4455 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4456 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4457 | rps_rsp = (RPS_RSP *)pcmd; |
| 4458 | |
| 4459 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| 4460 | status = 0x10; |
| 4461 | else |
| 4462 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4463 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4464 | status |= 0x4; |
| 4465 | |
| 4466 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4467 | rps_rsp->portStatus = cpu_to_be16(status); |
| 4468 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 4469 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 4470 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 4471 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 4472 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 4473 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4474 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4475 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 4476 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 4477 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4478 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4479 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4480 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4481 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4482 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 4483 | 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] | 4484 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4485 | return; |
| 4486 | } |
| 4487 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4488 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4489 | * lpfc_els_rcv_rps - Process an unsolicited rps iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4490 | * @vport: pointer to a host virtual N_Port data structure. |
| 4491 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4492 | * @ndlp: pointer to a node-list data structure. |
| 4493 | * |
| 4494 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 4495 | * ELS unsolicited event. It first checks the remote port state. If the |
| 4496 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 4497 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 4498 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 4499 | * for reading the HBA link statistics. It is for the callback function, |
| 4500 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 4501 | * to actually sending out RPS Accept (ACC) response. |
| 4502 | * |
| 4503 | * Return codes |
| 4504 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 4505 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4506 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4507 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4508 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4509 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4510 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4511 | uint32_t *lp; |
| 4512 | uint8_t flag; |
| 4513 | LPFC_MBOXQ_t *mbox; |
| 4514 | struct lpfc_dmabuf *pcmd; |
| 4515 | RPS *rps; |
| 4516 | struct ls_rjt stat; |
| 4517 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4518 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4519 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 4520 | /* reject the unsolicited RPS request and done with it */ |
| 4521 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4522 | |
| 4523 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4524 | lp = (uint32_t *) pcmd->virt; |
| 4525 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 4526 | rps = (RPS *) lp; |
| 4527 | |
| 4528 | if ((flag == 0) || |
| 4529 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4530 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4531 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4532 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4533 | printk("Fix me....\n"); |
| 4534 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4535 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 4536 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4537 | lpfc_read_lnk_stat(phba, mbox); |
| 4538 | mbox->context1 = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4539 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4540 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4541 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4542 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4543 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4544 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4545 | /* Mbox completion will send ELS Response */ |
| 4546 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4547 | /* Decrement reference count used for the failed mbox |
| 4548 | * command. |
| 4549 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4550 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4551 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4552 | } |
| 4553 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4554 | |
| 4555 | reject_out: |
| 4556 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4557 | stat.un.b.lsRjtRsvd0 = 0; |
| 4558 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4559 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4560 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4561 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4562 | return 0; |
| 4563 | } |
| 4564 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4565 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4566 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4567 | * @vport: pointer to a host virtual N_Port data structure. |
| 4568 | * @cmdsize: size of the ELS command. |
| 4569 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4570 | * @ndlp: pointer to a node-list data structure. |
| 4571 | * |
| 4572 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 4573 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 4574 | * |
| 4575 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4576 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4577 | * will be stored into the context1 field of the IOCB for the completion |
| 4578 | * callback function to the RPL Accept Response ELS command. |
| 4579 | * |
| 4580 | * Return code |
| 4581 | * 0 - Successfully issued ACC RPL ELS command |
| 4582 | * 1 - Failed to issue ACC RPL ELS command |
| 4583 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4584 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4585 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 4586 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4587 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4588 | struct lpfc_hba *phba = vport->phba; |
| 4589 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4590 | RPL_RSP rpl_rsp; |
| 4591 | struct lpfc_iocbq *elsiocb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4592 | uint8_t *pcmd; |
| 4593 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4594 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4595 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4596 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4597 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4598 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4599 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4600 | icmd = &elsiocb->iocb; |
| 4601 | oldcmd = &oldiocb->iocb; |
| 4602 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 4603 | |
| 4604 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4605 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4606 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4607 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 4608 | pcmd += sizeof(uint16_t); |
| 4609 | |
| 4610 | /* Setup the RPL ACC payload */ |
| 4611 | rpl_rsp.listLen = be32_to_cpu(1); |
| 4612 | rpl_rsp.index = 0; |
| 4613 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4614 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 4615 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4616 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4617 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4618 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4619 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4620 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 4621 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 4622 | "rpi x%x\n", |
| 4623 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4624 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4625 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4626 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4627 | phba->fc_stat.elsXmitACC++; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 4628 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 4629 | IOCB_ERROR) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4630 | lpfc_els_free_iocb(phba, elsiocb); |
| 4631 | return 1; |
| 4632 | } |
| 4633 | return 0; |
| 4634 | } |
| 4635 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4636 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4637 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4638 | * @vport: pointer to a host virtual N_Port data structure. |
| 4639 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4640 | * @ndlp: pointer to a node-list data structure. |
| 4641 | * |
| 4642 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 4643 | * unsolicited event. It first checks the remote port state. If the remote |
| 4644 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 4645 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 4646 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 4647 | * to accept the RPL. |
| 4648 | * |
| 4649 | * Return code |
| 4650 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 4651 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4652 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4653 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4654 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4655 | { |
| 4656 | struct lpfc_dmabuf *pcmd; |
| 4657 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4658 | uint32_t maxsize; |
| 4659 | uint16_t cmdsize; |
| 4660 | RPL *rpl; |
| 4661 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4662 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4663 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 4664 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4665 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4666 | stat.un.b.lsRjtRsvd0 = 0; |
| 4667 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4668 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4669 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4670 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4671 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4672 | /* rejected the unsolicited RPL request and done with it */ |
| 4673 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4674 | } |
| 4675 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4676 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4677 | lp = (uint32_t *) pcmd->virt; |
| 4678 | rpl = (RPL *) (lp + 1); |
| 4679 | |
| 4680 | maxsize = be32_to_cpu(rpl->maxsize); |
| 4681 | |
| 4682 | /* We support only one port */ |
| 4683 | if ((rpl->index == 0) && |
| 4684 | ((maxsize == 0) || |
| 4685 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 4686 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4687 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4688 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 4689 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4690 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4691 | |
| 4692 | return 0; |
| 4693 | } |
| 4694 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4695 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4696 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4697 | * @vport: pointer to a virtual N_Port data structure. |
| 4698 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4699 | * @ndlp: pointer to a node-list data structure. |
| 4700 | * |
| 4701 | * This routine processes Fibre Channel Address Resolution Protocol |
| 4702 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 4703 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 4704 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 4705 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 4706 | * remote PortName is compared against the FC PortName stored in the @vport |
| 4707 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 4708 | * compared against the FC NodeName stored in the @vport data structure. |
| 4709 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 4710 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 4711 | * invoked to send out FARP Response to the remote node. Before sending the |
| 4712 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 4713 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 4714 | * routine is invoked to log into the remote port first. |
| 4715 | * |
| 4716 | * Return code |
| 4717 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 4718 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4719 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4720 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4721 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4722 | { |
| 4723 | struct lpfc_dmabuf *pcmd; |
| 4724 | uint32_t *lp; |
| 4725 | IOCB_t *icmd; |
| 4726 | FARP *fp; |
| 4727 | uint32_t cmd, cnt, did; |
| 4728 | |
| 4729 | icmd = &cmdiocb->iocb; |
| 4730 | did = icmd->un.elsreq64.remoteID; |
| 4731 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4732 | lp = (uint32_t *) pcmd->virt; |
| 4733 | |
| 4734 | cmd = *lp++; |
| 4735 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4736 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4737 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4738 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4739 | /* We will only support match on WWPN or WWNN */ |
| 4740 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4741 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4742 | } |
| 4743 | |
| 4744 | cnt = 0; |
| 4745 | /* If this FARP command is searching for my portname */ |
| 4746 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4747 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4748 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4749 | cnt = 1; |
| 4750 | } |
| 4751 | |
| 4752 | /* If this FARP command is searching for my nodename */ |
| 4753 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4754 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4755 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4756 | cnt = 1; |
| 4757 | } |
| 4758 | |
| 4759 | if (cnt) { |
| 4760 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 4761 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 4762 | /* Log back into the node before sending the FARP. */ |
| 4763 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4764 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4765 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4766 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4767 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4768 | } |
| 4769 | |
| 4770 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4771 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 4772 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4773 | } |
| 4774 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4775 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4776 | } |
| 4777 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4778 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4779 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4780 | * @vport: pointer to a host virtual N_Port data structure. |
| 4781 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4782 | * @ndlp: pointer to a node-list data structure. |
| 4783 | * |
| 4784 | * This routine processes Fibre Channel Address Resolution Protocol |
| 4785 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 4786 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 4787 | * the FARP response request. |
| 4788 | * |
| 4789 | * Return code |
| 4790 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 4791 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4792 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4793 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4794 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4795 | { |
| 4796 | struct lpfc_dmabuf *pcmd; |
| 4797 | uint32_t *lp; |
| 4798 | IOCB_t *icmd; |
| 4799 | uint32_t cmd, did; |
| 4800 | |
| 4801 | icmd = &cmdiocb->iocb; |
| 4802 | did = icmd->un.elsreq64.remoteID; |
| 4803 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4804 | lp = (uint32_t *) pcmd->virt; |
| 4805 | |
| 4806 | cmd = *lp++; |
| 4807 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4808 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4809 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4810 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4811 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4812 | |
| 4813 | return 0; |
| 4814 | } |
| 4815 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4816 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4817 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4818 | * @vport: pointer to a host virtual N_Port data structure. |
| 4819 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4820 | * @fan_ndlp: pointer to a node-list data structure. |
| 4821 | * |
| 4822 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 4823 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 4824 | * only be processed on a physical port (i.e., the @vport represents the |
| 4825 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 4826 | * compared against those in the phba data structure. If any of those is |
| 4827 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 4828 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 4829 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 4830 | * is invoked to register login to the fabric. |
| 4831 | * |
| 4832 | * Return code |
| 4833 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 4834 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4835 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4836 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4837 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4838 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4839 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4840 | uint32_t *lp; |
| 4841 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4842 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4843 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 4844 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 4845 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4846 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4847 | if ((vport == phba->pport) && |
| 4848 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4849 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4850 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4851 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4852 | sizeof(struct lpfc_name)))) { |
| 4853 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4854 | lpfc_initial_flogi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4855 | } else { |
| 4856 | /* FAN verified - skip FLOGI */ |
| 4857 | vport->fc_myDID = vport->fc_prevDID; |
| 4858 | lpfc_issue_fabric_reglogin(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4859 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4860 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4861 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4862 | } |
| 4863 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4864 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4865 | * lpfc_els_timeout - Handler funciton to the els timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4866 | * @ptr: holder for the timer function associated data. |
| 4867 | * |
| 4868 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 4869 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 4870 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 4871 | * up the worker thread. It is for the worker thread to invoke the routine |
| 4872 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 4873 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4874 | void |
| 4875 | lpfc_els_timeout(unsigned long ptr) |
| 4876 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4877 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 4878 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4879 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4880 | unsigned long iflag; |
| 4881 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4882 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4883 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
| 4884 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4885 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4886 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4887 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4888 | if (!tmo_posted) |
| 4889 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4890 | return; |
| 4891 | } |
| 4892 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4893 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4894 | * lpfc_els_timeout_handler - Process an els timeout event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4895 | * @vport: pointer to a virtual N_Port data structure. |
| 4896 | * |
| 4897 | * This routine is the actual handler function that processes an ELS timeout |
| 4898 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 4899 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 4900 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 4901 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4902 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4903 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4904 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4905 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4906 | struct lpfc_sli_ring *pring; |
| 4907 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 4908 | IOCB_t *cmd = NULL; |
| 4909 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4910 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4911 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4912 | uint32_t remote_ID = 0xffffffff; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4913 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4914 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4915 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 4916 | |
| 4917 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4918 | |
| 4919 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 4920 | cmd = &piocb->iocb; |
| 4921 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4922 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 4923 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 4924 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4925 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4926 | |
| 4927 | if (piocb->vport != vport) |
| 4928 | continue; |
| 4929 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4930 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4931 | if (pcmd) |
| 4932 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4933 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4934 | if (els_command == ELS_CMD_FARP || |
| 4935 | els_command == ELS_CMD_FARPR || |
| 4936 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4937 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4938 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4939 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4940 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4941 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4942 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4943 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4944 | continue; |
| 4945 | } |
| 4946 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4947 | remote_ID = 0xffffffff; |
| 4948 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4949 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4950 | else { |
| 4951 | struct lpfc_nodelist *ndlp; |
| 4952 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4953 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4954 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4955 | } |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4956 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4957 | "0127 ELS timeout Data: x%x x%x x%x " |
| 4958 | "x%x\n", els_command, |
| 4959 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4960 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4961 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4962 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 4963 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4964 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
| 4965 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4966 | } |
| 4967 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4968 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4969 | * 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] | 4970 | * @vport: pointer to a host virtual N_Port data structure. |
| 4971 | * |
| 4972 | * This routine is used to clean up all the outstanding ELS commands on a |
| 4973 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 4974 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 4975 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 4976 | * the IOCBs with a non-NULL completion callback function, the callback |
| 4977 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 4978 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 4979 | * callback function, the IOCB will simply be released. Finally, it walks |
| 4980 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 4981 | * completion queue IOCB that is associated with the @vport and is not |
| 4982 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 4983 | * part of the discovery state machine) out to HBA by invoking the |
| 4984 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 4985 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 4986 | * the IOCBs are aborted when this function returns. |
| 4987 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4988 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4989 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4990 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4991 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4992 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4993 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4994 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 4995 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4996 | |
| 4997 | lpfc_fabric_abort_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4998 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4999 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5000 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5001 | cmd = &piocb->iocb; |
| 5002 | |
| 5003 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5004 | continue; |
| 5005 | } |
| 5006 | |
| 5007 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5008 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5009 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5010 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5011 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5012 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5013 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5014 | if (piocb->vport != vport) |
| 5015 | continue; |
| 5016 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5017 | list_move_tail(&piocb->list, &completions); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5018 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5019 | } |
| 5020 | |
| 5021 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5022 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5023 | continue; |
| 5024 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5025 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5026 | if (piocb->vport != vport) |
| 5027 | continue; |
| 5028 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5029 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5030 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5031 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5032 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5033 | /* Cancell all the IOCBs from the completions list */ |
| 5034 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5035 | IOERR_SLI_ABORTED); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5036 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5037 | return; |
| 5038 | } |
| 5039 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5040 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5041 | * 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] | 5042 | * @phba: pointer to lpfc hba data structure. |
| 5043 | * |
| 5044 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5045 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 5046 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5047 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5048 | * the IOCBs with the completion callback function associated, the callback |
| 5049 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5050 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 5051 | * callback function associated, the IOCB will simply be released. Finally, |
| 5052 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 5053 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 5054 | * management plane IOCBs that are not part of the discovery state machine) |
| 5055 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5056 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5057 | void |
| 5058 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 5059 | { |
| 5060 | LIST_HEAD(completions); |
| 5061 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 5062 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5063 | IOCB_t *cmd = NULL; |
| 5064 | |
| 5065 | lpfc_fabric_abort_hba(phba); |
| 5066 | spin_lock_irq(&phba->hbalock); |
| 5067 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5068 | cmd = &piocb->iocb; |
| 5069 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5070 | continue; |
| 5071 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
| 5072 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5073 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5074 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5075 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| 5076 | continue; |
| 5077 | list_move_tail(&piocb->list, &completions); |
| 5078 | pring->txq_cnt--; |
| 5079 | } |
| 5080 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5081 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5082 | continue; |
| 5083 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5084 | } |
| 5085 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5086 | |
| 5087 | /* Cancel all the IOCBs from the completions list */ |
| 5088 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5089 | IOERR_SLI_ABORTED); |
| 5090 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5091 | return; |
| 5092 | } |
| 5093 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5094 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5095 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5096 | * @phba: Pointer to hba context object. |
| 5097 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 5098 | * @rspiocbp: Pointer to response iocb which reported error. |
| 5099 | * |
| 5100 | * This function sends an event when there is an ELS command |
| 5101 | * failure. |
| 5102 | **/ |
| 5103 | void |
| 5104 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 5105 | struct lpfc_iocbq *cmdiocbp, |
| 5106 | struct lpfc_iocbq *rspiocbp) |
| 5107 | { |
| 5108 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 5109 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5110 | struct lpfc_lsrjt_event lsrjt_event; |
| 5111 | struct lpfc_fabric_event_header fabric_event; |
| 5112 | struct ls_rjt stat; |
| 5113 | struct lpfc_nodelist *ndlp; |
| 5114 | uint32_t *pcmd; |
| 5115 | |
| 5116 | ndlp = cmdiocbp->context1; |
| 5117 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 5118 | return; |
| 5119 | |
| 5120 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 5121 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 5122 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 5123 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 5124 | sizeof(struct lpfc_name)); |
| 5125 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 5126 | sizeof(struct lpfc_name)); |
| 5127 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 5128 | cmdiocbp->context2)->virt); |
| 5129 | lsrjt_event.command = *pcmd; |
| 5130 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 5131 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 5132 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 5133 | fc_host_post_vendor_event(shost, |
| 5134 | fc_get_event_number(), |
| 5135 | sizeof(lsrjt_event), |
| 5136 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5137 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5138 | return; |
| 5139 | } |
| 5140 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 5141 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 5142 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 5143 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 5144 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 5145 | else |
| 5146 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 5147 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 5148 | sizeof(struct lpfc_name)); |
| 5149 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 5150 | sizeof(struct lpfc_name)); |
| 5151 | fc_host_post_vendor_event(shost, |
| 5152 | fc_get_event_number(), |
| 5153 | sizeof(fabric_event), |
| 5154 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5155 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5156 | return; |
| 5157 | } |
| 5158 | |
| 5159 | } |
| 5160 | |
| 5161 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5162 | * lpfc_send_els_event - Posts unsolicited els event |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5163 | * @vport: Pointer to vport object. |
| 5164 | * @ndlp: Pointer FC node object. |
| 5165 | * @cmd: ELS command code. |
| 5166 | * |
| 5167 | * This function posts an event when there is an incoming |
| 5168 | * unsolicited ELS command. |
| 5169 | **/ |
| 5170 | static void |
| 5171 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 5172 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5173 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5174 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5175 | struct lpfc_els_event_header *els_data = NULL; |
| 5176 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5177 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5178 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5179 | if (*payload == ELS_CMD_LOGO) { |
| 5180 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 5181 | if (!logo_data) { |
| 5182 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5183 | "0148 Failed to allocate memory " |
| 5184 | "for LOGO event\n"); |
| 5185 | return; |
| 5186 | } |
| 5187 | els_data = &logo_data->header; |
| 5188 | } else { |
| 5189 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 5190 | GFP_KERNEL); |
| 5191 | if (!els_data) { |
| 5192 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5193 | "0149 Failed to allocate memory " |
| 5194 | "for ELS event\n"); |
| 5195 | return; |
| 5196 | } |
| 5197 | } |
| 5198 | els_data->event_type = FC_REG_ELS_EVENT; |
| 5199 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5200 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5201 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5202 | break; |
| 5203 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5204 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5205 | break; |
| 5206 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5207 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 5208 | break; |
| 5209 | case ELS_CMD_LOGO: |
| 5210 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 5211 | /* Copy the WWPN in the LOGO payload */ |
| 5212 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 5213 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5214 | break; |
| 5215 | default: |
Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 5216 | kfree(els_data); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5217 | return; |
| 5218 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5219 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 5220 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 5221 | if (*payload == ELS_CMD_LOGO) { |
| 5222 | fc_host_post_vendor_event(shost, |
| 5223 | fc_get_event_number(), |
| 5224 | sizeof(struct lpfc_logo_event), |
| 5225 | (char *)logo_data, |
| 5226 | LPFC_NL_VENDOR_ID); |
| 5227 | kfree(logo_data); |
| 5228 | } else { |
| 5229 | fc_host_post_vendor_event(shost, |
| 5230 | fc_get_event_number(), |
| 5231 | sizeof(struct lpfc_els_event_header), |
| 5232 | (char *)els_data, |
| 5233 | LPFC_NL_VENDOR_ID); |
| 5234 | kfree(els_data); |
| 5235 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5236 | |
| 5237 | return; |
| 5238 | } |
| 5239 | |
| 5240 | |
| 5241 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5242 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5243 | * @phba: pointer to lpfc hba data structure. |
| 5244 | * @pring: pointer to a SLI ring. |
| 5245 | * @vport: pointer to a host virtual N_Port data structure. |
| 5246 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 5247 | * |
| 5248 | * This routine is used for processing the IOCB associated with a unsolicited |
| 5249 | * event. It first determines whether there is an existing ndlp that matches |
| 5250 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 5251 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 5252 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 5253 | * of the discovery state machine. |
| 5254 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5255 | static void |
| 5256 | 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] | 5257 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5258 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5259 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5260 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5261 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5262 | uint32_t *payload; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5263 | uint32_t cmd, did, newnode, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5264 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5265 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5266 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5267 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5268 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5269 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5270 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 5271 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5272 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5273 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5274 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5275 | did = icmd->un.rcvels.remoteID; |
| 5276 | if (icmd->ulpStatus) { |
| 5277 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5278 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 5279 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5280 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5281 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5282 | |
| 5283 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5284 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5285 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5286 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5287 | /* Ignore traffic recevied during vport shutdown. */ |
| 5288 | if (vport->load_flag & FC_UNLOADING) |
| 5289 | goto dropit; |
| 5290 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5291 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5292 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5293 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5294 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5295 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5296 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5297 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5298 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5299 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5300 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5301 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5302 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5303 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5304 | ndlp = lpfc_enable_node(vport, ndlp, |
| 5305 | NLP_STE_UNUSED_NODE); |
| 5306 | if (!ndlp) |
| 5307 | goto dropit; |
| 5308 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5309 | newnode = 1; |
| 5310 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 5311 | ndlp->nlp_type |= NLP_FABRIC; |
| 5312 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 5313 | /* This is similar to the new node path */ |
| 5314 | ndlp = lpfc_nlp_get(ndlp); |
| 5315 | if (!ndlp) |
| 5316 | goto dropit; |
| 5317 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5318 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5319 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5320 | |
| 5321 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5322 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5323 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5324 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5325 | |
| 5326 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 5327 | cmd &= ELS_CMD_MASK; |
| 5328 | } |
| 5329 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5330 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5331 | "0112 ELS command x%x received from NPORT x%x " |
| 5332 | "Data: x%x\n", cmd, did, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5333 | switch (cmd) { |
| 5334 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5335 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5336 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 5337 | did, vport->port_state, ndlp->nlp_flag); |
| 5338 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5339 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5340 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
| 5341 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5342 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5343 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5344 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 5345 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 5346 | rjt_err = LSRJT_UNABLE_TPC; |
| 5347 | break; |
| 5348 | } |
| 5349 | /* We get here, and drop thru, if we are PT2PT with |
| 5350 | * another NPort and the other side has initiated |
| 5351 | * the PLOGI before responding to our FLOGI. |
| 5352 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5353 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5354 | |
| 5355 | shost = lpfc_shost_from_vport(vport); |
| 5356 | spin_lock_irq(shost->host_lock); |
| 5357 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 5358 | spin_unlock_irq(shost->host_lock); |
| 5359 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5360 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5361 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5362 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5363 | break; |
| 5364 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5365 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5366 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 5367 | did, vport->port_state, ndlp->nlp_flag); |
| 5368 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5369 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5370 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5371 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5372 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5373 | break; |
| 5374 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5375 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5376 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 5377 | did, vport->port_state, ndlp->nlp_flag); |
| 5378 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5379 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5380 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5381 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5382 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5383 | break; |
| 5384 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5385 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5386 | break; |
| 5387 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5388 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5389 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 5390 | did, vport->port_state, ndlp->nlp_flag); |
| 5391 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5392 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5393 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5394 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5395 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5396 | break; |
| 5397 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5398 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5399 | break; |
| 5400 | case ELS_CMD_RSCN: |
| 5401 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5402 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5403 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5404 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5405 | break; |
| 5406 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5407 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5408 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 5409 | did, vport->port_state, ndlp->nlp_flag); |
| 5410 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5411 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5412 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5413 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5414 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5415 | break; |
| 5416 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5417 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5418 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5419 | break; |
| 5420 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5421 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5422 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 5423 | did, vport->port_state, ndlp->nlp_flag); |
| 5424 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5425 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5426 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5427 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5428 | break; |
| 5429 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5430 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5431 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5432 | break; |
| 5433 | case ELS_CMD_FARPR: |
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 FARPR: 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.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5439 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5440 | break; |
| 5441 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5442 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5443 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 5444 | did, vport->port_state, ndlp->nlp_flag); |
| 5445 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5446 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5447 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5448 | break; |
| 5449 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5450 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5451 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 5452 | did, vport->port_state, ndlp->nlp_flag); |
| 5453 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5454 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5455 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5456 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5457 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5458 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5459 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 5460 | did, vport->port_state, ndlp->nlp_flag); |
| 5461 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5462 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5463 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5464 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5465 | break; |
| 5466 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5467 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5468 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5469 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5470 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5471 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 5472 | did, vport->port_state, ndlp->nlp_flag); |
| 5473 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5474 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5475 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5476 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5477 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5478 | break; |
| 5479 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5480 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5481 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 5482 | did, vport->port_state, ndlp->nlp_flag); |
| 5483 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5484 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5485 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5486 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5487 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5488 | break; |
| 5489 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5490 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5491 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 5492 | did, vport->port_state, ndlp->nlp_flag); |
| 5493 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5494 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5495 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5496 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5497 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5498 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5499 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5500 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5501 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 5502 | did, vport->port_state, ndlp->nlp_flag); |
| 5503 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5504 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5505 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5506 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5507 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5508 | break; |
| 5509 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5510 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5511 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 5512 | cmd, did, vport->port_state); |
| 5513 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5514 | /* Unsupported ELS command, reject */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5515 | rjt_err = LSRJT_INVALID_CMD; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5516 | |
| 5517 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5518 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5519 | "0115 Unknown ELS command x%x " |
| 5520 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5521 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5522 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5523 | break; |
| 5524 | } |
| 5525 | |
| 5526 | /* check if need to LS_RJT received ELS cmd */ |
| 5527 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5528 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5529 | stat.un.b.lsRjtRsnCode = rjt_err; |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 5530 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5531 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 5532 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5533 | } |
| 5534 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5535 | lpfc_nlp_put(elsiocb->context1); |
| 5536 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5537 | return; |
| 5538 | |
| 5539 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5540 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
| 5541 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5542 | "(%d):0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5543 | "Data: x%x x%x x%x\n", |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5544 | vport->vpi, icmd->ulpStatus, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5545 | icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5546 | phba->fc_stat.elsRcvDrop++; |
| 5547 | } |
| 5548 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5549 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5550 | * 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] | 5551 | * @phba: pointer to lpfc hba data structure. |
| 5552 | * @vpi: host virtual N_Port identifier. |
| 5553 | * |
| 5554 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 5555 | * @vpi. The function walks the HBA's vport list and returns the address |
| 5556 | * of the vport with the matching @vpi. |
| 5557 | * |
| 5558 | * Return code |
| 5559 | * NULL - No vport with the matching @vpi found |
| 5560 | * Otherwise - Address to the vport with the matching @vpi. |
| 5561 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5562 | static struct lpfc_vport * |
| 5563 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 5564 | { |
| 5565 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5566 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5567 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5568 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5569 | list_for_each_entry(vport, &phba->port_list, listentry) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5570 | if (vport->vpi == vpi) { |
| 5571 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5572 | return vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5573 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5574 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5575 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5576 | return NULL; |
| 5577 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5578 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5579 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5580 | * 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] | 5581 | * @phba: pointer to lpfc hba data structure. |
| 5582 | * @pring: pointer to a SLI ring. |
| 5583 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 5584 | * |
| 5585 | * This routine is used to process an unsolicited event received from a SLI |
| 5586 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 5587 | * associated with the unsolicited event is done by invoking the routine |
| 5588 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 5589 | * SLI ring on which the unsolicited event was received. |
| 5590 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5591 | void |
| 5592 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 5593 | struct lpfc_iocbq *elsiocb) |
| 5594 | { |
| 5595 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5596 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5597 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5598 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 5599 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5600 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5601 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5602 | elsiocb->context2 = NULL; |
| 5603 | elsiocb->context3 = NULL; |
| 5604 | |
| 5605 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 5606 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 5607 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 5608 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5609 | phba->fc_stat.NoRcvBuf++; |
| 5610 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5611 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5612 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5613 | return; |
| 5614 | } |
| 5615 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5616 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 5617 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 5618 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 5619 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 5620 | vport = phba->pport; |
| 5621 | else { |
| 5622 | uint16_t vpi = icmd->unsli3.rcvsli3.vpi; |
| 5623 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 5624 | } |
| 5625 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5626 | /* If there are no BDEs associated |
| 5627 | * with this IOCB, there is nothing to do. |
| 5628 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5629 | if (icmd->ulpBdeCount == 0) |
| 5630 | return; |
| 5631 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5632 | /* type of ELS cmd is first 32bit word |
| 5633 | * in packet |
| 5634 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5635 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5636 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5637 | } else { |
| 5638 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 5639 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5640 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 5641 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5642 | } |
| 5643 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5644 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 5645 | /* |
| 5646 | * The different unsolicited event handlers would tell us |
| 5647 | * if they are done with "mp" by setting context2 to NULL. |
| 5648 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5649 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5650 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 5651 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5652 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5653 | |
| 5654 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5655 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5656 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5657 | elsiocb->context2 = bdeBuf2; |
| 5658 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5659 | /* free mp if we are done with it */ |
| 5660 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5661 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 5662 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5663 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5664 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5665 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5666 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5667 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5668 | * 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] | 5669 | * @phba: pointer to lpfc hba data structure. |
| 5670 | * @vport: pointer to a virtual N_Port data structure. |
| 5671 | * |
| 5672 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 5673 | * State Change Request (SCR) for a @vport. This routine will create an |
| 5674 | * ndlp for the Name Server associated to the @vport if such node does |
| 5675 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 5676 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 5677 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 5678 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 5679 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5680 | void |
| 5681 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 5682 | { |
| 5683 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
| 5684 | |
| 5685 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 5686 | if (!ndlp) { |
| 5687 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 5688 | if (!ndlp) { |
| 5689 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5690 | lpfc_disc_start(vport); |
| 5691 | return; |
| 5692 | } |
| 5693 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5694 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5695 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5696 | return; |
| 5697 | } |
| 5698 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5699 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5700 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 5701 | if (!ndlp) { |
| 5702 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5703 | lpfc_disc_start(vport); |
| 5704 | return; |
| 5705 | } |
| 5706 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5707 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5708 | "0348 NameServer login: node freed\n"); |
| 5709 | return; |
| 5710 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5711 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5712 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5713 | |
| 5714 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 5715 | |
| 5716 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 5717 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5718 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5719 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5720 | return; |
| 5721 | } |
| 5722 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5723 | if (vport->cfg_fdmi_on) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5724 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 5725 | GFP_KERNEL); |
| 5726 | if (ndlp_fdmi) { |
| 5727 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 5728 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5729 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
| 5730 | NLP_STE_PLOGI_ISSUE); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5731 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, |
| 5732 | 0); |
| 5733 | } |
| 5734 | } |
| 5735 | return; |
| 5736 | } |
| 5737 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5738 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5739 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5740 | * @phba: pointer to lpfc hba data structure. |
| 5741 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 5742 | * |
| 5743 | * This routine is the completion callback function to register new vport |
| 5744 | * mailbox command. If the new vport mailbox command completes successfully, |
| 5745 | * the fabric registration login shall be performed on physical port (the |
| 5746 | * new vport created is actually a physical port, with VPI 0) or the port |
| 5747 | * login to Name Server for State Change Request (SCR) will be performed |
| 5748 | * on virtual port (real virtual port, with VPI greater than 0). |
| 5749 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5750 | static void |
| 5751 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 5752 | { |
| 5753 | struct lpfc_vport *vport = pmb->vport; |
| 5754 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5755 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 5756 | MAILBOX_t *mb = &pmb->mb; |
| 5757 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5758 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5759 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5760 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5761 | |
| 5762 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5763 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 5764 | "0915 Register VPI failed: 0x%x\n", |
| 5765 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5766 | |
| 5767 | switch (mb->mbxStatus) { |
| 5768 | case 0x11: /* unsupported feature */ |
| 5769 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5770 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5771 | /* giving up on vport registration */ |
| 5772 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5773 | spin_lock_irq(shost->host_lock); |
| 5774 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 5775 | spin_unlock_irq(shost->host_lock); |
| 5776 | lpfc_can_disctmo(vport); |
| 5777 | break; |
| 5778 | default: |
| 5779 | /* Try to recover from this error */ |
| 5780 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5781 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5782 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5783 | spin_unlock_irq(shost->host_lock); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5784 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 5785 | lpfc_initial_flogi(vport); |
| 5786 | else |
| 5787 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5788 | break; |
| 5789 | } |
| 5790 | |
| 5791 | } else { |
| 5792 | if (vport == phba->pport) |
| 5793 | lpfc_issue_fabric_reglogin(vport); |
| 5794 | else |
| 5795 | lpfc_do_scr_ns_plogi(phba, vport); |
| 5796 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5797 | |
| 5798 | /* Now, we decrement the ndlp reference count held for this |
| 5799 | * callback function |
| 5800 | */ |
| 5801 | lpfc_nlp_put(ndlp); |
| 5802 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5803 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5804 | return; |
| 5805 | } |
| 5806 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5807 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5808 | * lpfc_register_new_vport - Register a new vport with a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5809 | * @phba: pointer to lpfc hba data structure. |
| 5810 | * @vport: pointer to a host virtual N_Port data structure. |
| 5811 | * @ndlp: pointer to a node-list data structure. |
| 5812 | * |
| 5813 | * This routine registers the @vport as a new virtual port with a HBA. |
| 5814 | * It is done through a registering vpi mailbox command. |
| 5815 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5816 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5817 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 5818 | struct lpfc_nodelist *ndlp) |
| 5819 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5820 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5821 | LPFC_MBOXQ_t *mbox; |
| 5822 | |
| 5823 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5824 | if (mbox) { |
| 5825 | lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox); |
| 5826 | mbox->vport = vport; |
| 5827 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 5828 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5829 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5830 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5831 | /* mailbox command not success, decrement ndlp |
| 5832 | * reference count for this command |
| 5833 | */ |
| 5834 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5835 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5836 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5837 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 5838 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5839 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5840 | } |
| 5841 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5842 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 5843 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5844 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5845 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5846 | return; |
| 5847 | |
| 5848 | mbox_err_exit: |
| 5849 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5850 | spin_lock_irq(shost->host_lock); |
| 5851 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 5852 | spin_unlock_irq(shost->host_lock); |
| 5853 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5854 | } |
| 5855 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5856 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5857 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5858 | * @phba: pointer to lpfc hba data structure. |
| 5859 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5860 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 5861 | * |
| 5862 | * This routine is the completion callback function to a Fabric Discover |
| 5863 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 5864 | * single threaded, each FDISC completion callback function will reset |
| 5865 | * the discovery timer for all vports such that the timers will not get |
| 5866 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 5867 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 5868 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 5869 | * assigned to the vport has been changed with the completion of the FDISC |
| 5870 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 5871 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 5872 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 5873 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 5874 | * Server for State Change Request (SCR). |
| 5875 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5876 | static void |
| 5877 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 5878 | struct lpfc_iocbq *rspiocb) |
| 5879 | { |
| 5880 | struct lpfc_vport *vport = cmdiocb->vport; |
| 5881 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5882 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 5883 | struct lpfc_nodelist *np; |
| 5884 | struct lpfc_nodelist *next_np; |
| 5885 | IOCB_t *irsp = &rspiocb->iocb; |
| 5886 | struct lpfc_iocbq *piocb; |
| 5887 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5888 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5889 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 5890 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 5891 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5892 | /* Since all FDISCs are being single threaded, we |
| 5893 | * must reset the discovery timer for ALL vports |
| 5894 | * waiting to send FDISC when one completes. |
| 5895 | */ |
| 5896 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 5897 | lpfc_set_disctmo(piocb->vport); |
| 5898 | } |
| 5899 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5900 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 5901 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 5902 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 5903 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5904 | if (irsp->ulpStatus) { |
| 5905 | /* Check for retry */ |
| 5906 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 5907 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5908 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5909 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5910 | "0126 FDISC failed. (%d/%d)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5911 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5912 | goto fdisc_failed; |
| 5913 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5914 | if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING) |
| 5915 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5916 | lpfc_nlp_put(ndlp); |
| 5917 | /* giving up on FDISC. Cancel discovery timer */ |
| 5918 | lpfc_can_disctmo(vport); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5919 | spin_lock_irq(shost->host_lock); |
| 5920 | vport->fc_flag |= FC_FABRIC; |
| 5921 | if (vport->phba->fc_topology == TOPOLOGY_LOOP) |
| 5922 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 5923 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5924 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5925 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 5926 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
| 5927 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 5928 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 5929 | /* If our NportID changed, we need to ensure all |
| 5930 | * remaining NPORTs get unreg_login'ed so we can |
| 5931 | * issue unreg_vpi. |
| 5932 | */ |
| 5933 | list_for_each_entry_safe(np, next_np, |
| 5934 | &vport->fc_nodes, nlp_listp) { |
| 5935 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 5936 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 5937 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 5938 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5939 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5940 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5941 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5942 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5943 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5944 | lpfc_mbx_unreg_vpi(vport); |
| 5945 | spin_lock_irq(shost->host_lock); |
| 5946 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 5947 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5948 | } |
| 5949 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5950 | if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 5951 | lpfc_register_new_vport(phba, vport, ndlp); |
| 5952 | else |
| 5953 | lpfc_do_scr_ns_plogi(phba, vport); |
| 5954 | goto out; |
| 5955 | fdisc_failed: |
| 5956 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5957 | /* Cancel discovery timer */ |
| 5958 | lpfc_can_disctmo(vport); |
| 5959 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5960 | out: |
| 5961 | lpfc_els_free_iocb(phba, cmdiocb); |
| 5962 | } |
| 5963 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5964 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5965 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5966 | * @vport: pointer to a virtual N_Port data structure. |
| 5967 | * @ndlp: pointer to a node-list data structure. |
| 5968 | * @retry: number of retries to the command IOCB. |
| 5969 | * |
| 5970 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 5971 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 5972 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 5973 | * IOCB will be sent off HBA at any given time. |
| 5974 | * |
| 5975 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5976 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5977 | * will be stored into the context1 field of the IOCB for the completion |
| 5978 | * callback function to the FDISC ELS command. |
| 5979 | * |
| 5980 | * Return code |
| 5981 | * 0 - Successfully issued fdisc iocb command |
| 5982 | * 1 - Failed to issue fdisc iocb command |
| 5983 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5984 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5985 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 5986 | uint8_t retry) |
| 5987 | { |
| 5988 | struct lpfc_hba *phba = vport->phba; |
| 5989 | IOCB_t *icmd; |
| 5990 | struct lpfc_iocbq *elsiocb; |
| 5991 | struct serv_parm *sp; |
| 5992 | uint8_t *pcmd; |
| 5993 | uint16_t cmdsize; |
| 5994 | int did = ndlp->nlp_DID; |
| 5995 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5996 | |
| 5997 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 5998 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 5999 | ELS_CMD_FDISC); |
| 6000 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6001 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6002 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6003 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6004 | return 1; |
| 6005 | } |
| 6006 | |
| 6007 | icmd = &elsiocb->iocb; |
| 6008 | icmd->un.elsreq64.myID = 0; |
| 6009 | icmd->un.elsreq64.fl = 1; |
| 6010 | |
| 6011 | /* For FDISC, Let FDISC rsp set the NPortID for this VPI */ |
| 6012 | icmd->ulpCt_h = 1; |
| 6013 | icmd->ulpCt_l = 0; |
| 6014 | |
| 6015 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6016 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 6017 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 6018 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 6019 | sp = (struct serv_parm *) pcmd; |
| 6020 | /* Setup CSPs accordingly for Fabric */ |
| 6021 | sp->cmn.e_d_tov = 0; |
| 6022 | sp->cmn.w2.r_a_tov = 0; |
| 6023 | sp->cls1.classValid = 0; |
| 6024 | sp->cls2.seqDelivery = 1; |
| 6025 | sp->cls3.seqDelivery = 1; |
| 6026 | |
| 6027 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 6028 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 6029 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 6030 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 6031 | memcpy(pcmd, &vport->fc_portname, 8); |
| 6032 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6033 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6034 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 6035 | |
| 6036 | lpfc_set_disctmo(vport); |
| 6037 | |
| 6038 | phba->fc_stat.elsXmitFDISC++; |
| 6039 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 6040 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6041 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6042 | "Issue FDISC: did:x%x", |
| 6043 | did, 0, 0); |
| 6044 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6045 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 6046 | if (rc == IOCB_ERROR) { |
| 6047 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6048 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6049 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6050 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6051 | return 1; |
| 6052 | } |
| 6053 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
| 6054 | vport->port_state = LPFC_FDISC; |
| 6055 | return 0; |
| 6056 | } |
| 6057 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6058 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6059 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6060 | * @phba: pointer to lpfc hba data structure. |
| 6061 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6062 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6063 | * |
| 6064 | * This routine is the completion callback function to the issuing of a LOGO |
| 6065 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 6066 | * reference count held on ndlp for this completion function, indicating that |
| 6067 | * the reference to the ndlp is no long needed. Note that the |
| 6068 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 6069 | * callback function and an additional explicit ndlp reference decrementation |
| 6070 | * will trigger the actual release of the ndlp. |
| 6071 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6072 | static void |
| 6073 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6074 | struct lpfc_iocbq *rspiocb) |
| 6075 | { |
| 6076 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6077 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6078 | struct lpfc_nodelist *ndlp; |
| 6079 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6080 | |
| 6081 | irsp = &rspiocb->iocb; |
| 6082 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6083 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 6084 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6085 | |
| 6086 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6087 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6088 | |
| 6089 | /* Trigger the release of the ndlp after logo */ |
| 6090 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6091 | } |
| 6092 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6093 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6094 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6095 | * @vport: pointer to a virtual N_Port data structure. |
| 6096 | * @ndlp: pointer to a node-list data structure. |
| 6097 | * |
| 6098 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 6099 | * |
| 6100 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6101 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6102 | * will be stored into the context1 field of the IOCB for the completion |
| 6103 | * callback function to the LOGO ELS command. |
| 6104 | * |
| 6105 | * Return codes |
| 6106 | * 0 - Successfully issued logo off the @vport |
| 6107 | * 1 - Failed to issue logo off the @vport |
| 6108 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6109 | int |
| 6110 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 6111 | { |
| 6112 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6113 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6114 | IOCB_t *icmd; |
| 6115 | struct lpfc_iocbq *elsiocb; |
| 6116 | uint8_t *pcmd; |
| 6117 | uint16_t cmdsize; |
| 6118 | |
| 6119 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 6120 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 6121 | ELS_CMD_LOGO); |
| 6122 | if (!elsiocb) |
| 6123 | return 1; |
| 6124 | |
| 6125 | icmd = &elsiocb->iocb; |
| 6126 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6127 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 6128 | pcmd += sizeof(uint32_t); |
| 6129 | |
| 6130 | /* Fill in LOGO payload */ |
| 6131 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 6132 | pcmd += sizeof(uint32_t); |
| 6133 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 6134 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6135 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6136 | "Issue LOGO npiv did:x%x flg:x%x", |
| 6137 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 6138 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6139 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 6140 | spin_lock_irq(shost->host_lock); |
| 6141 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 6142 | spin_unlock_irq(shost->host_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 6143 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
| 6144 | IOCB_ERROR) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6145 | spin_lock_irq(shost->host_lock); |
| 6146 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 6147 | spin_unlock_irq(shost->host_lock); |
| 6148 | lpfc_els_free_iocb(phba, elsiocb); |
| 6149 | return 1; |
| 6150 | } |
| 6151 | return 0; |
| 6152 | } |
| 6153 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6154 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6155 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6156 | * @ptr: holder for the timer function associated data. |
| 6157 | * |
| 6158 | * This routine is invoked by the fabric iocb block timer after |
| 6159 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 6160 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 6161 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 6162 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 6163 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 6164 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6165 | void |
| 6166 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 6167 | { |
| 6168 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 6169 | unsigned long iflags; |
| 6170 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6171 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6172 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 6173 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 6174 | if (!tmo_posted) |
| 6175 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 6176 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 6177 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6178 | if (!tmo_posted) |
| 6179 | lpfc_worker_wake_up(phba); |
| 6180 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6181 | } |
| 6182 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6183 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6184 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6185 | * @phba: pointer to lpfc hba data structure. |
| 6186 | * |
| 6187 | * This routine issues one fabric iocb from the driver internal list to |
| 6188 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 6189 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 6190 | * remove one pending fabric iocb from the driver internal list and invokes |
| 6191 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 6192 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6193 | static void |
| 6194 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 6195 | { |
| 6196 | struct lpfc_iocbq *iocb; |
| 6197 | unsigned long iflags; |
| 6198 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6199 | IOCB_t *cmd; |
| 6200 | |
| 6201 | repeat: |
| 6202 | iocb = NULL; |
| 6203 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6204 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6205 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 6206 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 6207 | list); |
| 6208 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6209 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6210 | atomic_inc(&phba->fabric_iocb_count); |
| 6211 | } |
| 6212 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6213 | if (iocb) { |
| 6214 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6215 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6216 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6217 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6218 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6219 | "Fabric sched1: ste:x%x", |
| 6220 | iocb->vport->port_state, 0, 0); |
| 6221 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 6222 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6223 | |
| 6224 | if (ret == IOCB_ERROR) { |
| 6225 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6226 | iocb->fabric_iocb_cmpl = NULL; |
| 6227 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6228 | cmd = &iocb->iocb; |
| 6229 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6230 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6231 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 6232 | |
| 6233 | atomic_dec(&phba->fabric_iocb_count); |
| 6234 | goto repeat; |
| 6235 | } |
| 6236 | } |
| 6237 | |
| 6238 | return; |
| 6239 | } |
| 6240 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6241 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6242 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6243 | * @phba: pointer to lpfc hba data structure. |
| 6244 | * |
| 6245 | * This routine unblocks the issuing fabric iocb command. The function |
| 6246 | * will clear the fabric iocb block bit and then invoke the routine |
| 6247 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 6248 | * from the driver internal fabric iocb list. |
| 6249 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6250 | void |
| 6251 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 6252 | { |
| 6253 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6254 | |
| 6255 | lpfc_resume_fabric_iocbs(phba); |
| 6256 | return; |
| 6257 | } |
| 6258 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6259 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6260 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6261 | * @phba: pointer to lpfc hba data structure. |
| 6262 | * |
| 6263 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 6264 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 6265 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 6266 | * fabric iocb will be issued out of the HBA. |
| 6267 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6268 | static void |
| 6269 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 6270 | { |
| 6271 | int blocked; |
| 6272 | |
| 6273 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6274 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6275 | if (!blocked) |
| 6276 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); |
| 6277 | |
| 6278 | return; |
| 6279 | } |
| 6280 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6281 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6282 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6283 | * @phba: pointer to lpfc hba data structure. |
| 6284 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6285 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6286 | * |
| 6287 | * This routine is the callback function that is put to the fabric iocb's |
| 6288 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 6289 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 6290 | * function first restores and invokes the original iocb's callback function |
| 6291 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 6292 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 6293 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6294 | static void |
| 6295 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6296 | struct lpfc_iocbq *rspiocb) |
| 6297 | { |
| 6298 | struct ls_rjt stat; |
| 6299 | |
| 6300 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 6301 | BUG(); |
| 6302 | |
| 6303 | switch (rspiocb->iocb.ulpStatus) { |
| 6304 | case IOSTAT_NPORT_RJT: |
| 6305 | case IOSTAT_FABRIC_RJT: |
| 6306 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 6307 | lpfc_block_fabric_iocbs(phba); |
| 6308 | } |
| 6309 | break; |
| 6310 | |
| 6311 | case IOSTAT_NPORT_BSY: |
| 6312 | case IOSTAT_FABRIC_BSY: |
| 6313 | lpfc_block_fabric_iocbs(phba); |
| 6314 | break; |
| 6315 | |
| 6316 | case IOSTAT_LS_RJT: |
| 6317 | stat.un.lsRjtError = |
| 6318 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 6319 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 6320 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 6321 | lpfc_block_fabric_iocbs(phba); |
| 6322 | break; |
| 6323 | } |
| 6324 | |
| 6325 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 6326 | BUG(); |
| 6327 | |
| 6328 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 6329 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 6330 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6331 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 6332 | |
| 6333 | atomic_dec(&phba->fabric_iocb_count); |
| 6334 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6335 | /* Post any pending iocbs to HBA */ |
| 6336 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6337 | } |
| 6338 | } |
| 6339 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6340 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6341 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6342 | * @phba: pointer to lpfc hba data structure. |
| 6343 | * @iocb: pointer to lpfc command iocb data structure. |
| 6344 | * |
| 6345 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 6346 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 6347 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 6348 | * any given time. As such, this function will first check to see whether there |
| 6349 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 6350 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 6351 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 6352 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 6353 | * |
| 6354 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 6355 | * order. The problem is caused by the construction of the "ready" boolen does |
| 6356 | * not include the condition that the internal fabric IOCB list is empty. As |
| 6357 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 6358 | * ahead of the fabric IOCBs in the internal list. |
| 6359 | * |
| 6360 | * Return code |
| 6361 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 6362 | * IOCB_ERROR - failed to issue fabric iocb |
| 6363 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6364 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6365 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 6366 | { |
| 6367 | unsigned long iflags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6368 | int ready; |
| 6369 | int ret; |
| 6370 | |
| 6371 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 6372 | BUG(); |
| 6373 | |
| 6374 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6375 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 6376 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6377 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6378 | if (ready) |
| 6379 | /* Increment fabric iocb count to hold the position */ |
| 6380 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6381 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6382 | if (ready) { |
| 6383 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6384 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6385 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6386 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6387 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6388 | "Fabric sched2: ste:x%x", |
| 6389 | iocb->vport->port_state, 0, 0); |
| 6390 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 6391 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6392 | |
| 6393 | if (ret == IOCB_ERROR) { |
| 6394 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6395 | iocb->fabric_iocb_cmpl = NULL; |
| 6396 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6397 | atomic_dec(&phba->fabric_iocb_count); |
| 6398 | } |
| 6399 | } else { |
| 6400 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6401 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 6402 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6403 | ret = IOCB_SUCCESS; |
| 6404 | } |
| 6405 | return ret; |
| 6406 | } |
| 6407 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6408 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6409 | * lpfc_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] | 6410 | * @vport: pointer to a virtual N_Port data structure. |
| 6411 | * |
| 6412 | * This routine aborts all the IOCBs associated with a @vport from the |
| 6413 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6414 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6415 | * list, removes each IOCB associated with the @vport off the list, set the |
| 6416 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6417 | * associated with the IOCB. |
| 6418 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6419 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6420 | { |
| 6421 | LIST_HEAD(completions); |
| 6422 | struct lpfc_hba *phba = vport->phba; |
| 6423 | struct lpfc_iocbq *tmp_iocb, *piocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6424 | |
| 6425 | spin_lock_irq(&phba->hbalock); |
| 6426 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6427 | list) { |
| 6428 | |
| 6429 | if (piocb->vport != vport) |
| 6430 | continue; |
| 6431 | |
| 6432 | list_move_tail(&piocb->list, &completions); |
| 6433 | } |
| 6434 | spin_unlock_irq(&phba->hbalock); |
| 6435 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6436 | /* Cancel all the IOCBs from the completions list */ |
| 6437 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6438 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6439 | } |
| 6440 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6441 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6442 | * 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] | 6443 | * @ndlp: pointer to a node-list data structure. |
| 6444 | * |
| 6445 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 6446 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6447 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6448 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 6449 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6450 | * associated with the IOCB. |
| 6451 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6452 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 6453 | { |
| 6454 | LIST_HEAD(completions); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6455 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6456 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6457 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6458 | |
| 6459 | spin_lock_irq(&phba->hbalock); |
| 6460 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6461 | list) { |
| 6462 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 6463 | |
| 6464 | list_move_tail(&piocb->list, &completions); |
| 6465 | } |
| 6466 | } |
| 6467 | spin_unlock_irq(&phba->hbalock); |
| 6468 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6469 | /* Cancel all the IOCBs from the completions list */ |
| 6470 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6471 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6472 | } |
| 6473 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6474 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6475 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6476 | * @phba: pointer to lpfc hba data structure. |
| 6477 | * |
| 6478 | * This routine aborts all the IOCBs currently on the driver internal |
| 6479 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 6480 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 6481 | * list, removes IOCBs off the list, set the status feild to |
| 6482 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 6483 | * the IOCB. |
| 6484 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6485 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 6486 | { |
| 6487 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6488 | |
| 6489 | spin_lock_irq(&phba->hbalock); |
| 6490 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 6491 | spin_unlock_irq(&phba->hbalock); |
| 6492 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6493 | /* Cancel all the IOCBs from the completions list */ |
| 6494 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 6495 | IOERR_SLI_ABORTED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6496 | } |