| 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; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame^] | 224 | /* The CT field must be 0=INVALID_RPI for the ECHO cmd */ |
| 225 | if (elscmd == ELS_CMD_ECHO) |
| 226 | icmd->ulpCt_l = 0; /* context = invalid RPI */ |
| 227 | else |
| 228 | icmd->ulpCt_l = 1; /* context = VPI */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 229 | } |
| 230 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 231 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
| 232 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); |
| 233 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); |
| 234 | bpl->tus.f.bdeSize = cmdSize; |
| 235 | bpl->tus.f.bdeFlags = 0; |
| 236 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 237 | |
| 238 | if (expectRsp) { |
| 239 | bpl++; |
| 240 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); |
| 241 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); |
| 242 | bpl->tus.f.bdeSize = FCELSSIZE; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 243 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 244 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 245 | } |
| 246 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 247 | /* prevent preparing iocb with NULL ndlp reference */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 248 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 249 | if (!elsiocb->context1) |
| 250 | goto els_iocb_free_pbuf_exit; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 251 | elsiocb->context2 = pcmd; |
| 252 | elsiocb->context3 = pbuflist; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 253 | elsiocb->retry = retry; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 254 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 255 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
| 256 | |
| 257 | if (prsp) { |
| 258 | list_add(&prsp->list, &pcmd->list); |
| 259 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 260 | if (expectRsp) { |
| 261 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 262 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 263 | "0116 Xmit ELS command x%x to remote " |
| 264 | "NPORT x%x I/O tag: x%x, port state: x%x\n", |
| 265 | elscmd, did, elsiocb->iotag, |
| 266 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 267 | } else { |
| 268 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 269 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 270 | "0117 Xmit ELS response x%x to remote " |
| 271 | "NPORT x%x I/O tag: x%x, size: x%x\n", |
| 272 | elscmd, ndlp->nlp_DID, elsiocb->iotag, |
| 273 | cmdSize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 274 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 275 | return elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 276 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 277 | els_iocb_free_pbuf_exit: |
| 278 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); |
| 279 | kfree(pbuflist); |
| 280 | |
| 281 | els_iocb_free_prsp_exit: |
| 282 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 283 | kfree(prsp); |
| 284 | |
| 285 | els_iocb_free_pcmb_exit: |
| 286 | kfree(pcmd); |
| 287 | lpfc_sli_release_iocbq(phba, elsiocb); |
| 288 | return NULL; |
| 289 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 290 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 291 | /** |
| 292 | * lpfc_issue_fabric_reglogin: Issue fabric registration login for a vport. |
| 293 | * @vport: pointer to a host virtual N_Port data structure. |
| 294 | * |
| 295 | * This routine issues a fabric registration login for a @vport. An |
| 296 | * active ndlp node with Fabric_DID must already exist for this @vport. |
| 297 | * The routine invokes two mailbox commands to carry out fabric registration |
| 298 | * login through the HBA firmware: the first mailbox command requests the |
| 299 | * HBA to perform link configuration for the @vport; and the second mailbox |
| 300 | * command requests the HBA to perform the actual fabric registration login |
| 301 | * with the @vport. |
| 302 | * |
| 303 | * Return code |
| 304 | * 0 - successfully issued fabric registration login for @vport |
| 305 | * -ENXIO -- failed to issue fabric registration login for @vport |
| 306 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 307 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 308 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
| 309 | { |
| 310 | struct lpfc_hba *phba = vport->phba; |
| 311 | LPFC_MBOXQ_t *mbox; |
| 312 | struct lpfc_dmabuf *mp; |
| 313 | struct lpfc_nodelist *ndlp; |
| 314 | struct serv_parm *sp; |
| 315 | int rc; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 316 | int err = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 317 | |
| 318 | sp = &phba->fc_fabparam; |
| 319 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 320 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 321 | err = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 322 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 323 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 324 | |
| 325 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 326 | if (!mbox) { |
| 327 | err = 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 328 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 329 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 330 | |
| 331 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 332 | lpfc_config_link(phba, mbox); |
| 333 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 334 | mbox->vport = vport; |
| 335 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 336 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 337 | if (rc == MBX_NOT_FINISHED) { |
| 338 | err = 3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 339 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 340 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 341 | |
| 342 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 343 | if (!mbox) { |
| 344 | err = 4; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 345 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 346 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 347 | rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, |
| 348 | 0); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 349 | if (rc) { |
| 350 | err = 5; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 351 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 352 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 353 | |
| 354 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; |
| 355 | mbox->vport = vport; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 356 | /* increment the reference count on ndlp to hold reference |
| 357 | * for the callback routine. |
| 358 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 359 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 360 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 361 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 362 | if (rc == MBX_NOT_FINISHED) { |
| 363 | err = 6; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 364 | goto fail_issue_reg_login; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 365 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 366 | |
| 367 | return 0; |
| 368 | |
| 369 | fail_issue_reg_login: |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 370 | /* decrement the reference count on ndlp just incremented |
| 371 | * for the failed mbox command. |
| 372 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 373 | lpfc_nlp_put(ndlp); |
| 374 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 375 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 376 | kfree(mp); |
| 377 | fail_free_mbox: |
| 378 | mempool_free(mbox, phba->mbox_mem_pool); |
| 379 | |
| 380 | fail: |
| 381 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 382 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 383 | "0249 Cannot issue Register Fabric login: Err %d\n", err); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 384 | return -ENXIO; |
| 385 | } |
| 386 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 387 | /** |
| 388 | * lpfc_cmpl_els_flogi_fabric: Completion function for flogi to a fabric port. |
| 389 | * @vport: pointer to a host virtual N_Port data structure. |
| 390 | * @ndlp: pointer to a node-list data structure. |
| 391 | * @sp: pointer to service parameter data structure. |
| 392 | * @irsp: pointer to the IOCB within the lpfc response IOCB. |
| 393 | * |
| 394 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 395 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric |
| 396 | * port in a fabric topology. It properly sets up the parameters to the @ndlp |
| 397 | * from the IOCB response. It also check the newly assigned N_Port ID to the |
| 398 | * @vport against the previously assigned N_Port ID. If it is different from |
| 399 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine |
| 400 | * is invoked on all the remaining nodes with the @vport to unregister the |
| 401 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() |
| 402 | * is invoked to register login to the fabric. |
| 403 | * |
| 404 | * Return code |
| 405 | * 0 - Success (currently, always return 0) |
| 406 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 407 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 408 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 409 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 410 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 411 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 412 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 413 | struct lpfc_nodelist *np; |
| 414 | struct lpfc_nodelist *next_np; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 415 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 416 | spin_lock_irq(shost->host_lock); |
| 417 | vport->fc_flag |= FC_FABRIC; |
| 418 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 419 | |
| 420 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 421 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 422 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 423 | |
| 424 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 425 | |
| 426 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 427 | spin_lock_irq(shost->host_lock); |
| 428 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 429 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 430 | } else { |
| 431 | /* |
| 432 | * If we are a N-port connected to a Fabric, fixup sparam's so |
| 433 | * logins to devices on remote loops work. |
| 434 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 435 | vport->fc_sparam.cmn.altBbCredit = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 436 | } |
| 437 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 438 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 439 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 440 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 441 | ndlp->nlp_class_sup = 0; |
| 442 | if (sp->cls1.classValid) |
| 443 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 444 | if (sp->cls2.classValid) |
| 445 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 446 | if (sp->cls3.classValid) |
| 447 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 448 | if (sp->cls4.classValid) |
| 449 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 450 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 451 | sp->cmn.bbRcvSizeLsb; |
| 452 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 453 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 454 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 455 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 456 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 457 | LOG_ELS | LOG_VPORT, |
| 458 | "1816 FLOGI NPIV supported, " |
| 459 | "response data 0x%x\n", |
| 460 | sp->cmn.response_multiple_NPort); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 461 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 462 | } else { |
| 463 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 464 | to call reg_vnpid atleast for the physcial host */ |
| 465 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 466 | LOG_ELS | LOG_VPORT, |
| 467 | "1817 Fabric does not support NPIV " |
| 468 | "- configuring single port mode.\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 469 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 474 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 475 | |
| 476 | /* If our NportID changed, we need to ensure all |
| 477 | * remaining NPORTs get unreg_login'ed. |
| 478 | */ |
| 479 | list_for_each_entry_safe(np, next_np, |
| 480 | &vport->fc_nodes, nlp_listp) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 481 | if (!NLP_CHK_NODE_ACT(np)) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 482 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 483 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 484 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 485 | continue; |
| 486 | spin_lock_irq(shost->host_lock); |
| 487 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 488 | spin_unlock_irq(shost->host_lock); |
| 489 | lpfc_unreg_rpi(vport, np); |
| 490 | } |
| 491 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 492 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 493 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 494 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 495 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 496 | } |
| 497 | } |
| 498 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 499 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 500 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 501 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 502 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) { |
| 503 | lpfc_register_new_vport(phba, vport, ndlp); |
| 504 | return 0; |
| 505 | } |
| 506 | lpfc_issue_fabric_reglogin(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 507 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 508 | } |
| 509 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 510 | /** |
| 511 | * lpfc_cmpl_els_flogi_nport: Completion function for flogi to an N_Port. |
| 512 | * @vport: pointer to a host virtual N_Port data structure. |
| 513 | * @ndlp: pointer to a node-list data structure. |
| 514 | * @sp: pointer to service parameter data structure. |
| 515 | * |
| 516 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 517 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 518 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 519 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 520 | * the received N_Port Name lexicographically, this node shall assign local |
| 521 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 522 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 523 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 524 | * N_Port IDs. |
| 525 | * |
| 526 | * Return code |
| 527 | * 0 - Success |
| 528 | * -ENXIO - Fail |
| 529 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 530 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 531 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 532 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 533 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 534 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 535 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 536 | LPFC_MBOXQ_t *mbox; |
| 537 | int rc; |
| 538 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 539 | spin_lock_irq(shost->host_lock); |
| 540 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 541 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 542 | |
| 543 | phba->fc_edtov = FF_DEF_EDTOV; |
| 544 | phba->fc_ratov = FF_DEF_RATOV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 545 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 546 | sizeof(vport->fc_portname)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 547 | if (rc >= 0) { |
| 548 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 549 | spin_lock_irq(shost->host_lock); |
| 550 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 551 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 552 | |
| 553 | /* |
| 554 | * N_Port ID cannot be 0, set our to LocalID the other |
| 555 | * side will be RemoteID. |
| 556 | */ |
| 557 | |
| 558 | /* not equal */ |
| 559 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 560 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 561 | |
| 562 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 563 | if (!mbox) |
| 564 | goto fail; |
| 565 | |
| 566 | lpfc_config_link(phba, mbox); |
| 567 | |
| 568 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 569 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 570 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 571 | if (rc == MBX_NOT_FINISHED) { |
| 572 | mempool_free(mbox, phba->mbox_mem_pool); |
| 573 | goto fail; |
| 574 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 575 | /* Decrement ndlp reference count indicating that ndlp can be |
| 576 | * safely released when other references to it are done. |
| 577 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 578 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 579 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 580 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 581 | if (!ndlp) { |
| 582 | /* |
| 583 | * Cannot find existing Fabric ndlp, so allocate a |
| 584 | * new one |
| 585 | */ |
| 586 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 587 | if (!ndlp) |
| 588 | goto fail; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 589 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 590 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 591 | ndlp = lpfc_enable_node(vport, ndlp, |
| 592 | NLP_STE_UNUSED_NODE); |
| 593 | if(!ndlp) |
| 594 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 598 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 599 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 600 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 601 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 602 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 603 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 604 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 605 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 606 | } else |
| 607 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 608 | * count indicating that ndlp can be released when other |
| 609 | * references to it are done. |
| 610 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 611 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 612 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 613 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 614 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 615 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 616 | spin_lock_irq(shost->host_lock); |
| 617 | vport->fc_flag |= FC_PT2PT; |
| 618 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 619 | |
| 620 | /* Start discovery - this should just do CLEAR_LA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 621 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 622 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 623 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 624 | return -ENXIO; |
| 625 | } |
| 626 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 627 | /** |
| 628 | * lpfc_cmpl_els_flogi: Completion callback function for flogi. |
| 629 | * @phba: pointer to lpfc hba data structure. |
| 630 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 631 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 632 | * |
| 633 | * This routine is the top-level completion callback function for issuing |
| 634 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 635 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 636 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 637 | * returning 1), the command IOCB will be released and function returned. |
| 638 | * If the retry attempt has been given up (possibly reach the maximum |
| 639 | * number of retries), one additional decrement of ndlp reference shall be |
| 640 | * invoked before going out after releasing the command IOCB. This will |
| 641 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 642 | * invoke one decrement of ndlp reference count). If no error reported in |
| 643 | * the IOCB status, the command Port ID field is used to determine whether |
| 644 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 645 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 646 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 647 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 648 | * specific topology completion conditions. |
| 649 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 650 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 651 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 652 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 653 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 654 | struct lpfc_vport *vport = cmdiocb->vport; |
| 655 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 656 | IOCB_t *irsp = &rspiocb->iocb; |
| 657 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 658 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 659 | struct serv_parm *sp; |
| 660 | int rc; |
| 661 | |
| 662 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 663 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 664 | /* One additional decrement on node reference count to |
| 665 | * trigger the release of the node |
| 666 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 667 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 668 | goto out; |
| 669 | } |
| 670 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 671 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 672 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 673 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 674 | vport->port_state); |
| 675 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 676 | if (irsp->ulpStatus) { |
| 677 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 678 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 679 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 680 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 681 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 682 | spin_lock_irq(shost->host_lock); |
| 683 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 684 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 685 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 686 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 687 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 688 | * alpa map would take too long otherwise. |
| 689 | */ |
| 690 | if (phba->alpa_map[0] == 0) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 691 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | /* FLOGI failure */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 695 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 696 | "0100 FLOGI failure Data: x%x x%x " |
| 697 | "x%x\n", |
| 698 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 699 | irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 700 | goto flogifail; |
| 701 | } |
| 702 | |
| 703 | /* |
| 704 | * The FLogI succeeded. Sync the data for the CPU before |
| 705 | * accessing it. |
| 706 | */ |
| 707 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 708 | |
| 709 | sp = prsp->virt + sizeof(uint32_t); |
| 710 | |
| 711 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 712 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 713 | "0101 FLOGI completes sucessfully " |
| 714 | "Data: x%x x%x x%x x%x\n", |
| 715 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
| 716 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 717 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 718 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 719 | /* |
| 720 | * If Common Service Parameters indicate Nport |
| 721 | * we are point to point, if Fport we are Fabric. |
| 722 | */ |
| 723 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 724 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 725 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 726 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 727 | |
| 728 | if (!rc) |
| 729 | goto out; |
| 730 | } |
| 731 | |
| 732 | flogifail: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 733 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 734 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 735 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 736 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 737 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 738 | |
| 739 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 740 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 741 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 742 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && |
| 743 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) && |
| 744 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 745 | /* If FLOGI failed enable link interrupt. */ |
| 746 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 747 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 748 | out: |
| 749 | lpfc_els_free_iocb(phba, cmdiocb); |
| 750 | } |
| 751 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 752 | /** |
| 753 | * lpfc_issue_els_flogi: Issue an flogi iocb command for a vport. |
| 754 | * @vport: pointer to a host virtual N_Port data structure. |
| 755 | * @ndlp: pointer to a node-list data structure. |
| 756 | * @retry: number of retries to the command IOCB. |
| 757 | * |
| 758 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 759 | * for a @vport. The initiator service parameters are put into the payload |
| 760 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 761 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 762 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 763 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 764 | * |
| 765 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 766 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 767 | * will be stored into the context1 field of the IOCB for the completion |
| 768 | * callback function to the FLOGI ELS command. |
| 769 | * |
| 770 | * Return code |
| 771 | * 0 - successfully issued flogi iocb for @vport |
| 772 | * 1 - failed to issue flogi iocb for @vport |
| 773 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 774 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 775 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 776 | uint8_t retry) |
| 777 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 778 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 779 | struct serv_parm *sp; |
| 780 | IOCB_t *icmd; |
| 781 | struct lpfc_iocbq *elsiocb; |
| 782 | struct lpfc_sli_ring *pring; |
| 783 | uint8_t *pcmd; |
| 784 | uint16_t cmdsize; |
| 785 | uint32_t tmo; |
| 786 | int rc; |
| 787 | |
| 788 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 789 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 790 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 791 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 792 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 793 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 794 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 795 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 796 | |
| 797 | icmd = &elsiocb->iocb; |
| 798 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 799 | |
| 800 | /* For FLOGI request, remainder of payload is service parameters */ |
| 801 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 802 | pcmd += sizeof(uint32_t); |
| 803 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 804 | sp = (struct serv_parm *) pcmd; |
| 805 | |
| 806 | /* Setup CSPs accordingly for Fabric */ |
| 807 | sp->cmn.e_d_tov = 0; |
| 808 | sp->cmn.w2.r_a_tov = 0; |
| 809 | sp->cls1.classValid = 0; |
| 810 | sp->cls2.seqDelivery = 1; |
| 811 | sp->cls3.seqDelivery = 1; |
| 812 | if (sp->cmn.fcphLow < FC_PH3) |
| 813 | sp->cmn.fcphLow = FC_PH3; |
| 814 | if (sp->cmn.fcphHigh < FC_PH3) |
| 815 | sp->cmn.fcphHigh = FC_PH3; |
| 816 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 817 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 818 | sp->cmn.request_multiple_Nport = 1; |
| 819 | |
| 820 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 821 | icmd->ulpCt_h = 1; |
| 822 | icmd->ulpCt_l = 0; |
| 823 | } |
| 824 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 825 | if (phba->fc_topology != TOPOLOGY_LOOP) { |
| 826 | icmd->un.elsreq64.myID = 0; |
| 827 | icmd->un.elsreq64.fl = 1; |
| 828 | } |
| 829 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 830 | tmo = phba->fc_ratov; |
| 831 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 832 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 833 | phba->fc_ratov = tmo; |
| 834 | |
| 835 | phba->fc_stat.elsXmitFLOGI++; |
| 836 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 837 | |
| 838 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 839 | "Issue FLOGI: opt:x%x", |
| 840 | phba->sli3_options, 0, 0); |
| 841 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 842 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 843 | if (rc == IOCB_ERROR) { |
| 844 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 845 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 846 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 847 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 848 | } |
| 849 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 850 | /** |
| 851 | * lpfc_els_abort_flogi: Abort all outstanding flogi iocbs. |
| 852 | * @phba: pointer to lpfc hba data structure. |
| 853 | * |
| 854 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 855 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 856 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 857 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 858 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 859 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 860 | * |
| 861 | * Return code |
| 862 | * 0 - Sucessfully issued abort iocb on all outstanding flogis (Always 0) |
| 863 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 864 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 865 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 866 | { |
| 867 | struct lpfc_sli_ring *pring; |
| 868 | struct lpfc_iocbq *iocb, *next_iocb; |
| 869 | struct lpfc_nodelist *ndlp; |
| 870 | IOCB_t *icmd; |
| 871 | |
| 872 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 873 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 874 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 875 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 876 | |
| 877 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 878 | |
| 879 | /* |
| 880 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 881 | * searching for. |
| 882 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 883 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 884 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 885 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 886 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR && |
| 887 | icmd->un.elsreq64.bdl.ulpIoTag32) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 888 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 889 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 890 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 891 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 892 | } |
| 893 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 894 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 895 | |
| 896 | return 0; |
| 897 | } |
| 898 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 899 | /** |
| 900 | * lpfc_initial_flogi: Issue an initial fabric login for a vport. |
| 901 | * @vport: pointer to a host virtual N_Port data structure. |
| 902 | * |
| 903 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 904 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 905 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 906 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 907 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 908 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 909 | * @vport. |
| 910 | * |
| 911 | * Return code |
| 912 | * 0 - failed to issue initial flogi for @vport |
| 913 | * 1 - successfully issued initial flogi for @vport |
| 914 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 915 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 916 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 917 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 918 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 919 | struct lpfc_nodelist *ndlp; |
| 920 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 921 | vport->port_state = LPFC_FLOGI; |
| 922 | lpfc_set_disctmo(vport); |
| 923 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 924 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 925 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 926 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 927 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 928 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 929 | if (!ndlp) |
| 930 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 931 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 932 | /* Put ndlp onto node list */ |
| 933 | lpfc_enqueue_node(vport, ndlp); |
| 934 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 935 | /* re-setup ndlp without removing from node list */ |
| 936 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 937 | if (!ndlp) |
| 938 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 939 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 940 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 941 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 942 | /* This decrement of reference count to node shall kick off |
| 943 | * the release of the node. |
| 944 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 945 | lpfc_nlp_put(ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 946 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 947 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 948 | } |
| 949 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 950 | /** |
| 951 | * lpfc_initial_fdisc: Issue an initial fabric discovery for a vport. |
| 952 | * @vport: pointer to a host virtual N_Port data structure. |
| 953 | * |
| 954 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 955 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 956 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 957 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 958 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 959 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 960 | * @vport. |
| 961 | * |
| 962 | * Return code |
| 963 | * 0 - failed to issue initial fdisc for @vport |
| 964 | * 1 - successfully issued initial fdisc for @vport |
| 965 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 966 | int |
| 967 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 968 | { |
| 969 | struct lpfc_hba *phba = vport->phba; |
| 970 | struct lpfc_nodelist *ndlp; |
| 971 | |
| 972 | /* First look for the Fabric ndlp */ |
| 973 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 974 | if (!ndlp) { |
| 975 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 976 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 977 | if (!ndlp) |
| 978 | return 0; |
| 979 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 980 | /* Put ndlp onto node list */ |
| 981 | lpfc_enqueue_node(vport, ndlp); |
| 982 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 983 | /* re-setup ndlp without removing from node list */ |
| 984 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 985 | if (!ndlp) |
| 986 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 987 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 988 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 989 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 990 | /* decrement node reference count to trigger the release of |
| 991 | * the node. |
| 992 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 993 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 994 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 995 | } |
| 996 | return 1; |
| 997 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 998 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 999 | /** |
| 1000 | * lpfc_more_plogi: Check and issue remaining plogis for a vport. |
| 1001 | * @vport: pointer to a host virtual N_Port data structure. |
| 1002 | * |
| 1003 | * This routine checks whether there are more remaining Port Logins |
| 1004 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1005 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1006 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1007 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1008 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1009 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1010 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1011 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1012 | { |
| 1013 | int sentplogi; |
| 1014 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1015 | if (vport->num_disc_nodes) |
| 1016 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1017 | |
| 1018 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1019 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1020 | "0232 Continue discovery with %d PLOGIs to go " |
| 1021 | "Data: x%x x%x x%x\n", |
| 1022 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1023 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1024 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1025 | if (vport->fc_flag & FC_NLP_MORE) |
| 1026 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 1027 | sentplogi = lpfc_els_disc_plogi(vport); |
| 1028 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1029 | return; |
| 1030 | } |
| 1031 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1032 | /** |
| 1033 | * lpfc_plogi_confirm_nport: Confirm pologi wwpn matches stored ndlp. |
| 1034 | * @phba: pointer to lpfc hba data structure. |
| 1035 | * @prsp: pointer to response IOCB payload. |
| 1036 | * @ndlp: pointer to a node-list data structure. |
| 1037 | * |
| 1038 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1039 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1040 | * The following cases are considered N_Port confirmed: |
| 1041 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1042 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1043 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1044 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1045 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1046 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1047 | * on that node to release the RPI associated with the node; 2) if there is |
| 1048 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1049 | * into, a new node shall be allocated (or activated). In either case, the |
| 1050 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1051 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1052 | * its pointer returned as the confirmed node. |
| 1053 | * |
| 1054 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1055 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1056 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1057 | * into an inactive state on the vport node list and the vport node list |
| 1058 | * management algorithm does not allow two node with a same DID. |
| 1059 | * |
| 1060 | * Return code |
| 1061 | * pointer to the PLOGI N_Port @ndlp |
| 1062 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1063 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1064 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1065 | struct lpfc_nodelist *ndlp) |
| 1066 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1067 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1068 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1069 | struct lpfc_rport_data *rdata; |
| 1070 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1071 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1072 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1073 | uint32_t rc, keepDID = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1074 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1075 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1076 | * by WWPN. Just return the ndlp that was given to us. |
| 1077 | */ |
| 1078 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1079 | return ndlp; |
| 1080 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1081 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1082 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1083 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1084 | /* 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] | 1085 | * we have for that ndlp. If not, we have some work to do. |
| 1086 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1087 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1088 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1089 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1090 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1091 | |
| 1092 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1093 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1094 | sizeof(struct lpfc_name)); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1095 | if (!rc) |
| 1096 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1097 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
| 1098 | if (!new_ndlp) |
| 1099 | return ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1100 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1101 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1102 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1103 | sizeof(struct lpfc_name)); |
| 1104 | if (!rc) |
| 1105 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1106 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1107 | NLP_STE_UNUSED_NODE); |
| 1108 | if (!new_ndlp) |
| 1109 | return ndlp; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1110 | keepDID = new_ndlp->nlp_DID; |
| 1111 | } else |
| 1112 | keepDID = new_ndlp->nlp_DID; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1113 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1114 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1115 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1116 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1117 | |
| 1118 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) |
| 1119 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 1120 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 1121 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1122 | /* 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] | 1123 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1124 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1125 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1126 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1127 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1128 | * to put ndlp on UNUSED list and try to free it. |
| 1129 | */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1130 | |
| 1131 | /* Fix up the rport accordingly */ |
| 1132 | rport = ndlp->rport; |
| 1133 | if (rport) { |
| 1134 | rdata = rport->dd_data; |
| 1135 | if (rdata->pnode == ndlp) { |
| 1136 | lpfc_nlp_put(ndlp); |
| 1137 | ndlp->rport = NULL; |
| 1138 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1139 | new_ndlp->rport = rport; |
| 1140 | } |
| 1141 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1142 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1143 | /* We shall actually free the ndlp with both nlp_DID and |
| 1144 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1145 | * nodelist never to be used. |
| 1146 | */ |
| 1147 | if (ndlp->nlp_DID == 0) { |
| 1148 | spin_lock_irq(&phba->ndlp_lock); |
| 1149 | NLP_SET_FREE_REQ(ndlp); |
| 1150 | spin_unlock_irq(&phba->ndlp_lock); |
| 1151 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1152 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1153 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1154 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1155 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1156 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1157 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1158 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1159 | /* Two ndlps cannot have the same did */ |
| 1160 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1161 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1162 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1163 | return new_ndlp; |
| 1164 | } |
| 1165 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1166 | /** |
| 1167 | * lpfc_end_rscn: Check and handle more rscn for a vport. |
| 1168 | * @vport: pointer to a host virtual N_Port data structure. |
| 1169 | * |
| 1170 | * This routine checks whether more Registration State Change |
| 1171 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1172 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1173 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1174 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1175 | * handling the RSCNs. |
| 1176 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1177 | void |
| 1178 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1179 | { |
| 1180 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1181 | |
| 1182 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1183 | /* |
| 1184 | * Check to see if more RSCNs came in while we were |
| 1185 | * processing this one. |
| 1186 | */ |
| 1187 | if (vport->fc_rscn_id_cnt || |
| 1188 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1189 | lpfc_els_handle_rscn(vport); |
| 1190 | else { |
| 1191 | spin_lock_irq(shost->host_lock); |
| 1192 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1193 | spin_unlock_irq(shost->host_lock); |
| 1194 | } |
| 1195 | } |
| 1196 | } |
| 1197 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1198 | /** |
| 1199 | * lpfc_cmpl_els_plogi: Completion callback function for plogi. |
| 1200 | * @phba: pointer to lpfc hba data structure. |
| 1201 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1202 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1203 | * |
| 1204 | * This routine is the completion callback function for issuing the Port |
| 1205 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1206 | * ndlp on the vport node list that matches the remote node ID from the |
| 1207 | * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply |
| 1208 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1209 | * checked for error conditons. If there is error status reported, PLOGI |
| 1210 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1211 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1212 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1213 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1214 | * there are additional N_Port nodes with the vport that need to perform |
| 1215 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1216 | * PLOGIs. |
| 1217 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1218 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1219 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1220 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1221 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1222 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1223 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1224 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1225 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1226 | struct lpfc_dmabuf *prsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1227 | int disc, rc, did, type; |
| 1228 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1229 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1230 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1231 | |
| 1232 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1233 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1234 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1235 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1236 | irsp->un.elsreq64.remoteID); |
| 1237 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1238 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1239 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1240 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1241 | "0136 PLOGI completes to NPort x%x " |
| 1242 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1243 | irsp->un.elsreq64.remoteID, |
| 1244 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1245 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1246 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1247 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1248 | |
| 1249 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1250 | * is being used during discovery. |
| 1251 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1252 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1253 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1254 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1255 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1256 | rc = 0; |
| 1257 | |
| 1258 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1259 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1260 | "0102 PLOGI completes to NPort x%x " |
| 1261 | "Data: x%x x%x x%x x%x x%x\n", |
| 1262 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1263 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1264 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1265 | if (lpfc_els_chk_latt(vport)) { |
| 1266 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1267 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1268 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1269 | goto out; |
| 1270 | } |
| 1271 | |
| 1272 | /* ndlp could be freed in DSM, save these values now */ |
| 1273 | type = ndlp->nlp_type; |
| 1274 | did = ndlp->nlp_DID; |
| 1275 | |
| 1276 | if (irsp->ulpStatus) { |
| 1277 | /* Check for retry */ |
| 1278 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1279 | /* ELS command is being retried */ |
| 1280 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1281 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1282 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1283 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1284 | } |
| 1285 | goto out; |
| 1286 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1287 | /* PLOGI failed */ |
| 1288 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1289 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1290 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1291 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1292 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1293 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1294 | } else { |
| 1295 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1296 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1297 | cmdiocb->context2)->list.next, |
| 1298 | struct lpfc_dmabuf, list); |
| 1299 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1300 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1301 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1302 | } |
| 1303 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1304 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1305 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1306 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1307 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1308 | if (vport->num_disc_nodes == 0) { |
| 1309 | spin_lock_irq(shost->host_lock); |
| 1310 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1311 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1312 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1313 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1314 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | out: |
| 1319 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1320 | return; |
| 1321 | } |
| 1322 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1323 | /** |
| 1324 | * lpfc_issue_els_plogi: Issue an plogi iocb command for a vport. |
| 1325 | * @vport: pointer to a host virtual N_Port data structure. |
| 1326 | * @did: destination port identifier. |
| 1327 | * @retry: number of retries to the command IOCB. |
| 1328 | * |
| 1329 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1330 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1331 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1332 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1333 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1334 | * |
| 1335 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1336 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1337 | * will be stored into the context1 field of the IOCB for the completion |
| 1338 | * callback function to the PLOGI ELS command. |
| 1339 | * |
| 1340 | * Return code |
| 1341 | * 0 - Successfully issued a plogi for @vport |
| 1342 | * 1 - failed to issue a plogi for @vport |
| 1343 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1344 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1345 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1346 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1347 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1348 | struct serv_parm *sp; |
| 1349 | IOCB_t *icmd; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1350 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1351 | struct lpfc_iocbq *elsiocb; |
| 1352 | struct lpfc_sli_ring *pring; |
| 1353 | struct lpfc_sli *psli; |
| 1354 | uint8_t *pcmd; |
| 1355 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1356 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1357 | |
| 1358 | psli = &phba->sli; |
| 1359 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 1360 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1361 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1362 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1363 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1364 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1365 | /* 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] | 1366 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1367 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1368 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1369 | if (!elsiocb) |
| 1370 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1371 | |
| 1372 | icmd = &elsiocb->iocb; |
| 1373 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1374 | |
| 1375 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1376 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1377 | pcmd += sizeof(uint32_t); |
| 1378 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1379 | sp = (struct serv_parm *) pcmd; |
| 1380 | |
| 1381 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1382 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1383 | |
| 1384 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1385 | sp->cmn.fcphHigh = FC_PH3; |
| 1386 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1387 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1388 | "Issue PLOGI: did:x%x", |
| 1389 | did, 0, 0); |
| 1390 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1391 | phba->fc_stat.elsXmitPLOGI++; |
| 1392 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1393 | ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| 1394 | |
| 1395 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1396 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1397 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1398 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1399 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1400 | } |
| 1401 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1402 | /** |
| 1403 | * lpfc_cmpl_els_prli: Completion callback function for prli. |
| 1404 | * @phba: pointer to lpfc hba data structure. |
| 1405 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1406 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1407 | * |
| 1408 | * This routine is the completion callback function for a Process Login |
| 1409 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 1410 | * status. If there is error status reported, PRLI retry shall be attempted |
| 1411 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 1412 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 1413 | * ndlp to mark the PRLI completion. |
| 1414 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1415 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1416 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1417 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1418 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1419 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1420 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1421 | IOCB_t *irsp; |
| 1422 | struct lpfc_sli *psli; |
| 1423 | struct lpfc_nodelist *ndlp; |
| 1424 | |
| 1425 | psli = &phba->sli; |
| 1426 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1427 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1428 | |
| 1429 | irsp = &(rspiocb->iocb); |
| 1430 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1431 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1432 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1433 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1434 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1435 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1436 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 1437 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1438 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1439 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1440 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1441 | "0103 PRLI completes to NPort x%x " |
| 1442 | "Data: x%x x%x x%x x%x\n", |
| 1443 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1444 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1445 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1446 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1447 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1448 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1449 | goto out; |
| 1450 | |
| 1451 | if (irsp->ulpStatus) { |
| 1452 | /* Check for retry */ |
| 1453 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1454 | /* ELS command is being retried */ |
| 1455 | goto out; |
| 1456 | } |
| 1457 | /* PRLI failed */ |
| 1458 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1459 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1460 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1461 | else |
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); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1464 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1465 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1466 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1467 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1468 | out: |
| 1469 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1470 | return; |
| 1471 | } |
| 1472 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1473 | /** |
| 1474 | * lpfc_issue_els_prli: Issue a prli iocb command for a vport. |
| 1475 | * @vport: pointer to a host virtual N_Port data structure. |
| 1476 | * @ndlp: pointer to a node-list data structure. |
| 1477 | * @retry: number of retries to the command IOCB. |
| 1478 | * |
| 1479 | * This routine issues a Process Login (PRLI) ELS command for the |
| 1480 | * @vport. The PRLI service parameters are set up in the payload of the |
| 1481 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 1482 | * is put to the IOCB completion callback func field before invoking the |
| 1483 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 1484 | * |
| 1485 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1486 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1487 | * will be stored into the context1 field of the IOCB for the completion |
| 1488 | * callback function to the PRLI ELS command. |
| 1489 | * |
| 1490 | * Return code |
| 1491 | * 0 - successfully issued prli iocb command for @vport |
| 1492 | * 1 - failed to issue prli iocb command for @vport |
| 1493 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1494 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1495 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1496 | uint8_t retry) |
| 1497 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1498 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1499 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1500 | PRLI *npr; |
| 1501 | IOCB_t *icmd; |
| 1502 | struct lpfc_iocbq *elsiocb; |
| 1503 | struct lpfc_sli_ring *pring; |
| 1504 | struct lpfc_sli *psli; |
| 1505 | uint8_t *pcmd; |
| 1506 | uint16_t cmdsize; |
| 1507 | |
| 1508 | psli = &phba->sli; |
| 1509 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 1510 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1511 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1512 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1513 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1514 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1515 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1516 | |
| 1517 | icmd = &elsiocb->iocb; |
| 1518 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1519 | |
| 1520 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1521 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1522 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1523 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1524 | |
| 1525 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 1526 | npr = (PRLI *) pcmd; |
| 1527 | /* |
| 1528 | * If our firmware version is 3.20 or later, |
| 1529 | * set the following bits for FC-TAPE support. |
| 1530 | */ |
| 1531 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 1532 | npr->ConfmComplAllowed = 1; |
| 1533 | npr->Retry = 1; |
| 1534 | npr->TaskRetryIdReq = 1; |
| 1535 | } |
| 1536 | npr->estabImagePair = 1; |
| 1537 | npr->readXferRdyDis = 1; |
| 1538 | |
| 1539 | /* For FCP support */ |
| 1540 | npr->prliType = PRLI_FCP_TYPE; |
| 1541 | npr->initiatorFunc = 1; |
| 1542 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1543 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1544 | "Issue PRLI: did:x%x", |
| 1545 | ndlp->nlp_DID, 0, 0); |
| 1546 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1547 | phba->fc_stat.elsXmitPRLI++; |
| 1548 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
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 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1553 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1554 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1555 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1556 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1557 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1558 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1559 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1560 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1561 | } |
| 1562 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1563 | /** |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1564 | * lpfc_rscn_disc: Perform rscn discovery for a vport. |
| 1565 | * @vport: pointer to a host virtual N_Port data structure. |
| 1566 | * |
| 1567 | * This routine performs Registration State Change Notification (RSCN) |
| 1568 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 1569 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 1570 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 1571 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 1572 | * invoked to check and handle possible more RSCN came in during the period |
| 1573 | * of processing the current ones. |
| 1574 | **/ |
| 1575 | static void |
| 1576 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 1577 | { |
| 1578 | lpfc_can_disctmo(vport); |
| 1579 | |
| 1580 | /* RSCN discovery */ |
| 1581 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 1582 | if (vport->fc_npr_cnt) |
| 1583 | if (lpfc_els_disc_plogi(vport)) |
| 1584 | return; |
| 1585 | |
| 1586 | lpfc_end_rscn(vport); |
| 1587 | } |
| 1588 | |
| 1589 | /** |
| 1590 | * lpfc_adisc_done: Complete the adisc phase of discovery. |
| 1591 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 1592 | * |
| 1593 | * This function is called when the final ADISC is completed during discovery. |
| 1594 | * This function handles clearing link attention or issuing reg_vpi depending |
| 1595 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 1596 | * discovery. |
| 1597 | * This function is called with no locks held. |
| 1598 | **/ |
| 1599 | static void |
| 1600 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 1601 | { |
| 1602 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1603 | struct lpfc_hba *phba = vport->phba; |
| 1604 | |
| 1605 | /* |
| 1606 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 1607 | * and continue discovery. |
| 1608 | */ |
| 1609 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 1610 | !(vport->fc_flag & FC_RSCN_MODE)) { |
| 1611 | lpfc_issue_reg_vpi(phba, vport); |
| 1612 | return; |
| 1613 | } |
| 1614 | /* |
| 1615 | * For SLI2, we need to set port_state to READY |
| 1616 | * and continue discovery. |
| 1617 | */ |
| 1618 | if (vport->port_state < LPFC_VPORT_READY) { |
| 1619 | /* If we get here, there is nothing to ADISC */ |
| 1620 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1621 | lpfc_issue_clear_la(phba, vport); |
| 1622 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 1623 | vport->num_disc_nodes = 0; |
| 1624 | /* go thru NPR list, issue ELS PLOGIs */ |
| 1625 | if (vport->fc_npr_cnt) |
| 1626 | lpfc_els_disc_plogi(vport); |
| 1627 | if (!vport->num_disc_nodes) { |
| 1628 | spin_lock_irq(shost->host_lock); |
| 1629 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1630 | spin_unlock_irq(shost->host_lock); |
| 1631 | lpfc_can_disctmo(vport); |
| 1632 | lpfc_end_rscn(vport); |
| 1633 | } |
| 1634 | } |
| 1635 | vport->port_state = LPFC_VPORT_READY; |
| 1636 | } else |
| 1637 | lpfc_rscn_disc(vport); |
| 1638 | } |
| 1639 | |
| 1640 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1641 | * lpfc_more_adisc: Issue more adisc as needed. |
| 1642 | * @vport: pointer to a host virtual N_Port data structure. |
| 1643 | * |
| 1644 | * This routine determines whether there are more ndlps on a @vport |
| 1645 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 1646 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 1647 | * remaining nodes which need to have ADISC sent. |
| 1648 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1649 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1650 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1651 | { |
| 1652 | int sentadisc; |
| 1653 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1654 | if (vport->num_disc_nodes) |
| 1655 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1656 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1657 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1658 | "0210 Continue discovery with %d ADISCs to go " |
| 1659 | "Data: x%x x%x x%x\n", |
| 1660 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 1661 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1662 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1663 | if (vport->fc_flag & FC_NLP_MORE) { |
| 1664 | lpfc_set_disctmo(vport); |
| 1665 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 1666 | sentadisc = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1667 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1668 | if (!vport->num_disc_nodes) |
| 1669 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1670 | return; |
| 1671 | } |
| 1672 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1673 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1674 | * lpfc_cmpl_els_adisc: Completion callback function for adisc. |
| 1675 | * @phba: pointer to lpfc hba data structure. |
| 1676 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1677 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1678 | * |
| 1679 | * This routine is the completion function for issuing the Address Discover |
| 1680 | * (ADISC) command. It first checks to see whether link went down during |
| 1681 | * the discovery process. If so, the node will be marked as node port |
| 1682 | * recovery for issuing discover IOCB by the link attention handler and |
| 1683 | * exit. Otherwise, the response status is checked. If error was reported |
| 1684 | * in the response status, the ADISC command shall be retried by invoking |
| 1685 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 1686 | * the response status, the state machine is invoked to set transition |
| 1687 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 1688 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1689 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1690 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1691 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1692 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1693 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1694 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1695 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1696 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1697 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1698 | |
| 1699 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1700 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1701 | |
| 1702 | irsp = &(rspiocb->iocb); |
| 1703 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1704 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1705 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1706 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 1707 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1708 | ndlp->nlp_DID); |
| 1709 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1710 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1711 | * is being used during discovery. |
| 1712 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1713 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1714 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1715 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1716 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1717 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1718 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1719 | "0104 ADISC completes to NPort x%x " |
| 1720 | "Data: x%x x%x x%x x%x x%x\n", |
| 1721 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1722 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1723 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1724 | if (lpfc_els_chk_latt(vport)) { |
| 1725 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1726 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1727 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1728 | goto out; |
| 1729 | } |
| 1730 | |
| 1731 | if (irsp->ulpStatus) { |
| 1732 | /* Check for retry */ |
| 1733 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1734 | /* ELS command is being retried */ |
| 1735 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1736 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1737 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1738 | spin_unlock_irq(shost->host_lock); |
| 1739 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1740 | } |
| 1741 | goto out; |
| 1742 | } |
| 1743 | /* ADISC failed */ |
| 1744 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1745 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1746 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1747 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1748 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1749 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1750 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1751 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1752 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1753 | /* Check to see if there are more ADISCs to be sent */ |
| 1754 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1755 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1756 | out: |
| 1757 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1758 | return; |
| 1759 | } |
| 1760 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1761 | /** |
| 1762 | * lpfc_issue_els_adisc: Issue an address discover iocb to an node on a vport. |
| 1763 | * @vport: pointer to a virtual N_Port data structure. |
| 1764 | * @ndlp: pointer to a node-list data structure. |
| 1765 | * @retry: number of retries to the command IOCB. |
| 1766 | * |
| 1767 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 1768 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 1769 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 1770 | * to issue the ADISC ELS command. |
| 1771 | * |
| 1772 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1773 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1774 | * will be stored into the context1 field of the IOCB for the completion |
| 1775 | * callback function to the ADISC ELS command. |
| 1776 | * |
| 1777 | * Return code |
| 1778 | * 0 - successfully issued adisc |
| 1779 | * 1 - failed to issue adisc |
| 1780 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1781 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1782 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1783 | uint8_t retry) |
| 1784 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1785 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1786 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1787 | ADISC *ap; |
| 1788 | IOCB_t *icmd; |
| 1789 | struct lpfc_iocbq *elsiocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1790 | struct lpfc_sli *psli = &phba->sli; |
| 1791 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1792 | uint8_t *pcmd; |
| 1793 | uint16_t cmdsize; |
| 1794 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1795 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1796 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1797 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1798 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1799 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1800 | |
| 1801 | icmd = &elsiocb->iocb; |
| 1802 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1803 | |
| 1804 | /* For ADISC request, remainder of payload is service parameters */ |
| 1805 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1806 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1807 | |
| 1808 | /* Fill in ADISC payload */ |
| 1809 | ap = (ADISC *) pcmd; |
| 1810 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1811 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 1812 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1813 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1814 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1815 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1816 | "Issue ADISC: did:x%x", |
| 1817 | ndlp->nlp_DID, 0, 0); |
| 1818 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1819 | phba->fc_stat.elsXmitADISC++; |
| 1820 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
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 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1825 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1826 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1827 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1828 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1829 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1830 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1831 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1832 | } |
| 1833 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1834 | /** |
| 1835 | * lpfc_cmpl_els_logo: Completion callback function for logo. |
| 1836 | * @phba: pointer to lpfc hba data structure. |
| 1837 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1838 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1839 | * |
| 1840 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 1841 | * command. If no error status was reported from the LOGO response, the |
| 1842 | * state machine of the associated ndlp shall be invoked for transition with |
| 1843 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 1844 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 1845 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1846 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1847 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1848 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1849 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1850 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 1851 | struct lpfc_vport *vport = ndlp->vport; |
| 1852 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1853 | IOCB_t *irsp; |
| 1854 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1855 | |
| 1856 | psli = &phba->sli; |
| 1857 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1858 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1859 | |
| 1860 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1861 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1862 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1863 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1864 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1865 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1866 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 1867 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1868 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1869 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1870 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1871 | "0105 LOGO completes to NPort x%x " |
| 1872 | "Data: x%x x%x x%x x%x\n", |
| 1873 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1874 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1875 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1876 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1877 | goto out; |
| 1878 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1879 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 1880 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 1881 | * which should abort all outstanding IOs. |
| 1882 | */ |
| 1883 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 1884 | NLP_EVT_DEVICE_RM); |
| 1885 | goto out; |
| 1886 | } |
| 1887 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1888 | if (irsp->ulpStatus) { |
| 1889 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1890 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1891 | /* ELS command is being retried */ |
| 1892 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1893 | /* LOGO failed */ |
| 1894 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1895 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1896 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1897 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1898 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1899 | NLP_EVT_CMPL_LOGO); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1900 | } else |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1901 | /* Good status, call state machine. |
| 1902 | * This will unregister the rpi if needed. |
| 1903 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1904 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1905 | NLP_EVT_CMPL_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1906 | out: |
| 1907 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1908 | return; |
| 1909 | } |
| 1910 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1911 | /** |
| 1912 | * lpfc_issue_els_logo: Issue a logo to an node on a vport. |
| 1913 | * @vport: pointer to a virtual N_Port data structure. |
| 1914 | * @ndlp: pointer to a node-list data structure. |
| 1915 | * @retry: number of retries to the command IOCB. |
| 1916 | * |
| 1917 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 1918 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 1919 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 1920 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 1921 | * |
| 1922 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1923 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1924 | * will be stored into the context1 field of the IOCB for the completion |
| 1925 | * callback function to the LOGO ELS command. |
| 1926 | * |
| 1927 | * Return code |
| 1928 | * 0 - successfully issued logo |
| 1929 | * 1 - failed to issue logo |
| 1930 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1931 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1932 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1933 | uint8_t retry) |
| 1934 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1935 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1936 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1937 | IOCB_t *icmd; |
| 1938 | struct lpfc_iocbq *elsiocb; |
| 1939 | struct lpfc_sli_ring *pring; |
| 1940 | struct lpfc_sli *psli; |
| 1941 | uint8_t *pcmd; |
| 1942 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1943 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1944 | |
| 1945 | psli = &phba->sli; |
| 1946 | pring = &psli->ring[LPFC_ELS_RING]; |
| 1947 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1948 | spin_lock_irq(shost->host_lock); |
| 1949 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 1950 | spin_unlock_irq(shost->host_lock); |
| 1951 | return 0; |
| 1952 | } |
| 1953 | spin_unlock_irq(shost->host_lock); |
| 1954 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1955 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1956 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1957 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1958 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1959 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1960 | |
| 1961 | icmd = &elsiocb->iocb; |
| 1962 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1963 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1964 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1965 | |
| 1966 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1967 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1968 | pcmd += sizeof(uint32_t); |
| 1969 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1970 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1971 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1972 | "Issue LOGO: did:x%x", |
| 1973 | ndlp->nlp_DID, 0, 0); |
| 1974 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1975 | phba->fc_stat.elsXmitLOGO++; |
| 1976 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1977 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1978 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1979 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1980 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| 1981 | |
| 1982 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1983 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1984 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1985 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1986 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1987 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1988 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1989 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1990 | } |
| 1991 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1992 | /** |
| 1993 | * lpfc_cmpl_els_cmd: Completion callback function for generic els command. |
| 1994 | * @phba: pointer to lpfc hba data structure. |
| 1995 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1996 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1997 | * |
| 1998 | * This routine is a generic completion callback function for ELS commands. |
| 1999 | * Specifically, it is the callback function which does not need to perform |
| 2000 | * any command specific operations. It is currently used by the ELS command |
| 2001 | * issuing routines for the ELS State Change Request (SCR), |
| 2002 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 2003 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 2004 | * certain debug loggings, this callback function simply invokes the |
| 2005 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2006 | * discovery process. |
| 2007 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2008 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2009 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2010 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2011 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2012 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2013 | IOCB_t *irsp; |
| 2014 | |
| 2015 | irsp = &rspiocb->iocb; |
| 2016 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2017 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2018 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2019 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2020 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2021 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2022 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2023 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2024 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2025 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2026 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2027 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2028 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2029 | return; |
| 2030 | } |
| 2031 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2032 | /** |
| 2033 | * lpfc_issue_els_scr: Issue a scr to an node on a vport. |
| 2034 | * @vport: pointer to a host virtual N_Port data structure. |
| 2035 | * @nportid: N_Port identifier to the remote node. |
| 2036 | * @retry: number of retries to the command IOCB. |
| 2037 | * |
| 2038 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2039 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2040 | * first search the @vport node list to find the matching ndlp. If no such |
| 2041 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2042 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2043 | * routine is invoked to send the SCR IOCB. |
| 2044 | * |
| 2045 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2046 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2047 | * will be stored into the context1 field of the IOCB for the completion |
| 2048 | * callback function to the SCR ELS command. |
| 2049 | * |
| 2050 | * Return code |
| 2051 | * 0 - Successfully issued scr command |
| 2052 | * 1 - Failed to issue scr command |
| 2053 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2054 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2055 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2056 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2057 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2058 | IOCB_t *icmd; |
| 2059 | struct lpfc_iocbq *elsiocb; |
| 2060 | struct lpfc_sli_ring *pring; |
| 2061 | struct lpfc_sli *psli; |
| 2062 | uint8_t *pcmd; |
| 2063 | uint16_t cmdsize; |
| 2064 | struct lpfc_nodelist *ndlp; |
| 2065 | |
| 2066 | psli = &phba->sli; |
| 2067 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2068 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2069 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2070 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2071 | if (!ndlp) { |
| 2072 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2073 | if (!ndlp) |
| 2074 | return 1; |
| 2075 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2076 | lpfc_enqueue_node(vport, ndlp); |
| 2077 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2078 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2079 | if (!ndlp) |
| 2080 | return 1; |
| 2081 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2082 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2083 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2084 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2085 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2086 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2087 | /* This will trigger the release of the node just |
| 2088 | * allocated |
| 2089 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2090 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2091 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | icmd = &elsiocb->iocb; |
| 2095 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2096 | |
| 2097 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2098 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2099 | |
| 2100 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2101 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2102 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2103 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2104 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2105 | "Issue SCR: did:x%x", |
| 2106 | ndlp->nlp_DID, 0, 0); |
| 2107 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2108 | phba->fc_stat.elsXmitSCR++; |
| 2109 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2110 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2111 | /* The additional lpfc_nlp_put will cause the following |
| 2112 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2113 | * the node. |
| 2114 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2115 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2116 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2117 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2118 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2119 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2120 | * trigger the release of node. |
| 2121 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2122 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2123 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2124 | } |
| 2125 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2126 | /** |
| 2127 | * lpfc_issue_els_farpr: Issue a farp to an node on a vport. |
| 2128 | * @vport: pointer to a host virtual N_Port data structure. |
| 2129 | * @nportid: N_Port identifier to the remote node. |
| 2130 | * @retry: number of retries to the command IOCB. |
| 2131 | * |
| 2132 | * This routine issues a Fibre Channel Address Resolution Response |
| 2133 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2134 | * is passed into the function. It first search the @vport node list to find |
| 2135 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2136 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2137 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2138 | * |
| 2139 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2140 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2141 | * will be stored into the context1 field of the IOCB for the completion |
| 2142 | * callback function to the PARPR ELS command. |
| 2143 | * |
| 2144 | * Return code |
| 2145 | * 0 - Successfully issued farpr command |
| 2146 | * 1 - Failed to issue farpr command |
| 2147 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2148 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2149 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2150 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2151 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2152 | IOCB_t *icmd; |
| 2153 | struct lpfc_iocbq *elsiocb; |
| 2154 | struct lpfc_sli_ring *pring; |
| 2155 | struct lpfc_sli *psli; |
| 2156 | FARP *fp; |
| 2157 | uint8_t *pcmd; |
| 2158 | uint32_t *lp; |
| 2159 | uint16_t cmdsize; |
| 2160 | struct lpfc_nodelist *ondlp; |
| 2161 | struct lpfc_nodelist *ndlp; |
| 2162 | |
| 2163 | psli = &phba->sli; |
| 2164 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2165 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2166 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2167 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2168 | if (!ndlp) { |
| 2169 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2170 | if (!ndlp) |
| 2171 | return 1; |
| 2172 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2173 | lpfc_enqueue_node(vport, ndlp); |
| 2174 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2175 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2176 | if (!ndlp) |
| 2177 | return 1; |
| 2178 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2179 | |
| 2180 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2181 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2182 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2183 | /* This will trigger the release of the node just |
| 2184 | * allocated |
| 2185 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2186 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2187 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2188 | } |
| 2189 | |
| 2190 | icmd = &elsiocb->iocb; |
| 2191 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2192 | |
| 2193 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2194 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2195 | |
| 2196 | /* Fill in FARPR payload */ |
| 2197 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2198 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2199 | lp = (uint32_t *) pcmd; |
| 2200 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2201 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2202 | fp->Rflags = 0; |
| 2203 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2204 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2205 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2206 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2207 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2208 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2209 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2210 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2211 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2212 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2213 | } |
| 2214 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2215 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2216 | "Issue FARPR: did:x%x", |
| 2217 | ndlp->nlp_DID, 0, 0); |
| 2218 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2219 | phba->fc_stat.elsXmitFARPR++; |
| 2220 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2221 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2222 | /* The additional lpfc_nlp_put will cause the following |
| 2223 | * lpfc_els_free_iocb routine to trigger the release of |
| 2224 | * the node. |
| 2225 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2226 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2227 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2228 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2229 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2230 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2231 | * trigger the release of the node. |
| 2232 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2233 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2234 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2235 | } |
| 2236 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2237 | /** |
| 2238 | * lpfc_cancel_retry_delay_tmo: Cancel the timer with delayed iocb-cmd retry. |
| 2239 | * @vport: pointer to a host virtual N_Port data structure. |
| 2240 | * @nlp: pointer to a node-list data structure. |
| 2241 | * |
| 2242 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2243 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2244 | * removes the ELS retry event if it presents. In addition, if the |
| 2245 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2246 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2247 | * ADISC. |
| 2248 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2249 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2250 | 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] | 2251 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2252 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2253 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2254 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2255 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2256 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2257 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2258 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2259 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2260 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2261 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2262 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2263 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2264 | /* Decrement nlp reference count held for the delayed retry */ |
| 2265 | evtp = &nlp->els_retry_evt; |
| 2266 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2267 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2268 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2269 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2270 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2271 | spin_unlock_irq(shost->host_lock); |
| 2272 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2273 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2274 | /* Check if there are more ADISCs to be sent */ |
| 2275 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2276 | } else { |
| 2277 | /* Check if there are more PLOGIs to be sent */ |
| 2278 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2279 | if (vport->num_disc_nodes == 0) { |
| 2280 | spin_lock_irq(shost->host_lock); |
| 2281 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2282 | spin_unlock_irq(shost->host_lock); |
| 2283 | lpfc_can_disctmo(vport); |
| 2284 | lpfc_end_rscn(vport); |
| 2285 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2286 | } |
| 2287 | } |
| 2288 | } |
| 2289 | return; |
| 2290 | } |
| 2291 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2292 | /** |
| 2293 | * lpfc_els_retry_delay: Timer function with a ndlp delayed function timer. |
| 2294 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2295 | * |
| 2296 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2297 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2298 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2299 | * adds the delayed events to the HBA work list and invokes the |
| 2300 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2301 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2302 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2303 | * reference to ndlp will still be available when the worker thread gets |
| 2304 | * to the event associated with the ndlp. |
| 2305 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2306 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2307 | lpfc_els_retry_delay(unsigned long ptr) |
| 2308 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2309 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2310 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2311 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2312 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2313 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2314 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2315 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2316 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2317 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2318 | return; |
| 2319 | } |
| 2320 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2321 | /* We need to hold the node by incrementing the reference |
| 2322 | * count until the queued work is done |
| 2323 | */ |
| 2324 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2325 | if (evtp->evt_arg1) { |
| 2326 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2327 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2328 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2329 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2330 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2331 | return; |
| 2332 | } |
| 2333 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2334 | /** |
| 2335 | * lpfc_els_retry_delay_handler: Work thread handler for ndlp delayed function. |
| 2336 | * @ndlp: pointer to a node-list data structure. |
| 2337 | * |
| 2338 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 2339 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 2340 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 2341 | * function according to the delayed ELS command to retry the command. |
| 2342 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2343 | void |
| 2344 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 2345 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2346 | struct lpfc_vport *vport = ndlp->vport; |
| 2347 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2348 | uint32_t cmd, did, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2349 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2350 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2351 | did = ndlp->nlp_DID; |
| 2352 | cmd = ndlp->nlp_last_elscmd; |
| 2353 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2354 | |
| 2355 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2356 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2357 | return; |
| 2358 | } |
| 2359 | |
| 2360 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2361 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 2362 | /* |
| 2363 | * If a discovery event readded nlp_delayfunc after timer |
| 2364 | * firing and before processing the timer, cancel the |
| 2365 | * nlp_delayfunc. |
| 2366 | */ |
| 2367 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2368 | retry = ndlp->nlp_retry; |
| 2369 | |
| 2370 | switch (cmd) { |
| 2371 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2372 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2373 | break; |
| 2374 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2375 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2376 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2377 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2378 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2379 | break; |
| 2380 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2381 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2382 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2383 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2384 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2385 | break; |
| 2386 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2387 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2388 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2389 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2390 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2391 | break; |
| 2392 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2393 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2394 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2395 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2396 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2397 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2398 | case ELS_CMD_FDISC: |
| 2399 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
| 2400 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2401 | } |
| 2402 | return; |
| 2403 | } |
| 2404 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2405 | /** |
| 2406 | * lpfc_els_retry: Make retry decision on an els command iocb. |
| 2407 | * @phba: pointer to lpfc hba data structure. |
| 2408 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2409 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2410 | * |
| 2411 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 2412 | * failed. The following ELS IOCBs use this function for retrying the command |
| 2413 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 2414 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 2415 | * returned error status, it makes the decision whether a retry shall be |
| 2416 | * issued for the command, and whether a retry shall be made immediately or |
| 2417 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 2418 | * is called to retry the command. In the later case, the ELS command shall |
| 2419 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 2420 | * ndlp for the delayed command issusing. |
| 2421 | * |
| 2422 | * Return code |
| 2423 | * 0 - No retry of els command is made |
| 2424 | * 1 - Immediate or delayed retry of els command is made |
| 2425 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2426 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2427 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2428 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2429 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2430 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2431 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2432 | IOCB_t *irsp = &rspiocb->iocb; |
| 2433 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2434 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2435 | uint32_t *elscmd; |
| 2436 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2437 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2438 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2439 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2440 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2441 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2442 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2443 | /* Note: context2 may be 0 for internal driver abort |
| 2444 | * of delays ELS command. |
| 2445 | */ |
| 2446 | |
| 2447 | if (pcmd && pcmd->virt) { |
| 2448 | elscmd = (uint32_t *) (pcmd->virt); |
| 2449 | cmd = *elscmd++; |
| 2450 | } |
| 2451 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2452 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2453 | did = ndlp->nlp_DID; |
| 2454 | else { |
| 2455 | /* We should only hit this case for retrying PLOGI */ |
| 2456 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2457 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2458 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 2459 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2460 | return 1; |
| 2461 | } |
| 2462 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2463 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2464 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 2465 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 2466 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2467 | switch (irsp->ulpStatus) { |
| 2468 | case IOSTAT_FCP_RSP_ERROR: |
| 2469 | case IOSTAT_REMOTE_STOP: |
| 2470 | break; |
| 2471 | |
| 2472 | case IOSTAT_LOCAL_REJECT: |
| 2473 | switch ((irsp->un.ulpWord[4] & 0xff)) { |
| 2474 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2475 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2476 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2477 | retry = 1; |
| 2478 | break; |
| 2479 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2480 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2481 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2482 | "0124 Retry illegal cmd x%x " |
| 2483 | "retry:x%x delay:x%x\n", |
| 2484 | cmd, cmdiocb->retry, delay); |
| 2485 | retry = 1; |
| 2486 | /* All command's retry policy */ |
| 2487 | maxretry = 8; |
| 2488 | if (cmdiocb->retry > 2) |
| 2489 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2490 | break; |
| 2491 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2492 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2493 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2494 | retry = 1; |
| 2495 | if (cmdiocb->retry > 100) |
| 2496 | delay = 100; |
| 2497 | maxretry = 250; |
| 2498 | break; |
| 2499 | |
| 2500 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2501 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2502 | retry = 1; |
| 2503 | break; |
| 2504 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2505 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2506 | case IOERR_INVALID_RPI: |
| 2507 | retry = 1; |
| 2508 | break; |
| 2509 | } |
| 2510 | break; |
| 2511 | |
| 2512 | case IOSTAT_NPORT_RJT: |
| 2513 | case IOSTAT_FABRIC_RJT: |
| 2514 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 2515 | retry = 1; |
| 2516 | break; |
| 2517 | } |
| 2518 | break; |
| 2519 | |
| 2520 | case IOSTAT_NPORT_BSY: |
| 2521 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2522 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2523 | retry = 1; |
| 2524 | break; |
| 2525 | |
| 2526 | case IOSTAT_LS_RJT: |
| 2527 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 2528 | /* Added for Vendor specifc support |
| 2529 | * Just keep retrying for these Rsn / Exp codes |
| 2530 | */ |
| 2531 | switch (stat.un.b.lsRjtRsnCode) { |
| 2532 | case LSRJT_UNABLE_TPC: |
| 2533 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2534 | LSEXP_CMD_IN_PROGRESS) { |
| 2535 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2536 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2537 | maxretry = 48; |
| 2538 | } |
| 2539 | retry = 1; |
| 2540 | break; |
| 2541 | } |
| 2542 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2543 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2544 | maxretry = lpfc_max_els_tries + 1; |
| 2545 | retry = 1; |
| 2546 | break; |
| 2547 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2548 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2549 | (cmd == ELS_CMD_FDISC) && |
| 2550 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2551 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2552 | "0125 FDISC Failed (x%x). " |
| 2553 | "Fabric out of resources\n", |
| 2554 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2555 | lpfc_vport_set_state(vport, |
| 2556 | FC_VPORT_NO_FABRIC_RSCS); |
| 2557 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2558 | break; |
| 2559 | |
| 2560 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2561 | if ((cmd == ELS_CMD_PLOGI) || |
| 2562 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2563 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2564 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2565 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2566 | /* FDISC retry policy */ |
| 2567 | maxretry = 48; |
| 2568 | if (cmdiocb->retry >= 32) |
| 2569 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2570 | } |
| 2571 | retry = 1; |
| 2572 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2573 | |
| 2574 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2575 | /* There are some cases where switches return this |
| 2576 | * error when they are not ready and should be returning |
| 2577 | * Logical Busy. We should delay every time. |
| 2578 | */ |
| 2579 | if (cmd == ELS_CMD_FDISC && |
| 2580 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 2581 | maxretry = 3; |
| 2582 | delay = 1000; |
| 2583 | retry = 1; |
| 2584 | break; |
| 2585 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2586 | case LSRJT_PROTOCOL_ERR: |
| 2587 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2588 | (cmd == ELS_CMD_FDISC) && |
| 2589 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 2590 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 2591 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2592 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2593 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2594 | "Fabric Detected Bad WWN\n", |
| 2595 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2596 | lpfc_vport_set_state(vport, |
| 2597 | FC_VPORT_FABRIC_REJ_WWN); |
| 2598 | } |
| 2599 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2600 | } |
| 2601 | break; |
| 2602 | |
| 2603 | case IOSTAT_INTERMED_RSP: |
| 2604 | case IOSTAT_BA_RJT: |
| 2605 | break; |
| 2606 | |
| 2607 | default: |
| 2608 | break; |
| 2609 | } |
| 2610 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2611 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2612 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2613 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2614 | if ((cmd == ELS_CMD_FLOGI) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 2615 | (phba->fc_topology != TOPOLOGY_LOOP) && |
| 2616 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2617 | /* FLOGI retry policy */ |
| 2618 | retry = 1; |
| 2619 | maxretry = 48; |
| 2620 | if (cmdiocb->retry >= 32) |
| 2621 | delay = 1000; |
| 2622 | } |
| 2623 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2624 | if ((++cmdiocb->retry) >= maxretry) { |
| 2625 | phba->fc_stat.elsRetryExceeded++; |
| 2626 | retry = 0; |
| 2627 | } |
| 2628 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2629 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 2630 | retry = 0; |
| 2631 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2632 | if (retry) { |
| 2633 | |
| 2634 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2635 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2636 | "0107 Retry ELS command x%x to remote " |
| 2637 | "NPORT x%x Data: x%x x%x\n", |
| 2638 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2639 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2640 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 2641 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 2642 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { |
| 2643 | /* Don't reset timer for no resources */ |
| 2644 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2645 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2646 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2647 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2648 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2649 | } |
| 2650 | |
| 2651 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2652 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2653 | phba->fc_stat.elsDelayRetry++; |
| 2654 | ndlp->nlp_retry = cmdiocb->retry; |
| 2655 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2656 | /* delay is specified in milliseconds */ |
| 2657 | mod_timer(&ndlp->nlp_delayfunc, |
| 2658 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2659 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2660 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2661 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2662 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2663 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2664 | if (cmd == ELS_CMD_PRLI) |
| 2665 | lpfc_nlp_set_state(vport, ndlp, |
| 2666 | NLP_STE_REG_LOGIN_ISSUE); |
| 2667 | else |
| 2668 | lpfc_nlp_set_state(vport, ndlp, |
| 2669 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2670 | ndlp->nlp_last_elscmd = cmd; |
| 2671 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2672 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2673 | } |
| 2674 | switch (cmd) { |
| 2675 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2676 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2677 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2678 | case ELS_CMD_FDISC: |
| 2679 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 2680 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2681 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2682 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2683 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2684 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2685 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2686 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2687 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2688 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2689 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2690 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2691 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 2692 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2693 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2694 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2695 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2696 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 2697 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2698 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2699 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2700 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2701 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 2702 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2703 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2704 | } |
| 2705 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2706 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2707 | if (logerr) { |
| 2708 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2709 | "0137 No retry ELS command x%x to remote " |
| 2710 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 2711 | cmd, did, irsp->ulpStatus, |
| 2712 | irsp->un.ulpWord[4]); |
| 2713 | } |
| 2714 | else { |
| 2715 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2716 | "0108 No retry ELS command x%x to remote " |
| 2717 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 2718 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 2719 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2720 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2721 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2722 | } |
| 2723 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2724 | /** |
| 2725 | * lpfc_els_free_data: Free lpfc dma buffer and data structure with an iocb. |
| 2726 | * @phba: pointer to lpfc hba data structure. |
| 2727 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 2728 | * |
| 2729 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 2730 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 2731 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 2732 | * response of the command IOCB. If so, it will be released before releasing |
| 2733 | * the lpfc DMA buffer associated with the IOCB itself. |
| 2734 | * |
| 2735 | * Return code |
| 2736 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2737 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2738 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2739 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 2740 | { |
| 2741 | struct lpfc_dmabuf *buf_ptr; |
| 2742 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2743 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2744 | if (!list_empty(&buf_ptr1->list)) { |
| 2745 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 2746 | struct lpfc_dmabuf, |
| 2747 | list); |
| 2748 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2749 | kfree(buf_ptr); |
| 2750 | } |
| 2751 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 2752 | kfree(buf_ptr1); |
| 2753 | return 0; |
| 2754 | } |
| 2755 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2756 | /** |
| 2757 | * lpfc_els_free_bpl: Free lpfc dma buffer and data structure with bpl. |
| 2758 | * @phba: pointer to lpfc hba data structure. |
| 2759 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 2760 | * |
| 2761 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 2762 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 2763 | * pool. |
| 2764 | * |
| 2765 | * Return code |
| 2766 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2767 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2768 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2769 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 2770 | { |
| 2771 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2772 | kfree(buf_ptr); |
| 2773 | return 0; |
| 2774 | } |
| 2775 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2776 | /** |
| 2777 | * lpfc_els_free_iocb: Free a command iocb and its associated resources. |
| 2778 | * @phba: pointer to lpfc hba data structure. |
| 2779 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 2780 | * |
| 2781 | * This routine frees a command IOCB and its associated resources. The |
| 2782 | * command IOCB data structure contains the reference to various associated |
| 2783 | * resources, these fields must be set to NULL if the associated reference |
| 2784 | * not present: |
| 2785 | * context1 - reference to ndlp |
| 2786 | * context2 - reference to cmd |
| 2787 | * context2->next - reference to rsp |
| 2788 | * context3 - reference to bpl |
| 2789 | * |
| 2790 | * It first properly decrements the reference count held on ndlp for the |
| 2791 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 2792 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 2793 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 2794 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 2795 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 2796 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 2797 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 2798 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 2799 | * |
| 2800 | * Return code |
| 2801 | * 0 - Success (currently, always return 0) |
| 2802 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2803 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2804 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2805 | { |
| 2806 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2807 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2808 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2809 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 2810 | if (ndlp) { |
| 2811 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 2812 | lpfc_nlp_put(ndlp); |
| 2813 | |
| 2814 | /* If the ndlp is not being used by another discovery |
| 2815 | * thread, free it. |
| 2816 | */ |
| 2817 | if (!lpfc_nlp_not_used(ndlp)) { |
| 2818 | /* If ndlp is being used by another discovery |
| 2819 | * thread, just clear NLP_DEFER_RM |
| 2820 | */ |
| 2821 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 2822 | } |
| 2823 | } |
| 2824 | else |
| 2825 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2826 | elsiocb->context1 = NULL; |
| 2827 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2828 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 2829 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2830 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 2831 | /* Firmware could still be in progress of DMAing |
| 2832 | * payload, so don't free data buffer till after |
| 2833 | * a hbeat. |
| 2834 | */ |
| 2835 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 2836 | buf_ptr = elsiocb->context2; |
| 2837 | elsiocb->context2 = NULL; |
| 2838 | if (buf_ptr) { |
| 2839 | buf_ptr1 = NULL; |
| 2840 | spin_lock_irq(&phba->hbalock); |
| 2841 | if (!list_empty(&buf_ptr->list)) { |
| 2842 | list_remove_head(&buf_ptr->list, |
| 2843 | buf_ptr1, struct lpfc_dmabuf, |
| 2844 | list); |
| 2845 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 2846 | list_add_tail(&buf_ptr1->list, |
| 2847 | &phba->elsbuf); |
| 2848 | phba->elsbuf_cnt++; |
| 2849 | } |
| 2850 | INIT_LIST_HEAD(&buf_ptr->list); |
| 2851 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 2852 | phba->elsbuf_cnt++; |
| 2853 | spin_unlock_irq(&phba->hbalock); |
| 2854 | } |
| 2855 | } else { |
| 2856 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 2857 | lpfc_els_free_data(phba, buf_ptr1); |
| 2858 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2859 | } |
| 2860 | |
| 2861 | if (elsiocb->context3) { |
| 2862 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2863 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2864 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2865 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2866 | return 0; |
| 2867 | } |
| 2868 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2869 | /** |
| 2870 | * lpfc_cmpl_els_logo_acc: Completion callback function to logo acc response. |
| 2871 | * @phba: pointer to lpfc hba data structure. |
| 2872 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2873 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2874 | * |
| 2875 | * This routine is the completion callback function to the Logout (LOGO) |
| 2876 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 2877 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 2878 | * release the ndlp if it has the last reference remaining (reference count |
| 2879 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 2880 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 2881 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 2882 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 2883 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 2884 | * IOCB data structure. |
| 2885 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2886 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2887 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2888 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2889 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2890 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2891 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2892 | IOCB_t *irsp; |
| 2893 | |
| 2894 | irsp = &rspiocb->iocb; |
| 2895 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 2896 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 2897 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2898 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2899 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2900 | "0109 ACC to LOGO completes to NPort x%x " |
| 2901 | "Data: x%x x%x x%x\n", |
| 2902 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 2903 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2904 | |
| 2905 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 2906 | /* NPort Recovery mode or node is just allocated */ |
| 2907 | if (!lpfc_nlp_not_used(ndlp)) { |
| 2908 | /* If the ndlp is being used by another discovery |
| 2909 | * thread, just unregister the RPI. |
| 2910 | */ |
| 2911 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2912 | } else { |
| 2913 | /* Indicate the node has already released, should |
| 2914 | * not reference to it from within lpfc_els_free_iocb. |
| 2915 | */ |
| 2916 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2917 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2918 | } |
| 2919 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2920 | return; |
| 2921 | } |
| 2922 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2923 | /** |
| 2924 | * lpfc_mbx_cmpl_dflt_rpi: Completion callbk func for unreg dflt rpi mbox cmd. |
| 2925 | * @phba: pointer to lpfc hba data structure. |
| 2926 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 2927 | * |
| 2928 | * This routine is the completion callback function for unregister default |
| 2929 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 2930 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 2931 | * decrements the ndlp reference count held for this completion callback |
| 2932 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 2933 | * whether there is only one reference left on the ndlp. If so, it will |
| 2934 | * perform one more decrement and trigger the release of the ndlp. |
| 2935 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2936 | void |
| 2937 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2938 | { |
| 2939 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 2940 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 2941 | |
| 2942 | pmb->context1 = NULL; |
| 2943 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2944 | kfree(mp); |
| 2945 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2946 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2947 | lpfc_nlp_put(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2948 | /* This is the end of the default RPI cleanup logic for this |
| 2949 | * ndlp. If no other discovery threads are using this ndlp. |
| 2950 | * we should free all resources associated with it. |
| 2951 | */ |
| 2952 | lpfc_nlp_not_used(ndlp); |
| 2953 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2954 | return; |
| 2955 | } |
| 2956 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2957 | /** |
| 2958 | * lpfc_cmpl_els_rsp: Completion callback function for els response iocb cmd. |
| 2959 | * @phba: pointer to lpfc hba data structure. |
| 2960 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2961 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2962 | * |
| 2963 | * This routine is the completion callback function for ELS Response IOCB |
| 2964 | * command. In normal case, this callback function just properly sets the |
| 2965 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 2966 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 2967 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 2968 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 2969 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 2970 | * routine shall be invoked trying to release the ndlp if no other threads |
| 2971 | * are currently referring it. |
| 2972 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2973 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2974 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2975 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2976 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2977 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2978 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 2979 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2980 | IOCB_t *irsp; |
| 2981 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2982 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2983 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2984 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2985 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 2986 | irsp = &rspiocb->iocb; |
| 2987 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2988 | if (cmdiocb->context_un.mbox) |
| 2989 | mbox = cmdiocb->context_un.mbox; |
| 2990 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2991 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 2992 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 2993 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2994 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2995 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 2996 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2997 | /* A LS_RJT associated with Default RPI cleanup has its own |
| 2998 | * seperate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2999 | */ |
| 3000 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 3001 | ls_rjt = 1; |
| 3002 | } |
| 3003 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3004 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3005 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3006 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3007 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3008 | if (mp) { |
| 3009 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3010 | kfree(mp); |
| 3011 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3012 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3013 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3014 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3015 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3016 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3017 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3018 | /* Indicate the node has already released, |
| 3019 | * should not reference to it from within |
| 3020 | * the routine lpfc_els_free_iocb. |
| 3021 | */ |
| 3022 | cmdiocb->context1 = NULL; |
| 3023 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3024 | goto out; |
| 3025 | } |
| 3026 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3027 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3028 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3029 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3030 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3031 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3032 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3033 | "0110 ELS response tag x%x completes " |
| 3034 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3035 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3036 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3037 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3038 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3039 | if (mbox) { |
| 3040 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3041 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3042 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3043 | /* Increment reference count to ndlp to hold the |
| 3044 | * reference to ndlp for the callback function. |
| 3045 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3046 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3047 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3048 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3049 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3050 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3051 | } |
| 3052 | else { |
| 3053 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3054 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3055 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3056 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3057 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3058 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3059 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3060 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3061 | else |
| 3062 | /* Decrement the ndlp reference count we |
| 3063 | * set for this failed mailbox command. |
| 3064 | */ |
| 3065 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3066 | |
| 3067 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3068 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3069 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3070 | "Data: x%x x%x x%x\n", |
| 3071 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3072 | ndlp->nlp_rpi); |
| 3073 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3074 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3075 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3076 | /* Indicate node has already been released, |
| 3077 | * should not reference to it from within |
| 3078 | * the routine lpfc_els_free_iocb. |
| 3079 | */ |
| 3080 | cmdiocb->context1 = NULL; |
| 3081 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3082 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3083 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3084 | if (!lpfc_error_lost_link(irsp) && |
| 3085 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3086 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3087 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3088 | /* Indicate node has already been |
| 3089 | * released, should not reference |
| 3090 | * to it from within the routine |
| 3091 | * lpfc_els_free_iocb. |
| 3092 | */ |
| 3093 | cmdiocb->context1 = NULL; |
| 3094 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3095 | } |
| 3096 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3097 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3098 | if (mp) { |
| 3099 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3100 | kfree(mp); |
| 3101 | } |
| 3102 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3103 | } |
| 3104 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3105 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3106 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3107 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3108 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3109 | |
| 3110 | /* If the node is not being used by another discovery thread, |
| 3111 | * and we are sending a reject, we are done with it. |
| 3112 | * Release driver reference count here and free associated |
| 3113 | * resources. |
| 3114 | */ |
| 3115 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3116 | if (lpfc_nlp_not_used(ndlp)) |
| 3117 | /* Indicate node has already been released, |
| 3118 | * should not reference to it from within |
| 3119 | * the routine lpfc_els_free_iocb. |
| 3120 | */ |
| 3121 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3122 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3123 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3124 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3125 | return; |
| 3126 | } |
| 3127 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3128 | /** |
| 3129 | * lpfc_els_rsp_acc: Prepare and issue an acc response iocb command. |
| 3130 | * @vport: pointer to a host virtual N_Port data structure. |
| 3131 | * @flag: the els command code to be accepted. |
| 3132 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3133 | * @ndlp: pointer to a node-list data structure. |
| 3134 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3135 | * |
| 3136 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3137 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3138 | * specific ACC response command to be issued and invokes the |
| 3139 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3140 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3141 | * field of the IOCB for the completion callback function to issue the |
| 3142 | * mailbox command to the HBA later when callback is invoked. |
| 3143 | * |
| 3144 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3145 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3146 | * will be stored into the context1 field of the IOCB for the completion |
| 3147 | * callback function to the corresponding response ELS IOCB command. |
| 3148 | * |
| 3149 | * Return code |
| 3150 | * 0 - Successfully issued acc response |
| 3151 | * 1 - Failed to issue acc response |
| 3152 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3153 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3154 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3155 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3156 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3157 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3158 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3159 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3160 | IOCB_t *icmd; |
| 3161 | IOCB_t *oldcmd; |
| 3162 | struct lpfc_iocbq *elsiocb; |
| 3163 | struct lpfc_sli_ring *pring; |
| 3164 | struct lpfc_sli *psli; |
| 3165 | uint8_t *pcmd; |
| 3166 | uint16_t cmdsize; |
| 3167 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3168 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3169 | |
| 3170 | psli = &phba->sli; |
| 3171 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 3172 | oldcmd = &oldiocb->iocb; |
| 3173 | |
| 3174 | switch (flag) { |
| 3175 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3176 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3177 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3178 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3179 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3180 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3181 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3182 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3183 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3184 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3185 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3186 | icmd = &elsiocb->iocb; |
| 3187 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3188 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3189 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3190 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3191 | |
| 3192 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3193 | "Issue ACC: did:x%x flg:x%x", |
| 3194 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3195 | break; |
| 3196 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3197 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3198 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3199 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3200 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3201 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3202 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3203 | icmd = &elsiocb->iocb; |
| 3204 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3205 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3206 | |
| 3207 | if (mbox) |
| 3208 | elsiocb->context_un.mbox = mbox; |
| 3209 | |
| 3210 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3211 | pcmd += sizeof(uint32_t); |
| 3212 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3213 | |
| 3214 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3215 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 3216 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3217 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3218 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3219 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3220 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3221 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3222 | if (!elsiocb) |
| 3223 | return 1; |
| 3224 | |
| 3225 | icmd = &elsiocb->iocb; |
| 3226 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3227 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3228 | |
| 3229 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3230 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3231 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 3232 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 3233 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3234 | |
| 3235 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3236 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 3237 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3238 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3239 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3240 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3241 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3242 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3243 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3244 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
| 3245 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", |
| 3246 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3247 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3248 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3249 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3250 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3251 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3252 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3253 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 3254 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3255 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3256 | } |
| 3257 | |
| 3258 | phba->fc_stat.elsXmitACC++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3259 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3260 | if (rc == IOCB_ERROR) { |
| 3261 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3262 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3263 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3264 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3265 | } |
| 3266 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3267 | /** |
| 3268 | * lpfc_els_rsp_reject: Propare and issue a rjt response iocb command. |
| 3269 | * @vport: pointer to a virtual N_Port data structure. |
| 3270 | * @rejectError: |
| 3271 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3272 | * @ndlp: pointer to a node-list data structure. |
| 3273 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3274 | * |
| 3275 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 3276 | * command. If a @mbox pointer is passed in, it will be put into the |
| 3277 | * context_un.mbox field of the IOCB for the completion callback function |
| 3278 | * to issue to the HBA later. |
| 3279 | * |
| 3280 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3281 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3282 | * will be stored into the context1 field of the IOCB for the completion |
| 3283 | * callback function to the reject response ELS IOCB command. |
| 3284 | * |
| 3285 | * Return code |
| 3286 | * 0 - Successfully issued reject response |
| 3287 | * 1 - Failed to issue reject response |
| 3288 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3289 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3290 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3291 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 3292 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3293 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3294 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3295 | IOCB_t *icmd; |
| 3296 | IOCB_t *oldcmd; |
| 3297 | struct lpfc_iocbq *elsiocb; |
| 3298 | struct lpfc_sli_ring *pring; |
| 3299 | struct lpfc_sli *psli; |
| 3300 | uint8_t *pcmd; |
| 3301 | uint16_t cmdsize; |
| 3302 | int rc; |
| 3303 | |
| 3304 | psli = &phba->sli; |
| 3305 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 3306 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3307 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3308 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3309 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3310 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3311 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3312 | |
| 3313 | icmd = &elsiocb->iocb; |
| 3314 | oldcmd = &oldiocb->iocb; |
| 3315 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3316 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3317 | |
| 3318 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3319 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3320 | *((uint32_t *) (pcmd)) = rejectError; |
| 3321 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3322 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3323 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3324 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3325 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3326 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3327 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 3328 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 3329 | "rpi x%x\n", |
| 3330 | rejectError, elsiocb->iotag, |
| 3331 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 3332 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3333 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3334 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 3335 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 3336 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3337 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3338 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3339 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3340 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3341 | if (rc == IOCB_ERROR) { |
| 3342 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3343 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3344 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3345 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3346 | } |
| 3347 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3348 | /** |
| 3349 | * lpfc_els_rsp_adisc_acc: Prepare and issue acc response to adisc iocb cmd. |
| 3350 | * @vport: pointer to a virtual N_Port data structure. |
| 3351 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3352 | * @ndlp: pointer to a node-list data structure. |
| 3353 | * |
| 3354 | * This routine prepares and issues an Accept (ACC) response to Address |
| 3355 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 3356 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3357 | * |
| 3358 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3359 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3360 | * will be stored into the context1 field of the IOCB for the completion |
| 3361 | * callback function to the ADISC Accept response ELS IOCB command. |
| 3362 | * |
| 3363 | * Return code |
| 3364 | * 0 - Successfully issued acc adisc response |
| 3365 | * 1 - Failed to issue adisc acc response |
| 3366 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3367 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3368 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 3369 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3370 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3371 | struct lpfc_hba *phba = vport->phba; |
| 3372 | struct lpfc_sli *psli = &phba->sli; |
| 3373 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3374 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3375 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3376 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3377 | uint8_t *pcmd; |
| 3378 | uint16_t cmdsize; |
| 3379 | int rc; |
| 3380 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3381 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3382 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3383 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3384 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3385 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3386 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3387 | icmd = &elsiocb->iocb; |
| 3388 | oldcmd = &oldiocb->iocb; |
| 3389 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3390 | |
| 3391 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3392 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3393 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 3394 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 3395 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3396 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3397 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3398 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3399 | |
| 3400 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3401 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3402 | |
| 3403 | ap = (ADISC *) (pcmd); |
| 3404 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3405 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3406 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3407 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3408 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3409 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3410 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 3411 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3412 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3413 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3414 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3415 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3416 | if (rc == IOCB_ERROR) { |
| 3417 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3418 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3419 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3420 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3421 | } |
| 3422 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3423 | /** |
| 3424 | * lpfc_els_rsp_prli_acc: Prepare and issue acc response to prli iocb cmd. |
| 3425 | * @vport: pointer to a virtual N_Port data structure. |
| 3426 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3427 | * @ndlp: pointer to a node-list data structure. |
| 3428 | * |
| 3429 | * This routine prepares and issues an Accept (ACC) response to Process |
| 3430 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 3431 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3432 | * |
| 3433 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3434 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3435 | * will be stored into the context1 field of the IOCB for the completion |
| 3436 | * callback function to the PRLI Accept response ELS IOCB command. |
| 3437 | * |
| 3438 | * Return code |
| 3439 | * 0 - Successfully issued acc prli response |
| 3440 | * 1 - Failed to issue acc prli response |
| 3441 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3442 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3443 | 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] | 3444 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3445 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3446 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3447 | PRLI *npr; |
| 3448 | lpfc_vpd_t *vpd; |
| 3449 | IOCB_t *icmd; |
| 3450 | IOCB_t *oldcmd; |
| 3451 | struct lpfc_iocbq *elsiocb; |
| 3452 | struct lpfc_sli_ring *pring; |
| 3453 | struct lpfc_sli *psli; |
| 3454 | uint8_t *pcmd; |
| 3455 | uint16_t cmdsize; |
| 3456 | int rc; |
| 3457 | |
| 3458 | psli = &phba->sli; |
| 3459 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 3460 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3461 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3462 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3463 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3464 | if (!elsiocb) |
| 3465 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3466 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3467 | icmd = &elsiocb->iocb; |
| 3468 | oldcmd = &oldiocb->iocb; |
| 3469 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3470 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3471 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3472 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 3473 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 3474 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3475 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3476 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3477 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3478 | |
| 3479 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3480 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3481 | |
| 3482 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3483 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3484 | |
| 3485 | npr = (PRLI *) pcmd; |
| 3486 | vpd = &phba->vpd; |
| 3487 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3488 | * If the remote port is a target and our firmware version is 3.20 or |
| 3489 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3490 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3491 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 3492 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3493 | npr->ConfmComplAllowed = 1; |
| 3494 | npr->Retry = 1; |
| 3495 | npr->TaskRetryIdReq = 1; |
| 3496 | } |
| 3497 | |
| 3498 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 3499 | npr->estabImagePair = 1; |
| 3500 | npr->readXferRdyDis = 1; |
| 3501 | npr->ConfmComplAllowed = 1; |
| 3502 | |
| 3503 | npr->prliType = PRLI_FCP_TYPE; |
| 3504 | npr->initiatorFunc = 1; |
| 3505 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3506 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3507 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 3508 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3509 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3510 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3511 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3512 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3513 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3514 | if (rc == IOCB_ERROR) { |
| 3515 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3516 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3517 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3518 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3519 | } |
| 3520 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3521 | /** |
| 3522 | * lpfc_els_rsp_rnid_acc: Issue rnid acc response iocb command. |
| 3523 | * @vport: pointer to a virtual N_Port data structure. |
| 3524 | * @format: rnid command format. |
| 3525 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3526 | * @ndlp: pointer to a node-list data structure. |
| 3527 | * |
| 3528 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 3529 | * (ACC) response. It constructs the RNID ACC response command according to |
| 3530 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 3531 | * issue the response. Note that this command does not need to hold the ndlp |
| 3532 | * reference count for the callback. So, the ndlp reference count taken by |
| 3533 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 3534 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 3535 | * there is no ndlp reference available. |
| 3536 | * |
| 3537 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3538 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3539 | * will be stored into the context1 field of the IOCB for the completion |
| 3540 | * callback function. However, for the RNID Accept Response ELS command, |
| 3541 | * this is undone later by this routine after the IOCB is allocated. |
| 3542 | * |
| 3543 | * Return code |
| 3544 | * 0 - Successfully issued acc rnid response |
| 3545 | * 1 - Failed to issue acc rnid response |
| 3546 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3547 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3548 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3549 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3550 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3551 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3552 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3553 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3554 | struct lpfc_iocbq *elsiocb; |
| 3555 | struct lpfc_sli_ring *pring; |
| 3556 | struct lpfc_sli *psli; |
| 3557 | uint8_t *pcmd; |
| 3558 | uint16_t cmdsize; |
| 3559 | int rc; |
| 3560 | |
| 3561 | psli = &phba->sli; |
| 3562 | pring = &psli->ring[LPFC_ELS_RING]; |
| 3563 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3564 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 3565 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3566 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3567 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3568 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3569 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3570 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3571 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3572 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3573 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3574 | icmd = &elsiocb->iocb; |
| 3575 | oldcmd = &oldiocb->iocb; |
| 3576 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3577 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3578 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3579 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 3580 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3581 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3582 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3583 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3584 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3585 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3586 | rn = (RNID *) (pcmd); |
| 3587 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3588 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 3589 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3590 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3591 | switch (format) { |
| 3592 | case 0: |
| 3593 | rn->SpecificLen = 0; |
| 3594 | break; |
| 3595 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3596 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3597 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3598 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3599 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 3600 | rn->un.topologyDisc.physPort = 0; |
| 3601 | rn->un.topologyDisc.attachedNodes = 0; |
| 3602 | break; |
| 3603 | default: |
| 3604 | rn->CommonLen = 0; |
| 3605 | rn->SpecificLen = 0; |
| 3606 | break; |
| 3607 | } |
| 3608 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3609 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3610 | "Issue ACC RNID: did:x%x flg:x%x", |
| 3611 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3612 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3613 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3614 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3615 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3616 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 3617 | * it could be freed */ |
| 3618 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3619 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3620 | if (rc == IOCB_ERROR) { |
| 3621 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3622 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3623 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3624 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3625 | } |
| 3626 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3627 | /** |
| 3628 | * lpfc_els_disc_adisc: Issue remaining adisc iocbs to npr nodes of a vport. |
| 3629 | * @vport: pointer to a host virtual N_Port data structure. |
| 3630 | * |
| 3631 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 3632 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 3633 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 3634 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 3635 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 3636 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 3637 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 3638 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 3639 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 3640 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 3641 | * no more ADISC need to be sent. |
| 3642 | * |
| 3643 | * Return code |
| 3644 | * The number of N_Ports with adisc issued. |
| 3645 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3646 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3647 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3648 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3649 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3650 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3651 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3652 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3653 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3654 | 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] | 3655 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3656 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3657 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3658 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3659 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3660 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3661 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3662 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3663 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3664 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 3665 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3666 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3667 | vport->num_disc_nodes++; |
| 3668 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3669 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3670 | spin_lock_irq(shost->host_lock); |
| 3671 | vport->fc_flag |= FC_NLP_MORE; |
| 3672 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3673 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3674 | } |
| 3675 | } |
| 3676 | } |
| 3677 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3678 | spin_lock_irq(shost->host_lock); |
| 3679 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3680 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3681 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3682 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3683 | } |
| 3684 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3685 | /** |
| 3686 | * lpfc_els_disc_plogi: Issue plogi for all npr nodes of a vport before adisc. |
| 3687 | * @vport: pointer to a host virtual N_Port data structure. |
| 3688 | * |
| 3689 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 3690 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 3691 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 3692 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 3693 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 3694 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 3695 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 3696 | * later pick up. On the other hand, after walking through all the ndlps with |
| 3697 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 3698 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 3699 | * PLOGI need to be sent. |
| 3700 | * |
| 3701 | * Return code |
| 3702 | * The number of N_Ports with plogi issued. |
| 3703 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3704 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3705 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3706 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3707 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3708 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3709 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3710 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3711 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 3712 | 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] | 3713 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3714 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3715 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3716 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3717 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 3718 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 3719 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3720 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 3721 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3722 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3723 | vport->num_disc_nodes++; |
| 3724 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3725 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3726 | spin_lock_irq(shost->host_lock); |
| 3727 | vport->fc_flag |= FC_NLP_MORE; |
| 3728 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3729 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3730 | } |
| 3731 | } |
| 3732 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3733 | if (sentplogi) { |
| 3734 | lpfc_set_disctmo(vport); |
| 3735 | } |
| 3736 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3737 | spin_lock_irq(shost->host_lock); |
| 3738 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3739 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3740 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3741 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3742 | } |
| 3743 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3744 | /** |
| 3745 | * lpfc_els_flush_rscn: Clean up any rscn activities with a vport. |
| 3746 | * @vport: pointer to a host virtual N_Port data structure. |
| 3747 | * |
| 3748 | * This routine cleans up any Registration State Change Notification |
| 3749 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 3750 | * @vport together with the host_lock is used to prevent multiple thread |
| 3751 | * trying to access the RSCN array on a same @vport at the same time. |
| 3752 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3753 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3754 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3755 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3756 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3757 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3758 | int i; |
| 3759 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3760 | spin_lock_irq(shost->host_lock); |
| 3761 | if (vport->fc_rscn_flush) { |
| 3762 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3763 | spin_unlock_irq(shost->host_lock); |
| 3764 | return; |
| 3765 | } |
| 3766 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 3767 | vport->fc_rscn_flush = 1; |
| 3768 | spin_unlock_irq(shost->host_lock); |
| 3769 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3770 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3771 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3772 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3773 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3774 | spin_lock_irq(shost->host_lock); |
| 3775 | vport->fc_rscn_id_cnt = 0; |
| 3776 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 3777 | spin_unlock_irq(shost->host_lock); |
| 3778 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3779 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 3780 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3781 | } |
| 3782 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3783 | /** |
| 3784 | * lpfc_rscn_payload_check: Check whether there is a pending rscn to a did. |
| 3785 | * @vport: pointer to a host virtual N_Port data structure. |
| 3786 | * @did: remote destination port identifier. |
| 3787 | * |
| 3788 | * This routine checks whether there is any pending Registration State |
| 3789 | * Configuration Notification (RSCN) to a @did on @vport. |
| 3790 | * |
| 3791 | * Return code |
| 3792 | * None zero - The @did matched with a pending rscn |
| 3793 | * 0 - not able to match @did with a pending rscn |
| 3794 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3795 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3796 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3797 | { |
| 3798 | D_ID ns_did; |
| 3799 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3800 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3801 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3802 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3803 | |
| 3804 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3805 | |
| 3806 | /* Never match fabric nodes for RSCNs */ |
| 3807 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3808 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3809 | |
| 3810 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3811 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3812 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3813 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3814 | spin_lock_irq(shost->host_lock); |
| 3815 | if (vport->fc_rscn_flush) { |
| 3816 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3817 | spin_unlock_irq(shost->host_lock); |
| 3818 | return 0; |
| 3819 | } |
| 3820 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 3821 | vport->fc_rscn_flush = 1; |
| 3822 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3823 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3824 | lp = vport->fc_rscn_id_list[i]->virt; |
| 3825 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 3826 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3827 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3828 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 3829 | payload_len -= sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3830 | switch (rscn_did.un.b.resv) { |
| 3831 | case 0: /* Single N_Port ID effected */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3832 | if (ns_did.un.word == rscn_did.un.word) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3833 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3834 | break; |
| 3835 | case 1: /* Whole N_Port Area effected */ |
| 3836 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 3837 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
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 | case 2: /* Whole N_Port Domain effected */ |
| 3841 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3842 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3843 | break; |
| 3844 | default: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3845 | /* Unknown Identifier in RSCN node */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3846 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 3847 | "0217 Unknown Identifier in " |
| 3848 | "RSCN payload Data: x%x\n", |
| 3849 | rscn_did.un.word); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3850 | case 3: /* Whole Fabric effected */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3851 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3852 | } |
| 3853 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3854 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3855 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 3856 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3857 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3858 | return_did_out: |
| 3859 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 3860 | vport->fc_rscn_flush = 0; |
| 3861 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3862 | } |
| 3863 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3864 | /** |
| 3865 | * lpfc_rscn_recovery_check: Send recovery event to vport nodes matching rscn |
| 3866 | * @vport: pointer to a host virtual N_Port data structure. |
| 3867 | * |
| 3868 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 3869 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 3870 | * State Change Notification). |
| 3871 | * |
| 3872 | * Return code |
| 3873 | * 0 - Successful (currently alway return 0) |
| 3874 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3875 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3876 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3877 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3878 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3879 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3880 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3881 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3882 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3883 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 3884 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3885 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3886 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3887 | NLP_EVT_DEVICE_RECOVERY); |
| 3888 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3889 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3890 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3891 | } |
| 3892 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3893 | /** |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 3894 | * lpfc_send_rscn_event: Send an RSCN event to management application. |
| 3895 | * @vport: pointer to a host virtual N_Port data structure. |
| 3896 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3897 | * |
| 3898 | * lpfc_send_rscn_event sends an RSCN netlink event to management |
| 3899 | * applications. |
| 3900 | */ |
| 3901 | static void |
| 3902 | lpfc_send_rscn_event(struct lpfc_vport *vport, |
| 3903 | struct lpfc_iocbq *cmdiocb) |
| 3904 | { |
| 3905 | struct lpfc_dmabuf *pcmd; |
| 3906 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3907 | uint32_t *payload_ptr; |
| 3908 | uint32_t payload_len; |
| 3909 | struct lpfc_rscn_event_header *rscn_event_data; |
| 3910 | |
| 3911 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 3912 | payload_ptr = (uint32_t *) pcmd->virt; |
| 3913 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); |
| 3914 | |
| 3915 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + |
| 3916 | payload_len, GFP_KERNEL); |
| 3917 | if (!rscn_event_data) { |
| 3918 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3919 | "0147 Failed to allocate memory for RSCN event\n"); |
| 3920 | return; |
| 3921 | } |
| 3922 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; |
| 3923 | rscn_event_data->payload_length = payload_len; |
| 3924 | memcpy(rscn_event_data->rscn_payload, payload_ptr, |
| 3925 | payload_len); |
| 3926 | |
| 3927 | fc_host_post_vendor_event(shost, |
| 3928 | fc_get_event_number(), |
| 3929 | sizeof(struct lpfc_els_event_header) + payload_len, |
| 3930 | (char *)rscn_event_data, |
| 3931 | LPFC_NL_VENDOR_ID); |
| 3932 | |
| 3933 | kfree(rscn_event_data); |
| 3934 | } |
| 3935 | |
| 3936 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3937 | * lpfc_els_rcv_rscn: Process an unsolicited rscn iocb. |
| 3938 | * @vport: pointer to a host virtual N_Port data structure. |
| 3939 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3940 | * @ndlp: pointer to a node-list data structure. |
| 3941 | * |
| 3942 | * This routine processes an unsolicited RSCN (Registration State Change |
| 3943 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 3944 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 3945 | * discover state machine is about to begin discovery, it just accepts the |
| 3946 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 3947 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 3948 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 3949 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 3950 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 3951 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 3952 | * routine is invoked to handle the RSCN event. |
| 3953 | * |
| 3954 | * Return code |
| 3955 | * 0 - Just sent the acc response |
| 3956 | * 1 - Sent the acc response and waited for name server completion |
| 3957 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3958 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3959 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3960 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3961 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3962 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3963 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3964 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3965 | uint32_t *lp, *datap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3966 | IOCB_t *icmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3967 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3968 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3969 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 3970 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3971 | |
| 3972 | icmd = &cmdiocb->iocb; |
| 3973 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 3974 | lp = (uint32_t *) pcmd->virt; |
| 3975 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3976 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 3977 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3978 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3979 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 3980 | "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] | 3981 | vport->fc_flag, payload_len, *lp, |
| 3982 | vport->fc_rscn_id_cnt); |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 3983 | |
| 3984 | /* Send an RSCN event to the management application */ |
| 3985 | lpfc_send_rscn_event(vport, cmdiocb); |
| 3986 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 3987 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3988 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 3989 | FCH_EVT_RSCN, lp[i]); |
| 3990 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3991 | /* If we are about to begin discovery, just ACC the RSCN. |
| 3992 | * Discovery processing will satisfy it. |
| 3993 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3994 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3995 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 3996 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 3997 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 3998 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3999 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4000 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4001 | } |
| 4002 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4003 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 4004 | * just ACC and ignore it. |
| 4005 | */ |
| 4006 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4007 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4008 | i = payload_len; |
| 4009 | datap = lp; |
| 4010 | while (i > 0) { |
| 4011 | nportid = *datap++; |
| 4012 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 4013 | i -= sizeof(uint32_t); |
| 4014 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4015 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 4016 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4017 | } |
| 4018 | if (rscn_id == hba_id) { |
| 4019 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4020 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4021 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4022 | "Data: x%x x%x x%x x%x\n", |
| 4023 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4024 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4025 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4026 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 4027 | ndlp->nlp_DID, vport->port_state, |
| 4028 | ndlp->nlp_flag); |
| 4029 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4030 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4031 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4032 | return 0; |
| 4033 | } |
| 4034 | } |
| 4035 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4036 | spin_lock_irq(shost->host_lock); |
| 4037 | if (vport->fc_rscn_flush) { |
| 4038 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 4039 | spin_unlock_irq(shost->host_lock); |
| 4040 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4041 | /* Send back ACC */ |
| 4042 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4043 | return 0; |
| 4044 | } |
| 4045 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 4046 | vport->fc_rscn_flush = 1; |
| 4047 | spin_unlock_irq(shost->host_lock); |
| 4048 | /* Get the array count after sucessfully have the token */ |
| 4049 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4050 | /* If we are already processing an RSCN, save the received |
| 4051 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 4052 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4053 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4054 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4055 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 4056 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4057 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4058 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4059 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 4060 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4061 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4062 | vport->fc_flag |= FC_RSCN_MODE; |
| 4063 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4064 | if (rscn_cnt) { |
| 4065 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 4066 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 4067 | } |
| 4068 | if ((rscn_cnt) && |
| 4069 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 4070 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4071 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4072 | memcpy(((uint8_t *)cmd) + length, lp, |
| 4073 | payload_len); |
| 4074 | } else { |
| 4075 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 4076 | vport->fc_rscn_id_cnt++; |
| 4077 | /* If we zero, cmdiocb->context2, the calling |
| 4078 | * routine will not try to free it. |
| 4079 | */ |
| 4080 | cmdiocb->context2 = NULL; |
| 4081 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4082 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4083 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4084 | "0235 Deferred RSCN " |
| 4085 | "Data: x%x x%x x%x\n", |
| 4086 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4087 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4088 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4089 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 4090 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4091 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4092 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4093 | "0234 ReDiscovery RSCN " |
| 4094 | "Data: x%x x%x x%x\n", |
| 4095 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4096 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4097 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4098 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4099 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4100 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4101 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4102 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4103 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4104 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4105 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4106 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4107 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4108 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4109 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4110 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 4111 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4112 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4113 | spin_lock_irq(shost->host_lock); |
| 4114 | vport->fc_flag |= FC_RSCN_MODE; |
| 4115 | spin_unlock_irq(shost->host_lock); |
| 4116 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4117 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4118 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4119 | /* |
| 4120 | * If we zero, cmdiocb->context2, the calling routine will |
| 4121 | * not try to free it. |
| 4122 | */ |
| 4123 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4124 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4125 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4126 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4127 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4128 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4129 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4130 | } |
| 4131 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4132 | /** |
| 4133 | * lpfc_els_handle_rscn: Handle rscn for a vport. |
| 4134 | * @vport: pointer to a host virtual N_Port data structure. |
| 4135 | * |
| 4136 | * This routine handles the Registration State Configuration Notification |
| 4137 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 4138 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 4139 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 4140 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 4141 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 4142 | * RSCN activities with the @vport. |
| 4143 | * |
| 4144 | * Return code |
| 4145 | * 0 - Cleaned up rscn on the @vport |
| 4146 | * 1 - Wait for plogi to name server before proceed |
| 4147 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4148 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4149 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4150 | { |
| 4151 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4152 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4153 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4154 | /* Ignore RSCN if the port is being torn down. */ |
| 4155 | if (vport->load_flag & FC_UNLOADING) { |
| 4156 | lpfc_els_flush_rscn(vport); |
| 4157 | return 0; |
| 4158 | } |
| 4159 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4160 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4161 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4162 | |
| 4163 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4164 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4165 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 4166 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 4167 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4168 | |
| 4169 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4170 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4171 | vport->num_disc_nodes = 0; |
| 4172 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4173 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4174 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 4175 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4176 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4177 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4178 | /* Wait for NameServer query cmpl before we can |
| 4179 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4180 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4181 | } else { |
| 4182 | /* If login to NameServer does not exist, issue one */ |
| 4183 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4184 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4185 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4186 | /* Wait for NameServer login cmpl before we can |
| 4187 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4188 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4189 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4190 | if (ndlp) { |
| 4191 | ndlp = lpfc_enable_node(vport, ndlp, |
| 4192 | NLP_STE_PLOGI_ISSUE); |
| 4193 | if (!ndlp) { |
| 4194 | lpfc_els_flush_rscn(vport); |
| 4195 | return 0; |
| 4196 | } |
| 4197 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4198 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4199 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4200 | if (!ndlp) { |
| 4201 | lpfc_els_flush_rscn(vport); |
| 4202 | return 0; |
| 4203 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4204 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4205 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4206 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4207 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4208 | ndlp->nlp_type |= NLP_FABRIC; |
| 4209 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 4210 | /* Wait for NameServer login cmpl before we can |
| 4211 | * continue |
| 4212 | */ |
| 4213 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4214 | } |
| 4215 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4216 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4217 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4218 | } |
| 4219 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4220 | /** |
| 4221 | * lpfc_els_rcv_flogi: Process an unsolicited flogi iocb. |
| 4222 | * @vport: pointer to a host virtual N_Port data structure. |
| 4223 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4224 | * @ndlp: pointer to a node-list data structure. |
| 4225 | * |
| 4226 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 4227 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 4228 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 4229 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 4230 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 4231 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 4232 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 4233 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 4234 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 4235 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 4236 | * higher priority (as the winning port) and will initiate PLOGI and |
| 4237 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 4238 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 4239 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 4240 | * |
| 4241 | * Return code |
| 4242 | * 0 - Successfully processed the unsolicited flogi |
| 4243 | * 1 - Failed to process the unsolicited flogi |
| 4244 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4245 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4246 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4247 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4248 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4249 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4250 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4251 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4252 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 4253 | IOCB_t *icmd = &cmdiocb->iocb; |
| 4254 | struct serv_parm *sp; |
| 4255 | LPFC_MBOXQ_t *mbox; |
| 4256 | struct ls_rjt stat; |
| 4257 | uint32_t cmd, did; |
| 4258 | int rc; |
| 4259 | |
| 4260 | cmd = *lp++; |
| 4261 | sp = (struct serv_parm *) lp; |
| 4262 | |
| 4263 | /* FLOGI received */ |
| 4264 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4265 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4266 | |
| 4267 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 4268 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 4269 | did = icmd->un.elsreq64.remoteID; |
| 4270 | |
| 4271 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 4272 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4273 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4274 | "0113 An FLOGI ELS command x%x was " |
| 4275 | "received from DID x%x in Loop Mode\n", |
| 4276 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4277 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4278 | } |
| 4279 | |
| 4280 | did = Fabric_DID; |
| 4281 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4282 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4283 | /* For a FLOGI we accept, then if our portname is greater |
| 4284 | * then the remote portname we initiate Nport login. |
| 4285 | */ |
| 4286 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4287 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4288 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4289 | |
| 4290 | if (!rc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4291 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4292 | if (!mbox) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4293 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4294 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4295 | lpfc_linkdown(phba); |
| 4296 | lpfc_init_link(phba, mbox, |
| 4297 | phba->cfg_topology, |
| 4298 | phba->cfg_link_speed); |
| 4299 | mbox->mb.un.varInitLnk.lipsr_AL_PA = 0; |
| 4300 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4301 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4302 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4303 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4304 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4305 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4306 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4307 | return 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4308 | } else if (rc > 0) { /* greater than */ |
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_PLOGI; |
| 4311 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4312 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4313 | spin_lock_irq(shost->host_lock); |
| 4314 | vport->fc_flag |= FC_PT2PT; |
| 4315 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 4316 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4317 | } else { |
| 4318 | /* Reject this request because invalid parameters */ |
| 4319 | stat.un.b.lsRjtRsvd0 = 0; |
| 4320 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4321 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 4322 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4323 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4324 | NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4325 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4326 | } |
| 4327 | |
| 4328 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4329 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4330 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4331 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4332 | } |
| 4333 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4334 | /** |
| 4335 | * lpfc_els_rcv_rnid: Process an unsolicited rnid iocb. |
| 4336 | * @vport: pointer to a host virtual N_Port data structure. |
| 4337 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4338 | * @ndlp: pointer to a node-list data structure. |
| 4339 | * |
| 4340 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 4341 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 4342 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 4343 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 4344 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 4345 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 4346 | * |
| 4347 | * Return code |
| 4348 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 4349 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4350 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4351 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4352 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4353 | { |
| 4354 | struct lpfc_dmabuf *pcmd; |
| 4355 | uint32_t *lp; |
| 4356 | IOCB_t *icmd; |
| 4357 | RNID *rn; |
| 4358 | struct ls_rjt stat; |
| 4359 | uint32_t cmd, did; |
| 4360 | |
| 4361 | icmd = &cmdiocb->iocb; |
| 4362 | did = icmd->un.elsreq64.remoteID; |
| 4363 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4364 | lp = (uint32_t *) pcmd->virt; |
| 4365 | |
| 4366 | cmd = *lp++; |
| 4367 | rn = (RNID *) lp; |
| 4368 | |
| 4369 | /* RNID received */ |
| 4370 | |
| 4371 | switch (rn->Format) { |
| 4372 | case 0: |
| 4373 | case RNID_TOPOLOGY_DISC: |
| 4374 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4375 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4376 | break; |
| 4377 | default: |
| 4378 | /* Reject this request because format not supported */ |
| 4379 | stat.un.b.lsRjtRsvd0 = 0; |
| 4380 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4381 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4382 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4383 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4384 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4385 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4386 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4387 | } |
| 4388 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4389 | /** |
| 4390 | * lpfc_els_rcv_lirr: Process an unsolicited lirr iocb. |
| 4391 | * @vport: pointer to a host virtual N_Port data structure. |
| 4392 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4393 | * @ndlp: pointer to a node-list data structure. |
| 4394 | * |
| 4395 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 4396 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 4397 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 4398 | * |
| 4399 | * Return code |
| 4400 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 4401 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4402 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4403 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4404 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4405 | { |
| 4406 | struct ls_rjt stat; |
| 4407 | |
| 4408 | /* For now, unconditionally reject this command */ |
| 4409 | stat.un.b.lsRjtRsvd0 = 0; |
| 4410 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4411 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4412 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4413 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4414 | return 0; |
| 4415 | } |
| 4416 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4417 | /** |
| 4418 | * lpfc_els_rsp_rps_acc: Completion callbk func for MBX_READ_LNK_STAT mbox cmd. |
| 4419 | * @phba: pointer to lpfc hba data structure. |
| 4420 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4421 | * |
| 4422 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 4423 | * mailbox command. This callback function is to actually send the Accept |
| 4424 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 4425 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 4426 | * mailbox command, constructs the RPS response with the link statistics |
| 4427 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 4428 | * response to the RPS. |
| 4429 | * |
| 4430 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4431 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4432 | * will be stored into the context1 field of the IOCB for the completion |
| 4433 | * callback function to the RPS Accept Response ELS IOCB command. |
| 4434 | * |
| 4435 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4436 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4437 | 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] | 4438 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4439 | struct lpfc_sli *psli = &phba->sli; |
| 4440 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4441 | MAILBOX_t *mb; |
| 4442 | IOCB_t *icmd; |
| 4443 | RPS_RSP *rps_rsp; |
| 4444 | uint8_t *pcmd; |
| 4445 | struct lpfc_iocbq *elsiocb; |
| 4446 | struct lpfc_nodelist *ndlp; |
| 4447 | uint16_t xri, status; |
| 4448 | uint32_t cmdsize; |
| 4449 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4450 | mb = &pmb->mb; |
| 4451 | |
| 4452 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4453 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 4454 | pmb->context1 = NULL; |
| 4455 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4456 | |
| 4457 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4458 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4459 | return; |
| 4460 | } |
| 4461 | |
| 4462 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4463 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4464 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 4465 | lpfc_max_els_tries, ndlp, |
| 4466 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4467 | |
| 4468 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4469 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4470 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4471 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4472 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4473 | |
| 4474 | icmd = &elsiocb->iocb; |
| 4475 | icmd->ulpContext = xri; |
| 4476 | |
| 4477 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4478 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4479 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4480 | rps_rsp = (RPS_RSP *)pcmd; |
| 4481 | |
| 4482 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| 4483 | status = 0x10; |
| 4484 | else |
| 4485 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4486 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4487 | status |= 0x4; |
| 4488 | |
| 4489 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4490 | rps_rsp->portStatus = cpu_to_be16(status); |
| 4491 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 4492 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 4493 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 4494 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 4495 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 4496 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4497 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4498 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 4499 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 4500 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4501 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4502 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4503 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4504 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4505 | phba->fc_stat.elsXmitACC++; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4506 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4507 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4508 | return; |
| 4509 | } |
| 4510 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4511 | /** |
| 4512 | * lpfc_els_rcv_rps: Process an unsolicited rps iocb. |
| 4513 | * @vport: pointer to a host virtual N_Port data structure. |
| 4514 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4515 | * @ndlp: pointer to a node-list data structure. |
| 4516 | * |
| 4517 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 4518 | * ELS unsolicited event. It first checks the remote port state. If the |
| 4519 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 4520 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 4521 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 4522 | * for reading the HBA link statistics. It is for the callback function, |
| 4523 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 4524 | * to actually sending out RPS Accept (ACC) response. |
| 4525 | * |
| 4526 | * Return codes |
| 4527 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 4528 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4529 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4530 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4531 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4532 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4533 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4534 | uint32_t *lp; |
| 4535 | uint8_t flag; |
| 4536 | LPFC_MBOXQ_t *mbox; |
| 4537 | struct lpfc_dmabuf *pcmd; |
| 4538 | RPS *rps; |
| 4539 | struct ls_rjt stat; |
| 4540 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4541 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4542 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 4543 | /* reject the unsolicited RPS request and done with it */ |
| 4544 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4545 | |
| 4546 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4547 | lp = (uint32_t *) pcmd->virt; |
| 4548 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 4549 | rps = (RPS *) lp; |
| 4550 | |
| 4551 | if ((flag == 0) || |
| 4552 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4553 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4554 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4555 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4556 | printk("Fix me....\n"); |
| 4557 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4558 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 4559 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4560 | lpfc_read_lnk_stat(phba, mbox); |
| 4561 | mbox->context1 = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4562 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4563 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4564 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4565 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4566 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4567 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4568 | /* Mbox completion will send ELS Response */ |
| 4569 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4570 | /* Decrement reference count used for the failed mbox |
| 4571 | * command. |
| 4572 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4573 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4574 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4575 | } |
| 4576 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4577 | |
| 4578 | reject_out: |
| 4579 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4580 | stat.un.b.lsRjtRsvd0 = 0; |
| 4581 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4582 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4583 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4584 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4585 | return 0; |
| 4586 | } |
| 4587 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4588 | /** |
| 4589 | * lpfc_els_rsp_rpl_acc: Issue an accept rpl els command. |
| 4590 | * @vport: pointer to a host virtual N_Port data structure. |
| 4591 | * @cmdsize: size of the ELS command. |
| 4592 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4593 | * @ndlp: pointer to a node-list data structure. |
| 4594 | * |
| 4595 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 4596 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 4597 | * |
| 4598 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4599 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4600 | * will be stored into the context1 field of the IOCB for the completion |
| 4601 | * callback function to the RPL Accept Response ELS command. |
| 4602 | * |
| 4603 | * Return code |
| 4604 | * 0 - Successfully issued ACC RPL ELS command |
| 4605 | * 1 - Failed to issue ACC RPL ELS command |
| 4606 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4607 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4608 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 4609 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4610 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4611 | struct lpfc_hba *phba = vport->phba; |
| 4612 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4613 | RPL_RSP rpl_rsp; |
| 4614 | struct lpfc_iocbq *elsiocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4615 | struct lpfc_sli *psli = &phba->sli; |
| 4616 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4617 | uint8_t *pcmd; |
| 4618 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4619 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4620 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4621 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4622 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4623 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4624 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4625 | icmd = &elsiocb->iocb; |
| 4626 | oldcmd = &oldiocb->iocb; |
| 4627 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 4628 | |
| 4629 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4630 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4631 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4632 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 4633 | pcmd += sizeof(uint16_t); |
| 4634 | |
| 4635 | /* Setup the RPL ACC payload */ |
| 4636 | rpl_rsp.listLen = be32_to_cpu(1); |
| 4637 | rpl_rsp.index = 0; |
| 4638 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4639 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 4640 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4641 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4642 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4643 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4644 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4645 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 4646 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 4647 | "rpi x%x\n", |
| 4648 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4649 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4650 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4651 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4652 | phba->fc_stat.elsXmitACC++; |
| 4653 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
| 4654 | lpfc_els_free_iocb(phba, elsiocb); |
| 4655 | return 1; |
| 4656 | } |
| 4657 | return 0; |
| 4658 | } |
| 4659 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4660 | /** |
| 4661 | * lpfc_els_rcv_rpl: Process an unsolicited rpl iocb. |
| 4662 | * @vport: pointer to a host virtual N_Port data structure. |
| 4663 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4664 | * @ndlp: pointer to a node-list data structure. |
| 4665 | * |
| 4666 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 4667 | * unsolicited event. It first checks the remote port state. If the remote |
| 4668 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 4669 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 4670 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 4671 | * to accept the RPL. |
| 4672 | * |
| 4673 | * Return code |
| 4674 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 4675 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4676 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4677 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4678 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4679 | { |
| 4680 | struct lpfc_dmabuf *pcmd; |
| 4681 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4682 | uint32_t maxsize; |
| 4683 | uint16_t cmdsize; |
| 4684 | RPL *rpl; |
| 4685 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4686 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4687 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 4688 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4689 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4690 | stat.un.b.lsRjtRsvd0 = 0; |
| 4691 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4692 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4693 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4694 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4695 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4696 | /* rejected the unsolicited RPL request and done with it */ |
| 4697 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4698 | } |
| 4699 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4700 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4701 | lp = (uint32_t *) pcmd->virt; |
| 4702 | rpl = (RPL *) (lp + 1); |
| 4703 | |
| 4704 | maxsize = be32_to_cpu(rpl->maxsize); |
| 4705 | |
| 4706 | /* We support only one port */ |
| 4707 | if ((rpl->index == 0) && |
| 4708 | ((maxsize == 0) || |
| 4709 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 4710 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4711 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4712 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 4713 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4714 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4715 | |
| 4716 | return 0; |
| 4717 | } |
| 4718 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4719 | /** |
| 4720 | * lpfc_els_rcv_farp: Process an unsolicited farp request els command. |
| 4721 | * @vport: pointer to a virtual N_Port data structure. |
| 4722 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4723 | * @ndlp: pointer to a node-list data structure. |
| 4724 | * |
| 4725 | * This routine processes Fibre Channel Address Resolution Protocol |
| 4726 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 4727 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 4728 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 4729 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 4730 | * remote PortName is compared against the FC PortName stored in the @vport |
| 4731 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 4732 | * compared against the FC NodeName stored in the @vport data structure. |
| 4733 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 4734 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 4735 | * invoked to send out FARP Response to the remote node. Before sending the |
| 4736 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 4737 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 4738 | * routine is invoked to log into the remote port first. |
| 4739 | * |
| 4740 | * Return code |
| 4741 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 4742 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4743 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4744 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4745 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4746 | { |
| 4747 | struct lpfc_dmabuf *pcmd; |
| 4748 | uint32_t *lp; |
| 4749 | IOCB_t *icmd; |
| 4750 | FARP *fp; |
| 4751 | uint32_t cmd, cnt, did; |
| 4752 | |
| 4753 | icmd = &cmdiocb->iocb; |
| 4754 | did = icmd->un.elsreq64.remoteID; |
| 4755 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4756 | lp = (uint32_t *) pcmd->virt; |
| 4757 | |
| 4758 | cmd = *lp++; |
| 4759 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4760 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4761 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4762 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4763 | /* We will only support match on WWPN or WWNN */ |
| 4764 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4765 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4766 | } |
| 4767 | |
| 4768 | cnt = 0; |
| 4769 | /* If this FARP command is searching for my portname */ |
| 4770 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4771 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4772 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4773 | cnt = 1; |
| 4774 | } |
| 4775 | |
| 4776 | /* If this FARP command is searching for my nodename */ |
| 4777 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4778 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4779 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4780 | cnt = 1; |
| 4781 | } |
| 4782 | |
| 4783 | if (cnt) { |
| 4784 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 4785 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 4786 | /* Log back into the node before sending the FARP. */ |
| 4787 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4788 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4789 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4790 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4791 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4792 | } |
| 4793 | |
| 4794 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4795 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 4796 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4797 | } |
| 4798 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4799 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4800 | } |
| 4801 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4802 | /** |
| 4803 | * lpfc_els_rcv_farpr: Process an unsolicited farp response iocb. |
| 4804 | * @vport: pointer to a host virtual N_Port data structure. |
| 4805 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4806 | * @ndlp: pointer to a node-list data structure. |
| 4807 | * |
| 4808 | * This routine processes Fibre Channel Address Resolution Protocol |
| 4809 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 4810 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 4811 | * the FARP response request. |
| 4812 | * |
| 4813 | * Return code |
| 4814 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 4815 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4816 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4817 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4818 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4819 | { |
| 4820 | struct lpfc_dmabuf *pcmd; |
| 4821 | uint32_t *lp; |
| 4822 | IOCB_t *icmd; |
| 4823 | uint32_t cmd, did; |
| 4824 | |
| 4825 | icmd = &cmdiocb->iocb; |
| 4826 | did = icmd->un.elsreq64.remoteID; |
| 4827 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4828 | lp = (uint32_t *) pcmd->virt; |
| 4829 | |
| 4830 | cmd = *lp++; |
| 4831 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4832 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4833 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4834 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4835 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4836 | |
| 4837 | return 0; |
| 4838 | } |
| 4839 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4840 | /** |
| 4841 | * lpfc_els_rcv_fan: Process an unsolicited fan iocb command. |
| 4842 | * @vport: pointer to a host virtual N_Port data structure. |
| 4843 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4844 | * @fan_ndlp: pointer to a node-list data structure. |
| 4845 | * |
| 4846 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 4847 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 4848 | * only be processed on a physical port (i.e., the @vport represents the |
| 4849 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 4850 | * compared against those in the phba data structure. If any of those is |
| 4851 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 4852 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 4853 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 4854 | * is invoked to register login to the fabric. |
| 4855 | * |
| 4856 | * Return code |
| 4857 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 4858 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4859 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4860 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4861 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4862 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4863 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4864 | uint32_t *lp; |
| 4865 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4866 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4867 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 4868 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 4869 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4870 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4871 | if ((vport == phba->pport) && |
| 4872 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4873 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4874 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4875 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4876 | sizeof(struct lpfc_name)))) { |
| 4877 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4878 | lpfc_initial_flogi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4879 | } else { |
| 4880 | /* FAN verified - skip FLOGI */ |
| 4881 | vport->fc_myDID = vport->fc_prevDID; |
| 4882 | lpfc_issue_fabric_reglogin(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4883 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4884 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4885 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4886 | } |
| 4887 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4888 | /** |
| 4889 | * lpfc_els_timeout: Handler funciton to the els timer. |
| 4890 | * @ptr: holder for the timer function associated data. |
| 4891 | * |
| 4892 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 4893 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 4894 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 4895 | * up the worker thread. It is for the worker thread to invoke the routine |
| 4896 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 4897 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4898 | void |
| 4899 | lpfc_els_timeout(unsigned long ptr) |
| 4900 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4901 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 4902 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4903 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4904 | unsigned long iflag; |
| 4905 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4906 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4907 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
| 4908 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4909 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4910 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4911 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4912 | if (!tmo_posted) |
| 4913 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4914 | return; |
| 4915 | } |
| 4916 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4917 | /** |
| 4918 | * lpfc_els_timeout_handler: Process an els timeout event. |
| 4919 | * @vport: pointer to a virtual N_Port data structure. |
| 4920 | * |
| 4921 | * This routine is the actual handler function that processes an ELS timeout |
| 4922 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 4923 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 4924 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 4925 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4926 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4927 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4928 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4929 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4930 | struct lpfc_sli_ring *pring; |
| 4931 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 4932 | IOCB_t *cmd = NULL; |
| 4933 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4934 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4935 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4936 | uint32_t remote_ID = 0xffffffff; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4937 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4938 | /* If the timer is already canceled do nothing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4939 | if ((vport->work_port_events & WORKER_ELS_TMO) == 0) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4940 | return; |
| 4941 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4942 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4943 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 4944 | |
| 4945 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4946 | |
| 4947 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 4948 | cmd = &piocb->iocb; |
| 4949 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4950 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 4951 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 4952 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4953 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4954 | |
| 4955 | if (piocb->vport != vport) |
| 4956 | continue; |
| 4957 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4958 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4959 | if (pcmd) |
| 4960 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4961 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4962 | if (els_command == ELS_CMD_FARP || |
| 4963 | els_command == ELS_CMD_FARPR || |
| 4964 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4965 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4966 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4967 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4968 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4969 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4970 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4971 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4972 | continue; |
| 4973 | } |
| 4974 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4975 | remote_ID = 0xffffffff; |
| 4976 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4977 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4978 | else { |
| 4979 | struct lpfc_nodelist *ndlp; |
| 4980 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4981 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4982 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4983 | } |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4984 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4985 | "0127 ELS timeout Data: x%x x%x x%x " |
| 4986 | "x%x\n", els_command, |
| 4987 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4988 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4989 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4990 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 4991 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4992 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
| 4993 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4994 | } |
| 4995 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4996 | /** |
| 4997 | * lpfc_els_flush_cmd: Clean up the outstanding els commands to a vport. |
| 4998 | * @vport: pointer to a host virtual N_Port data structure. |
| 4999 | * |
| 5000 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5001 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 5002 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5003 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5004 | * the IOCBs with a non-NULL completion callback function, the callback |
| 5005 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5006 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 5007 | * callback function, the IOCB will simply be released. Finally, it walks |
| 5008 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 5009 | * completion queue IOCB that is associated with the @vport and is not |
| 5010 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 5011 | * part of the discovery state machine) out to HBA by invoking the |
| 5012 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 5013 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 5014 | * the IOCBs are aborted when this function returns. |
| 5015 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5016 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5017 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5018 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5019 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5020 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5021 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5022 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5023 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5024 | |
| 5025 | lpfc_fabric_abort_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5026 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5027 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5028 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5029 | cmd = &piocb->iocb; |
| 5030 | |
| 5031 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5032 | continue; |
| 5033 | } |
| 5034 | |
| 5035 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5036 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5037 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5038 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5039 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5040 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5041 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5042 | if (piocb->vport != vport) |
| 5043 | continue; |
| 5044 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5045 | list_move_tail(&piocb->list, &completions); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5046 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5047 | } |
| 5048 | |
| 5049 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5050 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 5051 | continue; |
| 5052 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5053 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5054 | if (piocb->vport != vport) |
| 5055 | continue; |
| 5056 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5057 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5058 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5059 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5060 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5061 | while (!list_empty(&completions)) { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5062 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 5063 | cmd = &piocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5064 | list_del_init(&piocb->list); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5065 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5066 | if (!piocb->iocb_cmpl) |
| 5067 | lpfc_sli_release_iocbq(phba, piocb); |
| 5068 | else { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5069 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 5070 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 5071 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5072 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5073 | } |
| 5074 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5075 | return; |
| 5076 | } |
| 5077 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5078 | /** |
| 5079 | * lpfc_els_flush_all_cmd: Clean up all the outstanding els commands to a HBA. |
| 5080 | * @phba: pointer to lpfc hba data structure. |
| 5081 | * |
| 5082 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5083 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 5084 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5085 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5086 | * the IOCBs with the completion callback function associated, the callback |
| 5087 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5088 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 5089 | * callback function associated, the IOCB will simply be released. Finally, |
| 5090 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 5091 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 5092 | * management plane IOCBs that are not part of the discovery state machine) |
| 5093 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5094 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5095 | void |
| 5096 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 5097 | { |
| 5098 | LIST_HEAD(completions); |
| 5099 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 5100 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5101 | IOCB_t *cmd = NULL; |
| 5102 | |
| 5103 | lpfc_fabric_abort_hba(phba); |
| 5104 | spin_lock_irq(&phba->hbalock); |
| 5105 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5106 | cmd = &piocb->iocb; |
| 5107 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5108 | continue; |
| 5109 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
| 5110 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5111 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5112 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5113 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| 5114 | continue; |
| 5115 | list_move_tail(&piocb->list, &completions); |
| 5116 | pring->txq_cnt--; |
| 5117 | } |
| 5118 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5119 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5120 | continue; |
| 5121 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5122 | } |
| 5123 | spin_unlock_irq(&phba->hbalock); |
| 5124 | while (!list_empty(&completions)) { |
| 5125 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 5126 | cmd = &piocb->iocb; |
| 5127 | list_del_init(&piocb->list); |
| 5128 | if (!piocb->iocb_cmpl) |
| 5129 | lpfc_sli_release_iocbq(phba, piocb); |
| 5130 | else { |
| 5131 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 5132 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 5133 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 5134 | } |
| 5135 | } |
| 5136 | return; |
| 5137 | } |
| 5138 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5139 | /** |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5140 | * lpfc_send_els_failure_event: Posts an ELS command failure event. |
| 5141 | * @phba: Pointer to hba context object. |
| 5142 | * @cmdiocbp: Pointer to command iocb which reported error. |
| 5143 | * @rspiocbp: Pointer to response iocb which reported error. |
| 5144 | * |
| 5145 | * This function sends an event when there is an ELS command |
| 5146 | * failure. |
| 5147 | **/ |
| 5148 | void |
| 5149 | lpfc_send_els_failure_event(struct lpfc_hba *phba, |
| 5150 | struct lpfc_iocbq *cmdiocbp, |
| 5151 | struct lpfc_iocbq *rspiocbp) |
| 5152 | { |
| 5153 | struct lpfc_vport *vport = cmdiocbp->vport; |
| 5154 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5155 | struct lpfc_lsrjt_event lsrjt_event; |
| 5156 | struct lpfc_fabric_event_header fabric_event; |
| 5157 | struct ls_rjt stat; |
| 5158 | struct lpfc_nodelist *ndlp; |
| 5159 | uint32_t *pcmd; |
| 5160 | |
| 5161 | ndlp = cmdiocbp->context1; |
| 5162 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 5163 | return; |
| 5164 | |
| 5165 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { |
| 5166 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; |
| 5167 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; |
| 5168 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, |
| 5169 | sizeof(struct lpfc_name)); |
| 5170 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, |
| 5171 | sizeof(struct lpfc_name)); |
| 5172 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 5173 | cmdiocbp->context2)->virt); |
| 5174 | lsrjt_event.command = *pcmd; |
| 5175 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
| 5176 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; |
| 5177 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; |
| 5178 | fc_host_post_vendor_event(shost, |
| 5179 | fc_get_event_number(), |
| 5180 | sizeof(lsrjt_event), |
| 5181 | (char *)&lsrjt_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5182 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5183 | return; |
| 5184 | } |
| 5185 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || |
| 5186 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { |
| 5187 | fabric_event.event_type = FC_REG_FABRIC_EVENT; |
| 5188 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) |
| 5189 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; |
| 5190 | else |
| 5191 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; |
| 5192 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, |
| 5193 | sizeof(struct lpfc_name)); |
| 5194 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, |
| 5195 | sizeof(struct lpfc_name)); |
| 5196 | fc_host_post_vendor_event(shost, |
| 5197 | fc_get_event_number(), |
| 5198 | sizeof(fabric_event), |
| 5199 | (char *)&fabric_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5200 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5201 | return; |
| 5202 | } |
| 5203 | |
| 5204 | } |
| 5205 | |
| 5206 | /** |
| 5207 | * lpfc_send_els_event: Posts unsolicited els event. |
| 5208 | * @vport: Pointer to vport object. |
| 5209 | * @ndlp: Pointer FC node object. |
| 5210 | * @cmd: ELS command code. |
| 5211 | * |
| 5212 | * This function posts an event when there is an incoming |
| 5213 | * unsolicited ELS command. |
| 5214 | **/ |
| 5215 | static void |
| 5216 | lpfc_send_els_event(struct lpfc_vport *vport, |
| 5217 | struct lpfc_nodelist *ndlp, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5218 | uint32_t *payload) |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5219 | { |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5220 | struct lpfc_els_event_header *els_data = NULL; |
| 5221 | struct lpfc_logo_event *logo_data = NULL; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5222 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5223 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5224 | if (*payload == ELS_CMD_LOGO) { |
| 5225 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); |
| 5226 | if (!logo_data) { |
| 5227 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5228 | "0148 Failed to allocate memory " |
| 5229 | "for LOGO event\n"); |
| 5230 | return; |
| 5231 | } |
| 5232 | els_data = &logo_data->header; |
| 5233 | } else { |
| 5234 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), |
| 5235 | GFP_KERNEL); |
| 5236 | if (!els_data) { |
| 5237 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5238 | "0149 Failed to allocate memory " |
| 5239 | "for ELS event\n"); |
| 5240 | return; |
| 5241 | } |
| 5242 | } |
| 5243 | els_data->event_type = FC_REG_ELS_EVENT; |
| 5244 | switch (*payload) { |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5245 | case ELS_CMD_PLOGI: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5246 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5247 | break; |
| 5248 | case ELS_CMD_PRLO: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5249 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5250 | break; |
| 5251 | case ELS_CMD_ADISC: |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5252 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
| 5253 | break; |
| 5254 | case ELS_CMD_LOGO: |
| 5255 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; |
| 5256 | /* Copy the WWPN in the LOGO payload */ |
| 5257 | memcpy(logo_data->logo_wwpn, &payload[2], |
| 5258 | sizeof(struct lpfc_name)); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5259 | break; |
| 5260 | default: |
| 5261 | return; |
| 5262 | } |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5263 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
| 5264 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); |
| 5265 | if (*payload == ELS_CMD_LOGO) { |
| 5266 | fc_host_post_vendor_event(shost, |
| 5267 | fc_get_event_number(), |
| 5268 | sizeof(struct lpfc_logo_event), |
| 5269 | (char *)logo_data, |
| 5270 | LPFC_NL_VENDOR_ID); |
| 5271 | kfree(logo_data); |
| 5272 | } else { |
| 5273 | fc_host_post_vendor_event(shost, |
| 5274 | fc_get_event_number(), |
| 5275 | sizeof(struct lpfc_els_event_header), |
| 5276 | (char *)els_data, |
| 5277 | LPFC_NL_VENDOR_ID); |
| 5278 | kfree(els_data); |
| 5279 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5280 | |
| 5281 | return; |
| 5282 | } |
| 5283 | |
| 5284 | |
| 5285 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5286 | * lpfc_els_unsol_buffer: Process an unsolicited event data buffer. |
| 5287 | * @phba: pointer to lpfc hba data structure. |
| 5288 | * @pring: pointer to a SLI ring. |
| 5289 | * @vport: pointer to a host virtual N_Port data structure. |
| 5290 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 5291 | * |
| 5292 | * This routine is used for processing the IOCB associated with a unsolicited |
| 5293 | * event. It first determines whether there is an existing ndlp that matches |
| 5294 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 5295 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 5296 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 5297 | * of the discovery state machine. |
| 5298 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5299 | static void |
| 5300 | 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] | 5301 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5302 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5303 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5304 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5305 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5306 | uint32_t *payload; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5307 | uint32_t cmd, did, newnode, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5308 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5309 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5310 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5311 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5312 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5313 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5314 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 5315 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5316 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5317 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5318 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5319 | did = icmd->un.rcvels.remoteID; |
| 5320 | if (icmd->ulpStatus) { |
| 5321 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5322 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 5323 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5324 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5325 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5326 | |
| 5327 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5328 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5329 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5330 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5331 | /* Ignore traffic recevied during vport shutdown. */ |
| 5332 | if (vport->load_flag & FC_UNLOADING) |
| 5333 | goto dropit; |
| 5334 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5335 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5336 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5337 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5338 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5339 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5340 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5341 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5342 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5343 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5344 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5345 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5346 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5347 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5348 | ndlp = lpfc_enable_node(vport, ndlp, |
| 5349 | NLP_STE_UNUSED_NODE); |
| 5350 | if (!ndlp) |
| 5351 | goto dropit; |
| 5352 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5353 | newnode = 1; |
| 5354 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 5355 | ndlp->nlp_type |= NLP_FABRIC; |
| 5356 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 5357 | /* This is similar to the new node path */ |
| 5358 | ndlp = lpfc_nlp_get(ndlp); |
| 5359 | if (!ndlp) |
| 5360 | goto dropit; |
| 5361 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5362 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5363 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5364 | |
| 5365 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5366 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5367 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5368 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5369 | |
| 5370 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 5371 | cmd &= ELS_CMD_MASK; |
| 5372 | } |
| 5373 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5374 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5375 | "0112 ELS command x%x received from NPORT x%x " |
| 5376 | "Data: x%x\n", cmd, did, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5377 | switch (cmd) { |
| 5378 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5379 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5380 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 5381 | did, vport->port_state, ndlp->nlp_flag); |
| 5382 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5383 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5384 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
| 5385 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5386 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5387 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5388 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 5389 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 5390 | rjt_err = LSRJT_UNABLE_TPC; |
| 5391 | break; |
| 5392 | } |
| 5393 | /* We get here, and drop thru, if we are PT2PT with |
| 5394 | * another NPort and the other side has initiated |
| 5395 | * the PLOGI before responding to our FLOGI. |
| 5396 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5397 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5398 | |
| 5399 | shost = lpfc_shost_from_vport(vport); |
| 5400 | spin_lock_irq(shost->host_lock); |
| 5401 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 5402 | spin_unlock_irq(shost->host_lock); |
| 5403 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5404 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5405 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5406 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5407 | break; |
| 5408 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5409 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5410 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 5411 | did, vport->port_state, ndlp->nlp_flag); |
| 5412 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5413 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5414 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5415 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5416 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5417 | break; |
| 5418 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5419 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5420 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 5421 | did, vport->port_state, ndlp->nlp_flag); |
| 5422 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5423 | phba->fc_stat.elsRcvLOGO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5424 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5425 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5426 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5427 | break; |
| 5428 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5429 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5430 | break; |
| 5431 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5432 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5433 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 5434 | did, vport->port_state, ndlp->nlp_flag); |
| 5435 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5436 | phba->fc_stat.elsRcvPRLO++; |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5437 | lpfc_send_els_event(vport, ndlp, payload); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5438 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5439 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5440 | break; |
| 5441 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5442 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5443 | break; |
| 5444 | case ELS_CMD_RSCN: |
| 5445 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5446 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5447 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5448 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5449 | break; |
| 5450 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5451 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5452 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 5453 | did, vport->port_state, ndlp->nlp_flag); |
| 5454 | |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5455 | lpfc_send_els_event(vport, ndlp, payload); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5456 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5457 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5458 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5459 | break; |
| 5460 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5461 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5462 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5463 | break; |
| 5464 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5465 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5466 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 5467 | did, vport->port_state, ndlp->nlp_flag); |
| 5468 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5469 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5470 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5471 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5472 | break; |
| 5473 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5474 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5475 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5476 | break; |
| 5477 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5478 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5479 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 5480 | did, vport->port_state, ndlp->nlp_flag); |
| 5481 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5482 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5483 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5484 | break; |
| 5485 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5486 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5487 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 5488 | did, vport->port_state, ndlp->nlp_flag); |
| 5489 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5490 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5491 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5492 | break; |
| 5493 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5494 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5495 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 5496 | did, vport->port_state, ndlp->nlp_flag); |
| 5497 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5498 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5499 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5500 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5501 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5502 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5503 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 5504 | did, vport->port_state, ndlp->nlp_flag); |
| 5505 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5506 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5507 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5508 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5509 | break; |
| 5510 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5511 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5512 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5513 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5514 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5515 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 5516 | did, vport->port_state, ndlp->nlp_flag); |
| 5517 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5518 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5519 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5520 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5521 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5522 | break; |
| 5523 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5524 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5525 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 5526 | did, vport->port_state, ndlp->nlp_flag); |
| 5527 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5528 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5529 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5530 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5531 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5532 | break; |
| 5533 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5534 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5535 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 5536 | did, vport->port_state, ndlp->nlp_flag); |
| 5537 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5538 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5539 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5540 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5541 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5542 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5543 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5544 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5545 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 5546 | did, vport->port_state, ndlp->nlp_flag); |
| 5547 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5548 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5549 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5550 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5551 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5552 | break; |
| 5553 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5554 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5555 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 5556 | cmd, did, vport->port_state); |
| 5557 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5558 | /* Unsupported ELS command, reject */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5559 | rjt_err = LSRJT_INVALID_CMD; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5560 | |
| 5561 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5562 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5563 | "0115 Unknown ELS command x%x " |
| 5564 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5565 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5566 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5567 | break; |
| 5568 | } |
| 5569 | |
| 5570 | /* check if need to LS_RJT received ELS cmd */ |
| 5571 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5572 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5573 | stat.un.b.lsRjtRsnCode = rjt_err; |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 5574 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5575 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 5576 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5577 | } |
| 5578 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5579 | lpfc_nlp_put(elsiocb->context1); |
| 5580 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5581 | return; |
| 5582 | |
| 5583 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5584 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
| 5585 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5586 | "(%d):0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5587 | "Data: x%x x%x x%x\n", |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5588 | vport->vpi, icmd->ulpStatus, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5589 | icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5590 | phba->fc_stat.elsRcvDrop++; |
| 5591 | } |
| 5592 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5593 | /** |
| 5594 | * lpfc_find_vport_by_vpid: Find a vport on a HBA through vport identifier. |
| 5595 | * @phba: pointer to lpfc hba data structure. |
| 5596 | * @vpi: host virtual N_Port identifier. |
| 5597 | * |
| 5598 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 5599 | * @vpi. The function walks the HBA's vport list and returns the address |
| 5600 | * of the vport with the matching @vpi. |
| 5601 | * |
| 5602 | * Return code |
| 5603 | * NULL - No vport with the matching @vpi found |
| 5604 | * Otherwise - Address to the vport with the matching @vpi. |
| 5605 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5606 | static struct lpfc_vport * |
| 5607 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 5608 | { |
| 5609 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5610 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5611 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5612 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5613 | list_for_each_entry(vport, &phba->port_list, listentry) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5614 | if (vport->vpi == vpi) { |
| 5615 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5616 | return vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5617 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5618 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5619 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5620 | return NULL; |
| 5621 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5622 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5623 | /** |
| 5624 | * lpfc_els_unsol_event: Process an unsolicited event from an els sli ring. |
| 5625 | * @phba: pointer to lpfc hba data structure. |
| 5626 | * @pring: pointer to a SLI ring. |
| 5627 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 5628 | * |
| 5629 | * This routine is used to process an unsolicited event received from a SLI |
| 5630 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 5631 | * associated with the unsolicited event is done by invoking the routine |
| 5632 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 5633 | * SLI ring on which the unsolicited event was received. |
| 5634 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5635 | void |
| 5636 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 5637 | struct lpfc_iocbq *elsiocb) |
| 5638 | { |
| 5639 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5640 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5641 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5642 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 5643 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5644 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5645 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5646 | elsiocb->context2 = NULL; |
| 5647 | elsiocb->context3 = NULL; |
| 5648 | |
| 5649 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 5650 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 5651 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 5652 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5653 | phba->fc_stat.NoRcvBuf++; |
| 5654 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5655 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5656 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5657 | return; |
| 5658 | } |
| 5659 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5660 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 5661 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 5662 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 5663 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 5664 | vport = phba->pport; |
| 5665 | else { |
| 5666 | uint16_t vpi = icmd->unsli3.rcvsli3.vpi; |
| 5667 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 5668 | } |
| 5669 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5670 | /* If there are no BDEs associated |
| 5671 | * with this IOCB, there is nothing to do. |
| 5672 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5673 | if (icmd->ulpBdeCount == 0) |
| 5674 | return; |
| 5675 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5676 | /* type of ELS cmd is first 32bit word |
| 5677 | * in packet |
| 5678 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5679 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5680 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5681 | } else { |
| 5682 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 5683 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5684 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 5685 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5686 | } |
| 5687 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5688 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 5689 | /* |
| 5690 | * The different unsolicited event handlers would tell us |
| 5691 | * if they are done with "mp" by setting context2 to NULL. |
| 5692 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5693 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5694 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 5695 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5696 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5697 | |
| 5698 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5699 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5700 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5701 | elsiocb->context2 = bdeBuf2; |
| 5702 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5703 | /* free mp if we are done with it */ |
| 5704 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5705 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 5706 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5707 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5708 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5709 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5710 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5711 | /** |
| 5712 | * lpfc_do_scr_ns_plogi: Issue a plogi to the name server for scr. |
| 5713 | * @phba: pointer to lpfc hba data structure. |
| 5714 | * @vport: pointer to a virtual N_Port data structure. |
| 5715 | * |
| 5716 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 5717 | * State Change Request (SCR) for a @vport. This routine will create an |
| 5718 | * ndlp for the Name Server associated to the @vport if such node does |
| 5719 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 5720 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 5721 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 5722 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 5723 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5724 | void |
| 5725 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 5726 | { |
| 5727 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
| 5728 | |
| 5729 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 5730 | if (!ndlp) { |
| 5731 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 5732 | if (!ndlp) { |
| 5733 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5734 | lpfc_disc_start(vport); |
| 5735 | return; |
| 5736 | } |
| 5737 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5738 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5739 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5740 | return; |
| 5741 | } |
| 5742 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5743 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5744 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 5745 | if (!ndlp) { |
| 5746 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5747 | lpfc_disc_start(vport); |
| 5748 | return; |
| 5749 | } |
| 5750 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5751 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5752 | "0348 NameServer login: node freed\n"); |
| 5753 | return; |
| 5754 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5755 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5756 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5757 | |
| 5758 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 5759 | |
| 5760 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 5761 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5762 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5763 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5764 | return; |
| 5765 | } |
| 5766 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5767 | if (vport->cfg_fdmi_on) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5768 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 5769 | GFP_KERNEL); |
| 5770 | if (ndlp_fdmi) { |
| 5771 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 5772 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5773 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
| 5774 | NLP_STE_PLOGI_ISSUE); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5775 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, |
| 5776 | 0); |
| 5777 | } |
| 5778 | } |
| 5779 | return; |
| 5780 | } |
| 5781 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5782 | /** |
| 5783 | * lpfc_cmpl_reg_new_vport: Completion callback function to register new vport. |
| 5784 | * @phba: pointer to lpfc hba data structure. |
| 5785 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 5786 | * |
| 5787 | * This routine is the completion callback function to register new vport |
| 5788 | * mailbox command. If the new vport mailbox command completes successfully, |
| 5789 | * the fabric registration login shall be performed on physical port (the |
| 5790 | * new vport created is actually a physical port, with VPI 0) or the port |
| 5791 | * login to Name Server for State Change Request (SCR) will be performed |
| 5792 | * on virtual port (real virtual port, with VPI greater than 0). |
| 5793 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5794 | static void |
| 5795 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 5796 | { |
| 5797 | struct lpfc_vport *vport = pmb->vport; |
| 5798 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5799 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 5800 | MAILBOX_t *mb = &pmb->mb; |
| 5801 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5802 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5803 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5804 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5805 | |
| 5806 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5807 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 5808 | "0915 Register VPI failed: 0x%x\n", |
| 5809 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5810 | |
| 5811 | switch (mb->mbxStatus) { |
| 5812 | case 0x11: /* unsupported feature */ |
| 5813 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5814 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5815 | /* giving up on vport registration */ |
| 5816 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5817 | spin_lock_irq(shost->host_lock); |
| 5818 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 5819 | spin_unlock_irq(shost->host_lock); |
| 5820 | lpfc_can_disctmo(vport); |
| 5821 | break; |
| 5822 | default: |
| 5823 | /* Try to recover from this error */ |
| 5824 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5825 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5826 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5827 | spin_unlock_irq(shost->host_lock); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5828 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 5829 | lpfc_initial_flogi(vport); |
| 5830 | else |
| 5831 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5832 | break; |
| 5833 | } |
| 5834 | |
| 5835 | } else { |
| 5836 | if (vport == phba->pport) |
| 5837 | lpfc_issue_fabric_reglogin(vport); |
| 5838 | else |
| 5839 | lpfc_do_scr_ns_plogi(phba, vport); |
| 5840 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5841 | |
| 5842 | /* Now, we decrement the ndlp reference count held for this |
| 5843 | * callback function |
| 5844 | */ |
| 5845 | lpfc_nlp_put(ndlp); |
| 5846 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5847 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5848 | return; |
| 5849 | } |
| 5850 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5851 | /** |
| 5852 | * lpfc_register_new_vport: Register a new vport with a HBA. |
| 5853 | * @phba: pointer to lpfc hba data structure. |
| 5854 | * @vport: pointer to a host virtual N_Port data structure. |
| 5855 | * @ndlp: pointer to a node-list data structure. |
| 5856 | * |
| 5857 | * This routine registers the @vport as a new virtual port with a HBA. |
| 5858 | * It is done through a registering vpi mailbox command. |
| 5859 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5860 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5861 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 5862 | struct lpfc_nodelist *ndlp) |
| 5863 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5864 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5865 | LPFC_MBOXQ_t *mbox; |
| 5866 | |
| 5867 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5868 | if (mbox) { |
| 5869 | lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox); |
| 5870 | mbox->vport = vport; |
| 5871 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 5872 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5873 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5874 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5875 | /* mailbox command not success, decrement ndlp |
| 5876 | * reference count for this command |
| 5877 | */ |
| 5878 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5879 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5880 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5881 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 5882 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5883 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5884 | } |
| 5885 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5886 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 5887 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5888 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5889 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5890 | return; |
| 5891 | |
| 5892 | mbox_err_exit: |
| 5893 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5894 | spin_lock_irq(shost->host_lock); |
| 5895 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 5896 | spin_unlock_irq(shost->host_lock); |
| 5897 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5898 | } |
| 5899 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5900 | /** |
| 5901 | * lpfc_cmpl_els_fdisc: Completion function for fdisc iocb command. |
| 5902 | * @phba: pointer to lpfc hba data structure. |
| 5903 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5904 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 5905 | * |
| 5906 | * This routine is the completion callback function to a Fabric Discover |
| 5907 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 5908 | * single threaded, each FDISC completion callback function will reset |
| 5909 | * the discovery timer for all vports such that the timers will not get |
| 5910 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 5911 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 5912 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 5913 | * assigned to the vport has been changed with the completion of the FDISC |
| 5914 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 5915 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 5916 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 5917 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 5918 | * Server for State Change Request (SCR). |
| 5919 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5920 | static void |
| 5921 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 5922 | struct lpfc_iocbq *rspiocb) |
| 5923 | { |
| 5924 | struct lpfc_vport *vport = cmdiocb->vport; |
| 5925 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5926 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 5927 | struct lpfc_nodelist *np; |
| 5928 | struct lpfc_nodelist *next_np; |
| 5929 | IOCB_t *irsp = &rspiocb->iocb; |
| 5930 | struct lpfc_iocbq *piocb; |
| 5931 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5932 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5933 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 5934 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 5935 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5936 | /* Since all FDISCs are being single threaded, we |
| 5937 | * must reset the discovery timer for ALL vports |
| 5938 | * waiting to send FDISC when one completes. |
| 5939 | */ |
| 5940 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 5941 | lpfc_set_disctmo(piocb->vport); |
| 5942 | } |
| 5943 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5944 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 5945 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 5946 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 5947 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5948 | if (irsp->ulpStatus) { |
| 5949 | /* Check for retry */ |
| 5950 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 5951 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5952 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5953 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5954 | "0126 FDISC failed. (%d/%d)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5955 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5956 | goto fdisc_failed; |
| 5957 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5958 | if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING) |
| 5959 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5960 | lpfc_nlp_put(ndlp); |
| 5961 | /* giving up on FDISC. Cancel discovery timer */ |
| 5962 | lpfc_can_disctmo(vport); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5963 | spin_lock_irq(shost->host_lock); |
| 5964 | vport->fc_flag |= FC_FABRIC; |
| 5965 | if (vport->phba->fc_topology == TOPOLOGY_LOOP) |
| 5966 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 5967 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5968 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5969 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 5970 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
| 5971 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 5972 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 5973 | /* If our NportID changed, we need to ensure all |
| 5974 | * remaining NPORTs get unreg_login'ed so we can |
| 5975 | * issue unreg_vpi. |
| 5976 | */ |
| 5977 | list_for_each_entry_safe(np, next_np, |
| 5978 | &vport->fc_nodes, nlp_listp) { |
| 5979 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 5980 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 5981 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 5982 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5983 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5984 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5985 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5986 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5987 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5988 | lpfc_mbx_unreg_vpi(vport); |
| 5989 | spin_lock_irq(shost->host_lock); |
| 5990 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 5991 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5992 | } |
| 5993 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5994 | if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 5995 | lpfc_register_new_vport(phba, vport, ndlp); |
| 5996 | else |
| 5997 | lpfc_do_scr_ns_plogi(phba, vport); |
| 5998 | goto out; |
| 5999 | fdisc_failed: |
| 6000 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 6001 | /* Cancel discovery timer */ |
| 6002 | lpfc_can_disctmo(vport); |
| 6003 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6004 | out: |
| 6005 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6006 | } |
| 6007 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6008 | /** |
| 6009 | * lpfc_issue_els_fdisc: Issue a fdisc iocb command. |
| 6010 | * @vport: pointer to a virtual N_Port data structure. |
| 6011 | * @ndlp: pointer to a node-list data structure. |
| 6012 | * @retry: number of retries to the command IOCB. |
| 6013 | * |
| 6014 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 6015 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 6016 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 6017 | * IOCB will be sent off HBA at any given time. |
| 6018 | * |
| 6019 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6020 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6021 | * will be stored into the context1 field of the IOCB for the completion |
| 6022 | * callback function to the FDISC ELS command. |
| 6023 | * |
| 6024 | * Return code |
| 6025 | * 0 - Successfully issued fdisc iocb command |
| 6026 | * 1 - Failed to issue fdisc iocb command |
| 6027 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6028 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6029 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 6030 | uint8_t retry) |
| 6031 | { |
| 6032 | struct lpfc_hba *phba = vport->phba; |
| 6033 | IOCB_t *icmd; |
| 6034 | struct lpfc_iocbq *elsiocb; |
| 6035 | struct serv_parm *sp; |
| 6036 | uint8_t *pcmd; |
| 6037 | uint16_t cmdsize; |
| 6038 | int did = ndlp->nlp_DID; |
| 6039 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6040 | |
| 6041 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 6042 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 6043 | ELS_CMD_FDISC); |
| 6044 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6045 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6046 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6047 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6048 | return 1; |
| 6049 | } |
| 6050 | |
| 6051 | icmd = &elsiocb->iocb; |
| 6052 | icmd->un.elsreq64.myID = 0; |
| 6053 | icmd->un.elsreq64.fl = 1; |
| 6054 | |
| 6055 | /* For FDISC, Let FDISC rsp set the NPortID for this VPI */ |
| 6056 | icmd->ulpCt_h = 1; |
| 6057 | icmd->ulpCt_l = 0; |
| 6058 | |
| 6059 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6060 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 6061 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 6062 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 6063 | sp = (struct serv_parm *) pcmd; |
| 6064 | /* Setup CSPs accordingly for Fabric */ |
| 6065 | sp->cmn.e_d_tov = 0; |
| 6066 | sp->cmn.w2.r_a_tov = 0; |
| 6067 | sp->cls1.classValid = 0; |
| 6068 | sp->cls2.seqDelivery = 1; |
| 6069 | sp->cls3.seqDelivery = 1; |
| 6070 | |
| 6071 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 6072 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 6073 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 6074 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 6075 | memcpy(pcmd, &vport->fc_portname, 8); |
| 6076 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6077 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 6078 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 6079 | |
| 6080 | lpfc_set_disctmo(vport); |
| 6081 | |
| 6082 | phba->fc_stat.elsXmitFDISC++; |
| 6083 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 6084 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6085 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6086 | "Issue FDISC: did:x%x", |
| 6087 | did, 0, 0); |
| 6088 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6089 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 6090 | if (rc == IOCB_ERROR) { |
| 6091 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6092 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6093 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 6094 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6095 | return 1; |
| 6096 | } |
| 6097 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
| 6098 | vport->port_state = LPFC_FDISC; |
| 6099 | return 0; |
| 6100 | } |
| 6101 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6102 | /** |
| 6103 | * lpfc_cmpl_els_npiv_logo: Completion function with vport logo. |
| 6104 | * @phba: pointer to lpfc hba data structure. |
| 6105 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6106 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6107 | * |
| 6108 | * This routine is the completion callback function to the issuing of a LOGO |
| 6109 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 6110 | * reference count held on ndlp for this completion function, indicating that |
| 6111 | * the reference to the ndlp is no long needed. Note that the |
| 6112 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 6113 | * callback function and an additional explicit ndlp reference decrementation |
| 6114 | * will trigger the actual release of the ndlp. |
| 6115 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6116 | static void |
| 6117 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6118 | struct lpfc_iocbq *rspiocb) |
| 6119 | { |
| 6120 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6121 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6122 | struct lpfc_nodelist *ndlp; |
| 6123 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6124 | |
| 6125 | irsp = &rspiocb->iocb; |
| 6126 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6127 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 6128 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6129 | |
| 6130 | lpfc_els_free_iocb(phba, cmdiocb); |
| 6131 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6132 | |
| 6133 | /* Trigger the release of the ndlp after logo */ |
| 6134 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6135 | } |
| 6136 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6137 | /** |
| 6138 | * lpfc_issue_els_npiv_logo: Issue a logo off a vport. |
| 6139 | * @vport: pointer to a virtual N_Port data structure. |
| 6140 | * @ndlp: pointer to a node-list data structure. |
| 6141 | * |
| 6142 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 6143 | * |
| 6144 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 6145 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 6146 | * will be stored into the context1 field of the IOCB for the completion |
| 6147 | * callback function to the LOGO ELS command. |
| 6148 | * |
| 6149 | * Return codes |
| 6150 | * 0 - Successfully issued logo off the @vport |
| 6151 | * 1 - Failed to issue logo off the @vport |
| 6152 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6153 | int |
| 6154 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 6155 | { |
| 6156 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 6157 | struct lpfc_hba *phba = vport->phba; |
| 6158 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 6159 | IOCB_t *icmd; |
| 6160 | struct lpfc_iocbq *elsiocb; |
| 6161 | uint8_t *pcmd; |
| 6162 | uint16_t cmdsize; |
| 6163 | |
| 6164 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 6165 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 6166 | ELS_CMD_LOGO); |
| 6167 | if (!elsiocb) |
| 6168 | return 1; |
| 6169 | |
| 6170 | icmd = &elsiocb->iocb; |
| 6171 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 6172 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 6173 | pcmd += sizeof(uint32_t); |
| 6174 | |
| 6175 | /* Fill in LOGO payload */ |
| 6176 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 6177 | pcmd += sizeof(uint32_t); |
| 6178 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 6179 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6180 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 6181 | "Issue LOGO npiv did:x%x flg:x%x", |
| 6182 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 6183 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6184 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 6185 | spin_lock_irq(shost->host_lock); |
| 6186 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 6187 | spin_unlock_irq(shost->host_lock); |
| 6188 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
| 6189 | spin_lock_irq(shost->host_lock); |
| 6190 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 6191 | spin_unlock_irq(shost->host_lock); |
| 6192 | lpfc_els_free_iocb(phba, elsiocb); |
| 6193 | return 1; |
| 6194 | } |
| 6195 | return 0; |
| 6196 | } |
| 6197 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6198 | /** |
| 6199 | * lpfc_fabric_block_timeout: Handler function to the fabric block timer. |
| 6200 | * @ptr: holder for the timer function associated data. |
| 6201 | * |
| 6202 | * This routine is invoked by the fabric iocb block timer after |
| 6203 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 6204 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 6205 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 6206 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 6207 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 6208 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6209 | void |
| 6210 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 6211 | { |
| 6212 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 6213 | unsigned long iflags; |
| 6214 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6215 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6216 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 6217 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 6218 | if (!tmo_posted) |
| 6219 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 6220 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 6221 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6222 | if (!tmo_posted) |
| 6223 | lpfc_worker_wake_up(phba); |
| 6224 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6225 | } |
| 6226 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6227 | /** |
| 6228 | * lpfc_resume_fabric_iocbs: Issue a fabric iocb from driver internal list. |
| 6229 | * @phba: pointer to lpfc hba data structure. |
| 6230 | * |
| 6231 | * This routine issues one fabric iocb from the driver internal list to |
| 6232 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 6233 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 6234 | * remove one pending fabric iocb from the driver internal list and invokes |
| 6235 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 6236 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6237 | static void |
| 6238 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 6239 | { |
| 6240 | struct lpfc_iocbq *iocb; |
| 6241 | unsigned long iflags; |
| 6242 | int ret; |
| 6243 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 6244 | IOCB_t *cmd; |
| 6245 | |
| 6246 | repeat: |
| 6247 | iocb = NULL; |
| 6248 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6249 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6250 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 6251 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 6252 | list); |
| 6253 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6254 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6255 | atomic_inc(&phba->fabric_iocb_count); |
| 6256 | } |
| 6257 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6258 | if (iocb) { |
| 6259 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6260 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6261 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6262 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6263 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6264 | "Fabric sched1: ste:x%x", |
| 6265 | iocb->vport->port_state, 0, 0); |
| 6266 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6267 | ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0); |
| 6268 | |
| 6269 | if (ret == IOCB_ERROR) { |
| 6270 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6271 | iocb->fabric_iocb_cmpl = NULL; |
| 6272 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6273 | cmd = &iocb->iocb; |
| 6274 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6275 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6276 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 6277 | |
| 6278 | atomic_dec(&phba->fabric_iocb_count); |
| 6279 | goto repeat; |
| 6280 | } |
| 6281 | } |
| 6282 | |
| 6283 | return; |
| 6284 | } |
| 6285 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6286 | /** |
| 6287 | * lpfc_unblock_fabric_iocbs: Unblock issuing fabric iocb command. |
| 6288 | * @phba: pointer to lpfc hba data structure. |
| 6289 | * |
| 6290 | * This routine unblocks the issuing fabric iocb command. The function |
| 6291 | * will clear the fabric iocb block bit and then invoke the routine |
| 6292 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 6293 | * from the driver internal fabric iocb list. |
| 6294 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6295 | void |
| 6296 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 6297 | { |
| 6298 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6299 | |
| 6300 | lpfc_resume_fabric_iocbs(phba); |
| 6301 | return; |
| 6302 | } |
| 6303 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6304 | /** |
| 6305 | * lpfc_block_fabric_iocbs: Block issuing fabric iocb command. |
| 6306 | * @phba: pointer to lpfc hba data structure. |
| 6307 | * |
| 6308 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 6309 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 6310 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 6311 | * fabric iocb will be issued out of the HBA. |
| 6312 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6313 | static void |
| 6314 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 6315 | { |
| 6316 | int blocked; |
| 6317 | |
| 6318 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6319 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6320 | if (!blocked) |
| 6321 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); |
| 6322 | |
| 6323 | return; |
| 6324 | } |
| 6325 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6326 | /** |
| 6327 | * lpfc_cmpl_fabric_iocb: Completion callback function for fabric iocb. |
| 6328 | * @phba: pointer to lpfc hba data structure. |
| 6329 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6330 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6331 | * |
| 6332 | * This routine is the callback function that is put to the fabric iocb's |
| 6333 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 6334 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 6335 | * function first restores and invokes the original iocb's callback function |
| 6336 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 6337 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 6338 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6339 | static void |
| 6340 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6341 | struct lpfc_iocbq *rspiocb) |
| 6342 | { |
| 6343 | struct ls_rjt stat; |
| 6344 | |
| 6345 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 6346 | BUG(); |
| 6347 | |
| 6348 | switch (rspiocb->iocb.ulpStatus) { |
| 6349 | case IOSTAT_NPORT_RJT: |
| 6350 | case IOSTAT_FABRIC_RJT: |
| 6351 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 6352 | lpfc_block_fabric_iocbs(phba); |
| 6353 | } |
| 6354 | break; |
| 6355 | |
| 6356 | case IOSTAT_NPORT_BSY: |
| 6357 | case IOSTAT_FABRIC_BSY: |
| 6358 | lpfc_block_fabric_iocbs(phba); |
| 6359 | break; |
| 6360 | |
| 6361 | case IOSTAT_LS_RJT: |
| 6362 | stat.un.lsRjtError = |
| 6363 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 6364 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 6365 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 6366 | lpfc_block_fabric_iocbs(phba); |
| 6367 | break; |
| 6368 | } |
| 6369 | |
| 6370 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 6371 | BUG(); |
| 6372 | |
| 6373 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 6374 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 6375 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6376 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 6377 | |
| 6378 | atomic_dec(&phba->fabric_iocb_count); |
| 6379 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6380 | /* Post any pending iocbs to HBA */ |
| 6381 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6382 | } |
| 6383 | } |
| 6384 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6385 | /** |
| 6386 | * lpfc_issue_fabric_iocb: Issue a fabric iocb command. |
| 6387 | * @phba: pointer to lpfc hba data structure. |
| 6388 | * @iocb: pointer to lpfc command iocb data structure. |
| 6389 | * |
| 6390 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 6391 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 6392 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 6393 | * any given time. As such, this function will first check to see whether there |
| 6394 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 6395 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 6396 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 6397 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 6398 | * |
| 6399 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 6400 | * order. The problem is caused by the construction of the "ready" boolen does |
| 6401 | * not include the condition that the internal fabric IOCB list is empty. As |
| 6402 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 6403 | * ahead of the fabric IOCBs in the internal list. |
| 6404 | * |
| 6405 | * Return code |
| 6406 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 6407 | * IOCB_ERROR - failed to issue fabric iocb |
| 6408 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6409 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6410 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 6411 | { |
| 6412 | unsigned long iflags; |
| 6413 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 6414 | int ready; |
| 6415 | int ret; |
| 6416 | |
| 6417 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 6418 | BUG(); |
| 6419 | |
| 6420 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6421 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 6422 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6423 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6424 | if (ready) |
| 6425 | /* Increment fabric iocb count to hold the position */ |
| 6426 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6427 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6428 | if (ready) { |
| 6429 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6430 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6431 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6432 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6433 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6434 | "Fabric sched2: ste:x%x", |
| 6435 | iocb->vport->port_state, 0, 0); |
| 6436 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6437 | ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0); |
| 6438 | |
| 6439 | if (ret == IOCB_ERROR) { |
| 6440 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6441 | iocb->fabric_iocb_cmpl = NULL; |
| 6442 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6443 | atomic_dec(&phba->fabric_iocb_count); |
| 6444 | } |
| 6445 | } else { |
| 6446 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6447 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 6448 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6449 | ret = IOCB_SUCCESS; |
| 6450 | } |
| 6451 | return ret; |
| 6452 | } |
| 6453 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6454 | /** |
| 6455 | * lpfc_fabric_abort_vport: Abort a vport's iocbs from driver fabric iocb list. |
| 6456 | * @vport: pointer to a virtual N_Port data structure. |
| 6457 | * |
| 6458 | * This routine aborts all the IOCBs associated with a @vport from the |
| 6459 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6460 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6461 | * list, removes each IOCB associated with the @vport off the list, set the |
| 6462 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6463 | * associated with the IOCB. |
| 6464 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6465 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6466 | { |
| 6467 | LIST_HEAD(completions); |
| 6468 | struct lpfc_hba *phba = vport->phba; |
| 6469 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6470 | IOCB_t *cmd; |
| 6471 | |
| 6472 | spin_lock_irq(&phba->hbalock); |
| 6473 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6474 | list) { |
| 6475 | |
| 6476 | if (piocb->vport != vport) |
| 6477 | continue; |
| 6478 | |
| 6479 | list_move_tail(&piocb->list, &completions); |
| 6480 | } |
| 6481 | spin_unlock_irq(&phba->hbalock); |
| 6482 | |
| 6483 | while (!list_empty(&completions)) { |
| 6484 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 6485 | list_del_init(&piocb->list); |
| 6486 | |
| 6487 | cmd = &piocb->iocb; |
| 6488 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6489 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6490 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 6491 | } |
| 6492 | } |
| 6493 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6494 | /** |
| 6495 | * lpfc_fabric_abort_nport: Abort a ndlp's iocbs from driver fabric iocb list. |
| 6496 | * @ndlp: pointer to a node-list data structure. |
| 6497 | * |
| 6498 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 6499 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6500 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6501 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 6502 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6503 | * associated with the IOCB. |
| 6504 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6505 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 6506 | { |
| 6507 | LIST_HEAD(completions); |
| 6508 | struct lpfc_hba *phba = ndlp->vport->phba; |
| 6509 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6510 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 6511 | IOCB_t *cmd; |
| 6512 | |
| 6513 | spin_lock_irq(&phba->hbalock); |
| 6514 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6515 | list) { |
| 6516 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 6517 | |
| 6518 | list_move_tail(&piocb->list, &completions); |
| 6519 | } |
| 6520 | } |
| 6521 | spin_unlock_irq(&phba->hbalock); |
| 6522 | |
| 6523 | while (!list_empty(&completions)) { |
| 6524 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 6525 | list_del_init(&piocb->list); |
| 6526 | |
| 6527 | cmd = &piocb->iocb; |
| 6528 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6529 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6530 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 6531 | } |
| 6532 | } |
| 6533 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6534 | /** |
| 6535 | * lpfc_fabric_abort_hba: Abort all iocbs on driver fabric iocb list. |
| 6536 | * @phba: pointer to lpfc hba data structure. |
| 6537 | * |
| 6538 | * This routine aborts all the IOCBs currently on the driver internal |
| 6539 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 6540 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 6541 | * list, removes IOCBs off the list, set the status feild to |
| 6542 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 6543 | * the IOCB. |
| 6544 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6545 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 6546 | { |
| 6547 | LIST_HEAD(completions); |
| 6548 | struct lpfc_iocbq *piocb; |
| 6549 | IOCB_t *cmd; |
| 6550 | |
| 6551 | spin_lock_irq(&phba->hbalock); |
| 6552 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 6553 | spin_unlock_irq(&phba->hbalock); |
| 6554 | |
| 6555 | while (!list_empty(&completions)) { |
| 6556 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 6557 | list_del_init(&piocb->list); |
| 6558 | |
| 6559 | cmd = &piocb->iocb; |
| 6560 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6561 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6562 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 6563 | } |
| 6564 | } |