| 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 | /** |
| 58 | * lpfc_els_chk_latt: Check host link attention event for a vport. |
| 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 || |
| 87 | phba->link_state == LPFC_LINK_DOWN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 88 | return 0; |
| 89 | |
| 90 | /* Read the HBA Host Attention Register */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 91 | ha_copy = readl(phba->HAregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 92 | |
| 93 | if (!(ha_copy & HA_LATT)) |
| 94 | return 0; |
| 95 | |
| 96 | /* Pending Link Event during Discovery */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 97 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 98 | "0237 Pending Link Event during " |
| 99 | "Discovery: State x%x\n", |
| 100 | phba->pport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 101 | |
| 102 | /* CLEAR_LA should re-enable link attention events and |
| 103 | * we should then imediately take a LATT event. The |
| 104 | * LATT processing should call lpfc_linkdown() which |
| 105 | * will cleanup any left over in-progress discovery |
| 106 | * events. |
| 107 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 108 | spin_lock_irq(shost->host_lock); |
| 109 | vport->fc_flag |= FC_ABORT_DISCOVERY; |
| 110 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 111 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 112 | if (phba->link_state != LPFC_CLEAR_LA) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 113 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 114 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 115 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 116 | } |
| 117 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 118 | /** |
| 119 | * lpfc_prep_els_iocb: Allocate and prepare a lpfc iocb data structure. |
| 120 | * @vport: pointer to a host virtual N_Port data structure. |
| 121 | * @expectRsp: flag indicating whether response is expected. |
| 122 | * @cmdSize: size of the ELS command. |
| 123 | * @retry: number of retries to the command IOCB when it fails. |
| 124 | * @ndlp: pointer to a node-list data structure. |
| 125 | * @did: destination identifier. |
| 126 | * @elscmd: the ELS command code. |
| 127 | * |
| 128 | * This routine is used for allocating a lpfc-IOCB data structure from |
| 129 | * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters |
| 130 | * passed into the routine for discovery state machine to issue an Extended |
| 131 | * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation |
| 132 | * and preparation routine that is used by all the discovery state machine |
| 133 | * routines and the ELS command-specific fields will be later set up by |
| 134 | * the individual discovery machine routines after calling this routine |
| 135 | * allocating and preparing a generic IOCB data structure. It fills in the |
| 136 | * Buffer Descriptor Entries (BDEs), allocates buffers for both command |
| 137 | * payload and response payload (if expected). The reference count on the |
| 138 | * ndlp is incremented by 1 and the reference to the ndlp is put into |
| 139 | * context1 of the IOCB data structure for this IOCB to hold the ndlp |
| 140 | * reference for the command's callback function to access later. |
| 141 | * |
| 142 | * Return code |
| 143 | * Pointer to the newly allocated/prepared els iocb data structure |
| 144 | * NULL - when els iocb data structure allocation/preparation failed |
| 145 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 146 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 147 | lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, |
| 148 | uint16_t cmdSize, uint8_t retry, |
| 149 | struct lpfc_nodelist *ndlp, uint32_t did, |
| 150 | uint32_t elscmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 151 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 152 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 153 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 154 | struct lpfc_dmabuf *pcmd, *prsp, *pbuflist; |
| 155 | struct ulp_bde64 *bpl; |
| 156 | IOCB_t *icmd; |
| 157 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 158 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 159 | if (!lpfc_is_link_up(phba)) |
| 160 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 161 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 162 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 163 | elsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 164 | |
| 165 | if (elsiocb == NULL) |
| 166 | return NULL; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 167 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 168 | icmd = &elsiocb->iocb; |
| 169 | |
| 170 | /* fill in BDEs for command */ |
| 171 | /* Allocate buffer for command payload */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 172 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 173 | if (pcmd) |
| 174 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 175 | if (!pcmd || !pcmd->virt) |
| 176 | goto els_iocb_free_pcmb_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 177 | |
| 178 | INIT_LIST_HEAD(&pcmd->list); |
| 179 | |
| 180 | /* Allocate buffer for response payload */ |
| 181 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 182 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 183 | if (prsp) |
| 184 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 185 | &prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 186 | if (!prsp || !prsp->virt) |
| 187 | goto els_iocb_free_prsp_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 188 | INIT_LIST_HEAD(&prsp->list); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 189 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 190 | prsp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 191 | |
| 192 | /* Allocate buffer for Buffer ptr list */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 193 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 194 | if (pbuflist) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 195 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 196 | &pbuflist->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 197 | if (!pbuflist || !pbuflist->virt) |
| 198 | goto els_iocb_free_pbuf_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 199 | |
| 200 | INIT_LIST_HEAD(&pbuflist->list); |
| 201 | |
| 202 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 203 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 204 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 205 | icmd->un.elsreq64.remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 206 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 207 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 208 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 209 | icmd->ulpTimeout = phba->fc_ratov * 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 210 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 211 | icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 212 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; |
| 213 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 214 | icmd->ulpBdeCount = 1; |
| 215 | icmd->ulpLe = 1; |
| 216 | icmd->ulpClass = CLASS3; |
| 217 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 218 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 219 | icmd->un.elsreq64.myID = vport->fc_myDID; |
| 220 | |
| 221 | /* For ELS_REQUEST64_CR, use the VPI by default */ |
| 222 | icmd->ulpContext = vport->vpi; |
| 223 | icmd->ulpCt_h = 0; |
| 224 | icmd->ulpCt_l = 1; |
| 225 | } |
| 226 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 227 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
| 228 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); |
| 229 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); |
| 230 | bpl->tus.f.bdeSize = cmdSize; |
| 231 | bpl->tus.f.bdeFlags = 0; |
| 232 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 233 | |
| 234 | if (expectRsp) { |
| 235 | bpl++; |
| 236 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); |
| 237 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); |
| 238 | bpl->tus.f.bdeSize = FCELSSIZE; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 239 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 240 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 241 | } |
| 242 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 243 | /* prevent preparing iocb with NULL ndlp reference */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 244 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 245 | if (!elsiocb->context1) |
| 246 | goto els_iocb_free_pbuf_exit; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 247 | elsiocb->context2 = pcmd; |
| 248 | elsiocb->context3 = pbuflist; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 249 | elsiocb->retry = retry; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 250 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 251 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
| 252 | |
| 253 | if (prsp) { |
| 254 | list_add(&prsp->list, &pcmd->list); |
| 255 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 256 | if (expectRsp) { |
| 257 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 258 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 259 | "0116 Xmit ELS command x%x to remote " |
| 260 | "NPORT x%x I/O tag: x%x, port state: x%x\n", |
| 261 | elscmd, did, elsiocb->iotag, |
| 262 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 263 | } else { |
| 264 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 265 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 266 | "0117 Xmit ELS response x%x to remote " |
| 267 | "NPORT x%x I/O tag: x%x, size: x%x\n", |
| 268 | elscmd, ndlp->nlp_DID, elsiocb->iotag, |
| 269 | cmdSize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 270 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 271 | return elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 272 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 273 | els_iocb_free_pbuf_exit: |
| 274 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); |
| 275 | kfree(pbuflist); |
| 276 | |
| 277 | els_iocb_free_prsp_exit: |
| 278 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 279 | kfree(prsp); |
| 280 | |
| 281 | els_iocb_free_pcmb_exit: |
| 282 | kfree(pcmd); |
| 283 | lpfc_sli_release_iocbq(phba, elsiocb); |
| 284 | return NULL; |
| 285 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 286 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 287 | /** |
| 288 | * lpfc_issue_fabric_reglogin: Issue fabric registration login for a vport. |
| 289 | * @vport: pointer to a host virtual N_Port data structure. |
| 290 | * |
| 291 | * This routine issues a fabric registration login for a @vport. An |
| 292 | * active ndlp node with Fabric_DID must already exist for this @vport. |
| 293 | * The routine invokes two mailbox commands to carry out fabric registration |
| 294 | * login through the HBA firmware: the first mailbox command requests the |
| 295 | * HBA to perform link configuration for the @vport; and the second mailbox |
| 296 | * command requests the HBA to perform the actual fabric registration login |
| 297 | * with the @vport. |
| 298 | * |
| 299 | * Return code |
| 300 | * 0 - successfully issued fabric registration login for @vport |
| 301 | * -ENXIO -- failed to issue fabric registration login for @vport |
| 302 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 303 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 304 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
| 305 | { |
| 306 | struct lpfc_hba *phba = vport->phba; |
| 307 | LPFC_MBOXQ_t *mbox; |
| 308 | struct lpfc_dmabuf *mp; |
| 309 | struct lpfc_nodelist *ndlp; |
| 310 | struct serv_parm *sp; |
| 311 | int rc; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 312 | int err = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 313 | |
| 314 | sp = &phba->fc_fabparam; |
| 315 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 316 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 317 | err = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 318 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 319 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 320 | |
| 321 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 322 | if (!mbox) { |
| 323 | err = 2; |
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 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 328 | lpfc_config_link(phba, mbox); |
| 329 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 330 | mbox->vport = vport; |
| 331 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 332 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 333 | if (rc == MBX_NOT_FINISHED) { |
| 334 | err = 3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 335 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 336 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 337 | |
| 338 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 339 | if (!mbox) { |
| 340 | err = 4; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 341 | goto fail; |
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 | rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, |
| 344 | 0); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 345 | if (rc) { |
| 346 | err = 5; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 347 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 348 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 349 | |
| 350 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; |
| 351 | mbox->vport = vport; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 352 | /* increment the reference count on ndlp to hold reference |
| 353 | * for the callback routine. |
| 354 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 355 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 356 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 357 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 358 | if (rc == MBX_NOT_FINISHED) { |
| 359 | err = 6; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 360 | goto fail_issue_reg_login; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 361 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 362 | |
| 363 | return 0; |
| 364 | |
| 365 | fail_issue_reg_login: |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 366 | /* decrement the reference count on ndlp just incremented |
| 367 | * for the failed mbox command. |
| 368 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 369 | lpfc_nlp_put(ndlp); |
| 370 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 371 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 372 | kfree(mp); |
| 373 | fail_free_mbox: |
| 374 | mempool_free(mbox, phba->mbox_mem_pool); |
| 375 | |
| 376 | fail: |
| 377 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 378 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 379 | "0249 Cannot issue Register Fabric login: Err %d\n", err); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 380 | return -ENXIO; |
| 381 | } |
| 382 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 383 | /** |
| 384 | * lpfc_cmpl_els_flogi_fabric: Completion function for flogi to a fabric port. |
| 385 | * @vport: pointer to a host virtual N_Port data structure. |
| 386 | * @ndlp: pointer to a node-list data structure. |
| 387 | * @sp: pointer to service parameter data structure. |
| 388 | * @irsp: pointer to the IOCB within the lpfc response IOCB. |
| 389 | * |
| 390 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 391 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric |
| 392 | * port in a fabric topology. It properly sets up the parameters to the @ndlp |
| 393 | * from the IOCB response. It also check the newly assigned N_Port ID to the |
| 394 | * @vport against the previously assigned N_Port ID. If it is different from |
| 395 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine |
| 396 | * is invoked on all the remaining nodes with the @vport to unregister the |
| 397 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() |
| 398 | * is invoked to register login to the fabric. |
| 399 | * |
| 400 | * Return code |
| 401 | * 0 - Success (currently, always return 0) |
| 402 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 403 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 404 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 405 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 406 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 407 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 408 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 409 | struct lpfc_nodelist *np; |
| 410 | struct lpfc_nodelist *next_np; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 411 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 412 | spin_lock_irq(shost->host_lock); |
| 413 | vport->fc_flag |= FC_FABRIC; |
| 414 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 415 | |
| 416 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 417 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 418 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 419 | |
| 420 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 421 | |
| 422 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 423 | spin_lock_irq(shost->host_lock); |
| 424 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 425 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 426 | } else { |
| 427 | /* |
| 428 | * If we are a N-port connected to a Fabric, fixup sparam's so |
| 429 | * logins to devices on remote loops work. |
| 430 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 431 | vport->fc_sparam.cmn.altBbCredit = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 432 | } |
| 433 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 434 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 435 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 436 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 437 | ndlp->nlp_class_sup = 0; |
| 438 | if (sp->cls1.classValid) |
| 439 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 440 | if (sp->cls2.classValid) |
| 441 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 442 | if (sp->cls3.classValid) |
| 443 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 444 | if (sp->cls4.classValid) |
| 445 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 446 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 447 | sp->cmn.bbRcvSizeLsb; |
| 448 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 449 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 450 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 451 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 452 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 453 | LOG_ELS | LOG_VPORT, |
| 454 | "1816 FLOGI NPIV supported, " |
| 455 | "response data 0x%x\n", |
| 456 | sp->cmn.response_multiple_NPort); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 457 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 458 | } else { |
| 459 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 460 | to call reg_vnpid atleast for the physcial host */ |
| 461 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 462 | LOG_ELS | LOG_VPORT, |
| 463 | "1817 Fabric does not support NPIV " |
| 464 | "- configuring single port mode.\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 465 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 470 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 471 | |
| 472 | /* If our NportID changed, we need to ensure all |
| 473 | * remaining NPORTs get unreg_login'ed. |
| 474 | */ |
| 475 | list_for_each_entry_safe(np, next_np, |
| 476 | &vport->fc_nodes, nlp_listp) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 477 | if (!NLP_CHK_NODE_ACT(np)) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 478 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 479 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 480 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 481 | continue; |
| 482 | spin_lock_irq(shost->host_lock); |
| 483 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 484 | spin_unlock_irq(shost->host_lock); |
| 485 | lpfc_unreg_rpi(vport, np); |
| 486 | } |
| 487 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 488 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 489 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 490 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 491 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 492 | } |
| 493 | } |
| 494 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 495 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 496 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 497 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 498 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) { |
| 499 | lpfc_register_new_vport(phba, vport, ndlp); |
| 500 | return 0; |
| 501 | } |
| 502 | lpfc_issue_fabric_reglogin(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 503 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 504 | } |
| 505 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 506 | /** |
| 507 | * lpfc_cmpl_els_flogi_nport: Completion function for flogi to an N_Port. |
| 508 | * @vport: pointer to a host virtual N_Port data structure. |
| 509 | * @ndlp: pointer to a node-list data structure. |
| 510 | * @sp: pointer to service parameter data structure. |
| 511 | * |
| 512 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 513 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 514 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 515 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 516 | * the received N_Port Name lexicographically, this node shall assign local |
| 517 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 518 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 519 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 520 | * N_Port IDs. |
| 521 | * |
| 522 | * Return code |
| 523 | * 0 - Success |
| 524 | * -ENXIO - Fail |
| 525 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 526 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 527 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 528 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 529 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 530 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 531 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 532 | LPFC_MBOXQ_t *mbox; |
| 533 | int rc; |
| 534 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 535 | spin_lock_irq(shost->host_lock); |
| 536 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 537 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 538 | |
| 539 | phba->fc_edtov = FF_DEF_EDTOV; |
| 540 | phba->fc_ratov = FF_DEF_RATOV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 541 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 542 | sizeof(vport->fc_portname)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 543 | if (rc >= 0) { |
| 544 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 545 | spin_lock_irq(shost->host_lock); |
| 546 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 547 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 548 | |
| 549 | /* |
| 550 | * N_Port ID cannot be 0, set our to LocalID the other |
| 551 | * side will be RemoteID. |
| 552 | */ |
| 553 | |
| 554 | /* not equal */ |
| 555 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 556 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 557 | |
| 558 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 559 | if (!mbox) |
| 560 | goto fail; |
| 561 | |
| 562 | lpfc_config_link(phba, mbox); |
| 563 | |
| 564 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 565 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 566 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 567 | if (rc == MBX_NOT_FINISHED) { |
| 568 | mempool_free(mbox, phba->mbox_mem_pool); |
| 569 | goto fail; |
| 570 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 571 | /* Decrement ndlp reference count indicating that ndlp can be |
| 572 | * safely released when other references to it are done. |
| 573 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 574 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 575 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 576 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 577 | if (!ndlp) { |
| 578 | /* |
| 579 | * Cannot find existing Fabric ndlp, so allocate a |
| 580 | * new one |
| 581 | */ |
| 582 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 583 | if (!ndlp) |
| 584 | goto fail; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 585 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 586 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 587 | ndlp = lpfc_enable_node(vport, ndlp, |
| 588 | NLP_STE_UNUSED_NODE); |
| 589 | if(!ndlp) |
| 590 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 594 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 595 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 596 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 597 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 598 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 599 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 600 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 601 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 602 | } else |
| 603 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 604 | * count indicating that ndlp can be released when other |
| 605 | * references to it are done. |
| 606 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 607 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 608 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 609 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 610 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 611 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 612 | spin_lock_irq(shost->host_lock); |
| 613 | vport->fc_flag |= FC_PT2PT; |
| 614 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 615 | |
| 616 | /* Start discovery - this should just do CLEAR_LA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 617 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 618 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 619 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 620 | return -ENXIO; |
| 621 | } |
| 622 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 623 | /** |
| 624 | * lpfc_cmpl_els_flogi: Completion callback function for flogi. |
| 625 | * @phba: pointer to lpfc hba data structure. |
| 626 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 627 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 628 | * |
| 629 | * This routine is the top-level completion callback function for issuing |
| 630 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 631 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 632 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 633 | * returning 1), the command IOCB will be released and function returned. |
| 634 | * If the retry attempt has been given up (possibly reach the maximum |
| 635 | * number of retries), one additional decrement of ndlp reference shall be |
| 636 | * invoked before going out after releasing the command IOCB. This will |
| 637 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 638 | * invoke one decrement of ndlp reference count). If no error reported in |
| 639 | * the IOCB status, the command Port ID field is used to determine whether |
| 640 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 641 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 642 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 643 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 644 | * specific topology completion conditions. |
| 645 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 646 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 647 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 648 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 649 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 650 | struct lpfc_vport *vport = cmdiocb->vport; |
| 651 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 652 | IOCB_t *irsp = &rspiocb->iocb; |
| 653 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 654 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 655 | struct serv_parm *sp; |
| 656 | int rc; |
| 657 | |
| 658 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 659 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 660 | /* One additional decrement on node reference count to |
| 661 | * trigger the release of the node |
| 662 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 663 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 664 | goto out; |
| 665 | } |
| 666 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 667 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 668 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 669 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 670 | vport->port_state); |
| 671 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 672 | if (irsp->ulpStatus) { |
| 673 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 674 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 675 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 676 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 677 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 678 | spin_lock_irq(shost->host_lock); |
| 679 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 680 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 681 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 682 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 683 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 684 | * alpa map would take too long otherwise. |
| 685 | */ |
| 686 | if (phba->alpa_map[0] == 0) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 687 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | /* FLOGI failure */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 691 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 692 | "0100 FLOGI failure Data: x%x x%x " |
| 693 | "x%x\n", |
| 694 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 695 | irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 696 | goto flogifail; |
| 697 | } |
| 698 | |
| 699 | /* |
| 700 | * The FLogI succeeded. Sync the data for the CPU before |
| 701 | * accessing it. |
| 702 | */ |
| 703 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 704 | |
| 705 | sp = prsp->virt + sizeof(uint32_t); |
| 706 | |
| 707 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 708 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 709 | "0101 FLOGI completes sucessfully " |
| 710 | "Data: x%x x%x x%x x%x\n", |
| 711 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
| 712 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 713 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 714 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 715 | /* |
| 716 | * If Common Service Parameters indicate Nport |
| 717 | * we are point to point, if Fport we are Fabric. |
| 718 | */ |
| 719 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 720 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 721 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 722 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 723 | |
| 724 | if (!rc) |
| 725 | goto out; |
| 726 | } |
| 727 | |
| 728 | flogifail: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 729 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 730 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 731 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 732 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 733 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 734 | |
| 735 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 736 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 737 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 738 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && |
| 739 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) && |
| 740 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 741 | /* If FLOGI failed enable link interrupt. */ |
| 742 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 743 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 744 | out: |
| 745 | lpfc_els_free_iocb(phba, cmdiocb); |
| 746 | } |
| 747 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 748 | /** |
| 749 | * lpfc_issue_els_flogi: Issue an flogi iocb command for a vport. |
| 750 | * @vport: pointer to a host virtual N_Port data structure. |
| 751 | * @ndlp: pointer to a node-list data structure. |
| 752 | * @retry: number of retries to the command IOCB. |
| 753 | * |
| 754 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 755 | * for a @vport. The initiator service parameters are put into the payload |
| 756 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 757 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 758 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 759 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 760 | * |
| 761 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 762 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 763 | * will be stored into the context1 field of the IOCB for the completion |
| 764 | * callback function to the FLOGI ELS command. |
| 765 | * |
| 766 | * Return code |
| 767 | * 0 - successfully issued flogi iocb for @vport |
| 768 | * 1 - failed to issue flogi iocb for @vport |
| 769 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 770 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 771 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 772 | uint8_t retry) |
| 773 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 774 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 775 | struct serv_parm *sp; |
| 776 | IOCB_t *icmd; |
| 777 | struct lpfc_iocbq *elsiocb; |
| 778 | struct lpfc_sli_ring *pring; |
| 779 | uint8_t *pcmd; |
| 780 | uint16_t cmdsize; |
| 781 | uint32_t tmo; |
| 782 | int rc; |
| 783 | |
| 784 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 785 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 786 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 787 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 788 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 789 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 790 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 791 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 792 | |
| 793 | icmd = &elsiocb->iocb; |
| 794 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 795 | |
| 796 | /* For FLOGI request, remainder of payload is service parameters */ |
| 797 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 798 | pcmd += sizeof(uint32_t); |
| 799 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 800 | sp = (struct serv_parm *) pcmd; |
| 801 | |
| 802 | /* Setup CSPs accordingly for Fabric */ |
| 803 | sp->cmn.e_d_tov = 0; |
| 804 | sp->cmn.w2.r_a_tov = 0; |
| 805 | sp->cls1.classValid = 0; |
| 806 | sp->cls2.seqDelivery = 1; |
| 807 | sp->cls3.seqDelivery = 1; |
| 808 | if (sp->cmn.fcphLow < FC_PH3) |
| 809 | sp->cmn.fcphLow = FC_PH3; |
| 810 | if (sp->cmn.fcphHigh < FC_PH3) |
| 811 | sp->cmn.fcphHigh = FC_PH3; |
| 812 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 813 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 814 | sp->cmn.request_multiple_Nport = 1; |
| 815 | |
| 816 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 817 | icmd->ulpCt_h = 1; |
| 818 | icmd->ulpCt_l = 0; |
| 819 | } |
| 820 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 821 | if (phba->fc_topology != TOPOLOGY_LOOP) { |
| 822 | icmd->un.elsreq64.myID = 0; |
| 823 | icmd->un.elsreq64.fl = 1; |
| 824 | } |
| 825 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 826 | tmo = phba->fc_ratov; |
| 827 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 828 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 829 | phba->fc_ratov = tmo; |
| 830 | |
| 831 | phba->fc_stat.elsXmitFLOGI++; |
| 832 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 833 | |
| 834 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 835 | "Issue FLOGI: opt:x%x", |
| 836 | phba->sli3_options, 0, 0); |
| 837 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 838 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 839 | if (rc == IOCB_ERROR) { |
| 840 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 841 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 842 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 843 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 844 | } |
| 845 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 846 | /** |
| 847 | * lpfc_els_abort_flogi: Abort all outstanding flogi iocbs. |
| 848 | * @phba: pointer to lpfc hba data structure. |
| 849 | * |
| 850 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 851 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 852 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 853 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 854 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 855 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 856 | * |
| 857 | * Return code |
| 858 | * 0 - Sucessfully issued abort iocb on all outstanding flogis (Always 0) |
| 859 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 860 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 861 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 862 | { |
| 863 | struct lpfc_sli_ring *pring; |
| 864 | struct lpfc_iocbq *iocb, *next_iocb; |
| 865 | struct lpfc_nodelist *ndlp; |
| 866 | IOCB_t *icmd; |
| 867 | |
| 868 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 869 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 870 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 871 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 872 | |
| 873 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 874 | |
| 875 | /* |
| 876 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 877 | * searching for. |
| 878 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 879 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 880 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 881 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 882 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR && |
| 883 | icmd->un.elsreq64.bdl.ulpIoTag32) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 884 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 885 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 886 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 887 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 888 | } |
| 889 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 890 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 891 | |
| 892 | return 0; |
| 893 | } |
| 894 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 895 | /** |
| 896 | * lpfc_initial_flogi: Issue an initial fabric login for a vport. |
| 897 | * @vport: pointer to a host virtual N_Port data structure. |
| 898 | * |
| 899 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 900 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 901 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 902 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 903 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 904 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 905 | * @vport. |
| 906 | * |
| 907 | * Return code |
| 908 | * 0 - failed to issue initial flogi for @vport |
| 909 | * 1 - successfully issued initial flogi for @vport |
| 910 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 911 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 912 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 913 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 914 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 915 | struct lpfc_nodelist *ndlp; |
| 916 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 917 | vport->port_state = LPFC_FLOGI; |
| 918 | lpfc_set_disctmo(vport); |
| 919 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 920 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 921 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 922 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 923 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 924 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 925 | if (!ndlp) |
| 926 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 927 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 928 | /* Put ndlp onto node list */ |
| 929 | lpfc_enqueue_node(vport, ndlp); |
| 930 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 931 | /* re-setup ndlp without removing from node list */ |
| 932 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 933 | if (!ndlp) |
| 934 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 935 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 936 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 937 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 938 | /* This decrement of reference count to node shall kick off |
| 939 | * the release of the node. |
| 940 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 941 | lpfc_nlp_put(ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 942 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 943 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 944 | } |
| 945 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 946 | /** |
| 947 | * lpfc_initial_fdisc: Issue an initial fabric discovery for a vport. |
| 948 | * @vport: pointer to a host virtual N_Port data structure. |
| 949 | * |
| 950 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 951 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 952 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 953 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 954 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 955 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 956 | * @vport. |
| 957 | * |
| 958 | * Return code |
| 959 | * 0 - failed to issue initial fdisc for @vport |
| 960 | * 1 - successfully issued initial fdisc for @vport |
| 961 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 962 | int |
| 963 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 964 | { |
| 965 | struct lpfc_hba *phba = vport->phba; |
| 966 | struct lpfc_nodelist *ndlp; |
| 967 | |
| 968 | /* First look for the Fabric ndlp */ |
| 969 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 970 | if (!ndlp) { |
| 971 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 972 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 973 | if (!ndlp) |
| 974 | return 0; |
| 975 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 976 | /* Put ndlp onto node list */ |
| 977 | lpfc_enqueue_node(vport, ndlp); |
| 978 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 979 | /* re-setup ndlp without removing from node list */ |
| 980 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 981 | if (!ndlp) |
| 982 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 983 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 984 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 985 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 986 | /* decrement node reference count to trigger the release of |
| 987 | * the node. |
| 988 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 989 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 990 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 991 | } |
| 992 | return 1; |
| 993 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 994 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 995 | /** |
| 996 | * lpfc_more_plogi: Check and issue remaining plogis for a vport. |
| 997 | * @vport: pointer to a host virtual N_Port data structure. |
| 998 | * |
| 999 | * This routine checks whether there are more remaining Port Logins |
| 1000 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1001 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1002 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1003 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1004 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1005 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1006 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1007 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1008 | { |
| 1009 | int sentplogi; |
| 1010 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1011 | if (vport->num_disc_nodes) |
| 1012 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1013 | |
| 1014 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1015 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1016 | "0232 Continue discovery with %d PLOGIs to go " |
| 1017 | "Data: x%x x%x x%x\n", |
| 1018 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1019 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1020 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1021 | if (vport->fc_flag & FC_NLP_MORE) |
| 1022 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 1023 | sentplogi = lpfc_els_disc_plogi(vport); |
| 1024 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1025 | return; |
| 1026 | } |
| 1027 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1028 | /** |
| 1029 | * lpfc_plogi_confirm_nport: Confirm pologi wwpn matches stored ndlp. |
| 1030 | * @phba: pointer to lpfc hba data structure. |
| 1031 | * @prsp: pointer to response IOCB payload. |
| 1032 | * @ndlp: pointer to a node-list data structure. |
| 1033 | * |
| 1034 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1035 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1036 | * The following cases are considered N_Port confirmed: |
| 1037 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1038 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1039 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1040 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1041 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1042 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1043 | * on that node to release the RPI associated with the node; 2) if there is |
| 1044 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1045 | * into, a new node shall be allocated (or activated). In either case, the |
| 1046 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1047 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1048 | * its pointer returned as the confirmed node. |
| 1049 | * |
| 1050 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1051 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1052 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1053 | * into an inactive state on the vport node list and the vport node list |
| 1054 | * management algorithm does not allow two node with a same DID. |
| 1055 | * |
| 1056 | * Return code |
| 1057 | * pointer to the PLOGI N_Port @ndlp |
| 1058 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1059 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1060 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1061 | struct lpfc_nodelist *ndlp) |
| 1062 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1063 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1064 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1065 | struct lpfc_rport_data *rdata; |
| 1066 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1067 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1068 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1069 | uint32_t rc, keepDID = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1070 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1071 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1072 | * by WWPN. Just return the ndlp that was given to us. |
| 1073 | */ |
| 1074 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1075 | return ndlp; |
| 1076 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1077 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1078 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1079 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1080 | /* 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] | 1081 | * we have for that ndlp. If not, we have some work to do. |
| 1082 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1083 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1084 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1085 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1086 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1087 | |
| 1088 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1089 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1090 | sizeof(struct lpfc_name)); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1091 | if (!rc) |
| 1092 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1093 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
| 1094 | if (!new_ndlp) |
| 1095 | return ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1096 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1097 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1098 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1099 | sizeof(struct lpfc_name)); |
| 1100 | if (!rc) |
| 1101 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1102 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1103 | NLP_STE_UNUSED_NODE); |
| 1104 | if (!new_ndlp) |
| 1105 | return ndlp; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1106 | keepDID = new_ndlp->nlp_DID; |
| 1107 | } else |
| 1108 | keepDID = new_ndlp->nlp_DID; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1109 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1110 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1111 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1112 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1113 | |
| 1114 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) |
| 1115 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 1116 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 1117 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1118 | /* 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] | 1119 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1120 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1121 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1122 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1123 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1124 | * to put ndlp on UNUSED list and try to free it. |
| 1125 | */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1126 | |
| 1127 | /* Fix up the rport accordingly */ |
| 1128 | rport = ndlp->rport; |
| 1129 | if (rport) { |
| 1130 | rdata = rport->dd_data; |
| 1131 | if (rdata->pnode == ndlp) { |
| 1132 | lpfc_nlp_put(ndlp); |
| 1133 | ndlp->rport = NULL; |
| 1134 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1135 | new_ndlp->rport = rport; |
| 1136 | } |
| 1137 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1138 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1139 | /* We shall actually free the ndlp with both nlp_DID and |
| 1140 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1141 | * nodelist never to be used. |
| 1142 | */ |
| 1143 | if (ndlp->nlp_DID == 0) { |
| 1144 | spin_lock_irq(&phba->ndlp_lock); |
| 1145 | NLP_SET_FREE_REQ(ndlp); |
| 1146 | spin_unlock_irq(&phba->ndlp_lock); |
| 1147 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1148 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1149 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1150 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1151 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1152 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1153 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1154 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1155 | /* Two ndlps cannot have the same did */ |
| 1156 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1157 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1158 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1159 | return new_ndlp; |
| 1160 | } |
| 1161 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1162 | /** |
| 1163 | * lpfc_end_rscn: Check and handle more rscn for a vport. |
| 1164 | * @vport: pointer to a host virtual N_Port data structure. |
| 1165 | * |
| 1166 | * This routine checks whether more Registration State Change |
| 1167 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1168 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1169 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1170 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1171 | * handling the RSCNs. |
| 1172 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1173 | void |
| 1174 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1175 | { |
| 1176 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1177 | |
| 1178 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1179 | /* |
| 1180 | * Check to see if more RSCNs came in while we were |
| 1181 | * processing this one. |
| 1182 | */ |
| 1183 | if (vport->fc_rscn_id_cnt || |
| 1184 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1185 | lpfc_els_handle_rscn(vport); |
| 1186 | else { |
| 1187 | spin_lock_irq(shost->host_lock); |
| 1188 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1189 | spin_unlock_irq(shost->host_lock); |
| 1190 | } |
| 1191 | } |
| 1192 | } |
| 1193 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1194 | /** |
| 1195 | * lpfc_cmpl_els_plogi: Completion callback function for plogi. |
| 1196 | * @phba: pointer to lpfc hba data structure. |
| 1197 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1198 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1199 | * |
| 1200 | * This routine is the completion callback function for issuing the Port |
| 1201 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1202 | * ndlp on the vport node list that matches the remote node ID from the |
| 1203 | * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply |
| 1204 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1205 | * checked for error conditons. If there is error status reported, PLOGI |
| 1206 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1207 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1208 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1209 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1210 | * there are additional N_Port nodes with the vport that need to perform |
| 1211 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1212 | * PLOGIs. |
| 1213 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1214 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1215 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1216 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1217 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1218 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1219 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1220 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1221 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1222 | struct lpfc_dmabuf *prsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1223 | int disc, rc, did, type; |
| 1224 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1225 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1226 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1227 | |
| 1228 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1229 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1230 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1231 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1232 | irsp->un.elsreq64.remoteID); |
| 1233 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1234 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1235 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1236 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1237 | "0136 PLOGI completes to NPort x%x " |
| 1238 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1239 | irsp->un.elsreq64.remoteID, |
| 1240 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1241 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1242 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1243 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1244 | |
| 1245 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1246 | * is being used during discovery. |
| 1247 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1248 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1249 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1250 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1251 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1252 | rc = 0; |
| 1253 | |
| 1254 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1255 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1256 | "0102 PLOGI completes to NPort x%x " |
| 1257 | "Data: x%x x%x x%x x%x x%x\n", |
| 1258 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1259 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1260 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1261 | if (lpfc_els_chk_latt(vport)) { |
| 1262 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1263 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1264 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1265 | goto out; |
| 1266 | } |
| 1267 | |
| 1268 | /* ndlp could be freed in DSM, save these values now */ |
| 1269 | type = ndlp->nlp_type; |
| 1270 | did = ndlp->nlp_DID; |
| 1271 | |
| 1272 | if (irsp->ulpStatus) { |
| 1273 | /* Check for retry */ |
| 1274 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1275 | /* ELS command is being retried */ |
| 1276 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1277 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1278 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1279 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1280 | } |
| 1281 | goto out; |
| 1282 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1283 | /* PLOGI failed */ |
| 1284 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1285 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1286 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1287 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1288 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1289 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1290 | } else { |
| 1291 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1292 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1293 | cmdiocb->context2)->list.next, |
| 1294 | struct lpfc_dmabuf, list); |
| 1295 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1296 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1297 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1298 | } |
| 1299 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1300 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1301 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1302 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1303 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1304 | if (vport->num_disc_nodes == 0) { |
| 1305 | spin_lock_irq(shost->host_lock); |
| 1306 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1307 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1308 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1309 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1310 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1311 | } |
| 1312 | } |
| 1313 | |
| 1314 | out: |
| 1315 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1316 | return; |
| 1317 | } |
| 1318 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1319 | /** |
| 1320 | * lpfc_issue_els_plogi: Issue an plogi iocb command for a vport. |
| 1321 | * @vport: pointer to a host virtual N_Port data structure. |
| 1322 | * @did: destination port identifier. |
| 1323 | * @retry: number of retries to the command IOCB. |
| 1324 | * |
| 1325 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1326 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1327 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1328 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1329 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1330 | * |
| 1331 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1332 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1333 | * will be stored into the context1 field of the IOCB for the completion |
| 1334 | * callback function to the PLOGI ELS command. |
| 1335 | * |
| 1336 | * Return code |
| 1337 | * 0 - Successfully issued a plogi for @vport |
| 1338 | * 1 - failed to issue a plogi for @vport |
| 1339 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1340 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1341 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1342 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1343 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1344 | struct serv_parm *sp; |
| 1345 | IOCB_t *icmd; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1346 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1347 | struct lpfc_iocbq *elsiocb; |
| 1348 | struct lpfc_sli_ring *pring; |
| 1349 | struct lpfc_sli *psli; |
| 1350 | uint8_t *pcmd; |
| 1351 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1352 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1353 | |
| 1354 | psli = &phba->sli; |
| 1355 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 1356 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1357 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1358 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1359 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1360 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1361 | /* 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] | 1362 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1363 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1364 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1365 | if (!elsiocb) |
| 1366 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1367 | |
| 1368 | icmd = &elsiocb->iocb; |
| 1369 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1370 | |
| 1371 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1372 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1373 | pcmd += sizeof(uint32_t); |
| 1374 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1375 | sp = (struct serv_parm *) pcmd; |
| 1376 | |
| 1377 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1378 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1379 | |
| 1380 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1381 | sp->cmn.fcphHigh = FC_PH3; |
| 1382 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1383 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1384 | "Issue PLOGI: did:x%x", |
| 1385 | did, 0, 0); |
| 1386 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1387 | phba->fc_stat.elsXmitPLOGI++; |
| 1388 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1389 | ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| 1390 | |
| 1391 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1392 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1393 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1394 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1395 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1396 | } |
| 1397 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1398 | /** |
| 1399 | * lpfc_cmpl_els_prli: Completion callback function for prli. |
| 1400 | * @phba: pointer to lpfc hba data structure. |
| 1401 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1402 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1403 | * |
| 1404 | * This routine is the completion callback function for a Process Login |
| 1405 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 1406 | * status. If there is error status reported, PRLI retry shall be attempted |
| 1407 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 1408 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 1409 | * ndlp to mark the PRLI completion. |
| 1410 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1411 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1412 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1413 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1414 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1415 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1416 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1417 | IOCB_t *irsp; |
| 1418 | struct lpfc_sli *psli; |
| 1419 | struct lpfc_nodelist *ndlp; |
| 1420 | |
| 1421 | psli = &phba->sli; |
| 1422 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1423 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1424 | |
| 1425 | irsp = &(rspiocb->iocb); |
| 1426 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1427 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1428 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1429 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1430 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1431 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1432 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 1433 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1434 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1435 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1436 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1437 | "0103 PRLI completes to NPort x%x " |
| 1438 | "Data: x%x x%x x%x x%x\n", |
| 1439 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1440 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1441 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1442 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1443 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1444 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1445 | goto out; |
| 1446 | |
| 1447 | if (irsp->ulpStatus) { |
| 1448 | /* Check for retry */ |
| 1449 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1450 | /* ELS command is being retried */ |
| 1451 | goto out; |
| 1452 | } |
| 1453 | /* PRLI failed */ |
| 1454 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1455 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1456 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1457 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1458 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1459 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1460 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1461 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1462 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1463 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1464 | out: |
| 1465 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1466 | return; |
| 1467 | } |
| 1468 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1469 | /** |
| 1470 | * lpfc_issue_els_prli: Issue a prli iocb command for a vport. |
| 1471 | * @vport: pointer to a host virtual N_Port data structure. |
| 1472 | * @ndlp: pointer to a node-list data structure. |
| 1473 | * @retry: number of retries to the command IOCB. |
| 1474 | * |
| 1475 | * This routine issues a Process Login (PRLI) ELS command for the |
| 1476 | * @vport. The PRLI service parameters are set up in the payload of the |
| 1477 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 1478 | * is put to the IOCB completion callback func field before invoking the |
| 1479 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 1480 | * |
| 1481 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1482 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1483 | * will be stored into the context1 field of the IOCB for the completion |
| 1484 | * callback function to the PRLI ELS command. |
| 1485 | * |
| 1486 | * Return code |
| 1487 | * 0 - successfully issued prli iocb command for @vport |
| 1488 | * 1 - failed to issue prli iocb command for @vport |
| 1489 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1490 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1491 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1492 | uint8_t retry) |
| 1493 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1494 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1495 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1496 | PRLI *npr; |
| 1497 | IOCB_t *icmd; |
| 1498 | struct lpfc_iocbq *elsiocb; |
| 1499 | struct lpfc_sli_ring *pring; |
| 1500 | struct lpfc_sli *psli; |
| 1501 | uint8_t *pcmd; |
| 1502 | uint16_t cmdsize; |
| 1503 | |
| 1504 | psli = &phba->sli; |
| 1505 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 1506 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1507 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1508 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1509 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1510 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1511 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1512 | |
| 1513 | icmd = &elsiocb->iocb; |
| 1514 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1515 | |
| 1516 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1517 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1518 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1519 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1520 | |
| 1521 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 1522 | npr = (PRLI *) pcmd; |
| 1523 | /* |
| 1524 | * If our firmware version is 3.20 or later, |
| 1525 | * set the following bits for FC-TAPE support. |
| 1526 | */ |
| 1527 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 1528 | npr->ConfmComplAllowed = 1; |
| 1529 | npr->Retry = 1; |
| 1530 | npr->TaskRetryIdReq = 1; |
| 1531 | } |
| 1532 | npr->estabImagePair = 1; |
| 1533 | npr->readXferRdyDis = 1; |
| 1534 | |
| 1535 | /* For FCP support */ |
| 1536 | npr->prliType = PRLI_FCP_TYPE; |
| 1537 | npr->initiatorFunc = 1; |
| 1538 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1539 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1540 | "Issue PRLI: did:x%x", |
| 1541 | ndlp->nlp_DID, 0, 0); |
| 1542 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1543 | phba->fc_stat.elsXmitPRLI++; |
| 1544 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1545 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1546 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1547 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1548 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1549 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1550 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1551 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1552 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1553 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1554 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1555 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1556 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1557 | } |
| 1558 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1559 | /** |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1560 | * lpfc_rscn_disc: Perform rscn discovery for a vport. |
| 1561 | * @vport: pointer to a host virtual N_Port data structure. |
| 1562 | * |
| 1563 | * This routine performs Registration State Change Notification (RSCN) |
| 1564 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 1565 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 1566 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 1567 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 1568 | * invoked to check and handle possible more RSCN came in during the period |
| 1569 | * of processing the current ones. |
| 1570 | **/ |
| 1571 | static void |
| 1572 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 1573 | { |
| 1574 | lpfc_can_disctmo(vport); |
| 1575 | |
| 1576 | /* RSCN discovery */ |
| 1577 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 1578 | if (vport->fc_npr_cnt) |
| 1579 | if (lpfc_els_disc_plogi(vport)) |
| 1580 | return; |
| 1581 | |
| 1582 | lpfc_end_rscn(vport); |
| 1583 | } |
| 1584 | |
| 1585 | /** |
| 1586 | * lpfc_adisc_done: Complete the adisc phase of discovery. |
| 1587 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 1588 | * |
| 1589 | * This function is called when the final ADISC is completed during discovery. |
| 1590 | * This function handles clearing link attention or issuing reg_vpi depending |
| 1591 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 1592 | * discovery. |
| 1593 | * This function is called with no locks held. |
| 1594 | **/ |
| 1595 | static void |
| 1596 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 1597 | { |
| 1598 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1599 | struct lpfc_hba *phba = vport->phba; |
| 1600 | |
| 1601 | /* |
| 1602 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 1603 | * and continue discovery. |
| 1604 | */ |
| 1605 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 1606 | !(vport->fc_flag & FC_RSCN_MODE)) { |
| 1607 | lpfc_issue_reg_vpi(phba, vport); |
| 1608 | return; |
| 1609 | } |
| 1610 | /* |
| 1611 | * For SLI2, we need to set port_state to READY |
| 1612 | * and continue discovery. |
| 1613 | */ |
| 1614 | if (vport->port_state < LPFC_VPORT_READY) { |
| 1615 | /* If we get here, there is nothing to ADISC */ |
| 1616 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1617 | lpfc_issue_clear_la(phba, vport); |
| 1618 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 1619 | vport->num_disc_nodes = 0; |
| 1620 | /* go thru NPR list, issue ELS PLOGIs */ |
| 1621 | if (vport->fc_npr_cnt) |
| 1622 | lpfc_els_disc_plogi(vport); |
| 1623 | if (!vport->num_disc_nodes) { |
| 1624 | spin_lock_irq(shost->host_lock); |
| 1625 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1626 | spin_unlock_irq(shost->host_lock); |
| 1627 | lpfc_can_disctmo(vport); |
| 1628 | lpfc_end_rscn(vport); |
| 1629 | } |
| 1630 | } |
| 1631 | vport->port_state = LPFC_VPORT_READY; |
| 1632 | } else |
| 1633 | lpfc_rscn_disc(vport); |
| 1634 | } |
| 1635 | |
| 1636 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1637 | * lpfc_more_adisc: Issue more adisc as needed. |
| 1638 | * @vport: pointer to a host virtual N_Port data structure. |
| 1639 | * |
| 1640 | * This routine determines whether there are more ndlps on a @vport |
| 1641 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 1642 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 1643 | * remaining nodes which need to have ADISC sent. |
| 1644 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1645 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1646 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1647 | { |
| 1648 | int sentadisc; |
| 1649 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1650 | if (vport->num_disc_nodes) |
| 1651 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1652 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1653 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1654 | "0210 Continue discovery with %d ADISCs to go " |
| 1655 | "Data: x%x x%x x%x\n", |
| 1656 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 1657 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1658 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1659 | if (vport->fc_flag & FC_NLP_MORE) { |
| 1660 | lpfc_set_disctmo(vport); |
| 1661 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 1662 | sentadisc = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1663 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1664 | if (!vport->num_disc_nodes) |
| 1665 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1666 | return; |
| 1667 | } |
| 1668 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1669 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1670 | * lpfc_cmpl_els_adisc: Completion callback function for adisc. |
| 1671 | * @phba: pointer to lpfc hba data structure. |
| 1672 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1673 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1674 | * |
| 1675 | * This routine is the completion function for issuing the Address Discover |
| 1676 | * (ADISC) command. It first checks to see whether link went down during |
| 1677 | * the discovery process. If so, the node will be marked as node port |
| 1678 | * recovery for issuing discover IOCB by the link attention handler and |
| 1679 | * exit. Otherwise, the response status is checked. If error was reported |
| 1680 | * in the response status, the ADISC command shall be retried by invoking |
| 1681 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 1682 | * the response status, the state machine is invoked to set transition |
| 1683 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 1684 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1685 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1686 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1687 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1688 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1689 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1690 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1691 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1692 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1693 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1694 | |
| 1695 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1696 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1697 | |
| 1698 | irsp = &(rspiocb->iocb); |
| 1699 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1700 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1701 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1702 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 1703 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1704 | ndlp->nlp_DID); |
| 1705 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1706 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1707 | * is being used during discovery. |
| 1708 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1709 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1710 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1711 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1712 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1713 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1714 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1715 | "0104 ADISC completes to NPort x%x " |
| 1716 | "Data: x%x x%x x%x x%x x%x\n", |
| 1717 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1718 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1719 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1720 | if (lpfc_els_chk_latt(vport)) { |
| 1721 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1722 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1723 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1724 | goto out; |
| 1725 | } |
| 1726 | |
| 1727 | if (irsp->ulpStatus) { |
| 1728 | /* Check for retry */ |
| 1729 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1730 | /* ELS command is being retried */ |
| 1731 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1732 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1733 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1734 | spin_unlock_irq(shost->host_lock); |
| 1735 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1736 | } |
| 1737 | goto out; |
| 1738 | } |
| 1739 | /* ADISC failed */ |
| 1740 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1741 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1742 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1743 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1744 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1745 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1746 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1747 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1748 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1749 | /* Check to see if there are more ADISCs to be sent */ |
| 1750 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1751 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1752 | out: |
| 1753 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1754 | return; |
| 1755 | } |
| 1756 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1757 | /** |
| 1758 | * lpfc_issue_els_adisc: Issue an address discover iocb to an node on a vport. |
| 1759 | * @vport: pointer to a virtual N_Port data structure. |
| 1760 | * @ndlp: pointer to a node-list data structure. |
| 1761 | * @retry: number of retries to the command IOCB. |
| 1762 | * |
| 1763 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 1764 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 1765 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 1766 | * to issue the ADISC ELS command. |
| 1767 | * |
| 1768 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1769 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1770 | * will be stored into the context1 field of the IOCB for the completion |
| 1771 | * callback function to the ADISC ELS command. |
| 1772 | * |
| 1773 | * Return code |
| 1774 | * 0 - successfully issued adisc |
| 1775 | * 1 - failed to issue adisc |
| 1776 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1777 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1778 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1779 | uint8_t retry) |
| 1780 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1781 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1782 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1783 | ADISC *ap; |
| 1784 | IOCB_t *icmd; |
| 1785 | struct lpfc_iocbq *elsiocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1786 | struct lpfc_sli *psli = &phba->sli; |
| 1787 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1788 | uint8_t *pcmd; |
| 1789 | uint16_t cmdsize; |
| 1790 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1791 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1792 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1793 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1794 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1795 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1796 | |
| 1797 | icmd = &elsiocb->iocb; |
| 1798 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1799 | |
| 1800 | /* For ADISC request, remainder of payload is service parameters */ |
| 1801 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1802 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1803 | |
| 1804 | /* Fill in ADISC payload */ |
| 1805 | ap = (ADISC *) pcmd; |
| 1806 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1807 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 1808 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1809 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1810 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1811 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1812 | "Issue ADISC: did:x%x", |
| 1813 | ndlp->nlp_DID, 0, 0); |
| 1814 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1815 | phba->fc_stat.elsXmitADISC++; |
| 1816 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1817 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1818 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1819 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1820 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1821 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1822 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1823 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1824 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1825 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1826 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1827 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1828 | } |
| 1829 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1830 | /** |
| 1831 | * lpfc_cmpl_els_logo: Completion callback function for logo. |
| 1832 | * @phba: pointer to lpfc hba data structure. |
| 1833 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1834 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1835 | * |
| 1836 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 1837 | * command. If no error status was reported from the LOGO response, the |
| 1838 | * state machine of the associated ndlp shall be invoked for transition with |
| 1839 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 1840 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 1841 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1842 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1843 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1844 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1845 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1846 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 1847 | struct lpfc_vport *vport = ndlp->vport; |
| 1848 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1849 | IOCB_t *irsp; |
| 1850 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1851 | |
| 1852 | psli = &phba->sli; |
| 1853 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1854 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1855 | |
| 1856 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1857 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1858 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1859 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1860 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1861 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1862 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 1863 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1864 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1865 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1866 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1867 | "0105 LOGO completes to NPort x%x " |
| 1868 | "Data: x%x x%x x%x x%x\n", |
| 1869 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1870 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1871 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1872 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1873 | goto out; |
| 1874 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1875 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 1876 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 1877 | * which should abort all outstanding IOs. |
| 1878 | */ |
| 1879 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 1880 | NLP_EVT_DEVICE_RM); |
| 1881 | goto out; |
| 1882 | } |
| 1883 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1884 | if (irsp->ulpStatus) { |
| 1885 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1886 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1887 | /* ELS command is being retried */ |
| 1888 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1889 | /* LOGO failed */ |
| 1890 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1891 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1892 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1893 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1894 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1895 | NLP_EVT_CMPL_LOGO); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1896 | } else |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1897 | /* Good status, call state machine. |
| 1898 | * This will unregister the rpi if needed. |
| 1899 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1900 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1901 | NLP_EVT_CMPL_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1902 | out: |
| 1903 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1904 | return; |
| 1905 | } |
| 1906 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1907 | /** |
| 1908 | * lpfc_issue_els_logo: Issue a logo to an node on a vport. |
| 1909 | * @vport: pointer to a virtual N_Port data structure. |
| 1910 | * @ndlp: pointer to a node-list data structure. |
| 1911 | * @retry: number of retries to the command IOCB. |
| 1912 | * |
| 1913 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 1914 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 1915 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 1916 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 1917 | * |
| 1918 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1919 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1920 | * will be stored into the context1 field of the IOCB for the completion |
| 1921 | * callback function to the LOGO ELS command. |
| 1922 | * |
| 1923 | * Return code |
| 1924 | * 0 - successfully issued logo |
| 1925 | * 1 - failed to issue logo |
| 1926 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1927 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1928 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1929 | uint8_t retry) |
| 1930 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1931 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1932 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1933 | IOCB_t *icmd; |
| 1934 | struct lpfc_iocbq *elsiocb; |
| 1935 | struct lpfc_sli_ring *pring; |
| 1936 | struct lpfc_sli *psli; |
| 1937 | uint8_t *pcmd; |
| 1938 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1939 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1940 | |
| 1941 | psli = &phba->sli; |
| 1942 | pring = &psli->ring[LPFC_ELS_RING]; |
| 1943 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1944 | spin_lock_irq(shost->host_lock); |
| 1945 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 1946 | spin_unlock_irq(shost->host_lock); |
| 1947 | return 0; |
| 1948 | } |
| 1949 | spin_unlock_irq(shost->host_lock); |
| 1950 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1951 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1952 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1953 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1954 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1955 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1956 | |
| 1957 | icmd = &elsiocb->iocb; |
| 1958 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1959 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1960 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1961 | |
| 1962 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1963 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1964 | pcmd += sizeof(uint32_t); |
| 1965 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1966 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1967 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1968 | "Issue LOGO: did:x%x", |
| 1969 | ndlp->nlp_DID, 0, 0); |
| 1970 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1971 | phba->fc_stat.elsXmitLOGO++; |
| 1972 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1973 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1974 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1975 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1976 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| 1977 | |
| 1978 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1979 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1980 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1981 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1982 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1983 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1984 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1985 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1986 | } |
| 1987 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1988 | /** |
| 1989 | * lpfc_cmpl_els_cmd: Completion callback function for generic els command. |
| 1990 | * @phba: pointer to lpfc hba data structure. |
| 1991 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1992 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1993 | * |
| 1994 | * This routine is a generic completion callback function for ELS commands. |
| 1995 | * Specifically, it is the callback function which does not need to perform |
| 1996 | * any command specific operations. It is currently used by the ELS command |
| 1997 | * issuing routines for the ELS State Change Request (SCR), |
| 1998 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 1999 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2000 | * certain debug loggings, this callback function simply invokes the |
| 2001 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2002 | * discovery process. |
| 2003 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2004 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2005 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2006 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2007 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2008 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2009 | IOCB_t *irsp; |
| 2010 | |
| 2011 | irsp = &rspiocb->iocb; |
| 2012 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2013 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2014 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2015 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2016 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2017 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2018 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2019 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2020 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2021 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2022 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2023 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2024 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2025 | return; |
| 2026 | } |
| 2027 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2028 | /** |
| 2029 | * lpfc_issue_els_scr: Issue a scr to an node on a vport. |
| 2030 | * @vport: pointer to a host virtual N_Port data structure. |
| 2031 | * @nportid: N_Port identifier to the remote node. |
| 2032 | * @retry: number of retries to the command IOCB. |
| 2033 | * |
| 2034 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2035 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2036 | * first search the @vport node list to find the matching ndlp. If no such |
| 2037 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2038 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2039 | * routine is invoked to send the SCR IOCB. |
| 2040 | * |
| 2041 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2042 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2043 | * will be stored into the context1 field of the IOCB for the completion |
| 2044 | * callback function to the SCR ELS command. |
| 2045 | * |
| 2046 | * Return code |
| 2047 | * 0 - Successfully issued scr command |
| 2048 | * 1 - Failed to issue scr command |
| 2049 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2050 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2051 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2052 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2053 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2054 | IOCB_t *icmd; |
| 2055 | struct lpfc_iocbq *elsiocb; |
| 2056 | struct lpfc_sli_ring *pring; |
| 2057 | struct lpfc_sli *psli; |
| 2058 | uint8_t *pcmd; |
| 2059 | uint16_t cmdsize; |
| 2060 | struct lpfc_nodelist *ndlp; |
| 2061 | |
| 2062 | psli = &phba->sli; |
| 2063 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2064 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2065 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2066 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2067 | if (!ndlp) { |
| 2068 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2069 | if (!ndlp) |
| 2070 | return 1; |
| 2071 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2072 | lpfc_enqueue_node(vport, ndlp); |
| 2073 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2074 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2075 | if (!ndlp) |
| 2076 | return 1; |
| 2077 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2078 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2079 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2080 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2081 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2082 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2083 | /* This will trigger the release of the node just |
| 2084 | * allocated |
| 2085 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2086 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2087 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2088 | } |
| 2089 | |
| 2090 | icmd = &elsiocb->iocb; |
| 2091 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2092 | |
| 2093 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2094 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2095 | |
| 2096 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2097 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2098 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2099 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2100 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2101 | "Issue SCR: did:x%x", |
| 2102 | ndlp->nlp_DID, 0, 0); |
| 2103 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2104 | phba->fc_stat.elsXmitSCR++; |
| 2105 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2106 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2107 | /* The additional lpfc_nlp_put will cause the following |
| 2108 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2109 | * the node. |
| 2110 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2111 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2112 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2113 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2114 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2115 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2116 | * trigger the release of node. |
| 2117 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2118 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2119 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2120 | } |
| 2121 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2122 | /** |
| 2123 | * lpfc_issue_els_farpr: Issue a farp to an node on a vport. |
| 2124 | * @vport: pointer to a host virtual N_Port data structure. |
| 2125 | * @nportid: N_Port identifier to the remote node. |
| 2126 | * @retry: number of retries to the command IOCB. |
| 2127 | * |
| 2128 | * This routine issues a Fibre Channel Address Resolution Response |
| 2129 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2130 | * is passed into the function. It first search the @vport node list to find |
| 2131 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2132 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2133 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2134 | * |
| 2135 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2136 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2137 | * will be stored into the context1 field of the IOCB for the completion |
| 2138 | * callback function to the PARPR ELS command. |
| 2139 | * |
| 2140 | * Return code |
| 2141 | * 0 - Successfully issued farpr command |
| 2142 | * 1 - Failed to issue farpr command |
| 2143 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2144 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2145 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2146 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2147 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2148 | IOCB_t *icmd; |
| 2149 | struct lpfc_iocbq *elsiocb; |
| 2150 | struct lpfc_sli_ring *pring; |
| 2151 | struct lpfc_sli *psli; |
| 2152 | FARP *fp; |
| 2153 | uint8_t *pcmd; |
| 2154 | uint32_t *lp; |
| 2155 | uint16_t cmdsize; |
| 2156 | struct lpfc_nodelist *ondlp; |
| 2157 | struct lpfc_nodelist *ndlp; |
| 2158 | |
| 2159 | psli = &phba->sli; |
| 2160 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2161 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2162 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2163 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2164 | if (!ndlp) { |
| 2165 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2166 | if (!ndlp) |
| 2167 | return 1; |
| 2168 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2169 | lpfc_enqueue_node(vport, ndlp); |
| 2170 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2171 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2172 | if (!ndlp) |
| 2173 | return 1; |
| 2174 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2175 | |
| 2176 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2177 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2178 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2179 | /* This will trigger the release of the node just |
| 2180 | * allocated |
| 2181 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2182 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2183 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2184 | } |
| 2185 | |
| 2186 | icmd = &elsiocb->iocb; |
| 2187 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2188 | |
| 2189 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2190 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2191 | |
| 2192 | /* Fill in FARPR payload */ |
| 2193 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2194 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2195 | lp = (uint32_t *) pcmd; |
| 2196 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2197 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2198 | fp->Rflags = 0; |
| 2199 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2200 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2201 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2202 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2203 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2204 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2205 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2206 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2207 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2208 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2209 | } |
| 2210 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2211 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2212 | "Issue FARPR: did:x%x", |
| 2213 | ndlp->nlp_DID, 0, 0); |
| 2214 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2215 | phba->fc_stat.elsXmitFARPR++; |
| 2216 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2217 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2218 | /* The additional lpfc_nlp_put will cause the following |
| 2219 | * lpfc_els_free_iocb routine to trigger the release of |
| 2220 | * the node. |
| 2221 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2222 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2223 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2224 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2225 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2226 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2227 | * trigger the release of the node. |
| 2228 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2229 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2230 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2231 | } |
| 2232 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2233 | /** |
| 2234 | * lpfc_cancel_retry_delay_tmo: Cancel the timer with delayed iocb-cmd retry. |
| 2235 | * @vport: pointer to a host virtual N_Port data structure. |
| 2236 | * @nlp: pointer to a node-list data structure. |
| 2237 | * |
| 2238 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2239 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2240 | * removes the ELS retry event if it presents. In addition, if the |
| 2241 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2242 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2243 | * ADISC. |
| 2244 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2245 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2246 | 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] | 2247 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2248 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2249 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2250 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2251 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2252 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2253 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2254 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2255 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2256 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2257 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2258 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2259 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2260 | /* Decrement nlp reference count held for the delayed retry */ |
| 2261 | evtp = &nlp->els_retry_evt; |
| 2262 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2263 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2264 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2265 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2266 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2267 | spin_unlock_irq(shost->host_lock); |
| 2268 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2269 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2270 | /* Check if there are more ADISCs to be sent */ |
| 2271 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2272 | } else { |
| 2273 | /* Check if there are more PLOGIs to be sent */ |
| 2274 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2275 | if (vport->num_disc_nodes == 0) { |
| 2276 | spin_lock_irq(shost->host_lock); |
| 2277 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2278 | spin_unlock_irq(shost->host_lock); |
| 2279 | lpfc_can_disctmo(vport); |
| 2280 | lpfc_end_rscn(vport); |
| 2281 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2282 | } |
| 2283 | } |
| 2284 | } |
| 2285 | return; |
| 2286 | } |
| 2287 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2288 | /** |
| 2289 | * lpfc_els_retry_delay: Timer function with a ndlp delayed function timer. |
| 2290 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2291 | * |
| 2292 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2293 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2294 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2295 | * adds the delayed events to the HBA work list and invokes the |
| 2296 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2297 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2298 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2299 | * reference to ndlp will still be available when the worker thread gets |
| 2300 | * to the event associated with the ndlp. |
| 2301 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2302 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2303 | lpfc_els_retry_delay(unsigned long ptr) |
| 2304 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2305 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2306 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2307 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2308 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2309 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2310 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2311 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2312 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2313 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2314 | return; |
| 2315 | } |
| 2316 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2317 | /* We need to hold the node by incrementing the reference |
| 2318 | * count until the queued work is done |
| 2319 | */ |
| 2320 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2321 | if (evtp->evt_arg1) { |
| 2322 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2323 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2324 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2325 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2326 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2327 | return; |
| 2328 | } |
| 2329 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2330 | /** |
| 2331 | * lpfc_els_retry_delay_handler: Work thread handler for ndlp delayed function. |
| 2332 | * @ndlp: pointer to a node-list data structure. |
| 2333 | * |
| 2334 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 2335 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 2336 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 2337 | * function according to the delayed ELS command to retry the command. |
| 2338 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2339 | void |
| 2340 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 2341 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2342 | struct lpfc_vport *vport = ndlp->vport; |
| 2343 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2344 | uint32_t cmd, did, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2345 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2346 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2347 | did = ndlp->nlp_DID; |
| 2348 | cmd = ndlp->nlp_last_elscmd; |
| 2349 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2350 | |
| 2351 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2352 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2353 | return; |
| 2354 | } |
| 2355 | |
| 2356 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2357 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 2358 | /* |
| 2359 | * If a discovery event readded nlp_delayfunc after timer |
| 2360 | * firing and before processing the timer, cancel the |
| 2361 | * nlp_delayfunc. |
| 2362 | */ |
| 2363 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2364 | retry = ndlp->nlp_retry; |
| 2365 | |
| 2366 | switch (cmd) { |
| 2367 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2368 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2369 | break; |
| 2370 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2371 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2372 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2373 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2374 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2375 | break; |
| 2376 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2377 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2378 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2379 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2380 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2381 | break; |
| 2382 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2383 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2384 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2385 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2386 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2387 | break; |
| 2388 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2389 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2390 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2391 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2392 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2393 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2394 | case ELS_CMD_FDISC: |
| 2395 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
| 2396 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2397 | } |
| 2398 | return; |
| 2399 | } |
| 2400 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2401 | /** |
| 2402 | * lpfc_els_retry: Make retry decision on an els command iocb. |
| 2403 | * @phba: pointer to lpfc hba data structure. |
| 2404 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2405 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2406 | * |
| 2407 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 2408 | * failed. The following ELS IOCBs use this function for retrying the command |
| 2409 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 2410 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 2411 | * returned error status, it makes the decision whether a retry shall be |
| 2412 | * issued for the command, and whether a retry shall be made immediately or |
| 2413 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 2414 | * is called to retry the command. In the later case, the ELS command shall |
| 2415 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 2416 | * ndlp for the delayed command issusing. |
| 2417 | * |
| 2418 | * Return code |
| 2419 | * 0 - No retry of els command is made |
| 2420 | * 1 - Immediate or delayed retry of els command is made |
| 2421 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2422 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2423 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2424 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2425 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2426 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2427 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2428 | IOCB_t *irsp = &rspiocb->iocb; |
| 2429 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2430 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2431 | uint32_t *elscmd; |
| 2432 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2433 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2434 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2435 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2436 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2437 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2438 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2439 | /* Note: context2 may be 0 for internal driver abort |
| 2440 | * of delays ELS command. |
| 2441 | */ |
| 2442 | |
| 2443 | if (pcmd && pcmd->virt) { |
| 2444 | elscmd = (uint32_t *) (pcmd->virt); |
| 2445 | cmd = *elscmd++; |
| 2446 | } |
| 2447 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2448 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2449 | did = ndlp->nlp_DID; |
| 2450 | else { |
| 2451 | /* We should only hit this case for retrying PLOGI */ |
| 2452 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2453 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2454 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 2455 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2456 | return 1; |
| 2457 | } |
| 2458 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2459 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2460 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 2461 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 2462 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2463 | switch (irsp->ulpStatus) { |
| 2464 | case IOSTAT_FCP_RSP_ERROR: |
| 2465 | case IOSTAT_REMOTE_STOP: |
| 2466 | break; |
| 2467 | |
| 2468 | case IOSTAT_LOCAL_REJECT: |
| 2469 | switch ((irsp->un.ulpWord[4] & 0xff)) { |
| 2470 | case IOERR_LOOP_OPEN_FAILURE: |
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 | /** |
| 2721 | * lpfc_els_free_data: Free lpfc dma buffer and data structure with an iocb. |
| 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 | /** |
| 2753 | * lpfc_els_free_bpl: Free lpfc dma buffer and data structure with bpl. |
| 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 | /** |
| 2773 | * lpfc_els_free_iocb: Free a command iocb and its associated resources. |
| 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 | /** |
| 2866 | * lpfc_cmpl_els_logo_acc: Completion callback function to logo acc response. |
| 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 | /** |
| 2920 | * lpfc_mbx_cmpl_dflt_rpi: Completion callbk func for unreg dflt rpi mbox cmd. |
| 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 | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2950 | return; |
| 2951 | } |
| 2952 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2953 | /** |
| 2954 | * lpfc_cmpl_els_rsp: Completion callback function for els response iocb cmd. |
| 2955 | * @phba: pointer to lpfc hba data structure. |
| 2956 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2957 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2958 | * |
| 2959 | * This routine is the completion callback function for ELS Response IOCB |
| 2960 | * command. In normal case, this callback function just properly sets the |
| 2961 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 2962 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 2963 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 2964 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 2965 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 2966 | * routine shall be invoked trying to release the ndlp if no other threads |
| 2967 | * are currently referring it. |
| 2968 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2969 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2970 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2971 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2972 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2973 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2974 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 2975 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2976 | IOCB_t *irsp; |
| 2977 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2978 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2979 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2980 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2981 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 2982 | irsp = &rspiocb->iocb; |
| 2983 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2984 | if (cmdiocb->context_un.mbox) |
| 2985 | mbox = cmdiocb->context_un.mbox; |
| 2986 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2987 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 2988 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 2989 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2990 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2991 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 2992 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2993 | /* A LS_RJT associated with Default RPI cleanup has its own |
| 2994 | * seperate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2995 | */ |
| 2996 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 2997 | ls_rjt = 1; |
| 2998 | } |
| 2999 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3000 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3001 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3002 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3003 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3004 | if (mp) { |
| 3005 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3006 | kfree(mp); |
| 3007 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3008 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3009 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3010 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3011 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3012 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3013 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3014 | /* Indicate the node has already released, |
| 3015 | * should not reference to it from within |
| 3016 | * the routine lpfc_els_free_iocb. |
| 3017 | */ |
| 3018 | cmdiocb->context1 = NULL; |
| 3019 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3020 | goto out; |
| 3021 | } |
| 3022 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3023 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3024 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3025 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3026 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3027 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3028 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3029 | "0110 ELS response tag x%x completes " |
| 3030 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3031 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3032 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3033 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3034 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3035 | if (mbox) { |
| 3036 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3037 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3038 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3039 | /* Increment reference count to ndlp to hold the |
| 3040 | * reference to ndlp for the callback function. |
| 3041 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3042 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3043 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3044 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3045 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3046 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3047 | } |
| 3048 | else { |
| 3049 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3050 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3051 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3052 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3053 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3054 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3055 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3056 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3057 | else |
| 3058 | /* Decrement the ndlp reference count we |
| 3059 | * set for this failed mailbox command. |
| 3060 | */ |
| 3061 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3062 | |
| 3063 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3064 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3065 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3066 | "Data: x%x x%x x%x\n", |
| 3067 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3068 | ndlp->nlp_rpi); |
| 3069 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3070 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3071 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3072 | /* Indicate node has already been released, |
| 3073 | * should not reference to it from within |
| 3074 | * the routine lpfc_els_free_iocb. |
| 3075 | */ |
| 3076 | cmdiocb->context1 = NULL; |
| 3077 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3078 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3079 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3080 | if (!lpfc_error_lost_link(irsp) && |
| 3081 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3082 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3083 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3084 | /* Indicate node has already been |
| 3085 | * released, should not reference |
| 3086 | * to it from within the routine |
| 3087 | * lpfc_els_free_iocb. |
| 3088 | */ |
| 3089 | cmdiocb->context1 = NULL; |
| 3090 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3091 | } |
| 3092 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3093 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3094 | if (mp) { |
| 3095 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3096 | kfree(mp); |
| 3097 | } |
| 3098 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3099 | } |
| 3100 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3101 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3102 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3103 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3104 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3105 | |
| 3106 | /* If the node is not being used by another discovery thread, |
| 3107 | * and we are sending a reject, we are done with it. |
| 3108 | * Release driver reference count here and free associated |
| 3109 | * resources. |
| 3110 | */ |
| 3111 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3112 | if (lpfc_nlp_not_used(ndlp)) |
| 3113 | /* Indicate node has already been released, |
| 3114 | * should not reference to it from within |
| 3115 | * the routine lpfc_els_free_iocb. |
| 3116 | */ |
| 3117 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3118 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3119 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3120 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3121 | return; |
| 3122 | } |
| 3123 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3124 | /** |
| 3125 | * lpfc_els_rsp_acc: Prepare and issue an acc response iocb command. |
| 3126 | * @vport: pointer to a host virtual N_Port data structure. |
| 3127 | * @flag: the els command code to be accepted. |
| 3128 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3129 | * @ndlp: pointer to a node-list data structure. |
| 3130 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3131 | * |
| 3132 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3133 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3134 | * specific ACC response command to be issued and invokes the |
| 3135 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3136 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3137 | * field of the IOCB for the completion callback function to issue the |
| 3138 | * mailbox command to the HBA later when callback is invoked. |
| 3139 | * |
| 3140 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3141 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3142 | * will be stored into the context1 field of the IOCB for the completion |
| 3143 | * callback function to the corresponding response ELS IOCB command. |
| 3144 | * |
| 3145 | * Return code |
| 3146 | * 0 - Successfully issued acc response |
| 3147 | * 1 - Failed to issue acc response |
| 3148 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3149 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3150 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3151 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3152 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3153 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3154 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3155 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3156 | IOCB_t *icmd; |
| 3157 | IOCB_t *oldcmd; |
| 3158 | struct lpfc_iocbq *elsiocb; |
| 3159 | struct lpfc_sli_ring *pring; |
| 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; |
| 3167 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 3168 | oldcmd = &oldiocb->iocb; |
| 3169 | |
| 3170 | switch (flag) { |
| 3171 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3172 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3173 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3174 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3175 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3176 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3177 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3178 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3179 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3180 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3181 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3182 | icmd = &elsiocb->iocb; |
| 3183 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3184 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3185 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3186 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3187 | |
| 3188 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3189 | "Issue ACC: did:x%x flg:x%x", |
| 3190 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3191 | break; |
| 3192 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3193 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3194 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3195 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3196 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3197 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3198 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3199 | icmd = &elsiocb->iocb; |
| 3200 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3201 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3202 | |
| 3203 | if (mbox) |
| 3204 | elsiocb->context_un.mbox = mbox; |
| 3205 | |
| 3206 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3207 | pcmd += sizeof(uint32_t); |
| 3208 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3209 | |
| 3210 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3211 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 3212 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3213 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3214 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3215 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3216 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3217 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3218 | if (!elsiocb) |
| 3219 | return 1; |
| 3220 | |
| 3221 | icmd = &elsiocb->iocb; |
| 3222 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3223 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3224 | |
| 3225 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3226 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3227 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 3228 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 3229 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3230 | |
| 3231 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3232 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 3233 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3234 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3235 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3236 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3237 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3238 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3239 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3240 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
| 3241 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", |
| 3242 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3243 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3244 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3245 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3246 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3247 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3248 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3249 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 3250 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3251 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3252 | } |
| 3253 | |
| 3254 | phba->fc_stat.elsXmitACC++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3255 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3256 | if (rc == IOCB_ERROR) { |
| 3257 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3258 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3259 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3260 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3261 | } |
| 3262 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3263 | /** |
| 3264 | * lpfc_els_rsp_reject: Propare and issue a rjt response iocb command. |
| 3265 | * @vport: pointer to a virtual N_Port data structure. |
| 3266 | * @rejectError: |
| 3267 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3268 | * @ndlp: pointer to a node-list data structure. |
| 3269 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3270 | * |
| 3271 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 3272 | * command. If a @mbox pointer is passed in, it will be put into the |
| 3273 | * context_un.mbox field of the IOCB for the completion callback function |
| 3274 | * to issue to the HBA later. |
| 3275 | * |
| 3276 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3277 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3278 | * will be stored into the context1 field of the IOCB for the completion |
| 3279 | * callback function to the reject response ELS IOCB command. |
| 3280 | * |
| 3281 | * Return code |
| 3282 | * 0 - Successfully issued reject response |
| 3283 | * 1 - Failed to issue reject response |
| 3284 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3285 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3286 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3287 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 3288 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3289 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3290 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3291 | IOCB_t *icmd; |
| 3292 | IOCB_t *oldcmd; |
| 3293 | struct lpfc_iocbq *elsiocb; |
| 3294 | struct lpfc_sli_ring *pring; |
| 3295 | struct lpfc_sli *psli; |
| 3296 | uint8_t *pcmd; |
| 3297 | uint16_t cmdsize; |
| 3298 | int rc; |
| 3299 | |
| 3300 | psli = &phba->sli; |
| 3301 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 3302 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3303 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3304 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3305 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3306 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3307 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3308 | |
| 3309 | icmd = &elsiocb->iocb; |
| 3310 | oldcmd = &oldiocb->iocb; |
| 3311 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3312 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3313 | |
| 3314 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3315 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3316 | *((uint32_t *) (pcmd)) = rejectError; |
| 3317 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3318 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3319 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3320 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3321 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3322 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3323 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 3324 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 3325 | "rpi x%x\n", |
| 3326 | rejectError, elsiocb->iotag, |
| 3327 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 3328 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3329 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3330 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 3331 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 3332 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3333 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3334 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3335 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3336 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3337 | if (rc == IOCB_ERROR) { |
| 3338 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3339 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3340 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3341 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3342 | } |
| 3343 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3344 | /** |
| 3345 | * lpfc_els_rsp_adisc_acc: Prepare and issue acc response to adisc iocb cmd. |
| 3346 | * @vport: pointer to a virtual N_Port data structure. |
| 3347 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3348 | * @ndlp: pointer to a node-list data structure. |
| 3349 | * |
| 3350 | * This routine prepares and issues an Accept (ACC) response to Address |
| 3351 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 3352 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3353 | * |
| 3354 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3355 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3356 | * will be stored into the context1 field of the IOCB for the completion |
| 3357 | * callback function to the ADISC Accept response ELS IOCB command. |
| 3358 | * |
| 3359 | * Return code |
| 3360 | * 0 - Successfully issued acc adisc response |
| 3361 | * 1 - Failed to issue adisc acc response |
| 3362 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3363 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3364 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 3365 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3366 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3367 | struct lpfc_hba *phba = vport->phba; |
| 3368 | struct lpfc_sli *psli = &phba->sli; |
| 3369 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3370 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3371 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3372 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3373 | uint8_t *pcmd; |
| 3374 | uint16_t cmdsize; |
| 3375 | int rc; |
| 3376 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3377 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3378 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3379 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3380 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3381 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3382 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3383 | icmd = &elsiocb->iocb; |
| 3384 | oldcmd = &oldiocb->iocb; |
| 3385 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3386 | |
| 3387 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3388 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3389 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 3390 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 3391 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3392 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3393 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3394 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3395 | |
| 3396 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3397 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3398 | |
| 3399 | ap = (ADISC *) (pcmd); |
| 3400 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3401 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3402 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3403 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3404 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3405 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3406 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 3407 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3408 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3409 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3410 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3411 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3412 | if (rc == IOCB_ERROR) { |
| 3413 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3414 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3415 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3416 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3417 | } |
| 3418 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3419 | /** |
| 3420 | * lpfc_els_rsp_prli_acc: Prepare and issue acc response to prli iocb cmd. |
| 3421 | * @vport: pointer to a virtual N_Port data structure. |
| 3422 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3423 | * @ndlp: pointer to a node-list data structure. |
| 3424 | * |
| 3425 | * This routine prepares and issues an Accept (ACC) response to Process |
| 3426 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 3427 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3428 | * |
| 3429 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3430 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3431 | * will be stored into the context1 field of the IOCB for the completion |
| 3432 | * callback function to the PRLI Accept response ELS IOCB command. |
| 3433 | * |
| 3434 | * Return code |
| 3435 | * 0 - Successfully issued acc prli response |
| 3436 | * 1 - Failed to issue acc prli response |
| 3437 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3438 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3439 | 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] | 3440 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3441 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3442 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3443 | PRLI *npr; |
| 3444 | lpfc_vpd_t *vpd; |
| 3445 | IOCB_t *icmd; |
| 3446 | IOCB_t *oldcmd; |
| 3447 | struct lpfc_iocbq *elsiocb; |
| 3448 | struct lpfc_sli_ring *pring; |
| 3449 | struct lpfc_sli *psli; |
| 3450 | uint8_t *pcmd; |
| 3451 | uint16_t cmdsize; |
| 3452 | int rc; |
| 3453 | |
| 3454 | psli = &phba->sli; |
| 3455 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 3456 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3457 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3458 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3459 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3460 | if (!elsiocb) |
| 3461 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3462 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3463 | icmd = &elsiocb->iocb; |
| 3464 | oldcmd = &oldiocb->iocb; |
| 3465 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3466 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3467 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3468 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 3469 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 3470 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3471 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3472 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3473 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3474 | |
| 3475 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3476 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3477 | |
| 3478 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3479 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3480 | |
| 3481 | npr = (PRLI *) pcmd; |
| 3482 | vpd = &phba->vpd; |
| 3483 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3484 | * If the remote port is a target and our firmware version is 3.20 or |
| 3485 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3486 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3487 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 3488 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3489 | npr->ConfmComplAllowed = 1; |
| 3490 | npr->Retry = 1; |
| 3491 | npr->TaskRetryIdReq = 1; |
| 3492 | } |
| 3493 | |
| 3494 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 3495 | npr->estabImagePair = 1; |
| 3496 | npr->readXferRdyDis = 1; |
| 3497 | npr->ConfmComplAllowed = 1; |
| 3498 | |
| 3499 | npr->prliType = PRLI_FCP_TYPE; |
| 3500 | npr->initiatorFunc = 1; |
| 3501 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3502 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3503 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 3504 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3505 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3506 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3507 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3508 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3509 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3510 | if (rc == IOCB_ERROR) { |
| 3511 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3512 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3513 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3514 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3515 | } |
| 3516 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3517 | /** |
| 3518 | * lpfc_els_rsp_rnid_acc: Issue rnid acc response iocb command. |
| 3519 | * @vport: pointer to a virtual N_Port data structure. |
| 3520 | * @format: rnid command format. |
| 3521 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3522 | * @ndlp: pointer to a node-list data structure. |
| 3523 | * |
| 3524 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 3525 | * (ACC) response. It constructs the RNID ACC response command according to |
| 3526 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 3527 | * issue the response. Note that this command does not need to hold the ndlp |
| 3528 | * reference count for the callback. So, the ndlp reference count taken by |
| 3529 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 3530 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 3531 | * there is no ndlp reference available. |
| 3532 | * |
| 3533 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3534 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3535 | * will be stored into the context1 field of the IOCB for the completion |
| 3536 | * callback function. However, for the RNID Accept Response ELS command, |
| 3537 | * this is undone later by this routine after the IOCB is allocated. |
| 3538 | * |
| 3539 | * Return code |
| 3540 | * 0 - Successfully issued acc rnid response |
| 3541 | * 1 - Failed to issue acc rnid response |
| 3542 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3543 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3544 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3545 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3546 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3547 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3548 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3549 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3550 | struct lpfc_iocbq *elsiocb; |
| 3551 | struct lpfc_sli_ring *pring; |
| 3552 | struct lpfc_sli *psli; |
| 3553 | uint8_t *pcmd; |
| 3554 | uint16_t cmdsize; |
| 3555 | int rc; |
| 3556 | |
| 3557 | psli = &phba->sli; |
| 3558 | pring = &psli->ring[LPFC_ELS_RING]; |
| 3559 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3560 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 3561 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3562 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3563 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3564 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3565 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3566 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3567 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3568 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3569 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3570 | icmd = &elsiocb->iocb; |
| 3571 | oldcmd = &oldiocb->iocb; |
| 3572 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3573 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3574 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3575 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 3576 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3577 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3578 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3579 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3580 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3581 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3582 | rn = (RNID *) (pcmd); |
| 3583 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3584 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 3585 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3586 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3587 | switch (format) { |
| 3588 | case 0: |
| 3589 | rn->SpecificLen = 0; |
| 3590 | break; |
| 3591 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3592 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3593 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3594 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3595 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 3596 | rn->un.topologyDisc.physPort = 0; |
| 3597 | rn->un.topologyDisc.attachedNodes = 0; |
| 3598 | break; |
| 3599 | default: |
| 3600 | rn->CommonLen = 0; |
| 3601 | rn->SpecificLen = 0; |
| 3602 | break; |
| 3603 | } |
| 3604 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3605 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3606 | "Issue ACC RNID: did:x%x flg:x%x", |
| 3607 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3608 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3609 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3610 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3611 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3612 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 3613 | * it could be freed */ |
| 3614 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3615 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3616 | if (rc == IOCB_ERROR) { |
| 3617 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3618 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3619 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3620 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3621 | } |
| 3622 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3623 | /** |
| 3624 | * lpfc_els_disc_adisc: Issue remaining adisc iocbs to npr nodes of a vport. |
| 3625 | * @vport: pointer to a host virtual N_Port data structure. |
| 3626 | * |
| 3627 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 3628 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 3629 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 3630 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 3631 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 3632 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 3633 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 3634 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 3635 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 3636 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 3637 | * no more ADISC need to be sent. |
| 3638 | * |
| 3639 | * Return code |
| 3640 | * The number of N_Ports with adisc issued. |
| 3641 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3642 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3643 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3644 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3645 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3646 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3647 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3648 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3649 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3650 | 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] | 3651 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3652 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3653 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3654 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3655 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3656 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3657 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3658 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3659 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3660 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 3661 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3662 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3663 | vport->num_disc_nodes++; |
| 3664 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3665 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3666 | spin_lock_irq(shost->host_lock); |
| 3667 | vport->fc_flag |= FC_NLP_MORE; |
| 3668 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3669 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3670 | } |
| 3671 | } |
| 3672 | } |
| 3673 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3674 | spin_lock_irq(shost->host_lock); |
| 3675 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3676 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3677 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3678 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3679 | } |
| 3680 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3681 | /** |
| 3682 | * lpfc_els_disc_plogi: Issue plogi for all npr nodes of a vport before adisc. |
| 3683 | * @vport: pointer to a host virtual N_Port data structure. |
| 3684 | * |
| 3685 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 3686 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 3687 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 3688 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 3689 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 3690 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 3691 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 3692 | * later pick up. On the other hand, after walking through all the ndlps with |
| 3693 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 3694 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 3695 | * PLOGI need to be sent. |
| 3696 | * |
| 3697 | * Return code |
| 3698 | * The number of N_Ports with plogi issued. |
| 3699 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3700 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3701 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3702 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3703 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3704 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3705 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3706 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3707 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 3708 | 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] | 3709 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3710 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3711 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3712 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3713 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 3714 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 3715 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3716 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 3717 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3718 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3719 | vport->num_disc_nodes++; |
| 3720 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3721 | vport->cfg_discovery_threads) { |
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); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3725 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3726 | } |
| 3727 | } |
| 3728 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3729 | if (sentplogi) { |
| 3730 | lpfc_set_disctmo(vport); |
| 3731 | } |
| 3732 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3733 | spin_lock_irq(shost->host_lock); |
| 3734 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3735 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3736 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3737 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3738 | } |
| 3739 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3740 | /** |
| 3741 | * lpfc_els_flush_rscn: Clean up any rscn activities with a vport. |
| 3742 | * @vport: pointer to a host virtual N_Port data structure. |
| 3743 | * |
| 3744 | * This routine cleans up any Registration State Change Notification |
| 3745 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 3746 | * @vport together with the host_lock is used to prevent multiple thread |
| 3747 | * trying to access the RSCN array on a same @vport at the same time. |
| 3748 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3749 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3750 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3751 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3752 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3753 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3754 | int i; |
| 3755 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3756 | spin_lock_irq(shost->host_lock); |
| 3757 | if (vport->fc_rscn_flush) { |
| 3758 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3759 | spin_unlock_irq(shost->host_lock); |
| 3760 | return; |
| 3761 | } |
| 3762 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 3763 | vport->fc_rscn_flush = 1; |
| 3764 | spin_unlock_irq(shost->host_lock); |
| 3765 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3766 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3767 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3768 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3769 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3770 | spin_lock_irq(shost->host_lock); |
| 3771 | vport->fc_rscn_id_cnt = 0; |
| 3772 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 3773 | spin_unlock_irq(shost->host_lock); |
| 3774 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3775 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 3776 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3777 | } |
| 3778 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3779 | /** |
| 3780 | * lpfc_rscn_payload_check: Check whether there is a pending rscn to a did. |
| 3781 | * @vport: pointer to a host virtual N_Port data structure. |
| 3782 | * @did: remote destination port identifier. |
| 3783 | * |
| 3784 | * This routine checks whether there is any pending Registration State |
| 3785 | * Configuration Notification (RSCN) to a @did on @vport. |
| 3786 | * |
| 3787 | * Return code |
| 3788 | * None zero - The @did matched with a pending rscn |
| 3789 | * 0 - not able to match @did with a pending rscn |
| 3790 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3791 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3792 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3793 | { |
| 3794 | D_ID ns_did; |
| 3795 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3796 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3797 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3798 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3799 | |
| 3800 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3801 | |
| 3802 | /* Never match fabric nodes for RSCNs */ |
| 3803 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3804 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3805 | |
| 3806 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3807 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3808 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3809 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3810 | spin_lock_irq(shost->host_lock); |
| 3811 | if (vport->fc_rscn_flush) { |
| 3812 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3813 | spin_unlock_irq(shost->host_lock); |
| 3814 | return 0; |
| 3815 | } |
| 3816 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 3817 | vport->fc_rscn_flush = 1; |
| 3818 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3819 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3820 | lp = vport->fc_rscn_id_list[i]->virt; |
| 3821 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 3822 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3823 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3824 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 3825 | payload_len -= sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3826 | switch (rscn_did.un.b.resv) { |
| 3827 | case 0: /* Single N_Port ID effected */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3828 | if (ns_did.un.word == rscn_did.un.word) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3829 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3830 | break; |
| 3831 | case 1: /* Whole N_Port Area effected */ |
| 3832 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 3833 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3834 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3835 | break; |
| 3836 | case 2: /* Whole N_Port Domain effected */ |
| 3837 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3838 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3839 | break; |
| 3840 | default: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3841 | /* Unknown Identifier in RSCN node */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3842 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 3843 | "0217 Unknown Identifier in " |
| 3844 | "RSCN payload Data: x%x\n", |
| 3845 | rscn_did.un.word); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3846 | case 3: /* Whole Fabric effected */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3847 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3848 | } |
| 3849 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3850 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3851 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 3852 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3853 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3854 | return_did_out: |
| 3855 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 3856 | vport->fc_rscn_flush = 0; |
| 3857 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3858 | } |
| 3859 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3860 | /** |
| 3861 | * lpfc_rscn_recovery_check: Send recovery event to vport nodes matching rscn |
| 3862 | * @vport: pointer to a host virtual N_Port data structure. |
| 3863 | * |
| 3864 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 3865 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 3866 | * State Change Notification). |
| 3867 | * |
| 3868 | * Return code |
| 3869 | * 0 - Successful (currently alway return 0) |
| 3870 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3871 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3872 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3873 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3874 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3875 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3876 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3877 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3878 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3879 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 3880 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3881 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3882 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3883 | NLP_EVT_DEVICE_RECOVERY); |
| 3884 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3885 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3886 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3887 | } |
| 3888 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3889 | /** |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame^] | 3890 | * lpfc_send_rscn_event: Send an RSCN event to management application. |
| 3891 | * @vport: pointer to a host virtual N_Port data structure. |
| 3892 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3893 | * |
| 3894 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 3895 | * applications. |
| 3896 | */ |
| 3897 | static void |
| 3898 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 3899 | struct lpfc_iocbq *cmdiocb) |
| 3900 | { |
| 3901 | struct lpfc_dmabuf *pcmd; |
| 3902 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3903 | uint32_t *payload_ptr; |
| 3904 | uint32_t payload_len; |
| 3905 | struct lpfc_rscn_event_header *rscn_event_data; |
| 3906 | |
| 3907 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 3908 | payload_ptr = (uint32_t *) pcmd->virt; |
| 3909 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 3910 | |
| 3911 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 3912 | payload_len, GFP_KERNEL); |
| 3913 | if (!rscn_event_data) { |
| 3914 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3915 | "0147 Failed to allocate memory for RSCN event\n"); |
| 3916 | return; |
| 3917 | } |
| 3918 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 3919 | rscn_event_data->payload_length = payload_len; |
| 3920 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 3921 | payload_len); |
| 3922 | |
| 3923 | fc_host_post_vendor_event(shost, |
| 3924 | fc_get_event_number(), |
| 3925 | sizeof(struct lpfc_els_event_header) + payload_len, |
| 3926 | (char *)rscn_event_data, |
| 3927 | LPFC_NL_VENDOR_ID); |
| 3928 | |
| 3929 | kfree(rscn_event_data); |
| 3930 | } |
| 3931 | |
| 3932 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3933 | * lpfc_els_rcv_rscn: Process an unsolicited rscn iocb. |
| 3934 | * @vport: pointer to a host virtual N_Port data structure. |
| 3935 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3936 | * @ndlp: pointer to a node-list data structure. |
| 3937 | * |
| 3938 | * This routine processes an unsolicited RSCN (Registration State Change |
| 3939 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 3940 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 3941 | * discover state machine is about to begin discovery, it just accepts the |
| 3942 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 3943 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 3944 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 3945 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 3946 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 3947 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 3948 | * routine is invoked to handle the RSCN event. |
| 3949 | * |
| 3950 | * Return code |
| 3951 | * 0 - Just sent the acc response |
| 3952 | * 1 - Sent the acc response and waited for name server completion |
| 3953 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3954 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3955 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3956 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3957 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3958 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3959 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3960 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3961 | uint32_t *lp, *datap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3962 | IOCB_t *icmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3963 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3964 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3965 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 3966 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3967 | |
| 3968 | icmd = &cmdiocb->iocb; |
| 3969 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 3970 | lp = (uint32_t *) pcmd->virt; |
| 3971 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3972 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 3973 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3974 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3975 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 3976 | "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] | 3977 | vport->fc_flag, payload_len, *lp, |
| 3978 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame^] | 3979 | |
| 3980 | /* Send an RSCN event to the management application */ |
| 3981 | lpfc_send_rscn_event(vport, cmdiocb); |
| 3982 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 3983 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3984 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 3985 | FCH_EVT_RSCN, lp[i]); |
| 3986 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3987 | /* If we are about to begin discovery, just ACC the RSCN. |
| 3988 | * Discovery processing will satisfy it. |
| 3989 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3990 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3991 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 3992 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 3993 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 3994 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3995 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3996 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3997 | } |
| 3998 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3999 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 4000 | * just ACC and ignore it. |
| 4001 | */ |
| 4002 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4003 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4004 | i = payload_len; |
| 4005 | datap = lp; |
| 4006 | while (i > 0) { |
| 4007 | nportid = *datap++; |
| 4008 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 4009 | i -= sizeof(uint32_t); |
| 4010 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4011 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 4012 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4013 | } |
| 4014 | if (rscn_id == hba_id) { |
| 4015 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4016 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4017 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4018 | "Data: x%x x%x x%x x%x\n", |
| 4019 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4020 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4021 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4022 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 4023 | ndlp->nlp_DID, vport->port_state, |
| 4024 | ndlp->nlp_flag); |
| 4025 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4026 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4027 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4028 | return 0; |
| 4029 | } |
| 4030 | } |
| 4031 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4032 | spin_lock_irq(shost->host_lock); |
| 4033 | if (vport->fc_rscn_flush) { |
| 4034 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4035 | spin_unlock_irq(shost->host_lock); |
| 4036 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4037 | /* Send back ACC */ |
| 4038 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4039 | return 0; |
| 4040 | } |
| 4041 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4042 | vport->fc_rscn_flush = 1; |
| 4043 | spin_unlock_irq(shost->host_lock); |
| 4044 | /* Get the array count after sucessfully have the token */ |
| 4045 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4046 | /* If we are already processing an RSCN, save the received |
| 4047 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 4048 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4049 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4050 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4051 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 4052 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4053 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4054 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4055 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 4056 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4057 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4058 | vport->fc_flag |= FC_RSCN_MODE; |
| 4059 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4060 | if (rscn_cnt) { |
| 4061 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 4062 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 4063 | } |
| 4064 | if ((rscn_cnt) && |
| 4065 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 4066 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4067 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4068 | memcpy(((uint8_t *)cmd) + length, lp, |
| 4069 | payload_len); |
| 4070 | } else { |
| 4071 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 4072 | vport->fc_rscn_id_cnt++; |
| 4073 | /* If we zero, cmdiocb->context2, the calling |
| 4074 | * routine will not try to free it. |
| 4075 | */ |
| 4076 | cmdiocb->context2 = NULL; |
| 4077 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4078 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4079 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4080 | "0235 Deferred RSCN " |
| 4081 | "Data: x%x x%x x%x\n", |
| 4082 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4083 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4084 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4085 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 4086 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4087 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4088 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4089 | "0234 ReDiscovery RSCN " |
| 4090 | "Data: x%x x%x x%x\n", |
| 4091 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4092 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4093 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4094 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4095 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4096 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4097 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4098 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4099 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4100 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4101 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4102 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4103 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4104 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4105 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4106 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 4107 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4108 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4109 | spin_lock_irq(shost->host_lock); |
| 4110 | vport->fc_flag |= FC_RSCN_MODE; |
| 4111 | spin_unlock_irq(shost->host_lock); |
| 4112 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4113 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4114 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4115 | /* |
| 4116 | * If we zero, cmdiocb->context2, the calling routine will |
| 4117 | * not try to free it. |
| 4118 | */ |
| 4119 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4120 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4121 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4122 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4123 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4124 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4125 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4126 | } |
| 4127 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4128 | /** |
| 4129 | * lpfc_els_handle_rscn: Handle rscn for a vport. |
| 4130 | * @vport: pointer to a host virtual N_Port data structure. |
| 4131 | * |
| 4132 | * This routine handles the Registration State Configuration Notification |
| 4133 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 4134 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 4135 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 4136 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 4137 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 4138 | * RSCN activities with the @vport. |
| 4139 | * |
| 4140 | * Return code |
| 4141 | * 0 - Cleaned up rscn on the @vport |
| 4142 | * 1 - Wait for plogi to name server before proceed |
| 4143 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4144 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4145 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4146 | { |
| 4147 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4148 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4149 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4150 | /* Ignore RSCN if the port is being torn down. */ |
| 4151 | if (vport->load_flag & FC_UNLOADING) { |
| 4152 | lpfc_els_flush_rscn(vport); |
| 4153 | return 0; |
| 4154 | } |
| 4155 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4156 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4157 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4158 | |
| 4159 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4160 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4161 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 4162 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 4163 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4164 | |
| 4165 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4166 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4167 | vport->num_disc_nodes = 0; |
| 4168 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4169 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4170 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 4171 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4172 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4173 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4174 | /* Wait for NameServer query cmpl before we can |
| 4175 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4176 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4177 | } else { |
| 4178 | /* If login to NameServer does not exist, issue one */ |
| 4179 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4180 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4181 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4182 | /* Wait for NameServer login cmpl before we can |
| 4183 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4184 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4185 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4186 | if (ndlp) { |
| 4187 | ndlp = lpfc_enable_node(vport, ndlp, |
| 4188 | NLP_STE_PLOGI_ISSUE); |
| 4189 | if (!ndlp) { |
| 4190 | lpfc_els_flush_rscn(vport); |
| 4191 | return 0; |
| 4192 | } |
| 4193 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4194 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4195 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4196 | if (!ndlp) { |
| 4197 | lpfc_els_flush_rscn(vport); |
| 4198 | return 0; |
| 4199 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4200 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4201 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4202 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4203 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4204 | ndlp->nlp_type |= NLP_FABRIC; |
| 4205 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 4206 | /* Wait for NameServer login cmpl before we can |
| 4207 | * continue |
| 4208 | */ |
| 4209 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4210 | } |
| 4211 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4212 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4213 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4214 | } |
| 4215 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4216 | /** |
| 4217 | * lpfc_els_rcv_flogi: Process an unsolicited flogi iocb. |
| 4218 | * @vport: pointer to a host virtual N_Port data structure. |
| 4219 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4220 | * @ndlp: pointer to a node-list data structure. |
| 4221 | * |
| 4222 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 4223 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 4224 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 4225 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 4226 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 4227 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 4228 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 4229 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 4230 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 4231 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 4232 | * higher priority (as the winning port) and will initiate PLOGI and |
| 4233 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 4234 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 4235 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 4236 | * |
| 4237 | * Return code |
| 4238 | * 0 - Successfully processed the unsolicited flogi |
| 4239 | * 1 - Failed to process the unsolicited flogi |
| 4240 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4241 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4242 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4243 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4244 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4245 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4246 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4247 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4248 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 4249 | IOCB_t *icmd = &cmdiocb->iocb; |
| 4250 | struct serv_parm *sp; |
| 4251 | LPFC_MBOXQ_t *mbox; |
| 4252 | struct ls_rjt stat; |
| 4253 | uint32_t cmd, did; |
| 4254 | int rc; |
| 4255 | |
| 4256 | cmd = *lp++; |
| 4257 | sp = (struct serv_parm *) lp; |
| 4258 | |
| 4259 | /* FLOGI received */ |
| 4260 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4261 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4262 | |
| 4263 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 4264 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 4265 | did = icmd->un.elsreq64.remoteID; |
| 4266 | |
| 4267 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 4268 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4269 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4270 | "0113 An FLOGI ELS command x%x was " |
| 4271 | "received from DID x%x in Loop Mode\n", |
| 4272 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4273 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4274 | } |
| 4275 | |
| 4276 | did = Fabric_DID; |
| 4277 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4278 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4279 | /* For a FLOGI we accept, then if our portname is greater |
| 4280 | * then the remote portname we initiate Nport login. |
| 4281 | */ |
| 4282 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4283 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4284 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4285 | |
| 4286 | if (!rc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4287 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4288 | if (!mbox) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4289 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4290 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4291 | lpfc_linkdown(phba); |
| 4292 | lpfc_init_link(phba, mbox, |
| 4293 | phba->cfg_topology, |
| 4294 | phba->cfg_link_speed); |
| 4295 | mbox->mb.un.varInitLnk.lipsr_AL_PA = 0; |
| 4296 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4297 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4298 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4299 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4300 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4301 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4302 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4303 | return 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4304 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4305 | spin_lock_irq(shost->host_lock); |
| 4306 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 4307 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4308 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4309 | spin_lock_irq(shost->host_lock); |
| 4310 | vport->fc_flag |= FC_PT2PT; |
| 4311 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 4312 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4313 | } else { |
| 4314 | /* Reject this request because invalid parameters */ |
| 4315 | stat.un.b.lsRjtRsvd0 = 0; |
| 4316 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4317 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 4318 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4319 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4320 | NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4321 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4322 | } |
| 4323 | |
| 4324 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4325 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4326 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4327 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4328 | } |
| 4329 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4330 | /** |
| 4331 | * lpfc_els_rcv_rnid: Process an unsolicited rnid iocb. |
| 4332 | * @vport: pointer to a host virtual N_Port data structure. |
| 4333 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4334 | * @ndlp: pointer to a node-list data structure. |
| 4335 | * |
| 4336 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 4337 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 4338 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 4339 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 4340 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 4341 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 4342 | * |
| 4343 | * Return code |
| 4344 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 4345 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4346 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4347 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4348 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4349 | { |
| 4350 | struct lpfc_dmabuf *pcmd; |
| 4351 | uint32_t *lp; |
| 4352 | IOCB_t *icmd; |
| 4353 | RNID *rn; |
| 4354 | struct ls_rjt stat; |
| 4355 | uint32_t cmd, did; |
| 4356 | |
| 4357 | icmd = &cmdiocb->iocb; |
| 4358 | did = icmd->un.elsreq64.remoteID; |
| 4359 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4360 | lp = (uint32_t *) pcmd->virt; |
| 4361 | |
| 4362 | cmd = *lp++; |
| 4363 | rn = (RNID *) lp; |
| 4364 | |
| 4365 | /* RNID received */ |
| 4366 | |
| 4367 | switch (rn->Format) { |
| 4368 | case 0: |
| 4369 | case RNID_TOPOLOGY_DISC: |
| 4370 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4371 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4372 | break; |
| 4373 | default: |
| 4374 | /* Reject this request because format not supported */ |
| 4375 | stat.un.b.lsRjtRsvd0 = 0; |
| 4376 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4377 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4378 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4379 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4380 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4381 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4382 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4383 | } |
| 4384 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4385 | /** |
| 4386 | * lpfc_els_rcv_lirr: Process an unsolicited lirr iocb. |
| 4387 | * @vport: pointer to a host virtual N_Port data structure. |
| 4388 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4389 | * @ndlp: pointer to a node-list data structure. |
| 4390 | * |
| 4391 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 4392 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 4393 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 4394 | * |
| 4395 | * Return code |
| 4396 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 4397 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4398 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4399 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4400 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4401 | { |
| 4402 | struct ls_rjt stat; |
| 4403 | |
| 4404 | /* For now, unconditionally reject this command */ |
| 4405 | stat.un.b.lsRjtRsvd0 = 0; |
| 4406 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4407 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4408 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4409 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4410 | return 0; |
| 4411 | } |
| 4412 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4413 | /** |
| 4414 | * lpfc_els_rsp_rps_acc: Completion callbk func for MBX_READ_LNK_STAT mbox cmd. |
| 4415 | * @phba: pointer to lpfc hba data structure. |
| 4416 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4417 | * |
| 4418 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 4419 | * mailbox command. This callback function is to actually send the Accept |
| 4420 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 4421 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 4422 | * mailbox command, constructs the RPS response with the link statistics |
| 4423 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 4424 | * response to the RPS. |
| 4425 | * |
| 4426 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4427 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4428 | * will be stored into the context1 field of the IOCB for the completion |
| 4429 | * callback function to the RPS Accept Response ELS IOCB command. |
| 4430 | * |
| 4431 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4432 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4433 | 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] | 4434 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4435 | struct lpfc_sli *psli = &phba->sli; |
| 4436 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4437 | MAILBOX_t *mb; |
| 4438 | IOCB_t *icmd; |
| 4439 | RPS_RSP *rps_rsp; |
| 4440 | uint8_t *pcmd; |
| 4441 | struct lpfc_iocbq *elsiocb; |
| 4442 | struct lpfc_nodelist *ndlp; |
| 4443 | uint16_t xri, status; |
| 4444 | uint32_t cmdsize; |
| 4445 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4446 | mb = &pmb->mb; |
| 4447 | |
| 4448 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4449 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 4450 | pmb->context1 = NULL; |
| 4451 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4452 | |
| 4453 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4454 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4455 | return; |
| 4456 | } |
| 4457 | |
| 4458 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4459 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4460 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 4461 | lpfc_max_els_tries, ndlp, |
| 4462 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4463 | |
| 4464 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4465 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4466 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4467 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4468 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4469 | |
| 4470 | icmd = &elsiocb->iocb; |
| 4471 | icmd->ulpContext = xri; |
| 4472 | |
| 4473 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4474 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4475 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4476 | rps_rsp = (RPS_RSP *)pcmd; |
| 4477 | |
| 4478 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| 4479 | status = 0x10; |
| 4480 | else |
| 4481 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4482 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4483 | status |= 0x4; |
| 4484 | |
| 4485 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4486 | rps_rsp->portStatus = cpu_to_be16(status); |
| 4487 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 4488 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 4489 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 4490 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 4491 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 4492 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4493 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4494 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 4495 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 4496 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4497 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4498 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4499 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4500 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4501 | phba->fc_stat.elsXmitACC++; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4502 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4503 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4504 | return; |
| 4505 | } |
| 4506 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4507 | /** |
| 4508 | * lpfc_els_rcv_rps: Process an unsolicited rps iocb. |
| 4509 | * @vport: pointer to a host virtual N_Port data structure. |
| 4510 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4511 | * @ndlp: pointer to a node-list data structure. |
| 4512 | * |
| 4513 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 4514 | * ELS unsolicited event. It first checks the remote port state. If the |
| 4515 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 4516 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 4517 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 4518 | * for reading the HBA link statistics. It is for the callback function, |
| 4519 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 4520 | * to actually sending out RPS Accept (ACC) response. |
| 4521 | * |
| 4522 | * Return codes |
| 4523 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 4524 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4525 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4526 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4527 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4528 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4529 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4530 | uint32_t *lp; |
| 4531 | uint8_t flag; |
| 4532 | LPFC_MBOXQ_t *mbox; |
| 4533 | struct lpfc_dmabuf *pcmd; |
| 4534 | RPS *rps; |
| 4535 | struct ls_rjt stat; |
| 4536 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4537 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4538 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 4539 | /* reject the unsolicited RPS request and done with it */ |
| 4540 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4541 | |
| 4542 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4543 | lp = (uint32_t *) pcmd->virt; |
| 4544 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 4545 | rps = (RPS *) lp; |
| 4546 | |
| 4547 | if ((flag == 0) || |
| 4548 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4549 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4550 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4551 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4552 | printk("Fix me....\n"); |
| 4553 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4554 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 4555 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4556 | lpfc_read_lnk_stat(phba, mbox); |
| 4557 | mbox->context1 = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4558 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4559 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4560 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4561 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4562 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4563 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4564 | /* Mbox completion will send ELS Response */ |
| 4565 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4566 | /* Decrement reference count used for the failed mbox |
| 4567 | * command. |
| 4568 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4569 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4570 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4571 | } |
| 4572 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4573 | |
| 4574 | reject_out: |
| 4575 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4576 | stat.un.b.lsRjtRsvd0 = 0; |
| 4577 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4578 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4579 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4580 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4581 | return 0; |
| 4582 | } |
| 4583 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4584 | /** |
| 4585 | * lpfc_els_rsp_rpl_acc: Issue an accept rpl els command. |
| 4586 | * @vport: pointer to a host virtual N_Port data structure. |
| 4587 | * @cmdsize: size of the ELS command. |
| 4588 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4589 | * @ndlp: pointer to a node-list data structure. |
| 4590 | * |
| 4591 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 4592 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 4593 | * |
| 4594 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4595 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4596 | * will be stored into the context1 field of the IOCB for the completion |
| 4597 | * callback function to the RPL Accept Response ELS command. |
| 4598 | * |
| 4599 | * Return code |
| 4600 | * 0 - Successfully issued ACC RPL ELS command |
| 4601 | * 1 - Failed to issue ACC RPL ELS command |
| 4602 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4603 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4604 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 4605 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4606 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4607 | struct lpfc_hba *phba = vport->phba; |
| 4608 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4609 | RPL_RSP rpl_rsp; |
| 4610 | struct lpfc_iocbq *elsiocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4611 | struct lpfc_sli *psli = &phba->sli; |
| 4612 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4613 | uint8_t *pcmd; |
| 4614 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4615 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4616 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4617 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4618 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4619 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4620 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4621 | icmd = &elsiocb->iocb; |
| 4622 | oldcmd = &oldiocb->iocb; |
| 4623 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 4624 | |
| 4625 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4626 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4627 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4628 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 4629 | pcmd += sizeof(uint16_t); |
| 4630 | |
| 4631 | /* Setup the RPL ACC payload */ |
| 4632 | rpl_rsp.listLen = be32_to_cpu(1); |
| 4633 | rpl_rsp.index = 0; |
| 4634 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4635 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 4636 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4637 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4638 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4639 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4640 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4641 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 4642 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 4643 | "rpi x%x\n", |
| 4644 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4645 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4646 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4647 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4648 | phba->fc_stat.elsXmitACC++; |
| 4649 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
| 4650 | lpfc_els_free_iocb(phba, elsiocb); |
| 4651 | return 1; |
| 4652 | } |
| 4653 | return 0; |
| 4654 | } |
| 4655 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4656 | /** |
| 4657 | * lpfc_els_rcv_rpl: Process an unsolicited rpl iocb. |
| 4658 | * @vport: pointer to a host virtual N_Port data structure. |
| 4659 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4660 | * @ndlp: pointer to a node-list data structure. |
| 4661 | * |
| 4662 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 4663 | * unsolicited event. It first checks the remote port state. If the remote |
| 4664 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 4665 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 4666 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 4667 | * to accept the RPL. |
| 4668 | * |
| 4669 | * Return code |
| 4670 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 4671 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4672 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4673 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4674 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4675 | { |
| 4676 | struct lpfc_dmabuf *pcmd; |
| 4677 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4678 | uint32_t maxsize; |
| 4679 | uint16_t cmdsize; |
| 4680 | RPL *rpl; |
| 4681 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4682 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4683 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 4684 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4685 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4686 | stat.un.b.lsRjtRsvd0 = 0; |
| 4687 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4688 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4689 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4690 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4691 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4692 | /* rejected the unsolicited RPL request and done with it */ |
| 4693 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4694 | } |
| 4695 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4696 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4697 | lp = (uint32_t *) pcmd->virt; |
| 4698 | rpl = (RPL *) (lp + 1); |
| 4699 | |
| 4700 | maxsize = be32_to_cpu(rpl->maxsize); |
| 4701 | |
| 4702 | /* We support only one port */ |
| 4703 | if ((rpl->index == 0) && |
| 4704 | ((maxsize == 0) || |
| 4705 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 4706 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4707 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4708 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 4709 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4710 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4711 | |
| 4712 | return 0; |
| 4713 | } |
| 4714 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4715 | /** |
| 4716 | * lpfc_els_rcv_farp: Process an unsolicited farp request els command. |
| 4717 | * @vport: pointer to a virtual N_Port data structure. |
| 4718 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4719 | * @ndlp: pointer to a node-list data structure. |
| 4720 | * |
| 4721 | * This routine processes Fibre Channel Address Resolution Protocol |
| 4722 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 4723 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 4724 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 4725 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 4726 | * remote PortName is compared against the FC PortName stored in the @vport |
| 4727 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 4728 | * compared against the FC NodeName stored in the @vport data structure. |
| 4729 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 4730 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 4731 | * invoked to send out FARP Response to the remote node. Before sending the |
| 4732 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 4733 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 4734 | * routine is invoked to log into the remote port first. |
| 4735 | * |
| 4736 | * Return code |
| 4737 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 4738 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4739 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4740 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4741 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4742 | { |
| 4743 | struct lpfc_dmabuf *pcmd; |
| 4744 | uint32_t *lp; |
| 4745 | IOCB_t *icmd; |
| 4746 | FARP *fp; |
| 4747 | uint32_t cmd, cnt, did; |
| 4748 | |
| 4749 | icmd = &cmdiocb->iocb; |
| 4750 | did = icmd->un.elsreq64.remoteID; |
| 4751 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4752 | lp = (uint32_t *) pcmd->virt; |
| 4753 | |
| 4754 | cmd = *lp++; |
| 4755 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4756 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4757 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4758 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4759 | /* We will only support match on WWPN or WWNN */ |
| 4760 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4761 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4762 | } |
| 4763 | |
| 4764 | cnt = 0; |
| 4765 | /* If this FARP command is searching for my portname */ |
| 4766 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4767 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4768 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4769 | cnt = 1; |
| 4770 | } |
| 4771 | |
| 4772 | /* If this FARP command is searching for my nodename */ |
| 4773 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4774 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4775 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4776 | cnt = 1; |
| 4777 | } |
| 4778 | |
| 4779 | if (cnt) { |
| 4780 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 4781 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 4782 | /* Log back into the node before sending the FARP. */ |
| 4783 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4784 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4785 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4786 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4787 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4788 | } |
| 4789 | |
| 4790 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4791 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 4792 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4793 | } |
| 4794 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4795 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4796 | } |
| 4797 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4798 | /** |
| 4799 | * lpfc_els_rcv_farpr: Process an unsolicited farp response iocb. |
| 4800 | * @vport: pointer to a host virtual N_Port data structure. |
| 4801 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4802 | * @ndlp: pointer to a node-list data structure. |
| 4803 | * |
| 4804 | * This routine processes Fibre Channel Address Resolution Protocol |
| 4805 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 4806 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 4807 | * the FARP response request. |
| 4808 | * |
| 4809 | * Return code |
| 4810 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 4811 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4812 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4813 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4814 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4815 | { |
| 4816 | struct lpfc_dmabuf *pcmd; |
| 4817 | uint32_t *lp; |
| 4818 | IOCB_t *icmd; |
| 4819 | uint32_t cmd, did; |
| 4820 | |
| 4821 | icmd = &cmdiocb->iocb; |
| 4822 | did = icmd->un.elsreq64.remoteID; |
| 4823 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4824 | lp = (uint32_t *) pcmd->virt; |
| 4825 | |
| 4826 | cmd = *lp++; |
| 4827 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4828 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4829 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4830 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4831 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4832 | |
| 4833 | return 0; |
| 4834 | } |
| 4835 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4836 | /** |
| 4837 | * lpfc_els_rcv_fan: Process an unsolicited fan iocb command. |
| 4838 | * @vport: pointer to a host virtual N_Port data structure. |
| 4839 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4840 | * @fan_ndlp: pointer to a node-list data structure. |
| 4841 | * |
| 4842 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 4843 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 4844 | * only be processed on a physical port (i.e., the @vport represents the |
| 4845 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 4846 | * compared against those in the phba data structure. If any of those is |
| 4847 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 4848 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 4849 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 4850 | * is invoked to register login to the fabric. |
| 4851 | * |
| 4852 | * Return code |
| 4853 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 4854 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4855 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4856 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4857 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4858 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4859 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4860 | uint32_t *lp; |
| 4861 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4862 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4863 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 4864 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 4865 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4866 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4867 | if ((vport == phba->pport) && |
| 4868 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4869 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4870 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4871 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4872 | sizeof(struct lpfc_name)))) { |
| 4873 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4874 | lpfc_initial_flogi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4875 | } else { |
| 4876 | /* FAN verified - skip FLOGI */ |
| 4877 | vport->fc_myDID = vport->fc_prevDID; |
| 4878 | lpfc_issue_fabric_reglogin(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4879 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4880 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4881 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4882 | } |
| 4883 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4884 | /** |
| 4885 | * lpfc_els_timeout: Handler funciton to the els timer. |
| 4886 | * @ptr: holder for the timer function associated data. |
| 4887 | * |
| 4888 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 4889 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 4890 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 4891 | * up the worker thread. It is for the worker thread to invoke the routine |
| 4892 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 4893 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4894 | void |
| 4895 | lpfc_els_timeout(unsigned long ptr) |
| 4896 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4897 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 4898 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4899 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4900 | unsigned long iflag; |
| 4901 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4902 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4903 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
| 4904 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4905 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4906 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4907 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4908 | if (!tmo_posted) |
| 4909 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4910 | return; |
| 4911 | } |
| 4912 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4913 | /** |
| 4914 | * lpfc_els_timeout_handler: Process an els timeout event. |
| 4915 | * @vport: pointer to a virtual N_Port data structure. |
| 4916 | * |
| 4917 | * This routine is the actual handler function that processes an ELS timeout |
| 4918 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 4919 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 4920 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 4921 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4922 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4923 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4924 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4925 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4926 | struct lpfc_sli_ring *pring; |
| 4927 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 4928 | IOCB_t *cmd = NULL; |
| 4929 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4930 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4931 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4932 | uint32_t remote_ID = 0xffffffff; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4933 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4934 | /* If the timer is already canceled do nothing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4935 | if ((vport->work_port_events & WORKER_ELS_TMO) == 0) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4936 | return; |
| 4937 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4938 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4939 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 4940 | |
| 4941 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4942 | |
| 4943 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 4944 | cmd = &piocb->iocb; |
| 4945 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4946 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 4947 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 4948 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4949 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4950 | |
| 4951 | if (piocb->vport != vport) |
| 4952 | continue; |
| 4953 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4954 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4955 | if (pcmd) |
| 4956 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4957 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4958 | if (els_command == ELS_CMD_FARP || |
| 4959 | els_command == ELS_CMD_FARPR || |
| 4960 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4961 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4962 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4963 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4964 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4965 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4966 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4967 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4968 | continue; |
| 4969 | } |
| 4970 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4971 | remote_ID = 0xffffffff; |
| 4972 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4973 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4974 | else { |
| 4975 | struct lpfc_nodelist *ndlp; |
| 4976 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4977 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4978 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4979 | } |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4980 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4981 | "0127 ELS timeout Data: x%x x%x x%x " |
| 4982 | "x%x\n", els_command, |
| 4983 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4984 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4985 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4986 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 4987 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4988 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
| 4989 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4990 | } |
| 4991 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4992 | /** |
| 4993 | * lpfc_els_flush_cmd: Clean up the outstanding els commands to a vport. |
| 4994 | * @vport: pointer to a host virtual N_Port data structure. |
| 4995 | * |
| 4996 | * This routine is used to clean up all the outstanding ELS commands on a |
| 4997 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 4998 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 4999 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5000 | * the IOCBs with a non-NULL completion callback function, the callback |
| 5001 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5002 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 5003 | * callback function, the IOCB will simply be released. Finally, it walks |
| 5004 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 5005 | * completion queue IOCB that is associated with the @vport and is not |
| 5006 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 5007 | * part of the discovery state machine) out to HBA by invoking the |
| 5008 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 5009 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 5010 | * the IOCBs are aborted when this function returns. |
| 5011 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5012 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5013 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5014 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5015 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5016 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5017 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5018 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5019 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5020 | |
| 5021 | lpfc_fabric_abort_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5022 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5023 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5024 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5025 | cmd = &piocb->iocb; |
| 5026 | |
| 5027 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5028 | continue; |
| 5029 | } |
| 5030 | |
| 5031 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5032 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5033 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5034 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5035 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5036 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5037 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5038 | if (piocb->vport != vport) |
| 5039 | continue; |
| 5040 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5041 | list_move_tail(&piocb->list, &completions); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5042 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5043 | } |
| 5044 | |
| 5045 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5046 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5047 | continue; |
| 5048 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5049 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5050 | if (piocb->vport != vport) |
| 5051 | continue; |
| 5052 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5053 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5054 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5055 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5056 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5057 | while (!list_empty(&completions)) { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5058 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 5059 | cmd = &piocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5060 | list_del_init(&piocb->list); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5061 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5062 | if (!piocb->iocb_cmpl) |
| 5063 | lpfc_sli_release_iocbq(phba, piocb); |
| 5064 | else { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5065 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 5066 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 5067 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5068 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5069 | } |
| 5070 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5071 | return; |
| 5072 | } |
| 5073 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5074 | /** |
| 5075 | * lpfc_els_flush_all_cmd: Clean up all the outstanding els commands to a HBA. |
| 5076 | * @phba: pointer to lpfc hba data structure. |
| 5077 | * |
| 5078 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5079 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 5080 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5081 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5082 | * the IOCBs with the completion callback function associated, the callback |
| 5083 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5084 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 5085 | * callback function associated, the IOCB will simply be released. Finally, |
| 5086 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 5087 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 5088 | * management plane IOCBs that are not part of the discovery state machine) |
| 5089 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5090 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5091 | void |
| 5092 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 5093 | { |
| 5094 | LIST_HEAD(completions); |
| 5095 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 5096 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5097 | IOCB_t *cmd = NULL; |
| 5098 | |
| 5099 | lpfc_fabric_abort_hba(phba); |
| 5100 | spin_lock_irq(&phba->hbalock); |
| 5101 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5102 | cmd = &piocb->iocb; |
| 5103 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5104 | continue; |
| 5105 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
| 5106 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5107 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5108 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5109 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| 5110 | continue; |
| 5111 | list_move_tail(&piocb->list, &completions); |
| 5112 | pring->txq_cnt--; |
| 5113 | } |
| 5114 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5115 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5116 | continue; |
| 5117 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5118 | } |
| 5119 | spin_unlock_irq(&phba->hbalock); |
| 5120 | while (!list_empty(&completions)) { |
| 5121 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 5122 | cmd = &piocb->iocb; |
| 5123 | list_del_init(&piocb->list); |
| 5124 | if (!piocb->iocb_cmpl) |
| 5125 | lpfc_sli_release_iocbq(phba, piocb); |
| 5126 | else { |
| 5127 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 5128 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 5129 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 5130 | } |
| 5131 | } |
| 5132 | return; |
| 5133 | } |
| 5134 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5135 | /** |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5136 | * lpfc_send_els_failure_event: Posts an ELS command failure event. |
| 5137 | * @phba: Pointer to hba context object. |
| 5138 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 5139 | * @rspiocbp: Pointer to response iocb which reported error. |
| 5140 | * |
| 5141 | * This function sends an event when there is an ELS command |
| 5142 | * failure. |
| 5143 | **/ |
| 5144 | void |
| 5145 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 5146 | struct lpfc_iocbq *cmdiocbp, |
| 5147 | struct lpfc_iocbq *rspiocbp) |
| 5148 | { |
| 5149 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 5150 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5151 | struct lpfc_lsrjt_event lsrjt_event; |
| 5152 | struct lpfc_fabric_event_header fabric_event; |
| 5153 | struct ls_rjt stat; |
| 5154 | struct lpfc_nodelist *ndlp; |
| 5155 | uint32_t *pcmd; |
| 5156 | |
| 5157 | ndlp = cmdiocbp->context1; |
| 5158 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 5159 | return; |
| 5160 | |
| 5161 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 5162 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 5163 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 5164 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 5165 | sizeof(struct lpfc_name)); |
| 5166 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 5167 | sizeof(struct lpfc_name)); |
| 5168 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 5169 | cmdiocbp->context2)->virt); |
| 5170 | lsrjt_event.command = *pcmd; |
| 5171 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 5172 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 5173 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 5174 | fc_host_post_vendor_event(shost, |
| 5175 | fc_get_event_number(), |
| 5176 | sizeof(lsrjt_event), |
| 5177 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame^] | 5178 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5179 | return; |
| 5180 | } |
| 5181 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 5182 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 5183 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 5184 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 5185 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 5186 | else |
| 5187 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 5188 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 5189 | sizeof(struct lpfc_name)); |
| 5190 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 5191 | sizeof(struct lpfc_name)); |
| 5192 | fc_host_post_vendor_event(shost, |
| 5193 | fc_get_event_number(), |
| 5194 | sizeof(fabric_event), |
| 5195 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame^] | 5196 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5197 | return; |
| 5198 | } |
| 5199 | |
| 5200 | } |
| 5201 | |
| 5202 | /** |
| 5203 | * lpfc_send_els_event: Posts unsolicited els event. |
| 5204 | * @vport: Pointer to vport object. |
| 5205 | * @ndlp: Pointer FC node object. |
| 5206 | * @cmd: ELS command code. |
| 5207 | * |
| 5208 | * This function posts an event when there is an incoming |
| 5209 | * unsolicited ELS command. |
| 5210 | **/ |
| 5211 | static void |
| 5212 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 5213 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame^] | 5214 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5215 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame^] | 5216 | struct lpfc_els_event_header *els_data = NULL; |
| 5217 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5218 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5219 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame^] | 5220 | if (*payload == ELS_CMD_LOGO) { |
| 5221 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 5222 | if (!logo_data) { |
| 5223 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5224 | "0148 Failed to allocate memory " |
| 5225 | "for LOGO event\n"); |
| 5226 | return; |
| 5227 | } |
| 5228 | els_data = &logo_data->header; |
| 5229 | } else { |
| 5230 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 5231 | GFP_KERNEL); |
| 5232 | if (!els_data) { |
| 5233 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5234 | "0149 Failed to allocate memory " |
| 5235 | "for ELS event\n"); |
| 5236 | return; |
| 5237 | } |
| 5238 | } |
| 5239 | els_data->event_type = FC_REG_ELS_EVENT; |
| 5240 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5241 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame^] | 5242 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5243 | break; |
| 5244 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame^] | 5245 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5246 | break; |
| 5247 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame^] | 5248 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 5249 | break; |
| 5250 | case ELS_CMD_LOGO: |
| 5251 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 5252 | /* Copy the WWPN in the LOGO payload */ |
| 5253 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 5254 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5255 | break; |
| 5256 | default: |
| 5257 | return; |
| 5258 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame^] | 5259 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 5260 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 5261 | if (*payload == ELS_CMD_LOGO) { |
| 5262 | fc_host_post_vendor_event(shost, |
| 5263 | fc_get_event_number(), |
| 5264 | sizeof(struct lpfc_logo_event), |
| 5265 | (char *)logo_data, |
| 5266 | LPFC_NL_VENDOR_ID); |
| 5267 | kfree(logo_data); |
| 5268 | } else { |
| 5269 | fc_host_post_vendor_event(shost, |
| 5270 | fc_get_event_number(), |
| 5271 | sizeof(struct lpfc_els_event_header), |
| 5272 | (char *)els_data, |
| 5273 | LPFC_NL_VENDOR_ID); |
| 5274 | kfree(els_data); |
| 5275 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5276 | |
| 5277 | return; |
| 5278 | } |
| 5279 | |
| 5280 | |
| 5281 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5282 | * lpfc_els_unsol_buffer: Process an unsolicited event data buffer. |
| 5283 | * @phba: pointer to lpfc hba data structure. |
| 5284 | * @pring: pointer to a SLI ring. |
| 5285 | * @vport: pointer to a host virtual N_Port data structure. |
| 5286 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 5287 | * |
| 5288 | * This routine is used for processing the IOCB associated with a unsolicited |
| 5289 | * event. It first determines whether there is an existing ndlp that matches |
| 5290 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 5291 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 5292 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 5293 | * of the discovery state machine. |
| 5294 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5295 | static void |
| 5296 | 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] | 5297 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5298 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5299 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5300 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5301 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5302 | uint32_t *payload; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5303 | uint32_t cmd, did, newnode, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5304 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5305 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5306 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5307 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5308 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5309 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5310 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 5311 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5312 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5313 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5314 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5315 | did = icmd->un.rcvels.remoteID; |
| 5316 | if (icmd->ulpStatus) { |
| 5317 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5318 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 5319 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5320 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5321 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5322 | |
| 5323 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5324 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5325 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5326 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5327 | /* Ignore traffic recevied during vport shutdown. */ |
| 5328 | if (vport->load_flag & FC_UNLOADING) |
| 5329 | goto dropit; |
| 5330 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5331 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5332 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5333 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5334 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5335 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5336 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5337 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5338 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5339 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5340 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5341 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5342 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5343 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5344 | ndlp = lpfc_enable_node(vport, ndlp, |
| 5345 | NLP_STE_UNUSED_NODE); |
| 5346 | if (!ndlp) |
| 5347 | goto dropit; |
| 5348 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5349 | newnode = 1; |
| 5350 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 5351 | ndlp->nlp_type |= NLP_FABRIC; |
| 5352 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 5353 | /* This is similar to the new node path */ |
| 5354 | ndlp = lpfc_nlp_get(ndlp); |
| 5355 | if (!ndlp) |
| 5356 | goto dropit; |
| 5357 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5358 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5359 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5360 | |
| 5361 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5362 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5363 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5364 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5365 | |
| 5366 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 5367 | cmd &= ELS_CMD_MASK; |
| 5368 | } |
| 5369 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5370 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5371 | "0112 ELS command x%x received from NPORT x%x " |
| 5372 | "Data: x%x\n", cmd, did, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5373 | switch (cmd) { |
| 5374 | case ELS_CMD_PLOGI: |
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 PLOGI: 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.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5380 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
| 5381 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame^] | 5382 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5383 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5384 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 5385 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 5386 | rjt_err = LSRJT_UNABLE_TPC; |
| 5387 | break; |
| 5388 | } |
| 5389 | /* We get here, and drop thru, if we are PT2PT with |
| 5390 | * another NPort and the other side has initiated |
| 5391 | * the PLOGI before responding to our FLOGI. |
| 5392 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5393 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5394 | |
| 5395 | shost = lpfc_shost_from_vport(vport); |
| 5396 | spin_lock_irq(shost->host_lock); |
| 5397 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 5398 | spin_unlock_irq(shost->host_lock); |
| 5399 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5400 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5401 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5402 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5403 | break; |
| 5404 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5405 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5406 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 5407 | did, vport->port_state, ndlp->nlp_flag); |
| 5408 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5409 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5410 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5411 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5412 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5413 | break; |
| 5414 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5415 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5416 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 5417 | did, vport->port_state, ndlp->nlp_flag); |
| 5418 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5419 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame^] | 5420 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5421 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5422 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5423 | break; |
| 5424 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5425 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5426 | break; |
| 5427 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5428 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5429 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 5430 | did, vport->port_state, ndlp->nlp_flag); |
| 5431 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5432 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame^] | 5433 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5434 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5435 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5436 | break; |
| 5437 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5438 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5439 | break; |
| 5440 | case ELS_CMD_RSCN: |
| 5441 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5442 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5443 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5444 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5445 | break; |
| 5446 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5447 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5448 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 5449 | did, vport->port_state, ndlp->nlp_flag); |
| 5450 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame^] | 5451 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5452 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5453 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5454 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5455 | break; |
| 5456 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5457 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5458 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5459 | break; |
| 5460 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5461 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5462 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 5463 | did, vport->port_state, ndlp->nlp_flag); |
| 5464 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5465 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5466 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5467 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5468 | break; |
| 5469 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5470 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5471 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5472 | break; |
| 5473 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5474 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5475 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 5476 | did, vport->port_state, ndlp->nlp_flag); |
| 5477 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5478 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5479 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5480 | break; |
| 5481 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5482 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5483 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 5484 | did, vport->port_state, ndlp->nlp_flag); |
| 5485 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5486 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5487 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5488 | break; |
| 5489 | case ELS_CMD_FAN: |
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 FAN: did:x%x/ste:x%x flg:x%x", |
| 5492 | did, vport->port_state, ndlp->nlp_flag); |
| 5493 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5494 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5495 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5496 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5497 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5498 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5499 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 5500 | did, vport->port_state, ndlp->nlp_flag); |
| 5501 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5502 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5503 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5504 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5505 | break; |
| 5506 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5507 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5508 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5509 | case ELS_CMD_LIRR: |
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 LIRR: did:x%x/ste:x%x flg:x%x", |
| 5512 | did, vport->port_state, ndlp->nlp_flag); |
| 5513 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5514 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5515 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5516 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5517 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5518 | break; |
| 5519 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5520 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5521 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 5522 | did, vport->port_state, ndlp->nlp_flag); |
| 5523 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5524 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5525 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5526 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5527 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5528 | break; |
| 5529 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5530 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5531 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 5532 | did, vport->port_state, ndlp->nlp_flag); |
| 5533 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5534 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5535 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5536 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5537 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5538 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5539 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5540 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5541 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 5542 | did, vport->port_state, ndlp->nlp_flag); |
| 5543 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5544 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5545 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5546 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5547 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5548 | break; |
| 5549 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5550 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5551 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 5552 | cmd, did, vport->port_state); |
| 5553 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5554 | /* Unsupported ELS command, reject */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5555 | rjt_err = LSRJT_INVALID_CMD; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5556 | |
| 5557 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5558 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5559 | "0115 Unknown ELS command x%x " |
| 5560 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5561 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5562 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5563 | break; |
| 5564 | } |
| 5565 | |
| 5566 | /* check if need to LS_RJT received ELS cmd */ |
| 5567 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5568 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5569 | stat.un.b.lsRjtRsnCode = rjt_err; |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 5570 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5571 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 5572 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5573 | } |
| 5574 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5575 | lpfc_nlp_put(elsiocb->context1); |
| 5576 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5577 | return; |
| 5578 | |
| 5579 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5580 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
| 5581 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5582 | "(%d):0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5583 | "Data: x%x x%x x%x\n", |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5584 | vport->vpi, icmd->ulpStatus, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5585 | icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5586 | phba->fc_stat.elsRcvDrop++; |
| 5587 | } |
| 5588 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5589 | /** |
| 5590 | * lpfc_find_vport_by_vpid: Find a vport on a HBA through vport identifier. |
| 5591 | * @phba: pointer to lpfc hba data structure. |
| 5592 | * @vpi: host virtual N_Port identifier. |
| 5593 | * |
| 5594 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 5595 | * @vpi. The function walks the HBA's vport list and returns the address |
| 5596 | * of the vport with the matching @vpi. |
| 5597 | * |
| 5598 | * Return code |
| 5599 | * NULL - No vport with the matching @vpi found |
| 5600 | * Otherwise - Address to the vport with the matching @vpi. |
| 5601 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5602 | static struct lpfc_vport * |
| 5603 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 5604 | { |
| 5605 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5606 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5607 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5608 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5609 | list_for_each_entry(vport, &phba->port_list, listentry) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5610 | if (vport->vpi == vpi) { |
| 5611 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5612 | return vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5613 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5614 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5615 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5616 | return NULL; |
| 5617 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5618 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5619 | /** |
| 5620 | * lpfc_els_unsol_event: Process an unsolicited event from an els sli ring. |
| 5621 | * @phba: pointer to lpfc hba data structure. |
| 5622 | * @pring: pointer to a SLI ring. |
| 5623 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 5624 | * |
| 5625 | * This routine is used to process an unsolicited event received from a SLI |
| 5626 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 5627 | * associated with the unsolicited event is done by invoking the routine |
| 5628 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 5629 | * SLI ring on which the unsolicited event was received. |
| 5630 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5631 | void |
| 5632 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 5633 | struct lpfc_iocbq *elsiocb) |
| 5634 | { |
| 5635 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5636 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5637 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5638 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 5639 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5640 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5641 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5642 | elsiocb->context2 = NULL; |
| 5643 | elsiocb->context3 = NULL; |
| 5644 | |
| 5645 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 5646 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 5647 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 5648 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5649 | phba->fc_stat.NoRcvBuf++; |
| 5650 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5651 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5652 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5653 | return; |
| 5654 | } |
| 5655 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5656 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 5657 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 5658 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 5659 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 5660 | vport = phba->pport; |
| 5661 | else { |
| 5662 | uint16_t vpi = icmd->unsli3.rcvsli3.vpi; |
| 5663 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 5664 | } |
| 5665 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5666 | /* If there are no BDEs associated |
| 5667 | * with this IOCB, there is nothing to do. |
| 5668 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5669 | if (icmd->ulpBdeCount == 0) |
| 5670 | return; |
| 5671 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5672 | /* type of ELS cmd is first 32bit word |
| 5673 | * in packet |
| 5674 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5675 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5676 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5677 | } else { |
| 5678 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 5679 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5680 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 5681 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5682 | } |
| 5683 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5684 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 5685 | /* |
| 5686 | * The different unsolicited event handlers would tell us |
| 5687 | * if they are done with "mp" by setting context2 to NULL. |
| 5688 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5689 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5690 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 5691 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5692 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5693 | |
| 5694 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5695 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5696 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5697 | elsiocb->context2 = bdeBuf2; |
| 5698 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5699 | /* free mp if we are done with it */ |
| 5700 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5701 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 5702 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5703 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5704 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5705 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5706 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5707 | /** |
| 5708 | * lpfc_do_scr_ns_plogi: Issue a plogi to the name server for scr. |
| 5709 | * @phba: pointer to lpfc hba data structure. |
| 5710 | * @vport: pointer to a virtual N_Port data structure. |
| 5711 | * |
| 5712 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 5713 | * State Change Request (SCR) for a @vport. This routine will create an |
| 5714 | * ndlp for the Name Server associated to the @vport if such node does |
| 5715 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 5716 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 5717 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 5718 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 5719 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5720 | void |
| 5721 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 5722 | { |
| 5723 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
| 5724 | |
| 5725 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 5726 | if (!ndlp) { |
| 5727 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 5728 | if (!ndlp) { |
| 5729 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5730 | lpfc_disc_start(vport); |
| 5731 | return; |
| 5732 | } |
| 5733 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5734 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5735 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5736 | return; |
| 5737 | } |
| 5738 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5739 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5740 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 5741 | if (!ndlp) { |
| 5742 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5743 | lpfc_disc_start(vport); |
| 5744 | return; |
| 5745 | } |
| 5746 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5747 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5748 | "0348 NameServer login: node freed\n"); |
| 5749 | return; |
| 5750 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5751 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5752 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5753 | |
| 5754 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 5755 | |
| 5756 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 5757 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5758 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5759 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5760 | return; |
| 5761 | } |
| 5762 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5763 | if (vport->cfg_fdmi_on) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5764 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 5765 | GFP_KERNEL); |
| 5766 | if (ndlp_fdmi) { |
| 5767 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 5768 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5769 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
| 5770 | NLP_STE_PLOGI_ISSUE); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5771 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, |
| 5772 | 0); |
| 5773 | } |
| 5774 | } |
| 5775 | return; |
| 5776 | } |
| 5777 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5778 | /** |
| 5779 | * lpfc_cmpl_reg_new_vport: Completion callback function to register new vport. |
| 5780 | * @phba: pointer to lpfc hba data structure. |
| 5781 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 5782 | * |
| 5783 | * This routine is the completion callback function to register new vport |
| 5784 | * mailbox command. If the new vport mailbox command completes successfully, |
| 5785 | * the fabric registration login shall be performed on physical port (the |
| 5786 | * new vport created is actually a physical port, with VPI 0) or the port |
| 5787 | * login to Name Server for State Change Request (SCR) will be performed |
| 5788 | * on virtual port (real virtual port, with VPI greater than 0). |
| 5789 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5790 | static void |
| 5791 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 5792 | { |
| 5793 | struct lpfc_vport *vport = pmb->vport; |
| 5794 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5795 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 5796 | MAILBOX_t *mb = &pmb->mb; |
| 5797 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5798 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5799 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5800 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5801 | |
| 5802 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5803 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 5804 | "0915 Register VPI failed: 0x%x\n", |
| 5805 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5806 | |
| 5807 | switch (mb->mbxStatus) { |
| 5808 | case 0x11: /* unsupported feature */ |
| 5809 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5810 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5811 | /* giving up on vport registration */ |
| 5812 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5813 | spin_lock_irq(shost->host_lock); |
| 5814 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 5815 | spin_unlock_irq(shost->host_lock); |
| 5816 | lpfc_can_disctmo(vport); |
| 5817 | break; |
| 5818 | default: |
| 5819 | /* Try to recover from this error */ |
| 5820 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5821 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5822 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5823 | spin_unlock_irq(shost->host_lock); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5824 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 5825 | lpfc_initial_flogi(vport); |
| 5826 | else |
| 5827 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5828 | break; |
| 5829 | } |
| 5830 | |
| 5831 | } else { |
| 5832 | if (vport == phba->pport) |
| 5833 | lpfc_issue_fabric_reglogin(vport); |
| 5834 | else |
| 5835 | lpfc_do_scr_ns_plogi(phba, vport); |
| 5836 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5837 | |
| 5838 | /* Now, we decrement the ndlp reference count held for this |
| 5839 | * callback function |
| 5840 | */ |
| 5841 | lpfc_nlp_put(ndlp); |
| 5842 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5843 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5844 | return; |
| 5845 | } |
| 5846 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5847 | /** |
| 5848 | * lpfc_register_new_vport: Register a new vport with a HBA. |
| 5849 | * @phba: pointer to lpfc hba data structure. |
| 5850 | * @vport: pointer to a host virtual N_Port data structure. |
| 5851 | * @ndlp: pointer to a node-list data structure. |
| 5852 | * |
| 5853 | * This routine registers the @vport as a new virtual port with a HBA. |
| 5854 | * It is done through a registering vpi mailbox command. |
| 5855 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5856 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5857 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 5858 | struct lpfc_nodelist *ndlp) |
| 5859 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5860 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5861 | LPFC_MBOXQ_t *mbox; |
| 5862 | |
| 5863 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5864 | if (mbox) { |
| 5865 | lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox); |
| 5866 | mbox->vport = vport; |
| 5867 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 5868 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5869 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5870 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5871 | /* mailbox command not success, decrement ndlp |
| 5872 | * reference count for this command |
| 5873 | */ |
| 5874 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5875 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5876 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5877 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 5878 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5879 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5880 | } |
| 5881 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5882 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 5883 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5884 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5885 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5886 | return; |
| 5887 | |
| 5888 | mbox_err_exit: |
| 5889 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5890 | spin_lock_irq(shost->host_lock); |
| 5891 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 5892 | spin_unlock_irq(shost->host_lock); |
| 5893 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5894 | } |
| 5895 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5896 | /** |
| 5897 | * lpfc_cmpl_els_fdisc: Completion function for fdisc iocb command. |
| 5898 | * @phba: pointer to lpfc hba data structure. |
| 5899 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5900 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 5901 | * |
| 5902 | * This routine is the completion callback function to a Fabric Discover |
| 5903 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 5904 | * single threaded, each FDISC completion callback function will reset |
| 5905 | * the discovery timer for all vports such that the timers will not get |
| 5906 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 5907 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 5908 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 5909 | * assigned to the vport has been changed with the completion of the FDISC |
| 5910 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 5911 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 5912 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 5913 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 5914 | * Server for State Change Request (SCR). |
| 5915 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5916 | static void |
| 5917 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 5918 | struct lpfc_iocbq *rspiocb) |
| 5919 | { |
| 5920 | struct lpfc_vport *vport = cmdiocb->vport; |
| 5921 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5922 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 5923 | struct lpfc_nodelist *np; |
| 5924 | struct lpfc_nodelist *next_np; |
| 5925 | IOCB_t *irsp = &rspiocb->iocb; |
| 5926 | struct lpfc_iocbq *piocb; |
| 5927 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5928 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5929 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 5930 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 5931 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5932 | /* Since all FDISCs are being single threaded, we |
| 5933 | * must reset the discovery timer for ALL vports |
| 5934 | * waiting to send FDISC when one completes. |
| 5935 | */ |
| 5936 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 5937 | lpfc_set_disctmo(piocb->vport); |
| 5938 | } |
| 5939 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5940 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 5941 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 5942 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 5943 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5944 | if (irsp->ulpStatus) { |
| 5945 | /* Check for retry */ |
| 5946 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 5947 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5948 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5949 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5950 | "0126 FDISC failed. (%d/%d)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5951 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5952 | goto fdisc_failed; |
| 5953 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5954 | if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING) |
| 5955 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5956 | lpfc_nlp_put(ndlp); |
| 5957 | /* giving up on FDISC. Cancel discovery timer */ |
| 5958 | lpfc_can_disctmo(vport); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5959 | spin_lock_irq(shost->host_lock); |
| 5960 | vport->fc_flag |= FC_FABRIC; |
| 5961 | if (vport->phba->fc_topology == TOPOLOGY_LOOP) |
| 5962 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 5963 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5964 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5965 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 5966 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
| 5967 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 5968 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 5969 | /* If our NportID changed, we need to ensure all |
| 5970 | * remaining NPORTs get unreg_login'ed so we can |
| 5971 | * issue unreg_vpi. |
| 5972 | */ |
| 5973 | list_for_each_entry_safe(np, next_np, |
| 5974 | &vport->fc_nodes, nlp_listp) { |
| 5975 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 5976 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 5977 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 5978 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5979 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5980 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5981 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5982 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5983 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5984 | lpfc_mbx_unreg_vpi(vport); |
| 5985 | spin_lock_irq(shost->host_lock); |
| 5986 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 5987 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5988 | } |
| 5989 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5990 | if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 5991 | lpfc_register_new_vport(phba, vport, ndlp); |
| 5992 | else |
| 5993 | lpfc_do_scr_ns_plogi(phba, vport); |
| 5994 | goto out; |
| 5995 | fdisc_failed: |
| 5996 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5997 | /* Cancel discovery timer */ |
| 5998 | lpfc_can_disctmo(vport); |
| 5999 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6000 | out: |
| 6001 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6002 | } |
| 6003 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6004 | /** |
| 6005 | * lpfc_issue_els_fdisc: Issue a fdisc iocb command. |
| 6006 | * @vport: pointer to a virtual N_Port data structure. |
| 6007 | * @ndlp: pointer to a node-list data structure. |
| 6008 | * @retry: number of retries to the command IOCB. |
| 6009 | * |
| 6010 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 6011 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 6012 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 6013 | * IOCB will be sent off HBA at any given time. |
| 6014 | * |
| 6015 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6016 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6017 | * will be stored into the context1 field of the IOCB for the completion |
| 6018 | * callback function to the FDISC ELS command. |
| 6019 | * |
| 6020 | * Return code |
| 6021 | * 0 - Successfully issued fdisc iocb command |
| 6022 | * 1 - Failed to issue fdisc iocb command |
| 6023 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6024 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6025 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 6026 | uint8_t retry) |
| 6027 | { |
| 6028 | struct lpfc_hba *phba = vport->phba; |
| 6029 | IOCB_t *icmd; |
| 6030 | struct lpfc_iocbq *elsiocb; |
| 6031 | struct serv_parm *sp; |
| 6032 | uint8_t *pcmd; |
| 6033 | uint16_t cmdsize; |
| 6034 | int did = ndlp->nlp_DID; |
| 6035 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6036 | |
| 6037 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 6038 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 6039 | ELS_CMD_FDISC); |
| 6040 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6041 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6042 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6043 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6044 | return 1; |
| 6045 | } |
| 6046 | |
| 6047 | icmd = &elsiocb->iocb; |
| 6048 | icmd->un.elsreq64.myID = 0; |
| 6049 | icmd->un.elsreq64.fl = 1; |
| 6050 | |
| 6051 | /* For FDISC, Let FDISC rsp set the NPortID for this VPI */ |
| 6052 | icmd->ulpCt_h = 1; |
| 6053 | icmd->ulpCt_l = 0; |
| 6054 | |
| 6055 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6056 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 6057 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 6058 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 6059 | sp = (struct serv_parm *) pcmd; |
| 6060 | /* Setup CSPs accordingly for Fabric */ |
| 6061 | sp->cmn.e_d_tov = 0; |
| 6062 | sp->cmn.w2.r_a_tov = 0; |
| 6063 | sp->cls1.classValid = 0; |
| 6064 | sp->cls2.seqDelivery = 1; |
| 6065 | sp->cls3.seqDelivery = 1; |
| 6066 | |
| 6067 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 6068 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 6069 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 6070 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 6071 | memcpy(pcmd, &vport->fc_portname, 8); |
| 6072 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6073 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6074 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 6075 | |
| 6076 | lpfc_set_disctmo(vport); |
| 6077 | |
| 6078 | phba->fc_stat.elsXmitFDISC++; |
| 6079 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 6080 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6081 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6082 | "Issue FDISC: did:x%x", |
| 6083 | did, 0, 0); |
| 6084 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6085 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 6086 | if (rc == IOCB_ERROR) { |
| 6087 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6088 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6089 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6090 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6091 | return 1; |
| 6092 | } |
| 6093 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
| 6094 | vport->port_state = LPFC_FDISC; |
| 6095 | return 0; |
| 6096 | } |
| 6097 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6098 | /** |
| 6099 | * lpfc_cmpl_els_npiv_logo: Completion function with vport logo. |
| 6100 | * @phba: pointer to lpfc hba data structure. |
| 6101 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6102 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6103 | * |
| 6104 | * This routine is the completion callback function to the issuing of a LOGO |
| 6105 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 6106 | * reference count held on ndlp for this completion function, indicating that |
| 6107 | * the reference to the ndlp is no long needed. Note that the |
| 6108 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 6109 | * callback function and an additional explicit ndlp reference decrementation |
| 6110 | * will trigger the actual release of the ndlp. |
| 6111 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6112 | static void |
| 6113 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6114 | struct lpfc_iocbq *rspiocb) |
| 6115 | { |
| 6116 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6117 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6118 | struct lpfc_nodelist *ndlp; |
| 6119 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6120 | |
| 6121 | irsp = &rspiocb->iocb; |
| 6122 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6123 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 6124 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6125 | |
| 6126 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6127 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6128 | |
| 6129 | /* Trigger the release of the ndlp after logo */ |
| 6130 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6131 | } |
| 6132 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6133 | /** |
| 6134 | * lpfc_issue_els_npiv_logo: Issue a logo off a vport. |
| 6135 | * @vport: pointer to a virtual N_Port data structure. |
| 6136 | * @ndlp: pointer to a node-list data structure. |
| 6137 | * |
| 6138 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 6139 | * |
| 6140 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6141 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6142 | * will be stored into the context1 field of the IOCB for the completion |
| 6143 | * callback function to the LOGO ELS command. |
| 6144 | * |
| 6145 | * Return codes |
| 6146 | * 0 - Successfully issued logo off the @vport |
| 6147 | * 1 - Failed to issue logo off the @vport |
| 6148 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6149 | int |
| 6150 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 6151 | { |
| 6152 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6153 | struct lpfc_hba *phba = vport->phba; |
| 6154 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 6155 | IOCB_t *icmd; |
| 6156 | struct lpfc_iocbq *elsiocb; |
| 6157 | uint8_t *pcmd; |
| 6158 | uint16_t cmdsize; |
| 6159 | |
| 6160 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 6161 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 6162 | ELS_CMD_LOGO); |
| 6163 | if (!elsiocb) |
| 6164 | return 1; |
| 6165 | |
| 6166 | icmd = &elsiocb->iocb; |
| 6167 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6168 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 6169 | pcmd += sizeof(uint32_t); |
| 6170 | |
| 6171 | /* Fill in LOGO payload */ |
| 6172 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 6173 | pcmd += sizeof(uint32_t); |
| 6174 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 6175 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6176 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6177 | "Issue LOGO npiv did:x%x flg:x%x", |
| 6178 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 6179 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6180 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 6181 | spin_lock_irq(shost->host_lock); |
| 6182 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 6183 | spin_unlock_irq(shost->host_lock); |
| 6184 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
| 6185 | spin_lock_irq(shost->host_lock); |
| 6186 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 6187 | spin_unlock_irq(shost->host_lock); |
| 6188 | lpfc_els_free_iocb(phba, elsiocb); |
| 6189 | return 1; |
| 6190 | } |
| 6191 | return 0; |
| 6192 | } |
| 6193 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6194 | /** |
| 6195 | * lpfc_fabric_block_timeout: Handler function to the fabric block timer. |
| 6196 | * @ptr: holder for the timer function associated data. |
| 6197 | * |
| 6198 | * This routine is invoked by the fabric iocb block timer after |
| 6199 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 6200 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 6201 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 6202 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 6203 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 6204 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6205 | void |
| 6206 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 6207 | { |
| 6208 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 6209 | unsigned long iflags; |
| 6210 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6211 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6212 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 6213 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 6214 | if (!tmo_posted) |
| 6215 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 6216 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 6217 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6218 | if (!tmo_posted) |
| 6219 | lpfc_worker_wake_up(phba); |
| 6220 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6221 | } |
| 6222 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6223 | /** |
| 6224 | * lpfc_resume_fabric_iocbs: Issue a fabric iocb from driver internal list. |
| 6225 | * @phba: pointer to lpfc hba data structure. |
| 6226 | * |
| 6227 | * This routine issues one fabric iocb from the driver internal list to |
| 6228 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 6229 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 6230 | * remove one pending fabric iocb from the driver internal list and invokes |
| 6231 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 6232 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6233 | static void |
| 6234 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 6235 | { |
| 6236 | struct lpfc_iocbq *iocb; |
| 6237 | unsigned long iflags; |
| 6238 | int ret; |
| 6239 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 6240 | IOCB_t *cmd; |
| 6241 | |
| 6242 | repeat: |
| 6243 | iocb = NULL; |
| 6244 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6245 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6246 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 6247 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 6248 | list); |
| 6249 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6250 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6251 | atomic_inc(&phba->fabric_iocb_count); |
| 6252 | } |
| 6253 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6254 | if (iocb) { |
| 6255 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6256 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6257 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6258 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6259 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6260 | "Fabric sched1: ste:x%x", |
| 6261 | iocb->vport->port_state, 0, 0); |
| 6262 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6263 | ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0); |
| 6264 | |
| 6265 | if (ret == IOCB_ERROR) { |
| 6266 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6267 | iocb->fabric_iocb_cmpl = NULL; |
| 6268 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6269 | cmd = &iocb->iocb; |
| 6270 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6271 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6272 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 6273 | |
| 6274 | atomic_dec(&phba->fabric_iocb_count); |
| 6275 | goto repeat; |
| 6276 | } |
| 6277 | } |
| 6278 | |
| 6279 | return; |
| 6280 | } |
| 6281 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6282 | /** |
| 6283 | * lpfc_unblock_fabric_iocbs: Unblock issuing fabric iocb command. |
| 6284 | * @phba: pointer to lpfc hba data structure. |
| 6285 | * |
| 6286 | * This routine unblocks the issuing fabric iocb command. The function |
| 6287 | * will clear the fabric iocb block bit and then invoke the routine |
| 6288 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 6289 | * from the driver internal fabric iocb list. |
| 6290 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6291 | void |
| 6292 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 6293 | { |
| 6294 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6295 | |
| 6296 | lpfc_resume_fabric_iocbs(phba); |
| 6297 | return; |
| 6298 | } |
| 6299 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6300 | /** |
| 6301 | * lpfc_block_fabric_iocbs: Block issuing fabric iocb command. |
| 6302 | * @phba: pointer to lpfc hba data structure. |
| 6303 | * |
| 6304 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 6305 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 6306 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 6307 | * fabric iocb will be issued out of the HBA. |
| 6308 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6309 | static void |
| 6310 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 6311 | { |
| 6312 | int blocked; |
| 6313 | |
| 6314 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6315 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6316 | if (!blocked) |
| 6317 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); |
| 6318 | |
| 6319 | return; |
| 6320 | } |
| 6321 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6322 | /** |
| 6323 | * lpfc_cmpl_fabric_iocb: Completion callback function for fabric iocb. |
| 6324 | * @phba: pointer to lpfc hba data structure. |
| 6325 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6326 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6327 | * |
| 6328 | * This routine is the callback function that is put to the fabric iocb's |
| 6329 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 6330 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 6331 | * function first restores and invokes the original iocb's callback function |
| 6332 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 6333 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 6334 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6335 | static void |
| 6336 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6337 | struct lpfc_iocbq *rspiocb) |
| 6338 | { |
| 6339 | struct ls_rjt stat; |
| 6340 | |
| 6341 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 6342 | BUG(); |
| 6343 | |
| 6344 | switch (rspiocb->iocb.ulpStatus) { |
| 6345 | case IOSTAT_NPORT_RJT: |
| 6346 | case IOSTAT_FABRIC_RJT: |
| 6347 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 6348 | lpfc_block_fabric_iocbs(phba); |
| 6349 | } |
| 6350 | break; |
| 6351 | |
| 6352 | case IOSTAT_NPORT_BSY: |
| 6353 | case IOSTAT_FABRIC_BSY: |
| 6354 | lpfc_block_fabric_iocbs(phba); |
| 6355 | break; |
| 6356 | |
| 6357 | case IOSTAT_LS_RJT: |
| 6358 | stat.un.lsRjtError = |
| 6359 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 6360 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 6361 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 6362 | lpfc_block_fabric_iocbs(phba); |
| 6363 | break; |
| 6364 | } |
| 6365 | |
| 6366 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 6367 | BUG(); |
| 6368 | |
| 6369 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 6370 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 6371 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6372 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 6373 | |
| 6374 | atomic_dec(&phba->fabric_iocb_count); |
| 6375 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6376 | /* Post any pending iocbs to HBA */ |
| 6377 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6378 | } |
| 6379 | } |
| 6380 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6381 | /** |
| 6382 | * lpfc_issue_fabric_iocb: Issue a fabric iocb command. |
| 6383 | * @phba: pointer to lpfc hba data structure. |
| 6384 | * @iocb: pointer to lpfc command iocb data structure. |
| 6385 | * |
| 6386 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 6387 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 6388 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 6389 | * any given time. As such, this function will first check to see whether there |
| 6390 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 6391 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 6392 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 6393 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 6394 | * |
| 6395 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 6396 | * order. The problem is caused by the construction of the "ready" boolen does |
| 6397 | * not include the condition that the internal fabric IOCB list is empty. As |
| 6398 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 6399 | * ahead of the fabric IOCBs in the internal list. |
| 6400 | * |
| 6401 | * Return code |
| 6402 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 6403 | * IOCB_ERROR - failed to issue fabric iocb |
| 6404 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6405 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6406 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 6407 | { |
| 6408 | unsigned long iflags; |
| 6409 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 6410 | int ready; |
| 6411 | int ret; |
| 6412 | |
| 6413 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 6414 | BUG(); |
| 6415 | |
| 6416 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6417 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 6418 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6419 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6420 | if (ready) |
| 6421 | /* Increment fabric iocb count to hold the position */ |
| 6422 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6423 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6424 | if (ready) { |
| 6425 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6426 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6427 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6428 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6429 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6430 | "Fabric sched2: ste:x%x", |
| 6431 | iocb->vport->port_state, 0, 0); |
| 6432 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6433 | ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0); |
| 6434 | |
| 6435 | if (ret == IOCB_ERROR) { |
| 6436 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6437 | iocb->fabric_iocb_cmpl = NULL; |
| 6438 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6439 | atomic_dec(&phba->fabric_iocb_count); |
| 6440 | } |
| 6441 | } else { |
| 6442 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6443 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 6444 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6445 | ret = IOCB_SUCCESS; |
| 6446 | } |
| 6447 | return ret; |
| 6448 | } |
| 6449 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6450 | /** |
| 6451 | * lpfc_fabric_abort_vport: Abort a vport's iocbs from driver fabric iocb list. |
| 6452 | * @vport: pointer to a virtual N_Port data structure. |
| 6453 | * |
| 6454 | * This routine aborts all the IOCBs associated with a @vport from the |
| 6455 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6456 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6457 | * list, removes each IOCB associated with the @vport off the list, set the |
| 6458 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6459 | * associated with the IOCB. |
| 6460 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6461 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6462 | { |
| 6463 | LIST_HEAD(completions); |
| 6464 | struct lpfc_hba *phba = vport->phba; |
| 6465 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6466 | IOCB_t *cmd; |
| 6467 | |
| 6468 | spin_lock_irq(&phba->hbalock); |
| 6469 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6470 | list) { |
| 6471 | |
| 6472 | if (piocb->vport != vport) |
| 6473 | continue; |
| 6474 | |
| 6475 | list_move_tail(&piocb->list, &completions); |
| 6476 | } |
| 6477 | spin_unlock_irq(&phba->hbalock); |
| 6478 | |
| 6479 | while (!list_empty(&completions)) { |
| 6480 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 6481 | list_del_init(&piocb->list); |
| 6482 | |
| 6483 | cmd = &piocb->iocb; |
| 6484 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6485 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6486 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 6487 | } |
| 6488 | } |
| 6489 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6490 | /** |
| 6491 | * lpfc_fabric_abort_nport: Abort a ndlp's iocbs from driver fabric iocb list. |
| 6492 | * @ndlp: pointer to a node-list data structure. |
| 6493 | * |
| 6494 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 6495 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6496 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6497 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 6498 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6499 | * associated with the IOCB. |
| 6500 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6501 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 6502 | { |
| 6503 | LIST_HEAD(completions); |
| 6504 | struct lpfc_hba *phba = ndlp->vport->phba; |
| 6505 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6506 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 6507 | IOCB_t *cmd; |
| 6508 | |
| 6509 | spin_lock_irq(&phba->hbalock); |
| 6510 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6511 | list) { |
| 6512 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 6513 | |
| 6514 | list_move_tail(&piocb->list, &completions); |
| 6515 | } |
| 6516 | } |
| 6517 | spin_unlock_irq(&phba->hbalock); |
| 6518 | |
| 6519 | while (!list_empty(&completions)) { |
| 6520 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 6521 | list_del_init(&piocb->list); |
| 6522 | |
| 6523 | cmd = &piocb->iocb; |
| 6524 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6525 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6526 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 6527 | } |
| 6528 | } |
| 6529 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6530 | /** |
| 6531 | * lpfc_fabric_abort_hba: Abort all iocbs on driver fabric iocb list. |
| 6532 | * @phba: pointer to lpfc hba data structure. |
| 6533 | * |
| 6534 | * This routine aborts all the IOCBs currently on the driver internal |
| 6535 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 6536 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 6537 | * list, removes IOCBs off the list, set the status feild to |
| 6538 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 6539 | * the IOCB. |
| 6540 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6541 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 6542 | { |
| 6543 | LIST_HEAD(completions); |
| 6544 | struct lpfc_iocbq *piocb; |
| 6545 | IOCB_t *cmd; |
| 6546 | |
| 6547 | spin_lock_irq(&phba->hbalock); |
| 6548 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 6549 | spin_unlock_irq(&phba->hbalock); |
| 6550 | |
| 6551 | while (!list_empty(&completions)) { |
| 6552 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 6553 | list_del_init(&piocb->list); |
| 6554 | |
| 6555 | cmd = &piocb->iocb; |
| 6556 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6557 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6558 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 6559 | } |
| 6560 | } |