blob: 79de8f26a2db9123afcde8f4ff1b5cd0db09e6cc [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smartd4379ac2012-03-01 22:37:07 -05004 * Copyright (C) 2004-2012 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * 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. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
James Smart09372822008-01-11 01:52:54 -050021/* See Fibre Channel protocol T11 FC-LS for details */
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050025#include <linux/interrupt.h>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_transport_fc.h>
31
James Smarte74c03c2013-04-17 20:15:19 -040032
James Smartda0436e2009-05-22 14:51:39 -040033#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050034#include "lpfc_hw.h"
35#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040036#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040037#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050038#include "lpfc_disc.h"
39#include "lpfc_scsi.h"
40#include "lpfc.h"
41#include "lpfc_logmsg.h"
42#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050043#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050044#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050045
46static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
47 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050048static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
49 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010050static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
51static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
52 struct lpfc_nodelist *ndlp, uint8_t retry);
53static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
54 struct lpfc_iocbq *iocb);
James Smart92d7f7b2007-06-17 19:56:38 -050055
dea31012005-04-17 16:05:31 -050056static int lpfc_max_els_tries = 3;
57
James Smarte59058c2008-08-24 21:49:00 -040058/**
James Smart3621a712009-04-06 18:47:14 -040059 * lpfc_els_chk_latt - Check host link attention event for a vport
James Smarte59058c2008-08-24 21:49:00 -040060 * @vport: pointer to a host virtual N_Port data structure.
61 *
62 * This routine checks whether there is an outstanding host link
63 * attention event during the discovery process with the @vport. It is done
64 * by reading the HBA's Host Attention (HA) register. If there is any host
65 * link attention events during this @vport's discovery process, the @vport
66 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
67 * be issued if the link state is not already in host link cleared state,
68 * and a return code shall indicate whether the host link attention event
69 * had happened.
70 *
71 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
72 * state in LPFC_VPORT_READY, the request for checking host link attention
73 * event will be ignored and a return code shall indicate no host link
74 * attention event had happened.
75 *
76 * Return codes
77 * 0 - no host link attention event happened
78 * 1 - host link attention event happened
79 **/
James Smart858c9f62007-06-17 19:56:39 -050080int
James Smart2e0fef82007-06-17 19:56:36 -050081lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050082{
James Smart2e0fef82007-06-17 19:56:36 -050083 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
84 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050085 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050086
James Smart2e0fef82007-06-17 19:56:36 -050087 if (vport->port_state >= LPFC_VPORT_READY ||
James Smart3772a992009-05-22 14:50:54 -040088 phba->link_state == LPFC_LINK_DOWN ||
89 phba->sli_rev > LPFC_SLI_REV3)
dea31012005-04-17 16:05:31 -050090 return 0;
91
92 /* Read the HBA Host Attention Register */
James Smart9940b972011-03-11 16:06:12 -050093 if (lpfc_readl(phba->HAregaddr, &ha_copy))
94 return 1;
dea31012005-04-17 16:05:31 -050095
96 if (!(ha_copy & HA_LATT))
97 return 0;
98
99 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -0400100 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
101 "0237 Pending Link Event during "
102 "Discovery: State x%x\n",
103 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500104
105 /* CLEAR_LA should re-enable link attention events and
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300106 * we should then immediately take a LATT event. The
dea31012005-04-17 16:05:31 -0500107 * LATT processing should call lpfc_linkdown() which
108 * will cleanup any left over in-progress discovery
109 * events.
110 */
James Smart2e0fef82007-06-17 19:56:36 -0500111 spin_lock_irq(shost->host_lock);
112 vport->fc_flag |= FC_ABORT_DISCOVERY;
113 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500114
James Smart92d7f7b2007-06-17 19:56:38 -0500115 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500116 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500117
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500118 return 1;
dea31012005-04-17 16:05:31 -0500119}
120
James Smarte59058c2008-08-24 21:49:00 -0400121/**
James Smart3621a712009-04-06 18:47:14 -0400122 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400123 * @vport: pointer to a host virtual N_Port data structure.
124 * @expectRsp: flag indicating whether response is expected.
125 * @cmdSize: size of the ELS command.
126 * @retry: number of retries to the command IOCB when it fails.
127 * @ndlp: pointer to a node-list data structure.
128 * @did: destination identifier.
129 * @elscmd: the ELS command code.
130 *
131 * This routine is used for allocating a lpfc-IOCB data structure from
132 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
133 * passed into the routine for discovery state machine to issue an Extended
134 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
135 * and preparation routine that is used by all the discovery state machine
136 * routines and the ELS command-specific fields will be later set up by
137 * the individual discovery machine routines after calling this routine
138 * allocating and preparing a generic IOCB data structure. It fills in the
139 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
140 * payload and response payload (if expected). The reference count on the
141 * ndlp is incremented by 1 and the reference to the ndlp is put into
142 * context1 of the IOCB data structure for this IOCB to hold the ndlp
143 * reference for the command's callback function to access later.
144 *
145 * Return code
146 * Pointer to the newly allocated/prepared els iocb data structure
147 * NULL - when els iocb data structure allocation/preparation failed
148 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400149struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500150lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
151 uint16_t cmdSize, uint8_t retry,
152 struct lpfc_nodelist *ndlp, uint32_t did,
153 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500154{
James Smart2e0fef82007-06-17 19:56:36 -0500155 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400156 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500157 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
158 struct ulp_bde64 *bpl;
159 IOCB_t *icmd;
160
dea31012005-04-17 16:05:31 -0500161
James Smart2e0fef82007-06-17 19:56:36 -0500162 if (!lpfc_is_link_up(phba))
163 return NULL;
dea31012005-04-17 16:05:31 -0500164
dea31012005-04-17 16:05:31 -0500165 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400166 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500167
168 if (elsiocb == NULL)
169 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500170
James Smart0c287582009-06-10 17:22:56 -0400171 /*
172 * If this command is for fabric controller and HBA running
173 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
174 */
175 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400176 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400177 ((elscmd == ELS_CMD_FLOGI) ||
178 (elscmd == ELS_CMD_FDISC) ||
179 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500180 switch (elscmd) {
181 case ELS_CMD_FLOGI:
James Smartf0d9bcc2010-10-22 11:07:09 -0400182 elsiocb->iocb_flag |=
183 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500184 & LPFC_FIP_ELS_ID_MASK);
185 break;
186 case ELS_CMD_FDISC:
James Smartf0d9bcc2010-10-22 11:07:09 -0400187 elsiocb->iocb_flag |=
188 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500189 & LPFC_FIP_ELS_ID_MASK);
190 break;
191 case ELS_CMD_LOGO:
James Smartf0d9bcc2010-10-22 11:07:09 -0400192 elsiocb->iocb_flag |=
193 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500194 & LPFC_FIP_ELS_ID_MASK);
195 break;
196 }
James Smart0c287582009-06-10 17:22:56 -0400197 else
James Smartc8685952009-11-18 15:39:16 -0500198 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400199
dea31012005-04-17 16:05:31 -0500200 icmd = &elsiocb->iocb;
201
202 /* fill in BDEs for command */
203 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400204 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
205 if (pcmd)
206 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500207 if (!pcmd || !pcmd->virt)
208 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500209
210 INIT_LIST_HEAD(&pcmd->list);
211
212 /* Allocate buffer for response payload */
213 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500214 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500215 if (prsp)
216 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
217 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500218 if (!prsp || !prsp->virt)
219 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500220 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500221 } else
dea31012005-04-17 16:05:31 -0500222 prsp = NULL;
dea31012005-04-17 16:05:31 -0500223
224 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500225 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500226 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500227 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
228 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500229 if (!pbuflist || !pbuflist->virt)
230 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500231
232 INIT_LIST_HEAD(&pbuflist->list);
233
dea31012005-04-17 16:05:31 -0500234 if (expectRsp) {
James Smart939723a2012-05-09 21:19:03 -0400235 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
236 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
237 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart92d7f7b2007-06-17 19:56:38 -0500238 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
James Smart939723a2012-05-09 21:19:03 -0400239
240 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500241 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400242 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500243 } else {
James Smart939723a2012-05-09 21:19:03 -0400244 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
245 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
246 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
247 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
248 icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500249 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
250 }
dea31012005-04-17 16:05:31 -0500251 icmd->ulpBdeCount = 1;
252 icmd->ulpLe = 1;
253 icmd->ulpClass = CLASS3;
254
James Smart939723a2012-05-09 21:19:03 -0400255 /*
256 * If we have NPIV enabled, we want to send ELS traffic by VPI.
257 * For SLI4, since the driver controls VPIs we also want to include
258 * all ELS pt2pt protocol traffic as well.
259 */
260 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
261 ((phba->sli_rev == LPFC_SLI_REV4) &&
262 (vport->fc_flag & FC_PT2PT))) {
James Smart92d7f7b2007-06-17 19:56:38 -0500263
James Smart939723a2012-05-09 21:19:03 -0400264 if (expectRsp) {
265 icmd->un.elsreq64.myID = vport->fc_myDID;
266
267 /* For ELS_REQUEST64_CR, use the VPI by default */
268 icmd->ulpContext = phba->vpi_ids[vport->vpi];
269 }
270
James Smart92d7f7b2007-06-17 19:56:38 -0500271 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500272 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
273 if (elscmd == ELS_CMD_ECHO)
274 icmd->ulpCt_l = 0; /* context = invalid RPI */
275 else
276 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500277 }
278
dea31012005-04-17 16:05:31 -0500279 bpl = (struct ulp_bde64 *) pbuflist->virt;
280 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
281 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
282 bpl->tus.f.bdeSize = cmdSize;
283 bpl->tus.f.bdeFlags = 0;
284 bpl->tus.w = le32_to_cpu(bpl->tus.w);
285
286 if (expectRsp) {
287 bpl++;
288 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
289 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
290 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400291 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500292 bpl->tus.w = le32_to_cpu(bpl->tus.w);
293 }
294
James Smartfa4066b2008-01-11 01:53:27 -0500295 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400296 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500297 if (!elsiocb->context1)
298 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400299 elsiocb->context2 = pcmd;
300 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500301 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500302 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500303 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
304
305 if (prsp) {
306 list_add(&prsp->list, &pcmd->list);
307 }
dea31012005-04-17 16:05:31 -0500308 if (expectRsp) {
309 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400310 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
311 "0116 Xmit ELS command x%x to remote "
James Smarte74c03c2013-04-17 20:15:19 -0400312 "NPORT x%x I/O tag: x%x, port state:x%x"
313 " fc_flag:x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400314 elscmd, did, elsiocb->iotag,
James Smarte74c03c2013-04-17 20:15:19 -0400315 vport->port_state,
316 vport->fc_flag);
dea31012005-04-17 16:05:31 -0500317 } else {
318 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400319 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
320 "0117 Xmit ELS response x%x to remote "
James Smarte74c03c2013-04-17 20:15:19 -0400321 "NPORT x%x I/O tag: x%x, size: x%x "
322 "port_state x%x fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400323 elscmd, ndlp->nlp_DID, elsiocb->iotag,
James Smarte74c03c2013-04-17 20:15:19 -0400324 cmdSize, vport->port_state,
325 vport->fc_flag);
dea31012005-04-17 16:05:31 -0500326 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500327 return elsiocb;
dea31012005-04-17 16:05:31 -0500328
James Smartfa4066b2008-01-11 01:53:27 -0500329els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500330 if (expectRsp)
331 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500332 kfree(pbuflist);
333
334els_iocb_free_prsp_exit:
335 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
336 kfree(prsp);
337
338els_iocb_free_pcmb_exit:
339 kfree(pcmd);
340 lpfc_sli_release_iocbq(phba, elsiocb);
341 return NULL;
342}
dea31012005-04-17 16:05:31 -0500343
James Smarte59058c2008-08-24 21:49:00 -0400344/**
James Smart3621a712009-04-06 18:47:14 -0400345 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400346 * @vport: pointer to a host virtual N_Port data structure.
347 *
348 * This routine issues a fabric registration login for a @vport. An
349 * active ndlp node with Fabric_DID must already exist for this @vport.
350 * The routine invokes two mailbox commands to carry out fabric registration
351 * login through the HBA firmware: the first mailbox command requests the
352 * HBA to perform link configuration for the @vport; and the second mailbox
353 * command requests the HBA to perform the actual fabric registration login
354 * with the @vport.
355 *
356 * Return code
357 * 0 - successfully issued fabric registration login for @vport
358 * -ENXIO -- failed to issue fabric registration login for @vport
359 **/
James Smart3772a992009-05-22 14:50:54 -0400360int
James Smart92d7f7b2007-06-17 19:56:38 -0500361lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
362{
363 struct lpfc_hba *phba = vport->phba;
364 LPFC_MBOXQ_t *mbox;
365 struct lpfc_dmabuf *mp;
366 struct lpfc_nodelist *ndlp;
367 struct serv_parm *sp;
368 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400369 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500370
371 sp = &phba->fc_fabparam;
372 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500373 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400374 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500375 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400376 }
James Smart92d7f7b2007-06-17 19:56:38 -0500377
378 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400379 if (!mbox) {
380 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500381 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400382 }
James Smart92d7f7b2007-06-17 19:56:38 -0500383
384 vport->port_state = LPFC_FABRIC_CFG_LINK;
385 lpfc_config_link(phba, mbox);
386 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
387 mbox->vport = vport;
388
James Smart0b727fe2007-10-27 13:37:25 -0400389 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400390 if (rc == MBX_NOT_FINISHED) {
391 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500392 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400393 }
James Smart92d7f7b2007-06-17 19:56:38 -0500394
395 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400396 if (!mbox) {
397 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500398 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400399 }
James Smart40426292010-12-15 17:58:10 -0500400 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
401 ndlp->nlp_rpi);
James Smart98c9ea52007-10-27 13:37:33 -0400402 if (rc) {
403 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500404 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400405 }
James Smart92d7f7b2007-06-17 19:56:38 -0500406
407 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
408 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500409 /* increment the reference count on ndlp to hold reference
410 * for the callback routine.
411 */
James Smart92d7f7b2007-06-17 19:56:38 -0500412 mbox->context2 = lpfc_nlp_get(ndlp);
413
James Smart0b727fe2007-10-27 13:37:25 -0400414 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400415 if (rc == MBX_NOT_FINISHED) {
416 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500417 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400418 }
James Smart92d7f7b2007-06-17 19:56:38 -0500419
420 return 0;
421
422fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500423 /* decrement the reference count on ndlp just incremented
424 * for the failed mbox command.
425 */
James Smart92d7f7b2007-06-17 19:56:38 -0500426 lpfc_nlp_put(ndlp);
427 mp = (struct lpfc_dmabuf *) mbox->context1;
428 lpfc_mbuf_free(phba, mp->virt, mp->phys);
429 kfree(mp);
430fail_free_mbox:
431 mempool_free(mbox, phba->mbox_mem_pool);
432
433fail:
434 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400435 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400436 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500437 return -ENXIO;
438}
439
James Smarte59058c2008-08-24 21:49:00 -0400440/**
James Smart6fb120a2009-05-22 14:52:59 -0400441 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
442 * @vport: pointer to a host virtual N_Port data structure.
443 *
444 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
James Smart1b511972011-12-13 13:23:09 -0500445 * the @vport. This mailbox command is necessary for SLI4 port only.
James Smart6fb120a2009-05-22 14:52:59 -0400446 *
447 * Return code
448 * 0 - successfully issued REG_VFI for @vport
449 * A failure code otherwise.
450 **/
James Smart1b511972011-12-13 13:23:09 -0500451int
James Smart6fb120a2009-05-22 14:52:59 -0400452lpfc_issue_reg_vfi(struct lpfc_vport *vport)
453{
454 struct lpfc_hba *phba = vport->phba;
455 LPFC_MBOXQ_t *mboxq;
456 struct lpfc_nodelist *ndlp;
457 struct serv_parm *sp;
458 struct lpfc_dmabuf *dmabuf;
459 int rc = 0;
460
461 sp = &phba->fc_fabparam;
James Smart939723a2012-05-09 21:19:03 -0400462 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
James Smart1b511972011-12-13 13:23:09 -0500463 if ((phba->sli_rev == LPFC_SLI_REV4) &&
James Smart939723a2012-05-09 21:19:03 -0400464 !(phba->link_flag & LS_LOOPBACK_MODE) &&
465 !(vport->fc_flag & FC_PT2PT)) {
James Smart1b511972011-12-13 13:23:09 -0500466 ndlp = lpfc_findnode_did(vport, Fabric_DID);
467 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
468 rc = -ENODEV;
469 goto fail;
470 }
James Smart6fb120a2009-05-22 14:52:59 -0400471 }
472
473 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
474 if (!dmabuf) {
475 rc = -ENOMEM;
476 goto fail;
477 }
478 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
479 if (!dmabuf->virt) {
480 rc = -ENOMEM;
481 goto fail_free_dmabuf;
482 }
James Smart6d368e52011-05-24 11:44:12 -0400483
James Smart6fb120a2009-05-22 14:52:59 -0400484 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
485 if (!mboxq) {
486 rc = -ENOMEM;
487 goto fail_free_coherent;
488 }
489 vport->port_state = LPFC_FABRIC_CFG_LINK;
490 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
491 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
James Smartae05ebe2013-03-01 16:35:38 -0500492
James Smart6fb120a2009-05-22 14:52:59 -0400493 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
494 mboxq->vport = vport;
495 mboxq->context1 = dmabuf;
496 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
497 if (rc == MBX_NOT_FINISHED) {
498 rc = -ENXIO;
499 goto fail_free_mbox;
500 }
501 return 0;
502
503fail_free_mbox:
504 mempool_free(mboxq, phba->mbox_mem_pool);
505fail_free_coherent:
506 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
507fail_free_dmabuf:
508 kfree(dmabuf);
509fail:
510 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
511 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
512 "0289 Issue Register VFI failed: Err %d\n", rc);
513 return rc;
514}
515
516/**
James Smart1b511972011-12-13 13:23:09 -0500517 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
518 * @vport: pointer to a host virtual N_Port data structure.
519 *
520 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
521 * the @vport. This mailbox command is necessary for SLI4 port only.
522 *
523 * Return code
524 * 0 - successfully issued REG_VFI for @vport
525 * A failure code otherwise.
526 **/
527int
528lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
529{
530 struct lpfc_hba *phba = vport->phba;
531 struct Scsi_Host *shost;
532 LPFC_MBOXQ_t *mboxq;
533 int rc;
534
535 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
536 if (!mboxq) {
537 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
538 "2556 UNREG_VFI mbox allocation failed"
539 "HBA state x%x\n", phba->pport->port_state);
540 return -ENOMEM;
541 }
542
543 lpfc_unreg_vfi(mboxq, vport);
544 mboxq->vport = vport;
545 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
546
547 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
548 if (rc == MBX_NOT_FINISHED) {
549 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
550 "2557 UNREG_VFI issue mbox failed rc x%x "
551 "HBA state x%x\n",
552 rc, phba->pport->port_state);
553 mempool_free(mboxq, phba->mbox_mem_pool);
554 return -EIO;
555 }
556
557 shost = lpfc_shost_from_vport(vport);
558 spin_lock_irq(shost->host_lock);
559 vport->fc_flag &= ~FC_VFI_REGISTERED;
560 spin_unlock_irq(shost->host_lock);
561 return 0;
562}
563
564/**
James Smart92494142011-02-16 12:39:44 -0500565 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
566 * @vport: pointer to a host virtual N_Port data structure.
567 * @sp: pointer to service parameter data structure.
568 *
569 * This routine is called from FLOGI/FDISC completion handler functions.
570 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
571 * node nodename is changed in the completion service parameter else return
572 * 0. This function also set flag in the vport data structure to delay
573 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
574 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
575 * node nodename is changed in the completion service parameter.
576 *
577 * Return code
578 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
579 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
580 *
581 **/
582static uint8_t
583lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
584 struct serv_parm *sp)
585{
586 uint8_t fabric_param_changed = 0;
587 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
588
589 if ((vport->fc_prevDID != vport->fc_myDID) ||
590 memcmp(&vport->fabric_portname, &sp->portName,
591 sizeof(struct lpfc_name)) ||
592 memcmp(&vport->fabric_nodename, &sp->nodeName,
593 sizeof(struct lpfc_name)))
594 fabric_param_changed = 1;
595
596 /*
597 * Word 1 Bit 31 in common service parameter is overloaded.
598 * Word 1 Bit 31 in FLOGI request is multiple NPort request
599 * Word 1 Bit 31 in FLOGI response is clean address bit
600 *
601 * If fabric parameter is changed and clean address bit is
602 * cleared delay nport discovery if
603 * - vport->fc_prevDID != 0 (not initial discovery) OR
604 * - lpfc_delay_discovery module parameter is set.
605 */
606 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
607 (vport->fc_prevDID || lpfc_delay_discovery)) {
608 spin_lock_irq(shost->host_lock);
609 vport->fc_flag |= FC_DISC_DELAYED;
610 spin_unlock_irq(shost->host_lock);
611 }
612
613 return fabric_param_changed;
614}
615
616
617/**
James Smart3621a712009-04-06 18:47:14 -0400618 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400619 * @vport: pointer to a host virtual N_Port data structure.
620 * @ndlp: pointer to a node-list data structure.
621 * @sp: pointer to service parameter data structure.
622 * @irsp: pointer to the IOCB within the lpfc response IOCB.
623 *
624 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
625 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
626 * port in a fabric topology. It properly sets up the parameters to the @ndlp
627 * from the IOCB response. It also check the newly assigned N_Port ID to the
628 * @vport against the previously assigned N_Port ID. If it is different from
629 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
630 * is invoked on all the remaining nodes with the @vport to unregister the
631 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
632 * is invoked to register login to the fabric.
633 *
634 * Return code
635 * 0 - Success (currently, always return 0)
636 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500637static int
James Smart2e0fef82007-06-17 19:56:36 -0500638lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
639 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500640{
James Smart2e0fef82007-06-17 19:56:36 -0500641 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
642 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500643 struct lpfc_nodelist *np;
644 struct lpfc_nodelist *next_np;
James Smart92494142011-02-16 12:39:44 -0500645 uint8_t fabric_param_changed;
dea31012005-04-17 16:05:31 -0500646
James Smart2e0fef82007-06-17 19:56:36 -0500647 spin_lock_irq(shost->host_lock);
648 vport->fc_flag |= FC_FABRIC;
649 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500650
651 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
652 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
653 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
654
James Smart12265f62010-10-22 11:05:53 -0400655 phba->fc_edtovResol = sp->cmn.edtovResolution;
dea31012005-04-17 16:05:31 -0500656 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
657
James Smart76a95d72010-11-20 23:11:48 -0500658 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500659 spin_lock_irq(shost->host_lock);
660 vport->fc_flag |= FC_PUBLIC_LOOP;
661 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500662 }
663
James Smart2e0fef82007-06-17 19:56:36 -0500664 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500665 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500666 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500667 ndlp->nlp_class_sup = 0;
668 if (sp->cls1.classValid)
669 ndlp->nlp_class_sup |= FC_COS_CLASS1;
670 if (sp->cls2.classValid)
671 ndlp->nlp_class_sup |= FC_COS_CLASS2;
672 if (sp->cls3.classValid)
673 ndlp->nlp_class_sup |= FC_COS_CLASS3;
674 if (sp->cls4.classValid)
675 ndlp->nlp_class_sup |= FC_COS_CLASS4;
676 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
677 sp->cmn.bbRcvSizeLsb;
James Smart92494142011-02-16 12:39:44 -0500678
679 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
680 memcpy(&vport->fabric_portname, &sp->portName,
681 sizeof(struct lpfc_name));
682 memcpy(&vport->fabric_nodename, &sp->nodeName,
683 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500684 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
685
James Smart92d7f7b2007-06-17 19:56:38 -0500686 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
687 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400688 lpfc_printf_vlog(vport, KERN_WARNING,
689 LOG_ELS | LOG_VPORT,
690 "1816 FLOGI NPIV supported, "
691 "response data 0x%x\n",
692 sp->cmn.response_multiple_NPort);
James Smart1b511972011-12-13 13:23:09 -0500693 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500694 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500695 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500696 } else {
697 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400698 to call reg_vnpid atleast for the physcial host */
699 lpfc_printf_vlog(vport, KERN_WARNING,
700 LOG_ELS | LOG_VPORT,
701 "1817 Fabric does not support NPIV "
702 "- configuring single port mode.\n");
James Smart1b511972011-12-13 13:23:09 -0500703 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500704 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500705 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500706 }
707 }
708
James Smartae05ebe2013-03-01 16:35:38 -0500709 /*
710 * For FC we need to do some special processing because of the SLI
711 * Port's default settings of the Common Service Parameters.
712 */
713 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC) {
714 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
715 if ((phba->sli_rev == LPFC_SLI_REV4) && fabric_param_changed)
716 lpfc_unregister_fcf_prep(phba);
717
718 /* This should just update the VFI CSPs*/
719 if (vport->fc_flag & FC_VFI_REGISTERED)
720 lpfc_issue_reg_vfi(vport);
721 }
722
James Smart92494142011-02-16 12:39:44 -0500723 if (fabric_param_changed &&
James Smart92d7f7b2007-06-17 19:56:38 -0500724 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
725
726 /* If our NportID changed, we need to ensure all
727 * remaining NPORTs get unreg_login'ed.
728 */
729 list_for_each_entry_safe(np, next_np,
730 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400731 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500732 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500733 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
734 !(np->nlp_flag & NLP_NPR_ADISC))
735 continue;
736 spin_lock_irq(shost->host_lock);
737 np->nlp_flag &= ~NLP_NPR_ADISC;
738 spin_unlock_irq(shost->host_lock);
739 lpfc_unreg_rpi(vport, np);
740 }
James Smart78730cf2010-04-06 15:06:30 -0400741 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -0400742
James Smart5248a742011-07-22 18:37:06 -0400743 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart5af5eee2010-10-22 11:06:38 -0400744 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500745 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500746 spin_lock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -0500747 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
748 spin_unlock_irq(shost->host_lock);
749 }
James Smart27aa1b72012-05-09 21:18:49 -0400750
751 /*
752 * For SLI3 and SLI4, the VPI needs to be reregistered in
753 * response to this fabric parameter change event.
754 */
755 spin_lock_irq(shost->host_lock);
756 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
757 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -0400758 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
759 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
760 /*
761 * Driver needs to re-reg VPI in order for f/w
762 * to update the MAC address.
763 */
James Smart9589b062011-04-16 11:03:17 -0400764 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart38b92ef2010-08-04 16:11:39 -0400765 lpfc_register_new_vport(phba, vport, ndlp);
766 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500767 }
768
James Smart6fb120a2009-05-22 14:52:59 -0400769 if (phba->sli_rev < LPFC_SLI_REV4) {
770 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
771 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
772 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
773 lpfc_register_new_vport(phba, vport, ndlp);
774 else
775 lpfc_issue_fabric_reglogin(vport);
776 } else {
777 ndlp->nlp_type |= NLP_FABRIC;
778 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500779 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
780 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400781 lpfc_start_fdiscs(phba);
782 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500783 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500784 lpfc_issue_init_vpi(vport);
James Smart1b511972011-12-13 13:23:09 -0500785 else {
786 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
787 "3135 Need register VFI: (x%x/%x)\n",
788 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -0400789 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -0500790 }
James Smart92d7f7b2007-06-17 19:56:38 -0500791 }
dea31012005-04-17 16:05:31 -0500792 return 0;
dea31012005-04-17 16:05:31 -0500793}
James Smart1b511972011-12-13 13:23:09 -0500794
James Smarte59058c2008-08-24 21:49:00 -0400795/**
James Smart3621a712009-04-06 18:47:14 -0400796 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400797 * @vport: pointer to a host virtual N_Port data structure.
798 * @ndlp: pointer to a node-list data structure.
799 * @sp: pointer to service parameter data structure.
800 *
801 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
802 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
803 * in a point-to-point topology. First, the @vport's N_Port Name is compared
804 * with the received N_Port Name: if the @vport's N_Port Name is greater than
805 * the received N_Port Name lexicographically, this node shall assign local
806 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
807 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
808 * this node shall just wait for the remote node to issue PLOGI and assign
809 * N_Port IDs.
810 *
811 * Return code
812 * 0 - Success
813 * -ENXIO - Fail
814 **/
dea31012005-04-17 16:05:31 -0500815static int
James Smart2e0fef82007-06-17 19:56:36 -0500816lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
817 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500818{
James Smart2e0fef82007-06-17 19:56:36 -0500819 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
820 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500821 LPFC_MBOXQ_t *mbox;
822 int rc;
823
James Smart2e0fef82007-06-17 19:56:36 -0500824 spin_lock_irq(shost->host_lock);
825 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
826 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500827
828 phba->fc_edtov = FF_DEF_EDTOV;
829 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500830 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500831 sizeof(vport->fc_portname));
James Smart2eb68622012-09-29 11:32:27 -0400832 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
833
dea31012005-04-17 16:05:31 -0500834 if (rc >= 0) {
835 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500836 spin_lock_irq(shost->host_lock);
837 vport->fc_flag |= FC_PT2PT_PLOGI;
838 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500839
840 /*
841 * N_Port ID cannot be 0, set our to LocalID the other
842 * side will be RemoteID.
843 */
844
845 /* not equal */
846 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500847 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500848
849 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
850 if (!mbox)
851 goto fail;
852
853 lpfc_config_link(phba, mbox);
854
855 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500856 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400857 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500858 if (rc == MBX_NOT_FINISHED) {
859 mempool_free(mbox, phba->mbox_mem_pool);
860 goto fail;
861 }
James Smart939723a2012-05-09 21:19:03 -0400862
863 /*
864 * For SLI4, the VFI/VPI are registered AFTER the
865 * Nport with the higher WWPN sends the PLOGI with
866 * an assigned NPortId.
867 */
868
869 /* not equal */
870 if ((phba->sli_rev == LPFC_SLI_REV4) && rc)
871 lpfc_issue_reg_vfi(vport);
872
James Smarte47c9092008-02-08 18:49:26 -0500873 /* Decrement ndlp reference count indicating that ndlp can be
874 * safely released when other references to it are done.
875 */
James Smart329f9bc2007-04-25 09:53:01 -0400876 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500877
James Smart2e0fef82007-06-17 19:56:36 -0500878 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500879 if (!ndlp) {
880 /*
881 * Cannot find existing Fabric ndlp, so allocate a
882 * new one
883 */
884 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
885 if (!ndlp)
886 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500887 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500888 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
889 ndlp = lpfc_enable_node(vport, ndlp,
890 NLP_STE_UNUSED_NODE);
891 if(!ndlp)
892 goto fail;
dea31012005-04-17 16:05:31 -0500893 }
894
895 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500896 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500897 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500898 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500899 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500900 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
901 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500902 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500903 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500904 } else
905 /* This side will wait for the PLOGI, decrement ndlp reference
906 * count indicating that ndlp can be released when other
907 * references to it are done.
908 */
James Smart329f9bc2007-04-25 09:53:01 -0400909 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500910
James Smart09372822008-01-11 01:52:54 -0500911 /* If we are pt2pt with another NPort, force NPIV off! */
912 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
913
James Smart2e0fef82007-06-17 19:56:36 -0500914 spin_lock_irq(shost->host_lock);
915 vport->fc_flag |= FC_PT2PT;
916 spin_unlock_irq(shost->host_lock);
James Smarte74c03c2013-04-17 20:15:19 -0400917 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
918 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
919 lpfc_unregister_fcf_prep(phba);
920
921 /* The FC_VFI_REGISTERED flag will get clear in the cmpl
922 * handler for unreg_vfi, but if we don't force the
923 * FC_VFI_REGISTERED flag then the reg_vfi mailbox could be
924 * built with the update bit set instead of just the vp bit to
925 * change the Nport ID. We need to have the vp set and the
926 * Upd cleared on topology changes.
927 */
928 spin_lock_irq(shost->host_lock);
929 vport->fc_flag &= ~FC_VFI_REGISTERED;
930 spin_unlock_irq(shost->host_lock);
931 phba->fc_topology_changed = 0;
932 lpfc_issue_reg_vfi(vport);
933 }
dea31012005-04-17 16:05:31 -0500934
935 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500936 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500937 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500938fail:
dea31012005-04-17 16:05:31 -0500939 return -ENXIO;
940}
941
James Smarte59058c2008-08-24 21:49:00 -0400942/**
James Smart3621a712009-04-06 18:47:14 -0400943 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400944 * @phba: pointer to lpfc hba data structure.
945 * @cmdiocb: pointer to lpfc command iocb data structure.
946 * @rspiocb: pointer to lpfc response iocb data structure.
947 *
948 * This routine is the top-level completion callback function for issuing
949 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
950 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
951 * retry has been made (either immediately or delayed with lpfc_els_retry()
952 * returning 1), the command IOCB will be released and function returned.
953 * If the retry attempt has been given up (possibly reach the maximum
954 * number of retries), one additional decrement of ndlp reference shall be
955 * invoked before going out after releasing the command IOCB. This will
956 * actually release the remote node (Note, lpfc_els_free_iocb() will also
957 * invoke one decrement of ndlp reference count). If no error reported in
958 * the IOCB status, the command Port ID field is used to determine whether
959 * this is a point-to-point topology or a fabric topology: if the Port ID
960 * field is assigned, it is a fabric topology; otherwise, it is a
961 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
962 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
963 * specific topology completion conditions.
964 **/
dea31012005-04-17 16:05:31 -0500965static void
James Smart329f9bc2007-04-25 09:53:01 -0400966lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
967 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500968{
James Smart2e0fef82007-06-17 19:56:36 -0500969 struct lpfc_vport *vport = cmdiocb->vport;
970 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500971 IOCB_t *irsp = &rspiocb->iocb;
972 struct lpfc_nodelist *ndlp = cmdiocb->context1;
973 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
974 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500975 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500976 int rc;
977
978 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500979 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500980 /* One additional decrement on node reference count to
981 * trigger the release of the node
982 */
James Smart329f9bc2007-04-25 09:53:01 -0400983 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500984 goto out;
985 }
986
James Smart858c9f62007-06-17 19:56:39 -0500987 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
988 "FLOGI cmpl: status:x%x/x%x state:x%x",
989 irsp->ulpStatus, irsp->un.ulpWord[4],
990 vport->port_state);
991
dea31012005-04-17 16:05:31 -0500992 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500993 /*
James Smarta93ff372010-10-22 11:06:08 -0400994 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -0500995 * due to new FCF discovery
996 */
997 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart80c17842012-03-01 22:35:45 -0500998 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
999 if (phba->link_state < LPFC_LINK_UP)
1000 goto stop_rr_fcf_flogi;
1001 if ((phba->fcoe_cvl_eventtag_attn ==
1002 phba->fcoe_cvl_eventtag) &&
1003 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -04001004 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1005 IOERR_SLI_ABORTED))
James Smart80c17842012-03-01 22:35:45 -05001006 goto stop_rr_fcf_flogi;
1007 else
1008 phba->fcoe_cvl_eventtag_attn =
1009 phba->fcoe_cvl_eventtag;
James Smart0c9ab6f2010-02-26 14:15:57 -05001010 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001011 "2611 FLOGI failed on FCF (x%x), "
1012 "status:x%x/x%x, tmo:x%x, perform "
1013 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -04001014 phba->fcf.current_rec.fcf_indx,
1015 irsp->ulpStatus, irsp->un.ulpWord[4],
1016 irsp->ulpTimeout);
James Smart7d791df2011-07-22 18:37:52 -04001017 lpfc_sli4_set_fcf_flogi_fail(phba,
1018 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001019 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -04001020 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1021 if (rc)
1022 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001023 }
1024
James Smart80c17842012-03-01 22:35:45 -05001025stop_rr_fcf_flogi:
James Smart38b92ef2010-08-04 16:11:39 -04001026 /* FLOGI failure */
1027 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1028 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1029 irsp->ulpStatus, irsp->un.ulpWord[4],
1030 irsp->ulpTimeout);
1031
dea31012005-04-17 16:05:31 -05001032 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001033 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001034 goto out;
James Smart2e0fef82007-06-17 19:56:36 -05001035
James Smart76a95d72010-11-20 23:11:48 -05001036 /* FLOGI failure */
1037 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1038 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1039 irsp->ulpStatus, irsp->un.ulpWord[4],
1040 irsp->ulpTimeout);
1041
dea31012005-04-17 16:05:31 -05001042 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -05001043 spin_lock_irq(shost->host_lock);
1044 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1045 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001046
James Smart329f9bc2007-04-25 09:53:01 -04001047 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -05001048 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1049 * alpa map would take too long otherwise.
1050 */
James Smart1b511972011-12-13 13:23:09 -05001051 if (phba->alpa_map[0] == 0)
James Smart3de2a652007-08-02 11:09:59 -04001052 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smartff78d8f2011-12-13 13:21:35 -05001053 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1054 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
James Smarte74c03c2013-04-17 20:15:19 -04001055 (vport->fc_prevDID != vport->fc_myDID) ||
1056 phba->fc_topology_changed)) {
1057 if (vport->fc_flag & FC_VFI_REGISTERED) {
1058 if (phba->fc_topology_changed) {
1059 lpfc_unregister_fcf_prep(phba);
1060 spin_lock_irq(shost->host_lock);
1061 vport->fc_flag &= ~FC_VFI_REGISTERED;
1062 spin_unlock_irq(shost->host_lock);
1063 phba->fc_topology_changed = 0;
1064 } else {
1065 lpfc_sli4_unreg_all_rpis(vport);
1066 }
1067 }
James Smartff78d8f2011-12-13 13:21:35 -05001068 lpfc_issue_reg_vfi(vport);
1069 lpfc_nlp_put(ndlp);
1070 goto out;
dea31012005-04-17 16:05:31 -05001071 }
dea31012005-04-17 16:05:31 -05001072 goto flogifail;
1073 }
James Smart695a8142010-01-26 23:08:03 -05001074 spin_lock_irq(shost->host_lock);
1075 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04001076 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -05001077 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001078
1079 /*
1080 * The FLogI succeeded. Sync the data for the CPU before
1081 * accessing it.
1082 */
1083 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1084
1085 sp = prsp->virt + sizeof(uint32_t);
1086
1087 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -04001088 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001089 "0101 FLOGI completes successfully "
James Smarte74c03c2013-04-17 20:15:19 -04001090 "Data: x%x x%x x%x x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001091 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
James Smarte74c03c2013-04-17 20:15:19 -04001092 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1093 vport->port_state, vport->fc_flag);
dea31012005-04-17 16:05:31 -05001094
James Smart2e0fef82007-06-17 19:56:36 -05001095 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -05001096 /*
1097 * If Common Service Parameters indicate Nport
1098 * we are point to point, if Fport we are Fabric.
1099 */
1100 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -05001101 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -05001102 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001103 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -04001104 else {
1105 lpfc_printf_vlog(vport, KERN_ERR,
1106 LOG_FIP | LOG_ELS,
1107 "2831 FLOGI response with cleared Fabric "
1108 "bit fcf_index 0x%x "
1109 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1110 "Fabric Name "
1111 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1112 phba->fcf.current_rec.fcf_indx,
1113 phba->fcf.current_rec.switch_name[0],
1114 phba->fcf.current_rec.switch_name[1],
1115 phba->fcf.current_rec.switch_name[2],
1116 phba->fcf.current_rec.switch_name[3],
1117 phba->fcf.current_rec.switch_name[4],
1118 phba->fcf.current_rec.switch_name[5],
1119 phba->fcf.current_rec.switch_name[6],
1120 phba->fcf.current_rec.switch_name[7],
1121 phba->fcf.current_rec.fabric_name[0],
1122 phba->fcf.current_rec.fabric_name[1],
1123 phba->fcf.current_rec.fabric_name[2],
1124 phba->fcf.current_rec.fabric_name[3],
1125 phba->fcf.current_rec.fabric_name[4],
1126 phba->fcf.current_rec.fabric_name[5],
1127 phba->fcf.current_rec.fabric_name[6],
1128 phba->fcf.current_rec.fabric_name[7]);
1129 lpfc_nlp_put(ndlp);
1130 spin_lock_irq(&phba->hbalock);
1131 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001132 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -04001133 spin_unlock_irq(&phba->hbalock);
1134 goto out;
1135 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001136 if (!rc) {
1137 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -04001138 if (phba->hba_flag & HBA_FIP_SUPPORT)
1139 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1140 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001141 "2769 FLOGI to FCF (x%x) "
1142 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -04001143 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001144 spin_lock_irq(&phba->hbalock);
1145 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001146 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -05001147 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001148 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001149 }
dea31012005-04-17 16:05:31 -05001150 }
1151
1152flogifail:
James Smart329f9bc2007-04-25 09:53:01 -04001153 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001154
James Smart858c9f62007-06-17 19:56:39 -05001155 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001156 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001157 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001158
1159 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001160 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001161 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04001162 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1163 IOERR_SLI_ABORTED) &&
1164 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1165 IOERR_SLI_DOWN))) &&
James Smart87af33f2007-10-27 13:37:43 -04001166 (phba->link_state != LPFC_CLEAR_LA)) {
1167 /* If FLOGI failed enable link interrupt. */
1168 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001169 }
dea31012005-04-17 16:05:31 -05001170out:
1171 lpfc_els_free_iocb(phba, cmdiocb);
1172}
1173
James Smarte59058c2008-08-24 21:49:00 -04001174/**
James Smart3621a712009-04-06 18:47:14 -04001175 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001176 * @vport: pointer to a host virtual N_Port data structure.
1177 * @ndlp: pointer to a node-list data structure.
1178 * @retry: number of retries to the command IOCB.
1179 *
1180 * This routine issues a Fabric Login (FLOGI) Request ELS command
1181 * for a @vport. The initiator service parameters are put into the payload
1182 * of the FLOGI Request IOCB and the top-level callback function pointer
1183 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1184 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1185 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1186 *
1187 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1188 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1189 * will be stored into the context1 field of the IOCB for the completion
1190 * callback function to the FLOGI ELS command.
1191 *
1192 * Return code
1193 * 0 - successfully issued flogi iocb for @vport
1194 * 1 - failed to issue flogi iocb for @vport
1195 **/
dea31012005-04-17 16:05:31 -05001196static int
James Smart2e0fef82007-06-17 19:56:36 -05001197lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001198 uint8_t retry)
1199{
James Smart2e0fef82007-06-17 19:56:36 -05001200 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001201 struct serv_parm *sp;
1202 IOCB_t *icmd;
1203 struct lpfc_iocbq *elsiocb;
1204 struct lpfc_sli_ring *pring;
1205 uint8_t *pcmd;
1206 uint16_t cmdsize;
1207 uint32_t tmo;
1208 int rc;
1209
1210 pring = &phba->sli.ring[LPFC_ELS_RING];
1211
James Smart92d7f7b2007-06-17 19:56:38 -05001212 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001213 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1214 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001215
James Smart488d1462006-03-07 15:02:37 -05001216 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001217 return 1;
dea31012005-04-17 16:05:31 -05001218
1219 icmd = &elsiocb->iocb;
1220 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1221
1222 /* For FLOGI request, remainder of payload is service parameters */
1223 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001224 pcmd += sizeof(uint32_t);
1225 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001226 sp = (struct serv_parm *) pcmd;
1227
1228 /* Setup CSPs accordingly for Fabric */
1229 sp->cmn.e_d_tov = 0;
1230 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05001231 sp->cmn.virtual_fabric_support = 0;
dea31012005-04-17 16:05:31 -05001232 sp->cls1.classValid = 0;
dea31012005-04-17 16:05:31 -05001233 if (sp->cmn.fcphLow < FC_PH3)
1234 sp->cmn.fcphLow = FC_PH3;
1235 if (sp->cmn.fcphHigh < FC_PH3)
1236 sp->cmn.fcphHigh = FC_PH3;
1237
James Smartc31098c2011-04-16 11:03:33 -04001238 if (phba->sli_rev == LPFC_SLI_REV4) {
1239 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1240 LPFC_SLI_INTF_IF_TYPE_0) {
1241 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1242 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1243 /* FLOGI needs to be 3 for WQE FCFI */
1244 /* Set the fcfi to the fcfi we registered with */
1245 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1246 }
James Smart0f378872012-10-31 14:45:01 -04001247 /* Can't do SLI4 class2 without support sequence coalescing */
1248 sp->cls2.classValid = 0;
1249 sp->cls2.seqDelivery = 0;
James Smart5248a742011-07-22 18:37:06 -04001250 } else {
James Smart0f378872012-10-31 14:45:01 -04001251 /* Historical, setting sequential-delivery bit for SLI3 */
1252 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1253 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
James Smart5248a742011-07-22 18:37:06 -04001254 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1255 sp->cmn.request_multiple_Nport = 1;
1256 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1257 icmd->ulpCt_h = 1;
1258 icmd->ulpCt_l = 0;
1259 } else
1260 sp->cmn.request_multiple_Nport = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001261 }
1262
James Smart76a95d72010-11-20 23:11:48 -05001263 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001264 icmd->un.elsreq64.myID = 0;
1265 icmd->un.elsreq64.fl = 1;
1266 }
1267
dea31012005-04-17 16:05:31 -05001268 tmo = phba->fc_ratov;
1269 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001270 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001271 phba->fc_ratov = tmo;
1272
1273 phba->fc_stat.elsXmitFLOGI++;
1274 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001275
1276 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1277 "Issue FLOGI: opt:x%x",
1278 phba->sli3_options, 0, 0);
1279
James Smart92d7f7b2007-06-17 19:56:38 -05001280 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001281 if (rc == IOCB_ERROR) {
1282 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001283 return 1;
dea31012005-04-17 16:05:31 -05001284 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001285 return 0;
dea31012005-04-17 16:05:31 -05001286}
1287
James Smarte59058c2008-08-24 21:49:00 -04001288/**
James Smart3621a712009-04-06 18:47:14 -04001289 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001290 * @phba: pointer to lpfc hba data structure.
1291 *
1292 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1293 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1294 * list and issues an abort IOCB commond on each outstanding IOCB that
1295 * contains a active Fabric_DID ndlp. Note that this function is to issue
1296 * the abort IOCB command on all the outstanding IOCBs, thus when this
1297 * function returns, it does not guarantee all the IOCBs are actually aborted.
1298 *
1299 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001300 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001301 **/
dea31012005-04-17 16:05:31 -05001302int
James Smart2e0fef82007-06-17 19:56:36 -05001303lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001304{
1305 struct lpfc_sli_ring *pring;
1306 struct lpfc_iocbq *iocb, *next_iocb;
1307 struct lpfc_nodelist *ndlp;
1308 IOCB_t *icmd;
1309
1310 /* Abort outstanding I/O on NPort <nlp_DID> */
1311 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001312 "0201 Abort outstanding I/O on NPort x%x\n",
1313 Fabric_DID);
dea31012005-04-17 16:05:31 -05001314
1315 pring = &phba->sli.ring[LPFC_ELS_RING];
1316
1317 /*
1318 * Check the txcmplq for an iocb that matches the nport the driver is
1319 * searching for.
1320 */
James Smart2e0fef82007-06-17 19:56:36 -05001321 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001322 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1323 icmd = &iocb->iocb;
James Smart1b511972011-12-13 13:23:09 -05001324 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
dea31012005-04-17 16:05:31 -05001325 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001326 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1327 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001328 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001329 }
1330 }
James Smart2e0fef82007-06-17 19:56:36 -05001331 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001332
1333 return 0;
1334}
1335
James Smarte59058c2008-08-24 21:49:00 -04001336/**
James Smart3621a712009-04-06 18:47:14 -04001337 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001338 * @vport: pointer to a host virtual N_Port data structure.
1339 *
1340 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1341 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1342 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1343 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1344 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1345 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1346 * @vport.
1347 *
1348 * Return code
1349 * 0 - failed to issue initial flogi for @vport
1350 * 1 - successfully issued initial flogi for @vport
1351 **/
dea31012005-04-17 16:05:31 -05001352int
James Smart2e0fef82007-06-17 19:56:36 -05001353lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001354{
James Smart2e0fef82007-06-17 19:56:36 -05001355 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001356 struct lpfc_nodelist *ndlp;
1357
James Smart98c9ea52007-10-27 13:37:33 -04001358 vport->port_state = LPFC_FLOGI;
1359 lpfc_set_disctmo(vport);
1360
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001361 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001362 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001363 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001364 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001365 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1366 if (!ndlp)
1367 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001368 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001369 /* Set the node type */
1370 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001371 /* Put ndlp onto node list */
1372 lpfc_enqueue_node(vport, ndlp);
1373 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1374 /* re-setup ndlp without removing from node list */
1375 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1376 if (!ndlp)
1377 return 0;
dea31012005-04-17 16:05:31 -05001378 }
James Smart87af33f2007-10-27 13:37:43 -04001379
James Smart5ac6b302010-10-22 11:05:36 -04001380 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001381 /* This decrement of reference count to node shall kick off
1382 * the release of the node.
1383 */
James Smart329f9bc2007-04-25 09:53:01 -04001384 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001385 return 0;
1386 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001387 return 1;
dea31012005-04-17 16:05:31 -05001388}
1389
James Smarte59058c2008-08-24 21:49:00 -04001390/**
James Smart3621a712009-04-06 18:47:14 -04001391 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001392 * @vport: pointer to a host virtual N_Port data structure.
1393 *
1394 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1395 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1396 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1397 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1398 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1399 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1400 * @vport.
1401 *
1402 * Return code
1403 * 0 - failed to issue initial fdisc for @vport
1404 * 1 - successfully issued initial fdisc for @vport
1405 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001406int
1407lpfc_initial_fdisc(struct lpfc_vport *vport)
1408{
1409 struct lpfc_hba *phba = vport->phba;
1410 struct lpfc_nodelist *ndlp;
1411
1412 /* First look for the Fabric ndlp */
1413 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1414 if (!ndlp) {
1415 /* Cannot find existing Fabric ndlp, so allocate a new one */
1416 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1417 if (!ndlp)
1418 return 0;
1419 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001420 /* Put ndlp onto node list */
1421 lpfc_enqueue_node(vport, ndlp);
1422 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1423 /* re-setup ndlp without removing from node list */
1424 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1425 if (!ndlp)
1426 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001427 }
James Smarte47c9092008-02-08 18:49:26 -05001428
James Smart92d7f7b2007-06-17 19:56:38 -05001429 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001430 /* decrement node reference count to trigger the release of
1431 * the node.
1432 */
James Smart92d7f7b2007-06-17 19:56:38 -05001433 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001434 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001435 }
1436 return 1;
1437}
James Smart87af33f2007-10-27 13:37:43 -04001438
James Smarte59058c2008-08-24 21:49:00 -04001439/**
James Smart3621a712009-04-06 18:47:14 -04001440 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001441 * @vport: pointer to a host virtual N_Port data structure.
1442 *
1443 * This routine checks whether there are more remaining Port Logins
1444 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1445 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1446 * to issue ELS PLOGIs up to the configured discover threads with the
1447 * @vport (@vport->cfg_discovery_threads). The function also decrement
1448 * the @vport's num_disc_node by 1 if it is not already 0.
1449 **/
James Smart87af33f2007-10-27 13:37:43 -04001450void
James Smart2e0fef82007-06-17 19:56:36 -05001451lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001452{
1453 int sentplogi;
1454
James Smart2e0fef82007-06-17 19:56:36 -05001455 if (vport->num_disc_nodes)
1456 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001457
1458 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001459 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1460 "0232 Continue discovery with %d PLOGIs to go "
1461 "Data: x%x x%x x%x\n",
1462 vport->num_disc_nodes, vport->fc_plogi_cnt,
1463 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001464 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001465 if (vport->fc_flag & FC_NLP_MORE)
1466 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1467 sentplogi = lpfc_els_disc_plogi(vport);
1468
dea31012005-04-17 16:05:31 -05001469 return;
1470}
1471
James Smarte59058c2008-08-24 21:49:00 -04001472/**
James Smart3621a712009-04-06 18:47:14 -04001473 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001474 * @phba: pointer to lpfc hba data structure.
1475 * @prsp: pointer to response IOCB payload.
1476 * @ndlp: pointer to a node-list data structure.
1477 *
1478 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1479 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1480 * The following cases are considered N_Port confirmed:
1481 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1482 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1483 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1484 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1485 * 1) if there is a node on vport list other than the @ndlp with the same
1486 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1487 * on that node to release the RPI associated with the node; 2) if there is
1488 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1489 * into, a new node shall be allocated (or activated). In either case, the
1490 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1491 * be released and the new_ndlp shall be put on to the vport node list and
1492 * its pointer returned as the confirmed node.
1493 *
1494 * Note that before the @ndlp got "released", the keepDID from not-matching
1495 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1496 * of the @ndlp. This is because the release of @ndlp is actually to put it
1497 * into an inactive state on the vport node list and the vport node list
1498 * management algorithm does not allow two node with a same DID.
1499 *
1500 * Return code
1501 * pointer to the PLOGI N_Port @ndlp
1502 **/
James Smart488d1462006-03-07 15:02:37 -05001503static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001504lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001505 struct lpfc_nodelist *ndlp)
1506{
James Smart2e0fef82007-06-17 19:56:36 -05001507 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001508 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001509 struct lpfc_rport_data *rdata;
1510 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001511 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001512 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001513 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001514 int put_node;
1515 int put_rport;
James Smart19ca7602010-11-20 23:11:55 -05001516 struct lpfc_node_rrqs rrq;
James Smart488d1462006-03-07 15:02:37 -05001517
James Smart2fb9bd82006-12-02 13:33:57 -05001518 /* Fabric nodes can have the same WWPN so we don't bother searching
1519 * by WWPN. Just return the ndlp that was given to us.
1520 */
1521 if (ndlp->nlp_type & NLP_FABRIC)
1522 return ndlp;
1523
James Smart92d7f7b2007-06-17 19:56:38 -05001524 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001525 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001526
James Smart685f0bf2007-04-25 09:53:08 -04001527 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001528 * we have for that ndlp. If not, we have some work to do.
1529 */
James Smart2e0fef82007-06-17 19:56:36 -05001530 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001531
James Smarte47c9092008-02-08 18:49:26 -05001532 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001533 return ndlp;
James Smart19ca7602010-11-20 23:11:55 -05001534 memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap));
James Smart488d1462006-03-07 15:02:37 -05001535
James Smart34f5ad82012-08-03 12:35:03 -04001536 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1537 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1538 ndlp, ndlp->nlp_DID, new_ndlp);
1539
James Smart488d1462006-03-07 15:02:37 -05001540 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001541 rc = memcmp(&ndlp->nlp_portname, name,
1542 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001543 if (!rc)
1544 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001545 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1546 if (!new_ndlp)
1547 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001548 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001549 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001550 rc = memcmp(&ndlp->nlp_portname, name,
1551 sizeof(struct lpfc_name));
1552 if (!rc)
1553 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001554 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1555 NLP_STE_UNUSED_NODE);
1556 if (!new_ndlp)
1557 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001558 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001559 if (phba->sli_rev == LPFC_SLI_REV4)
1560 memcpy(&rrq.xri_bitmap,
1561 &new_ndlp->active_rrqs.xri_bitmap,
1562 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1563 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001564 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001565 if (phba->sli_rev == LPFC_SLI_REV4)
1566 memcpy(&rrq.xri_bitmap,
1567 &new_ndlp->active_rrqs.xri_bitmap,
1568 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1569 }
James Smart488d1462006-03-07 15:02:37 -05001570
James Smart2e0fef82007-06-17 19:56:36 -05001571 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001572 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001573 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001574 if (phba->sli_rev == LPFC_SLI_REV4)
1575 memcpy(new_ndlp->active_rrqs.xri_bitmap,
1576 &ndlp->active_rrqs.xri_bitmap,
1577 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart0ff10d42008-01-11 01:52:36 -05001578
1579 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1580 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1581 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1582
James Smarte47c9092008-02-08 18:49:26 -05001583 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001584 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001585
James Smart2e0fef82007-06-17 19:56:36 -05001586 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001587 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1588 /* The new_ndlp is replacing ndlp totally, so we need
1589 * to put ndlp on UNUSED list and try to free it.
1590 */
James Smart34f5ad82012-08-03 12:35:03 -04001591 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1592 "3179 PLOGI confirm NEW: %x %x\n",
1593 new_ndlp->nlp_DID, keepDID);
James Smart0ff10d42008-01-11 01:52:36 -05001594
1595 /* Fix up the rport accordingly */
1596 rport = ndlp->rport;
1597 if (rport) {
1598 rdata = rport->dd_data;
1599 if (rdata->pnode == ndlp) {
1600 lpfc_nlp_put(ndlp);
1601 ndlp->rport = NULL;
1602 rdata->pnode = lpfc_nlp_get(new_ndlp);
1603 new_ndlp->rport = rport;
1604 }
1605 new_ndlp->nlp_type = ndlp->nlp_type;
1606 }
James Smart58da1ff2008-04-07 10:15:56 -04001607 /* We shall actually free the ndlp with both nlp_DID and
1608 * nlp_portname fields equals 0 to avoid any ndlp on the
1609 * nodelist never to be used.
1610 */
1611 if (ndlp->nlp_DID == 0) {
1612 spin_lock_irq(&phba->ndlp_lock);
1613 NLP_SET_FREE_REQ(ndlp);
1614 spin_unlock_irq(&phba->ndlp_lock);
1615 }
James Smart0ff10d42008-01-11 01:52:36 -05001616
James Smart58da1ff2008-04-07 10:15:56 -04001617 /* Two ndlps cannot have the same did on the nodelist */
1618 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001619 if (phba->sli_rev == LPFC_SLI_REV4)
1620 memcpy(&ndlp->active_rrqs.xri_bitmap,
1621 &rrq.xri_bitmap,
1622 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001623 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001624 }
James Smart92795652006-07-06 15:50:02 -04001625 else {
James Smart34f5ad82012-08-03 12:35:03 -04001626 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1627 "3180 PLOGI confirm SWAP: %x %x\n",
1628 new_ndlp->nlp_DID, keepDID);
1629
James Smart2e0fef82007-06-17 19:56:36 -05001630 lpfc_unreg_rpi(vport, ndlp);
James Smart34f5ad82012-08-03 12:35:03 -04001631
James Smart58da1ff2008-04-07 10:15:56 -04001632 /* Two ndlps cannot have the same did */
1633 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001634 if (phba->sli_rev == LPFC_SLI_REV4)
1635 memcpy(&ndlp->active_rrqs.xri_bitmap,
1636 &rrq.xri_bitmap,
1637 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart34f5ad82012-08-03 12:35:03 -04001638
James Smart38b92ef2010-08-04 16:11:39 -04001639 /* Since we are swapping the ndlp passed in with the new one
James Smart34f5ad82012-08-03 12:35:03 -04001640 * and the did has already been swapped, copy over state.
1641 * The new WWNs are already in new_ndlp since thats what
1642 * we looked it up by in the begining of this routine.
James Smart38b92ef2010-08-04 16:11:39 -04001643 */
James Smart38b92ef2010-08-04 16:11:39 -04001644 new_ndlp->nlp_state = ndlp->nlp_state;
James Smart34f5ad82012-08-03 12:35:03 -04001645
1646 /* Since we are switching over to the new_ndlp, the old
1647 * ndlp should be put in the NPR state, unless we have
1648 * already started re-discovery on it.
1649 */
1650 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1651 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1652 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1653
James Smart38b92ef2010-08-04 16:11:39 -04001654 /* Fix up the rport accordingly */
1655 rport = ndlp->rport;
1656 if (rport) {
1657 rdata = rport->dd_data;
1658 put_node = rdata->pnode != NULL;
1659 put_rport = ndlp->rport != NULL;
1660 rdata->pnode = NULL;
1661 ndlp->rport = NULL;
1662 if (put_node)
1663 lpfc_nlp_put(ndlp);
1664 if (put_rport)
1665 put_device(&rport->dev);
1666 }
James Smart92795652006-07-06 15:50:02 -04001667 }
James Smart488d1462006-03-07 15:02:37 -05001668 return new_ndlp;
1669}
1670
James Smarte59058c2008-08-24 21:49:00 -04001671/**
James Smart3621a712009-04-06 18:47:14 -04001672 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001673 * @vport: pointer to a host virtual N_Port data structure.
1674 *
1675 * This routine checks whether more Registration State Change
1676 * Notifications (RSCNs) came in while the discovery state machine was in
1677 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1678 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1679 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1680 * handling the RSCNs.
1681 **/
James Smart87af33f2007-10-27 13:37:43 -04001682void
1683lpfc_end_rscn(struct lpfc_vport *vport)
1684{
1685 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1686
1687 if (vport->fc_flag & FC_RSCN_MODE) {
1688 /*
1689 * Check to see if more RSCNs came in while we were
1690 * processing this one.
1691 */
1692 if (vport->fc_rscn_id_cnt ||
1693 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1694 lpfc_els_handle_rscn(vport);
1695 else {
1696 spin_lock_irq(shost->host_lock);
1697 vport->fc_flag &= ~FC_RSCN_MODE;
1698 spin_unlock_irq(shost->host_lock);
1699 }
1700 }
1701}
1702
James Smarte59058c2008-08-24 21:49:00 -04001703/**
James Smart19ca7602010-11-20 23:11:55 -05001704 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1705 * @phba: pointer to lpfc hba data structure.
1706 * @cmdiocb: pointer to lpfc command iocb data structure.
1707 * @rspiocb: pointer to lpfc response iocb data structure.
1708 *
1709 * This routine will call the clear rrq function to free the rrq and
1710 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1711 * exist then the clear_rrq is still called because the rrq needs to
1712 * be freed.
1713 **/
1714
1715static void
1716lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1717 struct lpfc_iocbq *rspiocb)
1718{
1719 struct lpfc_vport *vport = cmdiocb->vport;
1720 IOCB_t *irsp;
1721 struct lpfc_nodelist *ndlp;
1722 struct lpfc_node_rrq *rrq;
1723
1724 /* we pass cmdiocb to state machine which needs rspiocb as well */
1725 rrq = cmdiocb->context_un.rrq;
1726 cmdiocb->context_un.rsp_iocb = rspiocb;
1727
1728 irsp = &rspiocb->iocb;
1729 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1730 "RRQ cmpl: status:x%x/x%x did:x%x",
1731 irsp->ulpStatus, irsp->un.ulpWord[4],
1732 irsp->un.elsreq64.remoteID);
1733
1734 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1735 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1736 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1737 "2882 RRQ completes to NPort x%x "
1738 "with no ndlp. Data: x%x x%x x%x\n",
1739 irsp->un.elsreq64.remoteID,
1740 irsp->ulpStatus, irsp->un.ulpWord[4],
1741 irsp->ulpIoTag);
1742 goto out;
1743 }
1744
1745 /* rrq completes to NPort <nlp_DID> */
1746 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1747 "2880 RRQ completes to NPort x%x "
1748 "Data: x%x x%x x%x x%x x%x\n",
1749 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1750 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1751
1752 if (irsp->ulpStatus) {
1753 /* Check for retry */
1754 /* RRQ failed Don't print the vport to vport rjts */
1755 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1756 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1757 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1758 (phba)->pport->cfg_log_verbose & LOG_ELS)
1759 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1760 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1761 ndlp->nlp_DID, irsp->ulpStatus,
1762 irsp->un.ulpWord[4]);
1763 }
1764out:
1765 if (rrq)
1766 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1767 lpfc_els_free_iocb(phba, cmdiocb);
1768 return;
1769}
1770/**
James Smart3621a712009-04-06 18:47:14 -04001771 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001772 * @phba: pointer to lpfc hba data structure.
1773 * @cmdiocb: pointer to lpfc command iocb data structure.
1774 * @rspiocb: pointer to lpfc response iocb data structure.
1775 *
1776 * This routine is the completion callback function for issuing the Port
1777 * Login (PLOGI) command. For PLOGI completion, there must be an active
1778 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001779 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001780 * ignored and command IOCB released. The PLOGI response IOCB status is
1781 * checked for error conditons. If there is error status reported, PLOGI
1782 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1783 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1784 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1785 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1786 * there are additional N_Port nodes with the vport that need to perform
1787 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1788 * PLOGIs.
1789 **/
dea31012005-04-17 16:05:31 -05001790static void
James Smart2e0fef82007-06-17 19:56:36 -05001791lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1792 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001793{
James Smart2e0fef82007-06-17 19:56:36 -05001794 struct lpfc_vport *vport = cmdiocb->vport;
1795 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001796 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001797 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001798 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001799 int disc, rc, did, type;
1800
dea31012005-04-17 16:05:31 -05001801 /* we pass cmdiocb to state machine which needs rspiocb as well */
1802 cmdiocb->context_un.rsp_iocb = rspiocb;
1803
1804 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001805 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1806 "PLOGI cmpl: status:x%x/x%x did:x%x",
1807 irsp->ulpStatus, irsp->un.ulpWord[4],
1808 irsp->un.elsreq64.remoteID);
1809
James Smart2e0fef82007-06-17 19:56:36 -05001810 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001811 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001812 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1813 "0136 PLOGI completes to NPort x%x "
1814 "with no ndlp. Data: x%x x%x x%x\n",
1815 irsp->un.elsreq64.remoteID,
1816 irsp->ulpStatus, irsp->un.ulpWord[4],
1817 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001818 goto out;
James Smarted957682007-06-17 19:56:37 -05001819 }
dea31012005-04-17 16:05:31 -05001820
1821 /* Since ndlp can be freed in the disc state machine, note if this node
1822 * is being used during discovery.
1823 */
James Smart2e0fef82007-06-17 19:56:36 -05001824 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001825 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001826 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001827 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001828 rc = 0;
1829
1830 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001831 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1832 "0102 PLOGI completes to NPort x%x "
1833 "Data: x%x x%x x%x x%x x%x\n",
1834 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1835 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001836 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001837 if (lpfc_els_chk_latt(vport)) {
1838 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001839 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001840 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001841 goto out;
1842 }
1843
1844 /* ndlp could be freed in DSM, save these values now */
1845 type = ndlp->nlp_type;
1846 did = ndlp->nlp_DID;
1847
1848 if (irsp->ulpStatus) {
1849 /* Check for retry */
1850 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1851 /* ELS command is being retried */
1852 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001853 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001854 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001855 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001856 }
1857 goto out;
1858 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001859 /* PLOGI failed Don't print the vport to vport rjts */
1860 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1861 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1862 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1863 (phba)->pport->cfg_log_verbose & LOG_ELS)
1864 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001865 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1866 ndlp->nlp_DID, irsp->ulpStatus,
1867 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001868 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001869 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001870 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001871 else
James Smart2e0fef82007-06-17 19:56:36 -05001872 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001873 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001874 } else {
1875 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001876 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001877 cmdiocb->context2)->list.next,
1878 struct lpfc_dmabuf, list);
1879 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001880 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001881 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001882 }
1883
James Smart2e0fef82007-06-17 19:56:36 -05001884 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001885 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001886 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001887
James Smart2e0fef82007-06-17 19:56:36 -05001888 if (vport->num_disc_nodes == 0) {
1889 spin_lock_irq(shost->host_lock);
1890 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1891 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001892
James Smart2e0fef82007-06-17 19:56:36 -05001893 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001894 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001895 }
1896 }
1897
1898out:
1899 lpfc_els_free_iocb(phba, cmdiocb);
1900 return;
1901}
1902
James Smarte59058c2008-08-24 21:49:00 -04001903/**
James Smart3621a712009-04-06 18:47:14 -04001904 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001905 * @vport: pointer to a host virtual N_Port data structure.
1906 * @did: destination port identifier.
1907 * @retry: number of retries to the command IOCB.
1908 *
1909 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1910 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1911 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1912 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1913 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1914 *
1915 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1916 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1917 * will be stored into the context1 field of the IOCB for the completion
1918 * callback function to the PLOGI ELS command.
1919 *
1920 * Return code
1921 * 0 - Successfully issued a plogi for @vport
1922 * 1 - failed to issue a plogi for @vport
1923 **/
dea31012005-04-17 16:05:31 -05001924int
James Smart2e0fef82007-06-17 19:56:36 -05001925lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001926{
James Smart2e0fef82007-06-17 19:56:36 -05001927 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001928 struct serv_parm *sp;
1929 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001930 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001931 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001932 struct lpfc_sli *psli;
1933 uint8_t *pcmd;
1934 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001935 int ret;
dea31012005-04-17 16:05:31 -05001936
1937 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001938
James Smart98c9ea52007-10-27 13:37:33 -04001939 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001940 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1941 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001942
James Smarte47c9092008-02-08 18:49:26 -05001943 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001944 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001945 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001946 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001947 if (!elsiocb)
1948 return 1;
dea31012005-04-17 16:05:31 -05001949
1950 icmd = &elsiocb->iocb;
1951 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1952
1953 /* For PLOGI request, remainder of payload is service parameters */
1954 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001955 pcmd += sizeof(uint32_t);
1956 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001957 sp = (struct serv_parm *) pcmd;
1958
James Smart5ac6b302010-10-22 11:05:36 -04001959 /*
1960 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1961 * to device on remote loops work.
1962 */
1963 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1964 sp->cmn.altBbCredit = 1;
1965
dea31012005-04-17 16:05:31 -05001966 if (sp->cmn.fcphLow < FC_PH_4_3)
1967 sp->cmn.fcphLow = FC_PH_4_3;
1968
1969 if (sp->cmn.fcphHigh < FC_PH3)
1970 sp->cmn.fcphHigh = FC_PH3;
1971
James Smart858c9f62007-06-17 19:56:39 -05001972 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1973 "Issue PLOGI: did:x%x",
1974 did, 0, 0);
1975
dea31012005-04-17 16:05:31 -05001976 phba->fc_stat.elsXmitPLOGI++;
1977 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001978 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001979
1980 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001981 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001982 return 1;
dea31012005-04-17 16:05:31 -05001983 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001984 return 0;
dea31012005-04-17 16:05:31 -05001985}
1986
James Smarte59058c2008-08-24 21:49:00 -04001987/**
James Smart3621a712009-04-06 18:47:14 -04001988 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001989 * @phba: pointer to lpfc hba data structure.
1990 * @cmdiocb: pointer to lpfc command iocb data structure.
1991 * @rspiocb: pointer to lpfc response iocb data structure.
1992 *
1993 * This routine is the completion callback function for a Process Login
1994 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1995 * status. If there is error status reported, PRLI retry shall be attempted
1996 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1997 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1998 * ndlp to mark the PRLI completion.
1999 **/
dea31012005-04-17 16:05:31 -05002000static void
James Smart2e0fef82007-06-17 19:56:36 -05002001lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2002 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002003{
James Smart2e0fef82007-06-17 19:56:36 -05002004 struct lpfc_vport *vport = cmdiocb->vport;
2005 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002006 IOCB_t *irsp;
2007 struct lpfc_sli *psli;
2008 struct lpfc_nodelist *ndlp;
2009
2010 psli = &phba->sli;
2011 /* we pass cmdiocb to state machine which needs rspiocb as well */
2012 cmdiocb->context_un.rsp_iocb = rspiocb;
2013
2014 irsp = &(rspiocb->iocb);
2015 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05002016 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002017 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002018 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002019
James Smart858c9f62007-06-17 19:56:39 -05002020 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2021 "PRLI cmpl: status:x%x/x%x did:x%x",
2022 irsp->ulpStatus, irsp->un.ulpWord[4],
2023 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002024 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002025 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2026 "0103 PRLI completes to NPort x%x "
2027 "Data: x%x x%x x%x x%x\n",
2028 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2029 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002030
James Smart2e0fef82007-06-17 19:56:36 -05002031 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05002032 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002033 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002034 goto out;
2035
2036 if (irsp->ulpStatus) {
2037 /* Check for retry */
2038 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2039 /* ELS command is being retried */
2040 goto out;
2041 }
2042 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05002043 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2044 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
2045 ndlp->nlp_DID, irsp->ulpStatus,
2046 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002047 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002048 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002049 goto out;
James Smarte47c9092008-02-08 18:49:26 -05002050 else
James Smart2e0fef82007-06-17 19:56:36 -05002051 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002052 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05002053 } else
dea31012005-04-17 16:05:31 -05002054 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002055 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002056 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05002057out:
2058 lpfc_els_free_iocb(phba, cmdiocb);
2059 return;
2060}
2061
James Smarte59058c2008-08-24 21:49:00 -04002062/**
James Smart3621a712009-04-06 18:47:14 -04002063 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04002064 * @vport: pointer to a host virtual N_Port data structure.
2065 * @ndlp: pointer to a node-list data structure.
2066 * @retry: number of retries to the command IOCB.
2067 *
2068 * This routine issues a Process Login (PRLI) ELS command for the
2069 * @vport. The PRLI service parameters are set up in the payload of the
2070 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2071 * is put to the IOCB completion callback func field before invoking the
2072 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2073 *
2074 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2075 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2076 * will be stored into the context1 field of the IOCB for the completion
2077 * callback function to the PRLI ELS command.
2078 *
2079 * Return code
2080 * 0 - successfully issued prli iocb command for @vport
2081 * 1 - failed to issue prli iocb command for @vport
2082 **/
dea31012005-04-17 16:05:31 -05002083int
James Smart2e0fef82007-06-17 19:56:36 -05002084lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002085 uint8_t retry)
2086{
James Smart2e0fef82007-06-17 19:56:36 -05002087 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2088 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002089 PRLI *npr;
2090 IOCB_t *icmd;
2091 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002092 uint8_t *pcmd;
2093 uint16_t cmdsize;
2094
James Smart92d7f7b2007-06-17 19:56:38 -05002095 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05002096 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2097 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05002098 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002099 return 1;
dea31012005-04-17 16:05:31 -05002100
2101 icmd = &elsiocb->iocb;
2102 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2103
2104 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05002105 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05002106 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05002107 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002108
2109 /* For PRLI, remainder of payload is PRLI parameter page */
2110 npr = (PRLI *) pcmd;
2111 /*
2112 * If our firmware version is 3.20 or later,
2113 * set the following bits for FC-TAPE support.
2114 */
2115 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2116 npr->ConfmComplAllowed = 1;
2117 npr->Retry = 1;
2118 npr->TaskRetryIdReq = 1;
2119 }
2120 npr->estabImagePair = 1;
2121 npr->readXferRdyDis = 1;
2122
2123 /* For FCP support */
2124 npr->prliType = PRLI_FCP_TYPE;
2125 npr->initiatorFunc = 1;
2126
James Smart858c9f62007-06-17 19:56:39 -05002127 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2128 "Issue PRLI: did:x%x",
2129 ndlp->nlp_DID, 0, 0);
2130
dea31012005-04-17 16:05:31 -05002131 phba->fc_stat.elsXmitPRLI++;
2132 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05002133 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002134 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002135 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002136 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2137 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002138 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002139 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002140 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002141 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002142 return 1;
dea31012005-04-17 16:05:31 -05002143 }
James Smart2e0fef82007-06-17 19:56:36 -05002144 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002145 return 0;
dea31012005-04-17 16:05:31 -05002146}
2147
James Smarte59058c2008-08-24 21:49:00 -04002148/**
James Smart3621a712009-04-06 18:47:14 -04002149 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04002150 * @vport: pointer to a host virtual N_Port data structure.
2151 *
2152 * This routine performs Registration State Change Notification (RSCN)
2153 * discovery for a @vport. If the @vport's node port recovery count is not
2154 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2155 * the nodes that need recovery. If none of the PLOGI were needed through
2156 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2157 * invoked to check and handle possible more RSCN came in during the period
2158 * of processing the current ones.
2159 **/
2160static void
2161lpfc_rscn_disc(struct lpfc_vport *vport)
2162{
2163 lpfc_can_disctmo(vport);
2164
2165 /* RSCN discovery */
2166 /* go thru NPR nodes and issue ELS PLOGIs */
2167 if (vport->fc_npr_cnt)
2168 if (lpfc_els_disc_plogi(vport))
2169 return;
2170
2171 lpfc_end_rscn(vport);
2172}
2173
2174/**
James Smart3621a712009-04-06 18:47:14 -04002175 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002176 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2177 *
2178 * This function is called when the final ADISC is completed during discovery.
2179 * This function handles clearing link attention or issuing reg_vpi depending
2180 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2181 * discovery.
2182 * This function is called with no locks held.
2183 **/
2184static void
2185lpfc_adisc_done(struct lpfc_vport *vport)
2186{
2187 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2188 struct lpfc_hba *phba = vport->phba;
2189
2190 /*
2191 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2192 * and continue discovery.
2193 */
2194 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002195 !(vport->fc_flag & FC_RSCN_MODE) &&
2196 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04002197 lpfc_issue_reg_vpi(phba, vport);
2198 return;
2199 }
2200 /*
2201 * For SLI2, we need to set port_state to READY
2202 * and continue discovery.
2203 */
2204 if (vport->port_state < LPFC_VPORT_READY) {
2205 /* If we get here, there is nothing to ADISC */
2206 if (vport->port_type == LPFC_PHYSICAL_PORT)
2207 lpfc_issue_clear_la(phba, vport);
2208 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2209 vport->num_disc_nodes = 0;
2210 /* go thru NPR list, issue ELS PLOGIs */
2211 if (vport->fc_npr_cnt)
2212 lpfc_els_disc_plogi(vport);
2213 if (!vport->num_disc_nodes) {
2214 spin_lock_irq(shost->host_lock);
2215 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2216 spin_unlock_irq(shost->host_lock);
2217 lpfc_can_disctmo(vport);
2218 lpfc_end_rscn(vport);
2219 }
2220 }
2221 vport->port_state = LPFC_VPORT_READY;
2222 } else
2223 lpfc_rscn_disc(vport);
2224}
2225
2226/**
James Smart3621a712009-04-06 18:47:14 -04002227 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002228 * @vport: pointer to a host virtual N_Port data structure.
2229 *
2230 * This routine determines whether there are more ndlps on a @vport
2231 * node list need to have Address Discover (ADISC) issued. If so, it will
2232 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2233 * remaining nodes which need to have ADISC sent.
2234 **/
James Smart0ff10d42008-01-11 01:52:36 -05002235void
James Smart2e0fef82007-06-17 19:56:36 -05002236lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002237{
2238 int sentadisc;
2239
James Smart2e0fef82007-06-17 19:56:36 -05002240 if (vport->num_disc_nodes)
2241 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002242 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002243 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2244 "0210 Continue discovery with %d ADISCs to go "
2245 "Data: x%x x%x x%x\n",
2246 vport->num_disc_nodes, vport->fc_adisc_cnt,
2247 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002248 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002249 if (vport->fc_flag & FC_NLP_MORE) {
2250 lpfc_set_disctmo(vport);
2251 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2252 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002253 }
James Smart90160e02008-08-24 21:49:45 -04002254 if (!vport->num_disc_nodes)
2255 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002256 return;
2257}
2258
James Smarte59058c2008-08-24 21:49:00 -04002259/**
James Smart3621a712009-04-06 18:47:14 -04002260 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002261 * @phba: pointer to lpfc hba data structure.
2262 * @cmdiocb: pointer to lpfc command iocb data structure.
2263 * @rspiocb: pointer to lpfc response iocb data structure.
2264 *
2265 * This routine is the completion function for issuing the Address Discover
2266 * (ADISC) command. It first checks to see whether link went down during
2267 * the discovery process. If so, the node will be marked as node port
2268 * recovery for issuing discover IOCB by the link attention handler and
2269 * exit. Otherwise, the response status is checked. If error was reported
2270 * in the response status, the ADISC command shall be retried by invoking
2271 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2272 * the response status, the state machine is invoked to set transition
2273 * with respect to NLP_EVT_CMPL_ADISC event.
2274 **/
dea31012005-04-17 16:05:31 -05002275static void
James Smart2e0fef82007-06-17 19:56:36 -05002276lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2277 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002278{
James Smart2e0fef82007-06-17 19:56:36 -05002279 struct lpfc_vport *vport = cmdiocb->vport;
2280 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002281 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002282 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002283 int disc;
dea31012005-04-17 16:05:31 -05002284
2285 /* we pass cmdiocb to state machine which needs rspiocb as well */
2286 cmdiocb->context_un.rsp_iocb = rspiocb;
2287
2288 irsp = &(rspiocb->iocb);
2289 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002290
James Smart858c9f62007-06-17 19:56:39 -05002291 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2292 "ADISC cmpl: status:x%x/x%x did:x%x",
2293 irsp->ulpStatus, irsp->un.ulpWord[4],
2294 ndlp->nlp_DID);
2295
dea31012005-04-17 16:05:31 -05002296 /* Since ndlp can be freed in the disc state machine, note if this node
2297 * is being used during discovery.
2298 */
James Smart2e0fef82007-06-17 19:56:36 -05002299 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002300 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002301 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002302 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002303 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002304 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2305 "0104 ADISC completes to NPort x%x "
2306 "Data: x%x x%x x%x x%x x%x\n",
2307 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2308 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002309 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002310 if (lpfc_els_chk_latt(vport)) {
2311 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002312 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002313 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002314 goto out;
2315 }
2316
2317 if (irsp->ulpStatus) {
2318 /* Check for retry */
2319 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2320 /* ELS command is being retried */
2321 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002322 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002323 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002324 spin_unlock_irq(shost->host_lock);
2325 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002326 }
2327 goto out;
2328 }
2329 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002330 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2331 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2332 ndlp->nlp_DID, irsp->ulpStatus,
2333 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002334 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002335 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002336 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002337 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002338 } else
dea31012005-04-17 16:05:31 -05002339 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002340 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002341 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002342
James Smart90160e02008-08-24 21:49:45 -04002343 /* Check to see if there are more ADISCs to be sent */
2344 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002345 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002346out:
2347 lpfc_els_free_iocb(phba, cmdiocb);
2348 return;
2349}
2350
James Smarte59058c2008-08-24 21:49:00 -04002351/**
James Smart3621a712009-04-06 18:47:14 -04002352 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002353 * @vport: pointer to a virtual N_Port data structure.
2354 * @ndlp: pointer to a node-list data structure.
2355 * @retry: number of retries to the command IOCB.
2356 *
2357 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2358 * @vport. It prepares the payload of the ADISC ELS command, updates the
2359 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2360 * to issue the ADISC ELS command.
2361 *
2362 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2363 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2364 * will be stored into the context1 field of the IOCB for the completion
2365 * callback function to the ADISC ELS command.
2366 *
2367 * Return code
2368 * 0 - successfully issued adisc
2369 * 1 - failed to issue adisc
2370 **/
dea31012005-04-17 16:05:31 -05002371int
James Smart2e0fef82007-06-17 19:56:36 -05002372lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002373 uint8_t retry)
2374{
James Smart2e0fef82007-06-17 19:56:36 -05002375 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2376 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002377 ADISC *ap;
2378 IOCB_t *icmd;
2379 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002380 uint8_t *pcmd;
2381 uint16_t cmdsize;
2382
James Smart92d7f7b2007-06-17 19:56:38 -05002383 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002384 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2385 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002386 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002387 return 1;
dea31012005-04-17 16:05:31 -05002388
2389 icmd = &elsiocb->iocb;
2390 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2391
2392 /* For ADISC request, remainder of payload is service parameters */
2393 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002394 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002395
2396 /* Fill in ADISC payload */
2397 ap = (ADISC *) pcmd;
2398 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002399 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2400 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002401 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002402
James Smart858c9f62007-06-17 19:56:39 -05002403 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2404 "Issue ADISC: did:x%x",
2405 ndlp->nlp_DID, 0, 0);
2406
dea31012005-04-17 16:05:31 -05002407 phba->fc_stat.elsXmitADISC++;
2408 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002409 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002410 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002411 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002412 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2413 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002414 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002415 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002416 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002417 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002418 return 1;
dea31012005-04-17 16:05:31 -05002419 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002420 return 0;
dea31012005-04-17 16:05:31 -05002421}
2422
James Smarte59058c2008-08-24 21:49:00 -04002423/**
James Smart3621a712009-04-06 18:47:14 -04002424 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002425 * @phba: pointer to lpfc hba data structure.
2426 * @cmdiocb: pointer to lpfc command iocb data structure.
2427 * @rspiocb: pointer to lpfc response iocb data structure.
2428 *
2429 * This routine is the completion function for issuing the ELS Logout (LOGO)
2430 * command. If no error status was reported from the LOGO response, the
2431 * state machine of the associated ndlp shall be invoked for transition with
2432 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2433 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2434 **/
dea31012005-04-17 16:05:31 -05002435static void
James Smart2e0fef82007-06-17 19:56:36 -05002436lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2437 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002438{
James Smart2e0fef82007-06-17 19:56:36 -05002439 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2440 struct lpfc_vport *vport = ndlp->vport;
2441 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002442 IOCB_t *irsp;
2443 struct lpfc_sli *psli;
James Smart92494142011-02-16 12:39:44 -05002444 struct lpfcMboxq *mbox;
James Smart086a3452012-08-14 14:25:21 -04002445 unsigned long flags;
2446 uint32_t skip_recovery = 0;
dea31012005-04-17 16:05:31 -05002447
2448 psli = &phba->sli;
2449 /* we pass cmdiocb to state machine which needs rspiocb as well */
2450 cmdiocb->context_un.rsp_iocb = rspiocb;
2451
2452 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002453 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002454 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002455 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002456
James Smart858c9f62007-06-17 19:56:39 -05002457 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2458 "LOGO cmpl: status:x%x/x%x did:x%x",
2459 irsp->ulpStatus, irsp->un.ulpWord[4],
2460 ndlp->nlp_DID);
James Smart086a3452012-08-14 14:25:21 -04002461
dea31012005-04-17 16:05:31 -05002462 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002463 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2464 "0105 LOGO completes to NPort x%x "
2465 "Data: x%x x%x x%x x%x\n",
2466 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2467 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002468
James Smart086a3452012-08-14 14:25:21 -04002469 if (lpfc_els_chk_latt(vport)) {
2470 skip_recovery = 1;
2471 goto out;
2472 }
2473
2474 /* Check to see if link went down during discovery */
James Smart92d7f7b2007-06-17 19:56:38 -05002475 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2476 /* NLP_EVT_DEVICE_RM should unregister the RPI
2477 * which should abort all outstanding IOs.
2478 */
2479 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2480 NLP_EVT_DEVICE_RM);
James Smart086a3452012-08-14 14:25:21 -04002481 skip_recovery = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002482 goto out;
2483 }
2484
dea31012005-04-17 16:05:31 -05002485 if (irsp->ulpStatus) {
2486 /* Check for retry */
James Smart086a3452012-08-14 14:25:21 -04002487 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
dea31012005-04-17 16:05:31 -05002488 /* ELS command is being retried */
James Smart086a3452012-08-14 14:25:21 -04002489 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002490 goto out;
James Smart086a3452012-08-14 14:25:21 -04002491 }
dea31012005-04-17 16:05:31 -05002492 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002493 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2494 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2495 ndlp->nlp_DID, irsp->ulpStatus,
2496 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002497 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart086a3452012-08-14 14:25:21 -04002498 if (lpfc_error_lost_link(irsp)) {
2499 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002500 goto out;
James Smart086a3452012-08-14 14:25:21 -04002501 }
2502 }
2503
2504 /* Call state machine. This will unregister the rpi if needed. */
2505 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2506
dea31012005-04-17 16:05:31 -05002507out:
2508 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92494142011-02-16 12:39:44 -05002509 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2510 if ((vport->fc_flag & FC_PT2PT) &&
2511 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2512 phba->pport->fc_myDID = 0;
2513 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2514 if (mbox) {
2515 lpfc_config_link(phba, mbox);
2516 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2517 mbox->vport = vport;
2518 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2519 MBX_NOT_FINISHED) {
2520 mempool_free(mbox, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04002521 skip_recovery = 1;
James Smart92494142011-02-16 12:39:44 -05002522 }
2523 }
2524 }
James Smart086a3452012-08-14 14:25:21 -04002525
2526 /*
2527 * If the node is a target, the handling attempts to recover the port.
2528 * For any other port type, the rpi is unregistered as an implicit
2529 * LOGO.
2530 */
2531 if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) {
2532 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2533 spin_lock_irqsave(shost->host_lock, flags);
2534 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2535 spin_unlock_irqrestore(shost->host_lock, flags);
2536
2537 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2538 "3187 LOGO completes to NPort x%x: Start "
2539 "Recovery Data: x%x x%x x%x x%x\n",
2540 ndlp->nlp_DID, irsp->ulpStatus,
2541 irsp->un.ulpWord[4], irsp->ulpTimeout,
2542 vport->num_disc_nodes);
2543 lpfc_disc_start(vport);
2544 }
dea31012005-04-17 16:05:31 -05002545 return;
2546}
2547
James Smarte59058c2008-08-24 21:49:00 -04002548/**
James Smart3621a712009-04-06 18:47:14 -04002549 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002550 * @vport: pointer to a virtual N_Port data structure.
2551 * @ndlp: pointer to a node-list data structure.
2552 * @retry: number of retries to the command IOCB.
2553 *
2554 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2555 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2556 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2557 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2558 *
2559 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2560 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2561 * will be stored into the context1 field of the IOCB for the completion
2562 * callback function to the LOGO ELS command.
2563 *
2564 * Return code
2565 * 0 - successfully issued logo
2566 * 1 - failed to issue logo
2567 **/
dea31012005-04-17 16:05:31 -05002568int
James Smart2e0fef82007-06-17 19:56:36 -05002569lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002570 uint8_t retry)
2571{
James Smart2e0fef82007-06-17 19:56:36 -05002572 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2573 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002574 IOCB_t *icmd;
2575 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002576 uint8_t *pcmd;
2577 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002578 int rc;
dea31012005-04-17 16:05:31 -05002579
James Smart98c9ea52007-10-27 13:37:33 -04002580 spin_lock_irq(shost->host_lock);
2581 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2582 spin_unlock_irq(shost->host_lock);
2583 return 0;
2584 }
2585 spin_unlock_irq(shost->host_lock);
2586
James Smart92d7f7b2007-06-17 19:56:38 -05002587 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002588 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2589 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002590 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002591 return 1;
dea31012005-04-17 16:05:31 -05002592
2593 icmd = &elsiocb->iocb;
2594 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2595 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002596 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002597
2598 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002599 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002600 pcmd += sizeof(uint32_t);
2601 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002602
James Smart858c9f62007-06-17 19:56:39 -05002603 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2604 "Issue LOGO: did:x%x",
2605 ndlp->nlp_DID, 0, 0);
2606
James Smart086a3452012-08-14 14:25:21 -04002607 /*
2608 * If we are issuing a LOGO, we may try to recover the remote NPort
2609 * by issuing a PLOGI later. Even though we issue ELS cmds by the
2610 * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
2611 * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
2612 * for that ELS cmd. To avoid this situation, lets get rid of the
2613 * RPI right now, before any ELS cmds are sent.
2614 */
2615 spin_lock_irq(shost->host_lock);
2616 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
2617 spin_unlock_irq(shost->host_lock);
2618 if (lpfc_unreg_rpi(vport, ndlp)) {
2619 lpfc_els_free_iocb(phba, elsiocb);
2620 return 0;
2621 }
2622
dea31012005-04-17 16:05:31 -05002623 phba->fc_stat.elsXmitLOGO++;
2624 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002625 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002626 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart086a3452012-08-14 14:25:21 -04002627 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
James Smart2e0fef82007-06-17 19:56:36 -05002628 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002629 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002630
2631 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002632 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002633 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002634 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002635 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002636 return 1;
dea31012005-04-17 16:05:31 -05002637 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002638 return 0;
dea31012005-04-17 16:05:31 -05002639}
2640
James Smarte59058c2008-08-24 21:49:00 -04002641/**
James Smart3621a712009-04-06 18:47:14 -04002642 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002643 * @phba: pointer to lpfc hba data structure.
2644 * @cmdiocb: pointer to lpfc command iocb data structure.
2645 * @rspiocb: pointer to lpfc response iocb data structure.
2646 *
2647 * This routine is a generic completion callback function for ELS commands.
2648 * Specifically, it is the callback function which does not need to perform
2649 * any command specific operations. It is currently used by the ELS command
2650 * issuing routines for the ELS State Change Request (SCR),
2651 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2652 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2653 * certain debug loggings, this callback function simply invokes the
2654 * lpfc_els_chk_latt() routine to check whether link went down during the
2655 * discovery process.
2656 **/
dea31012005-04-17 16:05:31 -05002657static void
James Smart2e0fef82007-06-17 19:56:36 -05002658lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2659 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002660{
James Smart2e0fef82007-06-17 19:56:36 -05002661 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002662 IOCB_t *irsp;
2663
2664 irsp = &rspiocb->iocb;
2665
James Smart858c9f62007-06-17 19:56:39 -05002666 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2667 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2668 irsp->ulpStatus, irsp->un.ulpWord[4],
2669 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002670 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002671 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2672 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2673 irsp->ulpIoTag, irsp->ulpStatus,
2674 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002675 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002676 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002677 lpfc_els_free_iocb(phba, cmdiocb);
2678 return;
2679}
2680
James Smarte59058c2008-08-24 21:49:00 -04002681/**
James Smart3621a712009-04-06 18:47:14 -04002682 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002683 * @vport: pointer to a host virtual N_Port data structure.
2684 * @nportid: N_Port identifier to the remote node.
2685 * @retry: number of retries to the command IOCB.
2686 *
2687 * This routine issues a State Change Request (SCR) to a fabric node
2688 * on a @vport. The remote node @nportid is passed into the function. It
2689 * first search the @vport node list to find the matching ndlp. If no such
2690 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2691 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2692 * routine is invoked to send the SCR IOCB.
2693 *
2694 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2695 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2696 * will be stored into the context1 field of the IOCB for the completion
2697 * callback function to the SCR ELS command.
2698 *
2699 * Return code
2700 * 0 - Successfully issued scr command
2701 * 1 - Failed to issue scr command
2702 **/
dea31012005-04-17 16:05:31 -05002703int
James Smart2e0fef82007-06-17 19:56:36 -05002704lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002705{
James Smart2e0fef82007-06-17 19:56:36 -05002706 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002707 IOCB_t *icmd;
2708 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002709 struct lpfc_sli *psli;
2710 uint8_t *pcmd;
2711 uint16_t cmdsize;
2712 struct lpfc_nodelist *ndlp;
2713
2714 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002715 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002716
James Smarte47c9092008-02-08 18:49:26 -05002717 ndlp = lpfc_findnode_did(vport, nportid);
2718 if (!ndlp) {
2719 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2720 if (!ndlp)
2721 return 1;
2722 lpfc_nlp_init(vport, ndlp, nportid);
2723 lpfc_enqueue_node(vport, ndlp);
2724 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2725 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2726 if (!ndlp)
2727 return 1;
2728 }
dea31012005-04-17 16:05:31 -05002729
James Smart2e0fef82007-06-17 19:56:36 -05002730 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2731 ndlp->nlp_DID, ELS_CMD_SCR);
2732
James Smart488d1462006-03-07 15:02:37 -05002733 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002734 /* This will trigger the release of the node just
2735 * allocated
2736 */
James Smart329f9bc2007-04-25 09:53:01 -04002737 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002738 return 1;
dea31012005-04-17 16:05:31 -05002739 }
2740
2741 icmd = &elsiocb->iocb;
2742 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2743
2744 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002745 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002746
2747 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002748 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002749 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2750
James Smart858c9f62007-06-17 19:56:39 -05002751 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2752 "Issue SCR: did:x%x",
2753 ndlp->nlp_DID, 0, 0);
2754
dea31012005-04-17 16:05:31 -05002755 phba->fc_stat.elsXmitSCR++;
2756 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002757 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2758 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002759 /* The additional lpfc_nlp_put will cause the following
2760 * lpfc_els_free_iocb routine to trigger the rlease of
2761 * the node.
2762 */
James Smart329f9bc2007-04-25 09:53:01 -04002763 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002764 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002765 return 1;
dea31012005-04-17 16:05:31 -05002766 }
James Smartfa4066b2008-01-11 01:53:27 -05002767 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2768 * trigger the release of node.
2769 */
James Smart329f9bc2007-04-25 09:53:01 -04002770 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002771 return 0;
dea31012005-04-17 16:05:31 -05002772}
2773
James Smarte59058c2008-08-24 21:49:00 -04002774/**
James Smart3621a712009-04-06 18:47:14 -04002775 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002776 * @vport: pointer to a host virtual N_Port data structure.
2777 * @nportid: N_Port identifier to the remote node.
2778 * @retry: number of retries to the command IOCB.
2779 *
2780 * This routine issues a Fibre Channel Address Resolution Response
2781 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2782 * is passed into the function. It first search the @vport node list to find
2783 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2784 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2785 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2786 *
2787 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2788 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2789 * will be stored into the context1 field of the IOCB for the completion
2790 * callback function to the PARPR ELS command.
2791 *
2792 * Return code
2793 * 0 - Successfully issued farpr command
2794 * 1 - Failed to issue farpr command
2795 **/
dea31012005-04-17 16:05:31 -05002796static int
James Smart2e0fef82007-06-17 19:56:36 -05002797lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002798{
James Smart2e0fef82007-06-17 19:56:36 -05002799 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002800 IOCB_t *icmd;
2801 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002802 struct lpfc_sli *psli;
2803 FARP *fp;
2804 uint8_t *pcmd;
2805 uint32_t *lp;
2806 uint16_t cmdsize;
2807 struct lpfc_nodelist *ondlp;
2808 struct lpfc_nodelist *ndlp;
2809
2810 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002811 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002812
James Smarte47c9092008-02-08 18:49:26 -05002813 ndlp = lpfc_findnode_did(vport, nportid);
2814 if (!ndlp) {
2815 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2816 if (!ndlp)
2817 return 1;
2818 lpfc_nlp_init(vport, ndlp, nportid);
2819 lpfc_enqueue_node(vport, ndlp);
2820 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2821 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2822 if (!ndlp)
2823 return 1;
2824 }
James Smart2e0fef82007-06-17 19:56:36 -05002825
2826 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2827 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002828 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002829 /* This will trigger the release of the node just
2830 * allocated
2831 */
James Smart329f9bc2007-04-25 09:53:01 -04002832 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002833 return 1;
dea31012005-04-17 16:05:31 -05002834 }
2835
2836 icmd = &elsiocb->iocb;
2837 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2838
2839 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002840 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002841
2842 /* Fill in FARPR payload */
2843 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002844 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002845 lp = (uint32_t *) pcmd;
2846 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002847 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002848 fp->Rflags = 0;
2849 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2850
James Smart92d7f7b2007-06-17 19:56:38 -05002851 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2852 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002853 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002854 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002855 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002856 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002857 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002858 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002859 }
2860
James Smart858c9f62007-06-17 19:56:39 -05002861 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2862 "Issue FARPR: did:x%x",
2863 ndlp->nlp_DID, 0, 0);
2864
dea31012005-04-17 16:05:31 -05002865 phba->fc_stat.elsXmitFARPR++;
2866 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002867 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2868 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002869 /* The additional lpfc_nlp_put will cause the following
2870 * lpfc_els_free_iocb routine to trigger the release of
2871 * the node.
2872 */
James Smart329f9bc2007-04-25 09:53:01 -04002873 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002874 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002875 return 1;
dea31012005-04-17 16:05:31 -05002876 }
James Smartfa4066b2008-01-11 01:53:27 -05002877 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2878 * trigger the release of the node.
2879 */
James Smart329f9bc2007-04-25 09:53:01 -04002880 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002881 return 0;
dea31012005-04-17 16:05:31 -05002882}
2883
James Smarte59058c2008-08-24 21:49:00 -04002884/**
James Smart3621a712009-04-06 18:47:14 -04002885 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002886 * @vport: pointer to a host virtual N_Port data structure.
2887 * @nlp: pointer to a node-list data structure.
2888 *
2889 * This routine cancels the timer with a delayed IOCB-command retry for
2890 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2891 * removes the ELS retry event if it presents. In addition, if the
2892 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2893 * commands are sent for the @vport's nodes that require issuing discovery
2894 * ADISC.
2895 **/
dea31012005-04-17 16:05:31 -05002896void
James Smart2e0fef82007-06-17 19:56:36 -05002897lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002898{
James Smart2e0fef82007-06-17 19:56:36 -05002899 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002900 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002901
James Smart0d2b6b82008-06-14 22:52:47 -04002902 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2903 return;
James Smart2e0fef82007-06-17 19:56:36 -05002904 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002905 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002906 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002907 del_timer_sync(&nlp->nlp_delayfunc);
2908 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002909 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002910 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002911 /* Decrement nlp reference count held for the delayed retry */
2912 evtp = &nlp->els_retry_evt;
2913 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2914 }
James Smartfdcebe22006-03-07 15:04:01 -05002915 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002916 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002917 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002918 spin_unlock_irq(shost->host_lock);
2919 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002920 if (vport->port_state < LPFC_VPORT_READY) {
2921 /* Check if there are more ADISCs to be sent */
2922 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002923 } else {
2924 /* Check if there are more PLOGIs to be sent */
2925 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002926 if (vport->num_disc_nodes == 0) {
2927 spin_lock_irq(shost->host_lock);
2928 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2929 spin_unlock_irq(shost->host_lock);
2930 lpfc_can_disctmo(vport);
2931 lpfc_end_rscn(vport);
2932 }
James Smartfdcebe22006-03-07 15:04:01 -05002933 }
2934 }
2935 }
2936 return;
2937}
2938
James Smarte59058c2008-08-24 21:49:00 -04002939/**
James Smart3621a712009-04-06 18:47:14 -04002940 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002941 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2942 *
2943 * This routine is invoked by the ndlp delayed-function timer to check
2944 * whether there is any pending ELS retry event(s) with the node. If not, it
2945 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2946 * adds the delayed events to the HBA work list and invokes the
2947 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2948 * event. Note that lpfc_nlp_get() is called before posting the event to
2949 * the work list to hold reference count of ndlp so that it guarantees the
2950 * reference to ndlp will still be available when the worker thread gets
2951 * to the event associated with the ndlp.
2952 **/
James Smartfdcebe22006-03-07 15:04:01 -05002953void
dea31012005-04-17 16:05:31 -05002954lpfc_els_retry_delay(unsigned long ptr)
2955{
James Smart2e0fef82007-06-17 19:56:36 -05002956 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2957 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002958 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002959 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002960 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002961
James Smart92d7f7b2007-06-17 19:56:38 -05002962 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002963 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002964 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002965 return;
2966 }
2967
James Smartfa4066b2008-01-11 01:53:27 -05002968 /* We need to hold the node by incrementing the reference
2969 * count until the queued work is done
2970 */
2971 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002972 if (evtp->evt_arg1) {
2973 evtp->evt = LPFC_EVT_ELS_RETRY;
2974 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002975 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002976 }
James Smart92d7f7b2007-06-17 19:56:38 -05002977 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002978 return;
2979}
2980
James Smarte59058c2008-08-24 21:49:00 -04002981/**
James Smart3621a712009-04-06 18:47:14 -04002982 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002983 * @ndlp: pointer to a node-list data structure.
2984 *
2985 * This routine is the worker-thread handler for processing the @ndlp delayed
2986 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2987 * the last ELS command from the associated ndlp and invokes the proper ELS
2988 * function according to the delayed ELS command to retry the command.
2989 **/
dea31012005-04-17 16:05:31 -05002990void
2991lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2992{
James Smart2e0fef82007-06-17 19:56:36 -05002993 struct lpfc_vport *vport = ndlp->vport;
2994 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2995 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002996
James Smart2e0fef82007-06-17 19:56:36 -05002997 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002998 did = ndlp->nlp_DID;
2999 cmd = ndlp->nlp_last_elscmd;
3000 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05003001
3002 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05003003 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003004 return;
3005 }
3006
3007 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003008 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05003009 /*
3010 * If a discovery event readded nlp_delayfunc after timer
3011 * firing and before processing the timer, cancel the
3012 * nlp_delayfunc.
3013 */
3014 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05003015 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04003016 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05003017
3018 switch (cmd) {
3019 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003020 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05003021 break;
3022 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003023 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003024 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003025 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003026 }
dea31012005-04-17 16:05:31 -05003027 break;
3028 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05003029 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003030 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003031 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003032 }
dea31012005-04-17 16:05:31 -05003033 break;
3034 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05003035 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003036 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003037 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003038 }
dea31012005-04-17 16:05:31 -05003039 break;
3040 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05003041 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003042 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04003043 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003044 }
dea31012005-04-17 16:05:31 -05003045 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003046 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05003047 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3048 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05003049 break;
dea31012005-04-17 16:05:31 -05003050 }
3051 return;
3052}
3053
James Smarte59058c2008-08-24 21:49:00 -04003054/**
James Smart3621a712009-04-06 18:47:14 -04003055 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04003056 * @phba: pointer to lpfc hba data structure.
3057 * @cmdiocb: pointer to lpfc command iocb data structure.
3058 * @rspiocb: pointer to lpfc response iocb data structure.
3059 *
3060 * This routine makes a retry decision on an ELS command IOCB, which has
3061 * failed. The following ELS IOCBs use this function for retrying the command
3062 * when previously issued command responsed with error status: FLOGI, PLOGI,
3063 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3064 * returned error status, it makes the decision whether a retry shall be
3065 * issued for the command, and whether a retry shall be made immediately or
3066 * delayed. In the former case, the corresponding ELS command issuing-function
3067 * is called to retry the command. In the later case, the ELS command shall
3068 * be posted to the ndlp delayed event and delayed function timer set to the
3069 * ndlp for the delayed command issusing.
3070 *
3071 * Return code
3072 * 0 - No retry of els command is made
3073 * 1 - Immediate or delayed retry of els command is made
3074 **/
dea31012005-04-17 16:05:31 -05003075static int
James Smart2e0fef82007-06-17 19:56:36 -05003076lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3077 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003078{
James Smart2e0fef82007-06-17 19:56:36 -05003079 struct lpfc_vport *vport = cmdiocb->vport;
3080 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3081 IOCB_t *irsp = &rspiocb->iocb;
3082 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3083 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05003084 uint32_t *elscmd;
3085 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05003086 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04003087 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003088 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05003089 uint32_t did;
dea31012005-04-17 16:05:31 -05003090
James Smart488d1462006-03-07 15:02:37 -05003091
dea31012005-04-17 16:05:31 -05003092 /* Note: context2 may be 0 for internal driver abort
3093 * of delays ELS command.
3094 */
3095
3096 if (pcmd && pcmd->virt) {
3097 elscmd = (uint32_t *) (pcmd->virt);
3098 cmd = *elscmd++;
3099 }
3100
James Smarte47c9092008-02-08 18:49:26 -05003101 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05003102 did = ndlp->nlp_DID;
3103 else {
3104 /* We should only hit this case for retrying PLOGI */
3105 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003106 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05003107 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3108 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05003109 return 1;
3110 }
3111
James Smart858c9f62007-06-17 19:56:39 -05003112 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3113 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3114 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3115
dea31012005-04-17 16:05:31 -05003116 switch (irsp->ulpStatus) {
3117 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05003118 break;
James Smart1151e3e2011-02-16 12:39:35 -05003119 case IOSTAT_REMOTE_STOP:
3120 if (phba->sli_rev == LPFC_SLI_REV4) {
3121 /* This IO was aborted by the target, we don't
3122 * know the rxid and because we did not send the
3123 * ABTS we cannot generate and RRQ.
3124 */
3125 lpfc_set_rrq_active(phba, ndlp,
James Smartee0f4fe2012-05-09 21:19:14 -04003126 cmdiocb->sli4_lxritag, 0, 0);
James Smart1151e3e2011-02-16 12:39:35 -05003127 }
3128 break;
dea31012005-04-17 16:05:31 -05003129 case IOSTAT_LOCAL_REJECT:
James Smarte3d2b802012-08-14 14:25:43 -04003130 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
dea31012005-04-17 16:05:31 -05003131 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05003132 if (cmd == ELS_CMD_FLOGI) {
3133 if (PCI_DEVICE_ID_HORNET ==
3134 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05003135 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05003136 phba->pport->fc_myDID = 0;
3137 phba->alpa_map[0] = 0;
3138 phba->alpa_map[1] = 0;
3139 }
3140 }
James Smart2e0fef82007-06-17 19:56:36 -05003141 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003142 delay = 1000;
dea31012005-04-17 16:05:31 -05003143 retry = 1;
3144 break;
3145
James Smart92d7f7b2007-06-17 19:56:38 -05003146 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05003147 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3148 "0124 Retry illegal cmd x%x "
3149 "retry:x%x delay:x%x\n",
3150 cmd, cmdiocb->retry, delay);
3151 retry = 1;
3152 /* All command's retry policy */
3153 maxretry = 8;
3154 if (cmdiocb->retry > 2)
3155 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05003156 break;
3157
dea31012005-04-17 16:05:31 -05003158 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04003159 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05003160 retry = 1;
3161 if (cmdiocb->retry > 100)
3162 delay = 100;
3163 maxretry = 250;
3164 break;
3165
3166 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05003167 delay = 100;
dea31012005-04-17 16:05:31 -05003168 retry = 1;
3169 break;
3170
James Smart858c9f62007-06-17 19:56:39 -05003171 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05003172 case IOERR_INVALID_RPI:
James Smart5b5b36a2013-01-03 15:43:19 -05003173 if (cmd == ELS_CMD_PLOGI &&
3174 did == NameServer_DID) {
3175 /* Continue forever if plogi to */
3176 /* the nameserver fails */
3177 maxretry = 0;
3178 delay = 100;
3179 }
dea31012005-04-17 16:05:31 -05003180 retry = 1;
3181 break;
3182 }
3183 break;
3184
3185 case IOSTAT_NPORT_RJT:
3186 case IOSTAT_FABRIC_RJT:
3187 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3188 retry = 1;
3189 break;
3190 }
3191 break;
3192
3193 case IOSTAT_NPORT_BSY:
3194 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04003195 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05003196 retry = 1;
3197 break;
3198
3199 case IOSTAT_LS_RJT:
3200 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3201 /* Added for Vendor specifc support
3202 * Just keep retrying for these Rsn / Exp codes
3203 */
3204 switch (stat.un.b.lsRjtRsnCode) {
3205 case LSRJT_UNABLE_TPC:
3206 if (stat.un.b.lsRjtRsnCodeExp ==
3207 LSEXP_CMD_IN_PROGRESS) {
3208 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003209 delay = 1000;
dea31012005-04-17 16:05:31 -05003210 maxretry = 48;
3211 }
3212 retry = 1;
3213 break;
3214 }
James Smartffc95492010-06-07 15:23:17 -04003215 if (stat.un.b.lsRjtRsnCodeExp ==
3216 LSEXP_CANT_GIVE_DATA) {
3217 if (cmd == ELS_CMD_PLOGI) {
3218 delay = 1000;
3219 maxretry = 48;
3220 }
3221 retry = 1;
3222 break;
3223 }
James Smart4c1b64b2012-09-29 11:31:11 -04003224 if ((cmd == ELS_CMD_PLOGI) ||
3225 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003226 delay = 1000;
dea31012005-04-17 16:05:31 -05003227 maxretry = lpfc_max_els_tries + 1;
3228 retry = 1;
3229 break;
3230 }
James Smart92d7f7b2007-06-17 19:56:38 -05003231 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3232 (cmd == ELS_CMD_FDISC) &&
3233 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04003234 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3235 "0125 FDISC Failed (x%x). "
3236 "Fabric out of resources\n",
3237 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003238 lpfc_vport_set_state(vport,
3239 FC_VPORT_NO_FABRIC_RSCS);
3240 }
dea31012005-04-17 16:05:31 -05003241 break;
3242
3243 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003244 if ((cmd == ELS_CMD_PLOGI) ||
3245 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003246 delay = 1000;
dea31012005-04-17 16:05:31 -05003247 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003248 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003249 /* FDISC retry policy */
3250 maxretry = 48;
3251 if (cmdiocb->retry >= 32)
3252 delay = 1000;
dea31012005-04-17 16:05:31 -05003253 }
3254 retry = 1;
3255 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003256
3257 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05003258 /* There are some cases where switches return this
3259 * error when they are not ready and should be returning
3260 * Logical Busy. We should delay every time.
3261 */
3262 if (cmd == ELS_CMD_FDISC &&
3263 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3264 maxretry = 3;
3265 delay = 1000;
3266 retry = 1;
3267 break;
3268 }
James Smart92d7f7b2007-06-17 19:56:38 -05003269 case LSRJT_PROTOCOL_ERR:
3270 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3271 (cmd == ELS_CMD_FDISC) &&
3272 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3273 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3274 ) {
James Smarte8b62012007-08-02 11:10:09 -04003275 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04003276 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04003277 "Fabric Detected Bad WWN\n",
3278 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003279 lpfc_vport_set_state(vport,
3280 FC_VPORT_FABRIC_REJ_WWN);
3281 }
3282 break;
dea31012005-04-17 16:05:31 -05003283 }
3284 break;
3285
3286 case IOSTAT_INTERMED_RSP:
3287 case IOSTAT_BA_RJT:
3288 break;
3289
3290 default:
3291 break;
3292 }
3293
James Smart488d1462006-03-07 15:02:37 -05003294 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05003295 retry = 1;
dea31012005-04-17 16:05:31 -05003296
James Smartdf9e1b52011-12-13 13:22:17 -05003297 if ((cmd == ELS_CMD_FLOGI) &&
James Smart76a95d72010-11-20 23:11:48 -05003298 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05003299 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003300 /* FLOGI retry policy */
3301 retry = 1;
James Smartdf9e1b52011-12-13 13:22:17 -05003302 /* retry FLOGI forever */
James Smart6669f9b2009-10-02 15:16:45 -04003303 maxretry = 0;
3304 if (cmdiocb->retry >= 100)
3305 delay = 5000;
3306 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04003307 delay = 1000;
James Smartdf9e1b52011-12-13 13:22:17 -05003308 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3309 /* retry FDISCs every second up to devloss */
3310 retry = 1;
3311 maxretry = vport->cfg_devloss_tmo;
3312 delay = 1000;
James Smart98c9ea52007-10-27 13:37:33 -04003313 }
3314
James Smart6669f9b2009-10-02 15:16:45 -04003315 cmdiocb->retry++;
3316 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003317 phba->fc_stat.elsRetryExceeded++;
3318 retry = 0;
3319 }
3320
James Smarted957682007-06-17 19:56:37 -05003321 if ((vport->load_flag & FC_UNLOADING) != 0)
3322 retry = 0;
3323
dea31012005-04-17 16:05:31 -05003324 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003325 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3326 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3327 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3328 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3329 "2849 Stop retry ELS command "
3330 "x%x to remote NPORT x%x, "
3331 "Data: x%x x%x\n", cmd, did,
3332 cmdiocb->retry, delay);
3333 return 0;
3334 }
3335 }
dea31012005-04-17 16:05:31 -05003336
3337 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003338 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3339 "0107 Retry ELS command x%x to remote "
3340 "NPORT x%x Data: x%x x%x\n",
3341 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003342
James Smart858c9f62007-06-17 19:56:39 -05003343 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3344 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04003345 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3346 IOERR_NO_RESOURCES))) {
James Smart858c9f62007-06-17 19:56:39 -05003347 /* Don't reset timer for no resources */
3348
dea31012005-04-17 16:05:31 -05003349 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003350 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003351 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003352 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003353 }
3354
3355 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003356 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003357 phba->fc_stat.elsDelayRetry++;
3358 ndlp->nlp_retry = cmdiocb->retry;
3359
James Smart92d7f7b2007-06-17 19:56:38 -05003360 /* delay is specified in milliseconds */
3361 mod_timer(&ndlp->nlp_delayfunc,
3362 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003363 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003364 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003365 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003366
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003367 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05003368 if (cmd == ELS_CMD_PRLI)
3369 lpfc_nlp_set_state(vport, ndlp,
James Smart4c1b64b2012-09-29 11:31:11 -04003370 NLP_STE_PRLI_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003371 else
3372 lpfc_nlp_set_state(vport, ndlp,
3373 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003374 ndlp->nlp_last_elscmd = cmd;
3375
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003376 return 1;
dea31012005-04-17 16:05:31 -05003377 }
3378 switch (cmd) {
3379 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003380 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003381 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003382 case ELS_CMD_FDISC:
3383 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3384 return 1;
dea31012005-04-17 16:05:31 -05003385 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003386 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003387 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003388 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003389 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003390 }
James Smart2e0fef82007-06-17 19:56:36 -05003391 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003392 return 1;
dea31012005-04-17 16:05:31 -05003393 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003394 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003395 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3396 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003397 return 1;
dea31012005-04-17 16:05:31 -05003398 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003399 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003400 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3401 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003402 return 1;
dea31012005-04-17 16:05:31 -05003403 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003404 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04003405 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003406 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003407 return 1;
dea31012005-04-17 16:05:31 -05003408 }
3409 }
dea31012005-04-17 16:05:31 -05003410 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003411 if (logerr) {
3412 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3413 "0137 No retry ELS command x%x to remote "
3414 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3415 cmd, did, irsp->ulpStatus,
3416 irsp->un.ulpWord[4]);
3417 }
3418 else {
3419 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003420 "0108 No retry ELS command x%x to remote "
3421 "NPORT x%x Retried:%d Error:x%x/%x\n",
3422 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3423 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003424 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003425 return 0;
dea31012005-04-17 16:05:31 -05003426}
3427
James Smarte59058c2008-08-24 21:49:00 -04003428/**
James Smart3621a712009-04-06 18:47:14 -04003429 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003430 * @phba: pointer to lpfc hba data structure.
3431 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3432 *
3433 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3434 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3435 * checks to see whether there is a lpfc DMA buffer associated with the
3436 * response of the command IOCB. If so, it will be released before releasing
3437 * the lpfc DMA buffer associated with the IOCB itself.
3438 *
3439 * Return code
3440 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3441 **/
James Smart09372822008-01-11 01:52:54 -05003442static int
James Smart87af33f2007-10-27 13:37:43 -04003443lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3444{
3445 struct lpfc_dmabuf *buf_ptr;
3446
James Smarte59058c2008-08-24 21:49:00 -04003447 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003448 if (!list_empty(&buf_ptr1->list)) {
3449 list_remove_head(&buf_ptr1->list, buf_ptr,
3450 struct lpfc_dmabuf,
3451 list);
3452 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3453 kfree(buf_ptr);
3454 }
3455 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3456 kfree(buf_ptr1);
3457 return 0;
3458}
3459
James Smarte59058c2008-08-24 21:49:00 -04003460/**
James Smart3621a712009-04-06 18:47:14 -04003461 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003462 * @phba: pointer to lpfc hba data structure.
3463 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3464 *
3465 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3466 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3467 * pool.
3468 *
3469 * Return code
3470 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3471 **/
James Smart09372822008-01-11 01:52:54 -05003472static int
James Smart87af33f2007-10-27 13:37:43 -04003473lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3474{
3475 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3476 kfree(buf_ptr);
3477 return 0;
3478}
3479
James Smarte59058c2008-08-24 21:49:00 -04003480/**
James Smart3621a712009-04-06 18:47:14 -04003481 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003482 * @phba: pointer to lpfc hba data structure.
3483 * @elsiocb: pointer to lpfc els command iocb data structure.
3484 *
3485 * This routine frees a command IOCB and its associated resources. The
3486 * command IOCB data structure contains the reference to various associated
3487 * resources, these fields must be set to NULL if the associated reference
3488 * not present:
3489 * context1 - reference to ndlp
3490 * context2 - reference to cmd
3491 * context2->next - reference to rsp
3492 * context3 - reference to bpl
3493 *
3494 * It first properly decrements the reference count held on ndlp for the
3495 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3496 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3497 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3498 * adds the DMA buffer the @phba data structure for the delayed release.
3499 * If reference to the Buffer Pointer List (BPL) is present, the
3500 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3501 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3502 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3503 *
3504 * Return code
3505 * 0 - Success (currently, always return 0)
3506 **/
James Smart87af33f2007-10-27 13:37:43 -04003507int
James Smart329f9bc2007-04-25 09:53:01 -04003508lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003509{
3510 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003511 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003512
James Smarta8adb832007-10-27 13:37:53 -04003513 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3514 if (ndlp) {
3515 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3516 lpfc_nlp_put(ndlp);
3517
3518 /* If the ndlp is not being used by another discovery
3519 * thread, free it.
3520 */
3521 if (!lpfc_nlp_not_used(ndlp)) {
3522 /* If ndlp is being used by another discovery
3523 * thread, just clear NLP_DEFER_RM
3524 */
3525 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3526 }
3527 }
3528 else
3529 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003530 elsiocb->context1 = NULL;
3531 }
dea31012005-04-17 16:05:31 -05003532 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3533 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003534 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3535 /* Firmware could still be in progress of DMAing
3536 * payload, so don't free data buffer till after
3537 * a hbeat.
3538 */
3539 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3540 buf_ptr = elsiocb->context2;
3541 elsiocb->context2 = NULL;
3542 if (buf_ptr) {
3543 buf_ptr1 = NULL;
3544 spin_lock_irq(&phba->hbalock);
3545 if (!list_empty(&buf_ptr->list)) {
3546 list_remove_head(&buf_ptr->list,
3547 buf_ptr1, struct lpfc_dmabuf,
3548 list);
3549 INIT_LIST_HEAD(&buf_ptr1->list);
3550 list_add_tail(&buf_ptr1->list,
3551 &phba->elsbuf);
3552 phba->elsbuf_cnt++;
3553 }
3554 INIT_LIST_HEAD(&buf_ptr->list);
3555 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3556 phba->elsbuf_cnt++;
3557 spin_unlock_irq(&phba->hbalock);
3558 }
3559 } else {
3560 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3561 lpfc_els_free_data(phba, buf_ptr1);
3562 }
dea31012005-04-17 16:05:31 -05003563 }
3564
3565 if (elsiocb->context3) {
3566 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003567 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003568 }
James Bottomley604a3e32005-10-29 10:28:33 -05003569 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003570 return 0;
3571}
3572
James Smarte59058c2008-08-24 21:49:00 -04003573/**
James Smart3621a712009-04-06 18:47:14 -04003574 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003575 * @phba: pointer to lpfc hba data structure.
3576 * @cmdiocb: pointer to lpfc command iocb data structure.
3577 * @rspiocb: pointer to lpfc response iocb data structure.
3578 *
3579 * This routine is the completion callback function to the Logout (LOGO)
3580 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3581 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3582 * release the ndlp if it has the last reference remaining (reference count
3583 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3584 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3585 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3586 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3587 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3588 * IOCB data structure.
3589 **/
dea31012005-04-17 16:05:31 -05003590static void
James Smart2e0fef82007-06-17 19:56:36 -05003591lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3592 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003593{
James Smart2e0fef82007-06-17 19:56:36 -05003594 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3595 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003596 IOCB_t *irsp;
3597
3598 irsp = &rspiocb->iocb;
3599 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3600 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3601 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003602 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003603 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3604 "0109 ACC to LOGO completes to NPort x%x "
3605 "Data: x%x x%x x%x\n",
3606 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3607 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003608
3609 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3610 /* NPort Recovery mode or node is just allocated */
3611 if (!lpfc_nlp_not_used(ndlp)) {
3612 /* If the ndlp is being used by another discovery
3613 * thread, just unregister the RPI.
3614 */
3615 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003616 } else {
3617 /* Indicate the node has already released, should
3618 * not reference to it from within lpfc_els_free_iocb.
3619 */
3620 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003621 }
dea31012005-04-17 16:05:31 -05003622 }
James Smart73d91e52011-10-10 21:32:10 -04003623
3624 /*
3625 * The driver received a LOGO from the rport and has ACK'd it.
James Smartdf9e1b52011-12-13 13:22:17 -05003626 * At this point, the driver is done so release the IOCB
James Smart73d91e52011-10-10 21:32:10 -04003627 */
dea31012005-04-17 16:05:31 -05003628 lpfc_els_free_iocb(phba, cmdiocb);
James Smartdf9e1b52011-12-13 13:22:17 -05003629
3630 /*
3631 * Remove the ndlp reference if it's a fabric node that has
3632 * sent us an unsolicted LOGO.
3633 */
3634 if (ndlp->nlp_type & NLP_FABRIC)
3635 lpfc_nlp_put(ndlp);
3636
dea31012005-04-17 16:05:31 -05003637 return;
3638}
3639
James Smarte59058c2008-08-24 21:49:00 -04003640/**
James Smart3621a712009-04-06 18:47:14 -04003641 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003642 * @phba: pointer to lpfc hba data structure.
3643 * @pmb: pointer to the driver internal queue element for mailbox command.
3644 *
3645 * This routine is the completion callback function for unregister default
3646 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3647 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3648 * decrements the ndlp reference count held for this completion callback
3649 * function. After that, it invokes the lpfc_nlp_not_used() to check
3650 * whether there is only one reference left on the ndlp. If so, it will
3651 * perform one more decrement and trigger the release of the ndlp.
3652 **/
James Smart858c9f62007-06-17 19:56:39 -05003653void
3654lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3655{
3656 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3657 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3658
3659 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003660 pmb->context2 = NULL;
3661
James Smart858c9f62007-06-17 19:56:39 -05003662 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3663 kfree(mp);
3664 mempool_free(pmb, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04003665 if (ndlp) {
3666 if (NLP_CHK_NODE_ACT(ndlp)) {
3667 lpfc_nlp_put(ndlp);
3668 /* This is the end of the default RPI cleanup logic for
3669 * this ndlp. If no other discovery threads are using
3670 * this ndlp, free all resources associated with it.
3671 */
3672 lpfc_nlp_not_used(ndlp);
3673 } else {
3674 lpfc_drop_node(ndlp->vport, ndlp);
3675 }
James Smarta8adb832007-10-27 13:37:53 -04003676 }
James Smart3772a992009-05-22 14:50:54 -04003677
James Smart858c9f62007-06-17 19:56:39 -05003678 return;
3679}
3680
James Smarte59058c2008-08-24 21:49:00 -04003681/**
James Smart3621a712009-04-06 18:47:14 -04003682 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003683 * @phba: pointer to lpfc hba data structure.
3684 * @cmdiocb: pointer to lpfc command iocb data structure.
3685 * @rspiocb: pointer to lpfc response iocb data structure.
3686 *
3687 * This routine is the completion callback function for ELS Response IOCB
3688 * command. In normal case, this callback function just properly sets the
3689 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3690 * field in the command IOCB is not NULL, the referred mailbox command will
3691 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3692 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3693 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3694 * routine shall be invoked trying to release the ndlp if no other threads
3695 * are currently referring it.
3696 **/
dea31012005-04-17 16:05:31 -05003697static void
James Smart858c9f62007-06-17 19:56:39 -05003698lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003699 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003700{
James Smart2e0fef82007-06-17 19:56:36 -05003701 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3702 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3703 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003704 IOCB_t *irsp;
3705 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003706 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003707 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003708 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003709
James Smart33ccf8d2006-08-17 11:57:58 -04003710 irsp = &rspiocb->iocb;
3711
dea31012005-04-17 16:05:31 -05003712 if (cmdiocb->context_un.mbox)
3713 mbox = cmdiocb->context_un.mbox;
3714
James Smartfa4066b2008-01-11 01:53:27 -05003715 /* First determine if this is a LS_RJT cmpl. Note, this callback
3716 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3717 */
James Smart87af33f2007-10-27 13:37:43 -04003718 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003719 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3720 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003721 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003722 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003723 */
3724 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3725 ls_rjt = 1;
3726 }
3727
dea31012005-04-17 16:05:31 -05003728 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003729 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003730 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003731 mp = (struct lpfc_dmabuf *) mbox->context1;
3732 if (mp) {
3733 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3734 kfree(mp);
3735 }
James Smart329f9bc2007-04-25 09:53:01 -04003736 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003737 }
James Smart58da1ff2008-04-07 10:15:56 -04003738 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3739 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003740 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003741 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003742 /* Indicate the node has already released,
3743 * should not reference to it from within
3744 * the routine lpfc_els_free_iocb.
3745 */
3746 cmdiocb->context1 = NULL;
3747 }
dea31012005-04-17 16:05:31 -05003748 goto out;
3749 }
3750
James Smart858c9f62007-06-17 19:56:39 -05003751 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003752 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003753 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003754 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003755 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003756 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3757 "0110 ELS response tag x%x completes "
3758 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3759 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3760 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3761 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3762 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003763 if (mbox) {
3764 if ((rspiocb->iocb.ulpStatus == 0)
3765 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003766 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003767 /* Increment reference count to ndlp to hold the
3768 * reference to ndlp for the callback function.
3769 */
James Smart329f9bc2007-04-25 09:53:01 -04003770 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003771 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003772 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3773 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3774 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3775 }
3776 else {
3777 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3778 ndlp->nlp_prev_state = ndlp->nlp_state;
3779 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003780 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003781 }
James Smart0b727fe2007-10-27 13:37:25 -04003782 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003783 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003784 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003785 else
3786 /* Decrement the ndlp reference count we
3787 * set for this failed mailbox command.
3788 */
3789 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003790
3791 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3792 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3793 "0138 ELS rsp: Cannot issue reg_login for x%x "
3794 "Data: x%x x%x x%x\n",
3795 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3796 ndlp->nlp_rpi);
3797
James Smartfa4066b2008-01-11 01:53:27 -05003798 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003799 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003800 /* Indicate node has already been released,
3801 * should not reference to it from within
3802 * the routine lpfc_els_free_iocb.
3803 */
3804 cmdiocb->context1 = NULL;
3805 }
dea31012005-04-17 16:05:31 -05003806 } else {
James Smart858c9f62007-06-17 19:56:39 -05003807 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3808 if (!lpfc_error_lost_link(irsp) &&
3809 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003810 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003811 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003812 /* Indicate node has already been
3813 * released, should not reference
3814 * to it from within the routine
3815 * lpfc_els_free_iocb.
3816 */
3817 cmdiocb->context1 = NULL;
3818 }
dea31012005-04-17 16:05:31 -05003819 }
3820 }
James Smart14691152006-12-02 13:34:28 -05003821 mp = (struct lpfc_dmabuf *) mbox->context1;
3822 if (mp) {
3823 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3824 kfree(mp);
3825 }
3826 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003827 }
3828out:
James Smart58da1ff2008-04-07 10:15:56 -04003829 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003830 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003831 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003832 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003833
3834 /* If the node is not being used by another discovery thread,
3835 * and we are sending a reject, we are done with it.
3836 * Release driver reference count here and free associated
3837 * resources.
3838 */
3839 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003840 if (lpfc_nlp_not_used(ndlp))
3841 /* Indicate node has already been released,
3842 * should not reference to it from within
3843 * the routine lpfc_els_free_iocb.
3844 */
3845 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003846 }
James Smart87af33f2007-10-27 13:37:43 -04003847
dea31012005-04-17 16:05:31 -05003848 lpfc_els_free_iocb(phba, cmdiocb);
3849 return;
3850}
3851
James Smarte59058c2008-08-24 21:49:00 -04003852/**
James Smart3621a712009-04-06 18:47:14 -04003853 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003854 * @vport: pointer to a host virtual N_Port data structure.
3855 * @flag: the els command code to be accepted.
3856 * @oldiocb: pointer to the original lpfc command iocb data structure.
3857 * @ndlp: pointer to a node-list data structure.
3858 * @mbox: pointer to the driver internal queue element for mailbox command.
3859 *
3860 * This routine prepares and issues an Accept (ACC) response IOCB
3861 * command. It uses the @flag to properly set up the IOCB field for the
3862 * specific ACC response command to be issued and invokes the
3863 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3864 * @mbox pointer is passed in, it will be put into the context_un.mbox
3865 * field of the IOCB for the completion callback function to issue the
3866 * mailbox command to the HBA later when callback is invoked.
3867 *
3868 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3869 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3870 * will be stored into the context1 field of the IOCB for the completion
3871 * callback function to the corresponding response ELS IOCB command.
3872 *
3873 * Return code
3874 * 0 - Successfully issued acc response
3875 * 1 - Failed to issue acc response
3876 **/
dea31012005-04-17 16:05:31 -05003877int
James Smart2e0fef82007-06-17 19:56:36 -05003878lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3879 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003880 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003881{
James Smart2e0fef82007-06-17 19:56:36 -05003882 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3883 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003884 IOCB_t *icmd;
3885 IOCB_t *oldcmd;
3886 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003887 struct lpfc_sli *psli;
3888 uint8_t *pcmd;
3889 uint16_t cmdsize;
3890 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003891 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003892
3893 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003894 oldcmd = &oldiocb->iocb;
3895
3896 switch (flag) {
3897 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003898 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003899 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3900 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003901 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003902 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003903 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003904 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003905 return 1;
dea31012005-04-17 16:05:31 -05003906 }
James Smart2e0fef82007-06-17 19:56:36 -05003907
dea31012005-04-17 16:05:31 -05003908 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003909 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3910 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003911 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3912 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003913 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003914
3915 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3916 "Issue ACC: did:x%x flg:x%x",
3917 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003918 break;
3919 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003920 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003921 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3922 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003923 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003924 return 1;
James Smart488d1462006-03-07 15:02:37 -05003925
dea31012005-04-17 16:05:31 -05003926 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003927 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3928 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003929 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3930
3931 if (mbox)
3932 elsiocb->context_un.mbox = mbox;
3933
3934 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003935 pcmd += sizeof(uint32_t);
3936 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003937
3938 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3939 "Issue ACC PLOGI: did:x%x flg:x%x",
3940 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003941 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003942 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003943 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003944 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003945 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3946 if (!elsiocb)
3947 return 1;
3948
3949 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003950 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3951 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04003952 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3953
3954 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003955 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003956 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3957 els_pkt_ptr = (ELS_PKT *) pcmd;
3958 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003959
3960 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3961 "Issue ACC PRLO: did:x%x flg:x%x",
3962 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003963 break;
dea31012005-04-17 16:05:31 -05003964 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003965 return 1;
dea31012005-04-17 16:05:31 -05003966 }
dea31012005-04-17 16:05:31 -05003967 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003968 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3969 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
James Smarte6446432012-05-09 21:16:42 -04003970 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
3971 "fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003972 elsiocb->iotag, elsiocb->iocb.ulpContext,
3973 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
James Smarte6446432012-05-09 21:16:42 -04003974 ndlp->nlp_rpi, vport->fc_flag);
dea31012005-04-17 16:05:31 -05003975 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003976 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003977 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003978 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003979 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3980 } else {
James Smart858c9f62007-06-17 19:56:39 -05003981 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003982 }
3983
3984 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003985 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003986 if (rc == IOCB_ERROR) {
3987 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003988 return 1;
dea31012005-04-17 16:05:31 -05003989 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003990 return 0;
dea31012005-04-17 16:05:31 -05003991}
3992
James Smarte59058c2008-08-24 21:49:00 -04003993/**
James Smart3621a712009-04-06 18:47:14 -04003994 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003995 * @vport: pointer to a virtual N_Port data structure.
3996 * @rejectError:
3997 * @oldiocb: pointer to the original lpfc command iocb data structure.
3998 * @ndlp: pointer to a node-list data structure.
3999 * @mbox: pointer to the driver internal queue element for mailbox command.
4000 *
4001 * This routine prepares and issue an Reject (RJT) response IOCB
4002 * command. If a @mbox pointer is passed in, it will be put into the
4003 * context_un.mbox field of the IOCB for the completion callback function
4004 * to issue to the HBA later.
4005 *
4006 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4007 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4008 * will be stored into the context1 field of the IOCB for the completion
4009 * callback function to the reject response ELS IOCB command.
4010 *
4011 * Return code
4012 * 0 - Successfully issued reject response
4013 * 1 - Failed to issue reject response
4014 **/
dea31012005-04-17 16:05:31 -05004015int
James Smart2e0fef82007-06-17 19:56:36 -05004016lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05004017 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4018 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05004019{
James Smart2e0fef82007-06-17 19:56:36 -05004020 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004021 IOCB_t *icmd;
4022 IOCB_t *oldcmd;
4023 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004024 struct lpfc_sli *psli;
4025 uint8_t *pcmd;
4026 uint16_t cmdsize;
4027 int rc;
4028
4029 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05004030 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05004031 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4032 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05004033 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004034 return 1;
dea31012005-04-17 16:05:31 -05004035
4036 icmd = &elsiocb->iocb;
4037 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004038 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4039 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05004040 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4041
4042 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05004043 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004044 *((uint32_t *) (pcmd)) = rejectError;
4045
James Smart51ef4c22007-08-02 11:10:31 -04004046 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05004047 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05004048
dea31012005-04-17 16:05:31 -05004049 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004050 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4051 "0129 Xmit ELS RJT x%x response tag x%x "
4052 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4053 "rpi x%x\n",
4054 rejectError, elsiocb->iotag,
4055 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4056 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004057 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4058 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4059 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4060
dea31012005-04-17 16:05:31 -05004061 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05004062 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004063 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04004064
dea31012005-04-17 16:05:31 -05004065 if (rc == IOCB_ERROR) {
4066 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004067 return 1;
dea31012005-04-17 16:05:31 -05004068 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004069 return 0;
dea31012005-04-17 16:05:31 -05004070}
4071
James Smarte59058c2008-08-24 21:49:00 -04004072/**
James Smart3621a712009-04-06 18:47:14 -04004073 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004074 * @vport: pointer to a virtual N_Port data structure.
4075 * @oldiocb: pointer to the original lpfc command iocb data structure.
4076 * @ndlp: pointer to a node-list data structure.
4077 *
4078 * This routine prepares and issues an Accept (ACC) response to Address
4079 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4080 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4081 *
4082 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4083 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4084 * will be stored into the context1 field of the IOCB for the completion
4085 * callback function to the ADISC Accept response ELS IOCB command.
4086 *
4087 * Return code
4088 * 0 - Successfully issued acc adisc response
4089 * 1 - Failed to issue adisc acc response
4090 **/
dea31012005-04-17 16:05:31 -05004091int
James Smart2e0fef82007-06-17 19:56:36 -05004092lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4093 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004094{
James Smart2e0fef82007-06-17 19:56:36 -05004095 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004096 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05004097 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004098 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004099 uint8_t *pcmd;
4100 uint16_t cmdsize;
4101 int rc;
4102
James Smart92d7f7b2007-06-17 19:56:38 -05004103 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05004104 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4105 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004106 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004107 return 1;
dea31012005-04-17 16:05:31 -05004108
dea31012005-04-17 16:05:31 -05004109 icmd = &elsiocb->iocb;
4110 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004111 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4112 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04004113
4114 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004115 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4116 "0130 Xmit ADISC ACC response iotag x%x xri: "
4117 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4118 elsiocb->iotag, elsiocb->iocb.ulpContext,
4119 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4120 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004121 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4122
4123 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004124 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004125
4126 ap = (ADISC *) (pcmd);
4127 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05004128 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4129 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05004130 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05004131
James Smart858c9f62007-06-17 19:56:39 -05004132 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4133 "Issue ACC ADISC: did:x%x flg:x%x",
4134 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4135
dea31012005-04-17 16:05:31 -05004136 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004137 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004138 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004139 if (rc == IOCB_ERROR) {
4140 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004141 return 1;
dea31012005-04-17 16:05:31 -05004142 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004143 return 0;
dea31012005-04-17 16:05:31 -05004144}
4145
James Smarte59058c2008-08-24 21:49:00 -04004146/**
James Smart3621a712009-04-06 18:47:14 -04004147 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004148 * @vport: pointer to a virtual N_Port data structure.
4149 * @oldiocb: pointer to the original lpfc command iocb data structure.
4150 * @ndlp: pointer to a node-list data structure.
4151 *
4152 * This routine prepares and issues an Accept (ACC) response to Process
4153 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4154 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4155 *
4156 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4157 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4158 * will be stored into the context1 field of the IOCB for the completion
4159 * callback function to the PRLI Accept response ELS IOCB command.
4160 *
4161 * Return code
4162 * 0 - Successfully issued acc prli response
4163 * 1 - Failed to issue acc prli response
4164 **/
dea31012005-04-17 16:05:31 -05004165int
James Smart2e0fef82007-06-17 19:56:36 -05004166lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04004167 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004168{
James Smart2e0fef82007-06-17 19:56:36 -05004169 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004170 PRLI *npr;
4171 lpfc_vpd_t *vpd;
4172 IOCB_t *icmd;
4173 IOCB_t *oldcmd;
4174 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004175 struct lpfc_sli *psli;
4176 uint8_t *pcmd;
4177 uint16_t cmdsize;
4178 int rc;
4179
4180 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05004181
James Smart92d7f7b2007-06-17 19:56:38 -05004182 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05004183 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05004184 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004185 if (!elsiocb)
4186 return 1;
dea31012005-04-17 16:05:31 -05004187
dea31012005-04-17 16:05:31 -05004188 icmd = &elsiocb->iocb;
4189 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004190 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4191 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4192
James Smart5b8bd0c2007-04-25 09:52:49 -04004193 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004194 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4195 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4196 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4197 elsiocb->iotag, elsiocb->iocb.ulpContext,
4198 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4199 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004200 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4201
4202 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05004203 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004204
4205 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05004206 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05004207
4208 npr = (PRLI *) pcmd;
4209 vpd = &phba->vpd;
4210 /*
James Smart0d2b6b82008-06-14 22:52:47 -04004211 * If the remote port is a target and our firmware version is 3.20 or
4212 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05004213 */
James Smart0d2b6b82008-06-14 22:52:47 -04004214 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4215 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05004216 npr->ConfmComplAllowed = 1;
4217 npr->Retry = 1;
4218 npr->TaskRetryIdReq = 1;
4219 }
4220
4221 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4222 npr->estabImagePair = 1;
4223 npr->readXferRdyDis = 1;
4224 npr->ConfmComplAllowed = 1;
4225
4226 npr->prliType = PRLI_FCP_TYPE;
4227 npr->initiatorFunc = 1;
4228
James Smart858c9f62007-06-17 19:56:39 -05004229 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4230 "Issue ACC PRLI: did:x%x flg:x%x",
4231 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4232
dea31012005-04-17 16:05:31 -05004233 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004234 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004235
James Smart3772a992009-05-22 14:50:54 -04004236 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004237 if (rc == IOCB_ERROR) {
4238 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004239 return 1;
dea31012005-04-17 16:05:31 -05004240 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004241 return 0;
dea31012005-04-17 16:05:31 -05004242}
4243
James Smarte59058c2008-08-24 21:49:00 -04004244/**
James Smart3621a712009-04-06 18:47:14 -04004245 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004246 * @vport: pointer to a virtual N_Port data structure.
4247 * @format: rnid command format.
4248 * @oldiocb: pointer to the original lpfc command iocb data structure.
4249 * @ndlp: pointer to a node-list data structure.
4250 *
4251 * This routine issues a Request Node Identification Data (RNID) Accept
4252 * (ACC) response. It constructs the RNID ACC response command according to
4253 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4254 * issue the response. Note that this command does not need to hold the ndlp
4255 * reference count for the callback. So, the ndlp reference count taken by
4256 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4257 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4258 * there is no ndlp reference available.
4259 *
4260 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4261 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4262 * will be stored into the context1 field of the IOCB for the completion
4263 * callback function. However, for the RNID Accept Response ELS command,
4264 * this is undone later by this routine after the IOCB is allocated.
4265 *
4266 * Return code
4267 * 0 - Successfully issued acc rnid response
4268 * 1 - Failed to issue acc rnid response
4269 **/
dea31012005-04-17 16:05:31 -05004270static int
James Smart2e0fef82007-06-17 19:56:36 -05004271lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004272 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004273{
James Smart2e0fef82007-06-17 19:56:36 -05004274 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004275 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004276 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004277 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004278 struct lpfc_sli *psli;
4279 uint8_t *pcmd;
4280 uint16_t cmdsize;
4281 int rc;
4282
4283 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05004284 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4285 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004286 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004287 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004288
James Smart2e0fef82007-06-17 19:56:36 -05004289 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4290 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004291 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004292 return 1;
dea31012005-04-17 16:05:31 -05004293
dea31012005-04-17 16:05:31 -05004294 icmd = &elsiocb->iocb;
4295 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004296 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4297 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4298
James Smart5b8bd0c2007-04-25 09:52:49 -04004299 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004300 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4301 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4302 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004303 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004304 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004305 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004306
James Smart92d7f7b2007-06-17 19:56:38 -05004307 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004308 rn = (RNID *) (pcmd);
4309 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004310 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4311 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4312 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004313 switch (format) {
4314 case 0:
4315 rn->SpecificLen = 0;
4316 break;
4317 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004318 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004319 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004320 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004321 rn->un.topologyDisc.unitType = RNID_HBA;
4322 rn->un.topologyDisc.physPort = 0;
4323 rn->un.topologyDisc.attachedNodes = 0;
4324 break;
4325 default:
4326 rn->CommonLen = 0;
4327 rn->SpecificLen = 0;
4328 break;
4329 }
4330
James Smart858c9f62007-06-17 19:56:39 -05004331 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4332 "Issue ACC RNID: did:x%x flg:x%x",
4333 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4334
dea31012005-04-17 16:05:31 -05004335 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004336 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004337
James Smart3772a992009-05-22 14:50:54 -04004338 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004339 if (rc == IOCB_ERROR) {
4340 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004341 return 1;
dea31012005-04-17 16:05:31 -05004342 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004343 return 0;
dea31012005-04-17 16:05:31 -05004344}
4345
James Smarte59058c2008-08-24 21:49:00 -04004346/**
James Smart19ca7602010-11-20 23:11:55 -05004347 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4348 * @vport: pointer to a virtual N_Port data structure.
4349 * @iocb: pointer to the lpfc command iocb data structure.
4350 * @ndlp: pointer to a node-list data structure.
4351 *
4352 * Return
4353 **/
4354static void
4355lpfc_els_clear_rrq(struct lpfc_vport *vport,
4356 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4357{
4358 struct lpfc_hba *phba = vport->phba;
4359 uint8_t *pcmd;
4360 struct RRQ *rrq;
4361 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004362 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004363 struct lpfc_node_rrq *prrq;
4364
4365
4366 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4367 pcmd += sizeof(uint32_t);
4368 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004369 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b062011-04-16 11:03:17 -04004370 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05004371
4372 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4373 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4374 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004375 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b062011-04-16 11:03:17 -04004376 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05004377 rxid,
4378 iocb->iotag, iocb->iocb.ulpContext);
4379
4380 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4381 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4382 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004383 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b062011-04-16 11:03:17 -04004384 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05004385 else
4386 xri = rxid;
4387 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004388 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004389 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004390 return;
4391}
4392
4393/**
James Smart12265f62010-10-22 11:05:53 -04004394 * lpfc_els_rsp_echo_acc - Issue echo acc response
4395 * @vport: pointer to a virtual N_Port data structure.
4396 * @data: pointer to echo data to return in the accept.
4397 * @oldiocb: pointer to the original lpfc command iocb data structure.
4398 * @ndlp: pointer to a node-list data structure.
4399 *
4400 * Return code
4401 * 0 - Successfully issued acc echo response
4402 * 1 - Failed to issue acc echo response
4403 **/
4404static int
4405lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4406 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4407{
4408 struct lpfc_hba *phba = vport->phba;
4409 struct lpfc_iocbq *elsiocb;
4410 struct lpfc_sli *psli;
4411 uint8_t *pcmd;
4412 uint16_t cmdsize;
4413 int rc;
4414
4415 psli = &phba->sli;
4416 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4417
James Smartbf086112011-08-21 21:48:13 -04004418 /* The accumulated length can exceed the BPL_SIZE. For
4419 * now, use this as the limit
4420 */
4421 if (cmdsize > LPFC_BPL_SIZE)
4422 cmdsize = LPFC_BPL_SIZE;
James Smart12265f62010-10-22 11:05:53 -04004423 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4424 ndlp->nlp_DID, ELS_CMD_ACC);
4425 if (!elsiocb)
4426 return 1;
4427
James Smart7851fe22011-07-22 18:36:52 -04004428 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4429 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4430
James Smart12265f62010-10-22 11:05:53 -04004431 /* Xmit ECHO ACC response tag <ulpIoTag> */
4432 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4433 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4434 elsiocb->iotag, elsiocb->iocb.ulpContext);
4435 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4436 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4437 pcmd += sizeof(uint32_t);
4438 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4439
4440 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4441 "Issue ACC ECHO: did:x%x flg:x%x",
4442 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4443
4444 phba->fc_stat.elsXmitACC++;
4445 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart12265f62010-10-22 11:05:53 -04004446
4447 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4448 if (rc == IOCB_ERROR) {
4449 lpfc_els_free_iocb(phba, elsiocb);
4450 return 1;
4451 }
4452 return 0;
4453}
4454
4455/**
James Smart3621a712009-04-06 18:47:14 -04004456 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004457 * @vport: pointer to a host virtual N_Port data structure.
4458 *
4459 * This routine issues Address Discover (ADISC) ELS commands to those
4460 * N_Ports which are in node port recovery state and ADISC has not been issued
4461 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4462 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4463 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4464 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4465 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4466 * IOCBs quit for later pick up. On the other hand, after walking through
4467 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4468 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4469 * no more ADISC need to be sent.
4470 *
4471 * Return code
4472 * The number of N_Ports with adisc issued.
4473 **/
dea31012005-04-17 16:05:31 -05004474int
James Smart2e0fef82007-06-17 19:56:36 -05004475lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004476{
James Smart2e0fef82007-06-17 19:56:36 -05004477 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004478 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004479 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004480
James Smart685f0bf2007-04-25 09:53:08 -04004481 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004482 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004483 if (!NLP_CHK_NODE_ACT(ndlp))
4484 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004485 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4486 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4487 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004488 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004489 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004490 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004491 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004492 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4493 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004494 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004495 vport->num_disc_nodes++;
4496 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004497 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004498 spin_lock_irq(shost->host_lock);
4499 vport->fc_flag |= FC_NLP_MORE;
4500 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004501 break;
dea31012005-04-17 16:05:31 -05004502 }
4503 }
4504 }
4505 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004506 spin_lock_irq(shost->host_lock);
4507 vport->fc_flag &= ~FC_NLP_MORE;
4508 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004509 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004510 return sentadisc;
dea31012005-04-17 16:05:31 -05004511}
4512
James Smarte59058c2008-08-24 21:49:00 -04004513/**
James Smart3621a712009-04-06 18:47:14 -04004514 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004515 * @vport: pointer to a host virtual N_Port data structure.
4516 *
4517 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4518 * which are in node port recovery state, with a @vport. Each time an ELS
4519 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4520 * the per @vport number of discover count (num_disc_nodes) shall be
4521 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4522 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4523 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4524 * later pick up. On the other hand, after walking through all the ndlps with
4525 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4526 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4527 * PLOGI need to be sent.
4528 *
4529 * Return code
4530 * The number of N_Ports with plogi issued.
4531 **/
dea31012005-04-17 16:05:31 -05004532int
James Smart2e0fef82007-06-17 19:56:36 -05004533lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004534{
James Smart2e0fef82007-06-17 19:56:36 -05004535 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004536 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004537 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004538
James Smart2e0fef82007-06-17 19:56:36 -05004539 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4540 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004541 if (!NLP_CHK_NODE_ACT(ndlp))
4542 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004543 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4544 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4545 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4546 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4547 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004548 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4549 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004550 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004551 vport->num_disc_nodes++;
4552 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004553 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004554 spin_lock_irq(shost->host_lock);
4555 vport->fc_flag |= FC_NLP_MORE;
4556 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004557 break;
dea31012005-04-17 16:05:31 -05004558 }
4559 }
4560 }
James Smart87af33f2007-10-27 13:37:43 -04004561 if (sentplogi) {
4562 lpfc_set_disctmo(vport);
4563 }
4564 else {
James Smart2e0fef82007-06-17 19:56:36 -05004565 spin_lock_irq(shost->host_lock);
4566 vport->fc_flag &= ~FC_NLP_MORE;
4567 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004568 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004569 return sentplogi;
dea31012005-04-17 16:05:31 -05004570}
4571
James Smarte59058c2008-08-24 21:49:00 -04004572/**
James Smart3621a712009-04-06 18:47:14 -04004573 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004574 * @vport: pointer to a host virtual N_Port data structure.
4575 *
4576 * This routine cleans up any Registration State Change Notification
4577 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4578 * @vport together with the host_lock is used to prevent multiple thread
4579 * trying to access the RSCN array on a same @vport at the same time.
4580 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004581void
James Smart2e0fef82007-06-17 19:56:36 -05004582lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004583{
James Smart2e0fef82007-06-17 19:56:36 -05004584 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4585 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004586 int i;
4587
James Smart7f5f3d02008-02-08 18:50:14 -05004588 spin_lock_irq(shost->host_lock);
4589 if (vport->fc_rscn_flush) {
4590 /* Another thread is walking fc_rscn_id_list on this vport */
4591 spin_unlock_irq(shost->host_lock);
4592 return;
4593 }
4594 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4595 vport->fc_rscn_flush = 1;
4596 spin_unlock_irq(shost->host_lock);
4597
James Smart2e0fef82007-06-17 19:56:36 -05004598 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004599 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004600 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004601 }
James Smart2e0fef82007-06-17 19:56:36 -05004602 spin_lock_irq(shost->host_lock);
4603 vport->fc_rscn_id_cnt = 0;
4604 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4605 spin_unlock_irq(shost->host_lock);
4606 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004607 /* Indicate we are done walking this fc_rscn_id_list */
4608 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004609}
4610
James Smarte59058c2008-08-24 21:49:00 -04004611/**
James Smart3621a712009-04-06 18:47:14 -04004612 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004613 * @vport: pointer to a host virtual N_Port data structure.
4614 * @did: remote destination port identifier.
4615 *
4616 * This routine checks whether there is any pending Registration State
4617 * Configuration Notification (RSCN) to a @did on @vport.
4618 *
4619 * Return code
4620 * None zero - The @did matched with a pending rscn
4621 * 0 - not able to match @did with a pending rscn
4622 **/
dea31012005-04-17 16:05:31 -05004623int
James Smart2e0fef82007-06-17 19:56:36 -05004624lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004625{
4626 D_ID ns_did;
4627 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004628 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004629 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004630 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004631
4632 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004633
4634 /* Never match fabric nodes for RSCNs */
4635 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004636 return 0;
dea31012005-04-17 16:05:31 -05004637
4638 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004639 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004640 return did;
dea31012005-04-17 16:05:31 -05004641
James Smart7f5f3d02008-02-08 18:50:14 -05004642 spin_lock_irq(shost->host_lock);
4643 if (vport->fc_rscn_flush) {
4644 /* Another thread is walking fc_rscn_id_list on this vport */
4645 spin_unlock_irq(shost->host_lock);
4646 return 0;
4647 }
4648 /* Indicate we are walking fc_rscn_id_list on this vport */
4649 vport->fc_rscn_flush = 1;
4650 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004651 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004652 lp = vport->fc_rscn_id_list[i]->virt;
4653 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4654 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004655 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004656 rscn_did.un.word = be32_to_cpu(*lp++);
4657 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004658 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4659 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004660 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4661 && (ns_did.un.b.area == rscn_did.un.b.area)
4662 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004663 goto return_did_out;
dea31012005-04-17 16:05:31 -05004664 break;
James Smarteaf15d52008-12-04 22:39:29 -05004665 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004666 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4667 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004668 goto return_did_out;
dea31012005-04-17 16:05:31 -05004669 break;
James Smarteaf15d52008-12-04 22:39:29 -05004670 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004671 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004672 goto return_did_out;
dea31012005-04-17 16:05:31 -05004673 break;
James Smarteaf15d52008-12-04 22:39:29 -05004674 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004675 goto return_did_out;
dea31012005-04-17 16:05:31 -05004676 }
4677 }
James Smart92d7f7b2007-06-17 19:56:38 -05004678 }
James Smart7f5f3d02008-02-08 18:50:14 -05004679 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4680 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004681 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004682return_did_out:
4683 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4684 vport->fc_rscn_flush = 0;
4685 return did;
dea31012005-04-17 16:05:31 -05004686}
4687
James Smarte59058c2008-08-24 21:49:00 -04004688/**
James Smart3621a712009-04-06 18:47:14 -04004689 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004690 * @vport: pointer to a host virtual N_Port data structure.
4691 *
4692 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4693 * state machine for a @vport's nodes that are with pending RSCN (Registration
4694 * State Change Notification).
4695 *
4696 * Return code
4697 * 0 - Successful (currently alway return 0)
4698 **/
dea31012005-04-17 16:05:31 -05004699static int
James Smart2e0fef82007-06-17 19:56:36 -05004700lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004701{
James Smart685f0bf2007-04-25 09:53:08 -04004702 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004703
James Smart0d2b6b82008-06-14 22:52:47 -04004704 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004705 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004706 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004707 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4708 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004709 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004710 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004711 NLP_EVT_DEVICE_RECOVERY);
4712 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004713 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004714 return 0;
dea31012005-04-17 16:05:31 -05004715}
4716
James Smarte59058c2008-08-24 21:49:00 -04004717/**
James Smart3621a712009-04-06 18:47:14 -04004718 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004719 * @vport: pointer to a host virtual N_Port data structure.
4720 * @cmdiocb: pointer to lpfc command iocb data structure.
4721 *
4722 * lpfc_send_rscn_event sends an RSCN netlink event to management
4723 * applications.
4724 */
4725static void
4726lpfc_send_rscn_event(struct lpfc_vport *vport,
4727 struct lpfc_iocbq *cmdiocb)
4728{
4729 struct lpfc_dmabuf *pcmd;
4730 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4731 uint32_t *payload_ptr;
4732 uint32_t payload_len;
4733 struct lpfc_rscn_event_header *rscn_event_data;
4734
4735 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4736 payload_ptr = (uint32_t *) pcmd->virt;
4737 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4738
4739 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4740 payload_len, GFP_KERNEL);
4741 if (!rscn_event_data) {
4742 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4743 "0147 Failed to allocate memory for RSCN event\n");
4744 return;
4745 }
4746 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4747 rscn_event_data->payload_length = payload_len;
4748 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4749 payload_len);
4750
4751 fc_host_post_vendor_event(shost,
4752 fc_get_event_number(),
4753 sizeof(struct lpfc_els_event_header) + payload_len,
4754 (char *)rscn_event_data,
4755 LPFC_NL_VENDOR_ID);
4756
4757 kfree(rscn_event_data);
4758}
4759
4760/**
James Smart3621a712009-04-06 18:47:14 -04004761 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004762 * @vport: pointer to a host virtual N_Port data structure.
4763 * @cmdiocb: pointer to lpfc command iocb data structure.
4764 * @ndlp: pointer to a node-list data structure.
4765 *
4766 * This routine processes an unsolicited RSCN (Registration State Change
4767 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4768 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4769 * discover state machine is about to begin discovery, it just accepts the
4770 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4771 * contains N_Port IDs for other vports on this HBA, it just accepts the
4772 * RSCN and ignore processing it. If the state machine is in the recovery
4773 * state, the fc_rscn_id_list of this @vport is walked and the
4774 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4775 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4776 * routine is invoked to handle the RSCN event.
4777 *
4778 * Return code
4779 * 0 - Just sent the acc response
4780 * 1 - Sent the acc response and waited for name server completion
4781 **/
dea31012005-04-17 16:05:31 -05004782static int
James Smart2e0fef82007-06-17 19:56:36 -05004783lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004784 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004785{
James Smart2e0fef82007-06-17 19:56:36 -05004786 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4787 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004788 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004789 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004790 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004791 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004792 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004793 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004794 int i;
dea31012005-04-17 16:05:31 -05004795
4796 icmd = &cmdiocb->iocb;
4797 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4798 lp = (uint32_t *) pcmd->virt;
4799
James Smart92d7f7b2007-06-17 19:56:38 -05004800 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4801 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004802 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004803 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4804 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004805 vport->fc_flag, payload_len, *lp,
4806 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004807
4808 /* Send an RSCN event to the management application */
4809 lpfc_send_rscn_event(vport, cmdiocb);
4810
James Smartd2873e42006-08-18 17:46:43 -04004811 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004812 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004813 FCH_EVT_RSCN, lp[i]);
4814
dea31012005-04-17 16:05:31 -05004815 /* If we are about to begin discovery, just ACC the RSCN.
4816 * Discovery processing will satisfy it.
4817 */
James Smart2e0fef82007-06-17 19:56:36 -05004818 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004819 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4820 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4821 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4822
James Smart51ef4c22007-08-02 11:10:31 -04004823 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004824 return 0;
dea31012005-04-17 16:05:31 -05004825 }
4826
James Smart92d7f7b2007-06-17 19:56:38 -05004827 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4828 * just ACC and ignore it.
4829 */
4830 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004831 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004832 i = payload_len;
4833 datap = lp;
4834 while (i > 0) {
4835 nportid = *datap++;
4836 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4837 i -= sizeof(uint32_t);
4838 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004839 if (lpfc_find_vport_by_did(phba, nportid))
4840 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004841 }
4842 if (rscn_id == hba_id) {
4843 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004844 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004845 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004846 "Data: x%x x%x x%x x%x\n",
4847 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004848 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004849 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4850 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4851 ndlp->nlp_DID, vport->port_state,
4852 ndlp->nlp_flag);
4853
James Smart92d7f7b2007-06-17 19:56:38 -05004854 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004855 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004856 return 0;
4857 }
4858 }
4859
James Smart7f5f3d02008-02-08 18:50:14 -05004860 spin_lock_irq(shost->host_lock);
4861 if (vport->fc_rscn_flush) {
4862 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004863 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004864 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004865 /* Send back ACC */
4866 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004867 return 0;
4868 }
4869 /* Indicate we are walking fc_rscn_id_list on this vport */
4870 vport->fc_rscn_flush = 1;
4871 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004872 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004873 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004874 /* If we are already processing an RSCN, save the received
4875 * RSCN payload buffer, cmdiocb->context2 to process later.
4876 */
James Smart2e0fef82007-06-17 19:56:36 -05004877 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004878 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4879 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4880 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4881
James Smart09372822008-01-11 01:52:54 -05004882 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004883 vport->fc_flag |= FC_RSCN_DEFERRED;
4884 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004885 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004886 vport->fc_flag |= FC_RSCN_MODE;
4887 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004888 if (rscn_cnt) {
4889 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4890 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4891 }
4892 if ((rscn_cnt) &&
4893 (payload_len + length <= LPFC_BPL_SIZE)) {
4894 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004895 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004896 memcpy(((uint8_t *)cmd) + length, lp,
4897 payload_len);
4898 } else {
4899 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4900 vport->fc_rscn_id_cnt++;
4901 /* If we zero, cmdiocb->context2, the calling
4902 * routine will not try to free it.
4903 */
4904 cmdiocb->context2 = NULL;
4905 }
dea31012005-04-17 16:05:31 -05004906 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004907 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4908 "0235 Deferred RSCN "
4909 "Data: x%x x%x x%x\n",
4910 vport->fc_rscn_id_cnt, vport->fc_flag,
4911 vport->port_state);
dea31012005-04-17 16:05:31 -05004912 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004913 vport->fc_flag |= FC_RSCN_DISCOVERY;
4914 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004915 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004916 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4917 "0234 ReDiscovery RSCN "
4918 "Data: x%x x%x x%x\n",
4919 vport->fc_rscn_id_cnt, vport->fc_flag,
4920 vport->port_state);
dea31012005-04-17 16:05:31 -05004921 }
James Smart7f5f3d02008-02-08 18:50:14 -05004922 /* Indicate we are done walking fc_rscn_id_list on this vport */
4923 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004924 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004925 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004926 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004927 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004928 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004929 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004930 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004931 return 0;
dea31012005-04-17 16:05:31 -05004932 }
James Smart858c9f62007-06-17 19:56:39 -05004933 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4934 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4935 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4936
James Smart2e0fef82007-06-17 19:56:36 -05004937 spin_lock_irq(shost->host_lock);
4938 vport->fc_flag |= FC_RSCN_MODE;
4939 spin_unlock_irq(shost->host_lock);
4940 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004941 /* Indicate we are done walking fc_rscn_id_list on this vport */
4942 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004943 /*
4944 * If we zero, cmdiocb->context2, the calling routine will
4945 * not try to free it.
4946 */
4947 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004948 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004949 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004950 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004951 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004952 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004953 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004954}
4955
James Smarte59058c2008-08-24 21:49:00 -04004956/**
James Smart3621a712009-04-06 18:47:14 -04004957 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004958 * @vport: pointer to a host virtual N_Port data structure.
4959 *
4960 * This routine handles the Registration State Configuration Notification
4961 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4962 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4963 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4964 * NameServer shall be issued. If CT command to the NameServer fails to be
4965 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4966 * RSCN activities with the @vport.
4967 *
4968 * Return code
4969 * 0 - Cleaned up rscn on the @vport
4970 * 1 - Wait for plogi to name server before proceed
4971 **/
dea31012005-04-17 16:05:31 -05004972int
James Smart2e0fef82007-06-17 19:56:36 -05004973lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004974{
4975 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004976 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004977
James Smart92d7f7b2007-06-17 19:56:38 -05004978 /* Ignore RSCN if the port is being torn down. */
4979 if (vport->load_flag & FC_UNLOADING) {
4980 lpfc_els_flush_rscn(vport);
4981 return 0;
4982 }
4983
dea31012005-04-17 16:05:31 -05004984 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004985 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004986
4987 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004988 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4989 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4990 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4991 vport->port_state);
dea31012005-04-17 16:05:31 -05004992
4993 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004994 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004995 vport->num_disc_nodes = 0;
4996
James Smart2e0fef82007-06-17 19:56:36 -05004997 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004998 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4999 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05005000 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05005001 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05005002 /* Wait for NameServer query cmpl before we can
5003 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005004 return 1;
dea31012005-04-17 16:05:31 -05005005 } else {
5006 /* If login to NameServer does not exist, issue one */
5007 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05005008 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005009 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05005010 /* Wait for NameServer login cmpl before we can
5011 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005012 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05005013
James Smarte47c9092008-02-08 18:49:26 -05005014 if (ndlp) {
5015 ndlp = lpfc_enable_node(vport, ndlp,
5016 NLP_STE_PLOGI_ISSUE);
5017 if (!ndlp) {
5018 lpfc_els_flush_rscn(vport);
5019 return 0;
5020 }
5021 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05005022 } else {
James Smarte47c9092008-02-08 18:49:26 -05005023 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5024 if (!ndlp) {
5025 lpfc_els_flush_rscn(vport);
5026 return 0;
5027 }
James Smart2e0fef82007-06-17 19:56:36 -05005028 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005029 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005030 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05005031 }
James Smarte47c9092008-02-08 18:49:26 -05005032 ndlp->nlp_type |= NLP_FABRIC;
5033 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
5034 /* Wait for NameServer login cmpl before we can
5035 * continue
5036 */
5037 return 1;
dea31012005-04-17 16:05:31 -05005038 }
5039
James Smart2e0fef82007-06-17 19:56:36 -05005040 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005041 return 0;
dea31012005-04-17 16:05:31 -05005042}
5043
James Smarte59058c2008-08-24 21:49:00 -04005044/**
James Smart3621a712009-04-06 18:47:14 -04005045 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04005046 * @vport: pointer to a host virtual N_Port data structure.
5047 * @cmdiocb: pointer to lpfc command iocb data structure.
5048 * @ndlp: pointer to a node-list data structure.
5049 *
5050 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
5051 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
5052 * point topology. As an unsolicited FLOGI should not be received in a loop
5053 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
5054 * lpfc_check_sparm() routine is invoked to check the parameters in the
5055 * unsolicited FLOGI. If parameters validation failed, the routine
5056 * lpfc_els_rsp_reject() shall be called with reject reason code set to
5057 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
5058 * FLOGI shall be compared with the Port WWN of the @vport to determine who
5059 * will initiate PLOGI. The higher lexicographical value party shall has
5060 * higher priority (as the winning port) and will initiate PLOGI and
5061 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
5062 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
5063 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
5064 *
5065 * Return code
5066 * 0 - Successfully processed the unsolicited flogi
5067 * 1 - Failed to process the unsolicited flogi
5068 **/
dea31012005-04-17 16:05:31 -05005069static int
James Smart2e0fef82007-06-17 19:56:36 -05005070lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04005071 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005072{
James Smart2e0fef82007-06-17 19:56:36 -05005073 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5074 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005075 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5076 uint32_t *lp = (uint32_t *) pcmd->virt;
5077 IOCB_t *icmd = &cmdiocb->iocb;
5078 struct serv_parm *sp;
5079 LPFC_MBOXQ_t *mbox;
5080 struct ls_rjt stat;
5081 uint32_t cmd, did;
5082 int rc;
James Smarte74c03c2013-04-17 20:15:19 -04005083 uint32_t fc_flag = 0;
5084 uint32_t port_state = 0;
dea31012005-04-17 16:05:31 -05005085
5086 cmd = *lp++;
5087 sp = (struct serv_parm *) lp;
5088
5089 /* FLOGI received */
5090
James Smart2e0fef82007-06-17 19:56:36 -05005091 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05005092
James Smart76a95d72010-11-20 23:11:48 -05005093 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05005094 /* We should never receive a FLOGI in loop mode, ignore it */
5095 did = icmd->un.elsreq64.remoteID;
5096
5097 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
5098 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04005099 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5100 "0113 An FLOGI ELS command x%x was "
5101 "received from DID x%x in Loop Mode\n",
5102 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005103 return 1;
dea31012005-04-17 16:05:31 -05005104 }
5105
James Smart341af102010-01-26 23:07:37 -05005106 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05005107 /* For a FLOGI we accept, then if our portname is greater
5108 * then the remote portname we initiate Nport login.
5109 */
5110
James Smart2e0fef82007-06-17 19:56:36 -05005111 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05005112 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05005113
5114 if (!rc) {
James Smart1b511972011-12-13 13:23:09 -05005115 if (phba->sli_rev < LPFC_SLI_REV4) {
5116 mbox = mempool_alloc(phba->mbox_mem_pool,
5117 GFP_KERNEL);
5118 if (!mbox)
5119 return 1;
5120 lpfc_linkdown(phba);
5121 lpfc_init_link(phba, mbox,
5122 phba->cfg_topology,
5123 phba->cfg_link_speed);
5124 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
5125 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5126 mbox->vport = vport;
5127 rc = lpfc_sli_issue_mbox(phba, mbox,
5128 MBX_NOWAIT);
5129 lpfc_set_loopback_flag(phba);
5130 if (rc == MBX_NOT_FINISHED)
5131 mempool_free(mbox, phba->mbox_mem_pool);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005132 return 1;
James Smart1b511972011-12-13 13:23:09 -05005133 } else {
5134 /* abort the flogi coming back to ourselves
5135 * due to external loopback on the port.
5136 */
5137 lpfc_els_abort_flogi(phba);
5138 return 0;
dea31012005-04-17 16:05:31 -05005139 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005140 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05005141 spin_lock_irq(shost->host_lock);
5142 vport->fc_flag |= FC_PT2PT_PLOGI;
5143 spin_unlock_irq(shost->host_lock);
James Smart939723a2012-05-09 21:19:03 -04005144
5145 /* If we have the high WWPN we can assign our own
5146 * myDID; otherwise, we have to WAIT for a PLOGI
5147 * from the remote NPort to find out what it
5148 * will be.
5149 */
James Smarte6446432012-05-09 21:16:42 -04005150 vport->fc_myDID = PT2PT_LocalID;
James Smarte74c03c2013-04-17 20:15:19 -04005151 } else
5152 vport->fc_myDID = PT2PT_RemoteID;
James Smart939723a2012-05-09 21:19:03 -04005153
5154 /*
5155 * The vport state should go to LPFC_FLOGI only
5156 * AFTER we issue a FLOGI, not receive one.
5157 */
James Smart2e0fef82007-06-17 19:56:36 -05005158 spin_lock_irq(shost->host_lock);
James Smarte74c03c2013-04-17 20:15:19 -04005159 fc_flag = vport->fc_flag;
5160 port_state = vport->port_state;
James Smart2e0fef82007-06-17 19:56:36 -05005161 vport->fc_flag |= FC_PT2PT;
5162 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
James Smarte74c03c2013-04-17 20:15:19 -04005163 vport->port_state = LPFC_FLOGI;
James Smart2e0fef82007-06-17 19:56:36 -05005164 spin_unlock_irq(shost->host_lock);
James Smarte74c03c2013-04-17 20:15:19 -04005165 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5166 "3311 Rcv Flogi PS x%x new PS x%x "
5167 "fc_flag x%x new fc_flag x%x\n",
5168 port_state, vport->port_state,
5169 fc_flag, vport->fc_flag);
James Smart939723a2012-05-09 21:19:03 -04005170
5171 /*
5172 * We temporarily set fc_myDID to make it look like we are
5173 * a Fabric. This is done just so we end up with the right
5174 * did / sid on the FLOGI ACC rsp.
5175 */
5176 did = vport->fc_myDID;
5177 vport->fc_myDID = Fabric_DID;
5178
dea31012005-04-17 16:05:31 -05005179 } else {
5180 /* Reject this request because invalid parameters */
5181 stat.un.b.lsRjtRsvd0 = 0;
5182 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5183 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
5184 stat.un.b.vendorUnique = 0;
James Smart939723a2012-05-09 21:19:03 -04005185
5186 /*
5187 * We temporarily set fc_myDID to make it look like we are
5188 * a Fabric. This is done just so we end up with the right
5189 * did / sid on the FLOGI LS_RJT rsp.
5190 */
5191 did = vport->fc_myDID;
5192 vport->fc_myDID = Fabric_DID;
5193
James Smart858c9f62007-06-17 19:56:39 -05005194 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5195 NULL);
James Smart939723a2012-05-09 21:19:03 -04005196
5197 /* Now lets put fc_myDID back to what its supposed to be */
5198 vport->fc_myDID = did;
5199
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005200 return 1;
dea31012005-04-17 16:05:31 -05005201 }
5202
5203 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04005204 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005205
James Smart939723a2012-05-09 21:19:03 -04005206 /* Now lets put fc_myDID back to what its supposed to be */
5207 vport->fc_myDID = did;
5208
James Smarte6446432012-05-09 21:16:42 -04005209 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
James Smart939723a2012-05-09 21:19:03 -04005210
James Smarte6446432012-05-09 21:16:42 -04005211 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5212 if (!mbox)
5213 goto fail;
5214
5215 lpfc_config_link(phba, mbox);
5216
5217 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5218 mbox->vport = vport;
5219 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5220 if (rc == MBX_NOT_FINISHED) {
5221 mempool_free(mbox, phba->mbox_mem_pool);
5222 goto fail;
5223 }
5224 }
5225
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005226 return 0;
James Smarte6446432012-05-09 21:16:42 -04005227fail:
5228 return 1;
dea31012005-04-17 16:05:31 -05005229}
5230
James Smarte59058c2008-08-24 21:49:00 -04005231/**
James Smart3621a712009-04-06 18:47:14 -04005232 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04005233 * @vport: pointer to a host virtual N_Port data structure.
5234 * @cmdiocb: pointer to lpfc command iocb data structure.
5235 * @ndlp: pointer to a node-list data structure.
5236 *
5237 * This routine processes Request Node Identification Data (RNID) IOCB
5238 * received as an ELS unsolicited event. Only when the RNID specified format
5239 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
5240 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
5241 * Accept (ACC) the RNID ELS command. All the other RNID formats are
5242 * rejected by invoking the lpfc_els_rsp_reject() routine.
5243 *
5244 * Return code
5245 * 0 - Successfully processed rnid iocb (currently always return 0)
5246 **/
dea31012005-04-17 16:05:31 -05005247static int
James Smart2e0fef82007-06-17 19:56:36 -05005248lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5249 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005250{
5251 struct lpfc_dmabuf *pcmd;
5252 uint32_t *lp;
5253 IOCB_t *icmd;
5254 RNID *rn;
5255 struct ls_rjt stat;
5256 uint32_t cmd, did;
5257
5258 icmd = &cmdiocb->iocb;
5259 did = icmd->un.elsreq64.remoteID;
5260 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5261 lp = (uint32_t *) pcmd->virt;
5262
5263 cmd = *lp++;
5264 rn = (RNID *) lp;
5265
5266 /* RNID received */
5267
5268 switch (rn->Format) {
5269 case 0:
5270 case RNID_TOPOLOGY_DISC:
5271 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05005272 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005273 break;
5274 default:
5275 /* Reject this request because format not supported */
5276 stat.un.b.lsRjtRsvd0 = 0;
5277 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5278 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5279 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005280 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5281 NULL);
dea31012005-04-17 16:05:31 -05005282 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005283 return 0;
dea31012005-04-17 16:05:31 -05005284}
5285
James Smarte59058c2008-08-24 21:49:00 -04005286/**
James Smart12265f62010-10-22 11:05:53 -04005287 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
5288 * @vport: pointer to a host virtual N_Port data structure.
5289 * @cmdiocb: pointer to lpfc command iocb data structure.
5290 * @ndlp: pointer to a node-list data structure.
5291 *
5292 * Return code
5293 * 0 - Successfully processed echo iocb (currently always return 0)
5294 **/
5295static int
5296lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5297 struct lpfc_nodelist *ndlp)
5298{
5299 uint8_t *pcmd;
5300
5301 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
5302
5303 /* skip over first word of echo command to find echo data */
5304 pcmd += sizeof(uint32_t);
5305
5306 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
5307 return 0;
5308}
5309
5310/**
James Smart3621a712009-04-06 18:47:14 -04005311 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04005312 * @vport: pointer to a host virtual N_Port data structure.
5313 * @cmdiocb: pointer to lpfc command iocb data structure.
5314 * @ndlp: pointer to a node-list data structure.
5315 *
5316 * This routine processes a Link Incident Report Registration(LIRR) IOCB
5317 * received as an ELS unsolicited event. Currently, this function just invokes
5318 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
5319 *
5320 * Return code
5321 * 0 - Successfully processed lirr iocb (currently always return 0)
5322 **/
dea31012005-04-17 16:05:31 -05005323static int
James Smart2e0fef82007-06-17 19:56:36 -05005324lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5325 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005326{
5327 struct ls_rjt stat;
5328
5329 /* For now, unconditionally reject this command */
5330 stat.un.b.lsRjtRsvd0 = 0;
5331 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5332 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5333 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005334 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005335 return 0;
5336}
5337
James Smarte59058c2008-08-24 21:49:00 -04005338/**
James Smart5ffc2662009-11-18 15:39:44 -05005339 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5340 * @vport: pointer to a host virtual N_Port data structure.
5341 * @cmdiocb: pointer to lpfc command iocb data structure.
5342 * @ndlp: pointer to a node-list data structure.
5343 *
5344 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5345 * received as an ELS unsolicited event. A request to RRQ shall only
5346 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5347 * Nx_Port N_Port_ID of the target Exchange is the same as the
5348 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5349 * not accepted, an LS_RJT with reason code "Unable to perform
5350 * command request" and reason code explanation "Invalid Originator
5351 * S_ID" shall be returned. For now, we just unconditionally accept
5352 * RRQ from the target.
5353 **/
5354static void
5355lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5356 struct lpfc_nodelist *ndlp)
5357{
5358 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05005359 if (vport->phba->sli_rev == LPFC_SLI_REV4)
5360 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05005361}
5362
5363/**
James Smart12265f62010-10-22 11:05:53 -04005364 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5365 * @phba: pointer to lpfc hba data structure.
5366 * @pmb: pointer to the driver internal queue element for mailbox command.
5367 *
5368 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5369 * mailbox command. This callback function is to actually send the Accept
5370 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5371 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5372 * mailbox command, constructs the RPS response with the link statistics
5373 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5374 * response to the RPS.
5375 *
5376 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5377 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5378 * will be stored into the context1 field of the IOCB for the completion
5379 * callback function to the RPS Accept Response ELS IOCB command.
5380 *
5381 **/
5382static void
5383lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5384{
5385 MAILBOX_t *mb;
5386 IOCB_t *icmd;
5387 struct RLS_RSP *rls_rsp;
5388 uint8_t *pcmd;
5389 struct lpfc_iocbq *elsiocb;
5390 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005391 uint16_t oxid;
5392 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04005393 uint32_t cmdsize;
5394
5395 mb = &pmb->u.mb;
5396
5397 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005398 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5399 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
James Smart12265f62010-10-22 11:05:53 -04005400 pmb->context1 = NULL;
5401 pmb->context2 = NULL;
5402
5403 if (mb->mbxStatus) {
5404 mempool_free(pmb, phba->mbox_mem_pool);
5405 return;
5406 }
5407
5408 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
James Smart12265f62010-10-22 11:05:53 -04005409 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5410 lpfc_max_els_tries, ndlp,
5411 ndlp->nlp_DID, ELS_CMD_ACC);
5412
5413 /* Decrement the ndlp reference count from previous mbox command */
5414 lpfc_nlp_put(ndlp);
5415
James Smart37db57e2012-05-09 21:17:16 -04005416 if (!elsiocb) {
5417 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04005418 return;
James Smart37db57e2012-05-09 21:17:16 -04005419 }
James Smart12265f62010-10-22 11:05:53 -04005420
5421 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005422 icmd->ulpContext = rxid;
5423 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04005424
5425 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5426 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5427 pcmd += sizeof(uint32_t); /* Skip past command */
5428 rls_rsp = (struct RLS_RSP *)pcmd;
5429
5430 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5431 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5432 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5433 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5434 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5435 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
James Smart37db57e2012-05-09 21:17:16 -04005436 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04005437 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5438 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5439 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5440 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5441 elsiocb->iotag, elsiocb->iocb.ulpContext,
5442 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5443 ndlp->nlp_rpi);
5444 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5445 phba->fc_stat.elsXmitACC++;
5446 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5447 lpfc_els_free_iocb(phba, elsiocb);
5448}
5449
5450/**
James Smart3621a712009-04-06 18:47:14 -04005451 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04005452 * @phba: pointer to lpfc hba data structure.
5453 * @pmb: pointer to the driver internal queue element for mailbox command.
5454 *
5455 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5456 * mailbox command. This callback function is to actually send the Accept
5457 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5458 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5459 * mailbox command, constructs the RPS response with the link statistics
5460 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5461 * response to the RPS.
5462 *
5463 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5464 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5465 * will be stored into the context1 field of the IOCB for the completion
5466 * callback function to the RPS Accept Response ELS IOCB command.
5467 *
5468 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005469static void
James Smart329f9bc2007-04-25 09:53:01 -04005470lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005471{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005472 MAILBOX_t *mb;
5473 IOCB_t *icmd;
5474 RPS_RSP *rps_rsp;
5475 uint8_t *pcmd;
5476 struct lpfc_iocbq *elsiocb;
5477 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005478 uint16_t status;
5479 uint16_t oxid;
5480 uint16_t rxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005481 uint32_t cmdsize;
5482
James Smart04c68492009-05-22 14:52:52 -04005483 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005484
5485 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005486 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5487 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
Randy Dunlap041976f2006-06-25 01:58:51 -07005488 pmb->context1 = NULL;
5489 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005490
5491 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04005492 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005493 return;
5494 }
5495
5496 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04005497 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005498 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5499 lpfc_max_els_tries, ndlp,
5500 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05005501
5502 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04005503 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05005504
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005505 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005506 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005507
5508 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005509 icmd->ulpContext = rxid;
5510 icmd->unsli3.rcvsli3.ox_id = oxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005511
5512 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5513 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005514 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005515 rps_rsp = (RPS_RSP *)pcmd;
5516
James Smart76a95d72010-11-20 23:11:48 -05005517 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005518 status = 0x10;
5519 else
5520 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05005521 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005522 status |= 0x4;
5523
5524 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05005525 rps_rsp->portStatus = cpu_to_be16(status);
5526 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5527 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5528 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5529 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5530 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5531 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005532 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005533 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5534 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5535 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5536 elsiocb->iotag, elsiocb->iocb.ulpContext,
5537 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5538 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005539 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005540 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005541 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005542 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005543 return;
5544}
5545
James Smarte59058c2008-08-24 21:49:00 -04005546/**
James Smart12265f62010-10-22 11:05:53 -04005547 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5548 * @vport: pointer to a host virtual N_Port data structure.
5549 * @cmdiocb: pointer to lpfc command iocb data structure.
5550 * @ndlp: pointer to a node-list data structure.
5551 *
5552 * This routine processes Read Port Status (RPL) IOCB received as an
5553 * ELS unsolicited event. It first checks the remote port state. If the
5554 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5555 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5556 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5557 * for reading the HBA link statistics. It is for the callback function,
5558 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5559 * to actually sending out RPL Accept (ACC) response.
5560 *
5561 * Return codes
5562 * 0 - Successfully processed rls iocb (currently always return 0)
5563 **/
5564static int
5565lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5566 struct lpfc_nodelist *ndlp)
5567{
5568 struct lpfc_hba *phba = vport->phba;
5569 LPFC_MBOXQ_t *mbox;
5570 struct lpfc_dmabuf *pcmd;
5571 struct ls_rjt stat;
5572
5573 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5574 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5575 /* reject the unsolicited RPS request and done with it */
5576 goto reject_out;
5577
5578 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5579
5580 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5581 if (mbox) {
5582 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005583 mbox->context1 = (void *)((unsigned long)
5584 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5585 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart12265f62010-10-22 11:05:53 -04005586 mbox->context2 = lpfc_nlp_get(ndlp);
5587 mbox->vport = vport;
5588 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5589 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5590 != MBX_NOT_FINISHED)
5591 /* Mbox completion will send ELS Response */
5592 return 0;
5593 /* Decrement reference count used for the failed mbox
5594 * command.
5595 */
5596 lpfc_nlp_put(ndlp);
5597 mempool_free(mbox, phba->mbox_mem_pool);
5598 }
5599reject_out:
5600 /* issue rejection response */
5601 stat.un.b.lsRjtRsvd0 = 0;
5602 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5603 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5604 stat.un.b.vendorUnique = 0;
5605 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5606 return 0;
5607}
5608
5609/**
5610 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5611 * @vport: pointer to a host virtual N_Port data structure.
5612 * @cmdiocb: pointer to lpfc command iocb data structure.
5613 * @ndlp: pointer to a node-list data structure.
5614 *
5615 * This routine processes Read Timout Value (RTV) IOCB received as an
5616 * ELS unsolicited event. It first checks the remote port state. If the
5617 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5618 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5619 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5620 * Value (RTV) unsolicited IOCB event.
5621 *
5622 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5623 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5624 * will be stored into the context1 field of the IOCB for the completion
5625 * callback function to the RPS Accept Response ELS IOCB command.
5626 *
5627 * Return codes
5628 * 0 - Successfully processed rtv iocb (currently always return 0)
5629 **/
5630static int
5631lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5632 struct lpfc_nodelist *ndlp)
5633{
5634 struct lpfc_hba *phba = vport->phba;
5635 struct ls_rjt stat;
5636 struct RTV_RSP *rtv_rsp;
5637 uint8_t *pcmd;
5638 struct lpfc_iocbq *elsiocb;
5639 uint32_t cmdsize;
5640
5641
5642 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5643 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5644 /* reject the unsolicited RPS request and done with it */
5645 goto reject_out;
5646
5647 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5648 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5649 lpfc_max_els_tries, ndlp,
5650 ndlp->nlp_DID, ELS_CMD_ACC);
5651
5652 if (!elsiocb)
5653 return 1;
5654
5655 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5656 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5657 pcmd += sizeof(uint32_t); /* Skip past command */
5658
5659 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04005660 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
5661 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04005662
5663 rtv_rsp = (struct RTV_RSP *)pcmd;
5664
5665 /* populate RTV payload */
5666 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5667 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5668 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5669 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5670 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5671
5672 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5673 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5674 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5675 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5676 "Data: x%x x%x x%x\n",
5677 elsiocb->iotag, elsiocb->iocb.ulpContext,
5678 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5679 ndlp->nlp_rpi,
5680 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5681 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5682 phba->fc_stat.elsXmitACC++;
5683 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5684 lpfc_els_free_iocb(phba, elsiocb);
5685 return 0;
5686
5687reject_out:
5688 /* issue rejection response */
5689 stat.un.b.lsRjtRsvd0 = 0;
5690 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5691 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5692 stat.un.b.vendorUnique = 0;
5693 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5694 return 0;
5695}
5696
5697/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005698 * @vport: pointer to a host virtual N_Port data structure.
5699 * @cmdiocb: pointer to lpfc command iocb data structure.
5700 * @ndlp: pointer to a node-list data structure.
5701 *
5702 * This routine processes Read Port Status (RPS) IOCB received as an
5703 * ELS unsolicited event. It first checks the remote port state. If the
5704 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5705 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5706 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5707 * for reading the HBA link statistics. It is for the callback function,
5708 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5709 * to actually sending out RPS Accept (ACC) response.
5710 *
5711 * Return codes
5712 * 0 - Successfully processed rps iocb (currently always return 0)
5713 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005714static int
James Smart2e0fef82007-06-17 19:56:36 -05005715lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5716 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005717{
James Smart2e0fef82007-06-17 19:56:36 -05005718 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005719 uint32_t *lp;
5720 uint8_t flag;
5721 LPFC_MBOXQ_t *mbox;
5722 struct lpfc_dmabuf *pcmd;
5723 RPS *rps;
5724 struct ls_rjt stat;
5725
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005726 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005727 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5728 /* reject the unsolicited RPS request and done with it */
5729 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005730
5731 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5732 lp = (uint32_t *) pcmd->virt;
5733 flag = (be32_to_cpu(*lp++) & 0xf);
5734 rps = (RPS *) lp;
5735
5736 if ((flag == 0) ||
5737 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005738 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005739 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005740
James Smart92d7f7b2007-06-17 19:56:38 -05005741 printk("Fix me....\n");
5742 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005743 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5744 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005745 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005746 mbox->context1 = (void *)((unsigned long)
5747 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5748 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart329f9bc2007-04-25 09:53:01 -04005749 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005750 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005751 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005752 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005753 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005754 /* Mbox completion will send ELS Response */
5755 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005756 /* Decrement reference count used for the failed mbox
5757 * command.
5758 */
James Smart329f9bc2007-04-25 09:53:01 -04005759 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005760 mempool_free(mbox, phba->mbox_mem_pool);
5761 }
5762 }
James Smart90160e02008-08-24 21:49:45 -04005763
5764reject_out:
5765 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005766 stat.un.b.lsRjtRsvd0 = 0;
5767 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5768 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5769 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005770 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005771 return 0;
5772}
5773
James Smart19ca7602010-11-20 23:11:55 -05005774/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5775 * @vport: pointer to a host virtual N_Port data structure.
5776 * @ndlp: pointer to a node-list data structure.
5777 * @did: DID of the target.
5778 * @rrq: Pointer to the rrq struct.
5779 *
5780 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5781 * Successful the the completion handler will clear the RRQ.
5782 *
5783 * Return codes
5784 * 0 - Successfully sent rrq els iocb.
5785 * 1 - Failed to send rrq els iocb.
5786 **/
5787static int
5788lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5789 uint32_t did, struct lpfc_node_rrq *rrq)
5790{
5791 struct lpfc_hba *phba = vport->phba;
5792 struct RRQ *els_rrq;
5793 IOCB_t *icmd;
5794 struct lpfc_iocbq *elsiocb;
5795 uint8_t *pcmd;
5796 uint16_t cmdsize;
5797 int ret;
5798
5799
5800 if (ndlp != rrq->ndlp)
5801 ndlp = rrq->ndlp;
5802 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5803 return 1;
5804
5805 /* If ndlp is not NULL, we will bump the reference count on it */
5806 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
5807 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
5808 ELS_CMD_RRQ);
5809 if (!elsiocb)
5810 return 1;
5811
5812 icmd = &elsiocb->iocb;
5813 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5814
5815 /* For RRQ request, remainder of payload is Exchange IDs */
5816 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
5817 pcmd += sizeof(uint32_t);
5818 els_rrq = (struct RRQ *) pcmd;
5819
James Smartee0f4fe2012-05-09 21:19:14 -04005820 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
James Smart19ca7602010-11-20 23:11:55 -05005821 bf_set(rrq_rxid, els_rrq, rrq->rxid);
5822 bf_set(rrq_did, els_rrq, vport->fc_myDID);
5823 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
5824 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
5825
5826
5827 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5828 "Issue RRQ: did:x%x",
5829 did, rrq->xritag, rrq->rxid);
5830 elsiocb->context_un.rrq = rrq;
5831 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
5832 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5833
5834 if (ret == IOCB_ERROR) {
5835 lpfc_els_free_iocb(phba, elsiocb);
5836 return 1;
5837 }
5838 return 0;
5839}
5840
5841/**
5842 * lpfc_send_rrq - Sends ELS RRQ if needed.
5843 * @phba: pointer to lpfc hba data structure.
5844 * @rrq: pointer to the active rrq.
5845 *
5846 * This routine will call the lpfc_issue_els_rrq if the rrq is
5847 * still active for the xri. If this function returns a failure then
5848 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5849 *
5850 * Returns 0 Success.
5851 * 1 Failure.
5852 **/
5853int
5854lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
5855{
5856 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
5857 rrq->nlp_DID);
5858 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
5859 return lpfc_issue_els_rrq(rrq->vport, ndlp,
5860 rrq->nlp_DID, rrq);
5861 else
5862 return 1;
5863}
5864
James Smarte59058c2008-08-24 21:49:00 -04005865/**
James Smart3621a712009-04-06 18:47:14 -04005866 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005867 * @vport: pointer to a host virtual N_Port data structure.
5868 * @cmdsize: size of the ELS command.
5869 * @oldiocb: pointer to the original lpfc command iocb data structure.
5870 * @ndlp: pointer to a node-list data structure.
5871 *
5872 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5873 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5874 *
5875 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5876 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5877 * will be stored into the context1 field of the IOCB for the completion
5878 * callback function to the RPL Accept Response ELS command.
5879 *
5880 * Return code
5881 * 0 - Successfully issued ACC RPL ELS command
5882 * 1 - Failed to issue ACC RPL ELS command
5883 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005884static int
James Smart2e0fef82007-06-17 19:56:36 -05005885lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5886 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005887{
James Smart2e0fef82007-06-17 19:56:36 -05005888 struct lpfc_hba *phba = vport->phba;
5889 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005890 RPL_RSP rpl_rsp;
5891 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005892 uint8_t *pcmd;
5893
James Smart2e0fef82007-06-17 19:56:36 -05005894 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5895 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005896
James Smart488d1462006-03-07 15:02:37 -05005897 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005898 return 1;
James Smart488d1462006-03-07 15:02:37 -05005899
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005900 icmd = &elsiocb->iocb;
5901 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005902 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5903 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005904
5905 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5906 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005907 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005908 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5909 pcmd += sizeof(uint16_t);
5910
5911 /* Setup the RPL ACC payload */
5912 rpl_rsp.listLen = be32_to_cpu(1);
5913 rpl_rsp.index = 0;
5914 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005915 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5916 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005917 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005918 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005919 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005920 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5921 "0120 Xmit ELS RPL ACC response tag x%x "
5922 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5923 "rpi x%x\n",
5924 elsiocb->iotag, elsiocb->iocb.ulpContext,
5925 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5926 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005927 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005928 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005929 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5930 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005931 lpfc_els_free_iocb(phba, elsiocb);
5932 return 1;
5933 }
5934 return 0;
5935}
5936
James Smarte59058c2008-08-24 21:49:00 -04005937/**
James Smart3621a712009-04-06 18:47:14 -04005938 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005939 * @vport: pointer to a host virtual N_Port data structure.
5940 * @cmdiocb: pointer to lpfc command iocb data structure.
5941 * @ndlp: pointer to a node-list data structure.
5942 *
5943 * This routine processes Read Port List (RPL) IOCB received as an ELS
5944 * unsolicited event. It first checks the remote port state. If the remote
5945 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5946 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5947 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5948 * to accept the RPL.
5949 *
5950 * Return code
5951 * 0 - Successfully processed rpl iocb (currently always return 0)
5952 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005953static int
James Smart2e0fef82007-06-17 19:56:36 -05005954lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5955 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005956{
5957 struct lpfc_dmabuf *pcmd;
5958 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005959 uint32_t maxsize;
5960 uint16_t cmdsize;
5961 RPL *rpl;
5962 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005963
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005964 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5965 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005966 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005967 stat.un.b.lsRjtRsvd0 = 0;
5968 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5969 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5970 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005971 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5972 NULL);
James Smart90160e02008-08-24 21:49:45 -04005973 /* rejected the unsolicited RPL request and done with it */
5974 return 0;
dea31012005-04-17 16:05:31 -05005975 }
5976
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005977 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5978 lp = (uint32_t *) pcmd->virt;
5979 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005980 maxsize = be32_to_cpu(rpl->maxsize);
5981
5982 /* We support only one port */
5983 if ((rpl->index == 0) &&
5984 ((maxsize == 0) ||
5985 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5986 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005987 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005988 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5989 }
James Smart2e0fef82007-06-17 19:56:36 -05005990 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005991
5992 return 0;
5993}
5994
James Smarte59058c2008-08-24 21:49:00 -04005995/**
James Smart3621a712009-04-06 18:47:14 -04005996 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005997 * @vport: pointer to a virtual N_Port data structure.
5998 * @cmdiocb: pointer to lpfc command iocb data structure.
5999 * @ndlp: pointer to a node-list data structure.
6000 *
6001 * This routine processes Fibre Channel Address Resolution Protocol
6002 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
6003 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
6004 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
6005 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
6006 * remote PortName is compared against the FC PortName stored in the @vport
6007 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
6008 * compared against the FC NodeName stored in the @vport data structure.
6009 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
6010 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
6011 * invoked to send out FARP Response to the remote node. Before sending the
6012 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
6013 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
6014 * routine is invoked to log into the remote port first.
6015 *
6016 * Return code
6017 * 0 - Either the FARP Match Mode not supported or successfully processed
6018 **/
dea31012005-04-17 16:05:31 -05006019static int
James Smart2e0fef82007-06-17 19:56:36 -05006020lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6021 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006022{
6023 struct lpfc_dmabuf *pcmd;
6024 uint32_t *lp;
6025 IOCB_t *icmd;
6026 FARP *fp;
6027 uint32_t cmd, cnt, did;
6028
6029 icmd = &cmdiocb->iocb;
6030 did = icmd->un.elsreq64.remoteID;
6031 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6032 lp = (uint32_t *) pcmd->virt;
6033
6034 cmd = *lp++;
6035 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05006036 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04006037 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6038 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05006039 /* We will only support match on WWPN or WWNN */
6040 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006041 return 0;
dea31012005-04-17 16:05:31 -05006042 }
6043
6044 cnt = 0;
6045 /* If this FARP command is searching for my portname */
6046 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05006047 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05006048 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05006049 cnt = 1;
6050 }
6051
6052 /* If this FARP command is searching for my nodename */
6053 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05006054 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05006055 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05006056 cnt = 1;
6057 }
6058
6059 if (cnt) {
6060 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
6061 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
6062 /* Log back into the node before sending the FARP. */
6063 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006064 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05006065 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04006066 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05006067 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05006068 }
6069
6070 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05006071 if (fp->Rflags & FARP_REQUEST_FARPR)
6072 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05006073 }
6074 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006075 return 0;
dea31012005-04-17 16:05:31 -05006076}
6077
James Smarte59058c2008-08-24 21:49:00 -04006078/**
James Smart3621a712009-04-06 18:47:14 -04006079 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04006080 * @vport: pointer to a host virtual N_Port data structure.
6081 * @cmdiocb: pointer to lpfc command iocb data structure.
6082 * @ndlp: pointer to a node-list data structure.
6083 *
6084 * This routine processes Fibre Channel Address Resolution Protocol
6085 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
6086 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
6087 * the FARP response request.
6088 *
6089 * Return code
6090 * 0 - Successfully processed FARPR IOCB (currently always return 0)
6091 **/
dea31012005-04-17 16:05:31 -05006092static int
James Smart2e0fef82007-06-17 19:56:36 -05006093lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6094 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006095{
6096 struct lpfc_dmabuf *pcmd;
6097 uint32_t *lp;
6098 IOCB_t *icmd;
6099 uint32_t cmd, did;
6100
6101 icmd = &cmdiocb->iocb;
6102 did = icmd->un.elsreq64.remoteID;
6103 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6104 lp = (uint32_t *) pcmd->virt;
6105
6106 cmd = *lp++;
6107 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04006108 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6109 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05006110 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04006111 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006112
6113 return 0;
6114}
6115
James Smarte59058c2008-08-24 21:49:00 -04006116/**
James Smart3621a712009-04-06 18:47:14 -04006117 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04006118 * @vport: pointer to a host virtual N_Port data structure.
6119 * @cmdiocb: pointer to lpfc command iocb data structure.
6120 * @fan_ndlp: pointer to a node-list data structure.
6121 *
6122 * This routine processes a Fabric Address Notification (FAN) IOCB
6123 * command received as an ELS unsolicited event. The FAN ELS command will
6124 * only be processed on a physical port (i.e., the @vport represents the
6125 * physical port). The fabric NodeName and PortName from the FAN IOCB are
6126 * compared against those in the phba data structure. If any of those is
6127 * different, the lpfc_initial_flogi() routine is invoked to initialize
6128 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
6129 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
6130 * is invoked to register login to the fabric.
6131 *
6132 * Return code
6133 * 0 - Successfully processed fan iocb (currently always return 0).
6134 **/
dea31012005-04-17 16:05:31 -05006135static int
James Smart2e0fef82007-06-17 19:56:36 -05006136lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6137 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05006138{
James Smart2e0fef82007-06-17 19:56:36 -05006139 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04006140 uint32_t *lp;
6141 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006142
James Smart0d2b6b82008-06-14 22:52:47 -04006143 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
6144 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
6145 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006146 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04006147 if ((vport == phba->pport) &&
6148 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006149 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04006150 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006151 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04006152 sizeof(struct lpfc_name)))) {
6153 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05006154 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04006155 } else {
6156 /* FAN verified - skip FLOGI */
6157 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04006158 if (phba->sli_rev < LPFC_SLI_REV4)
6159 lpfc_issue_fabric_reglogin(vport);
James Smart1b511972011-12-13 13:23:09 -05006160 else {
6161 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6162 "3138 Need register VFI: (x%x/%x)\n",
6163 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -04006164 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -05006165 }
dea31012005-04-17 16:05:31 -05006166 }
dea31012005-04-17 16:05:31 -05006167 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006168 return 0;
dea31012005-04-17 16:05:31 -05006169}
6170
James Smarte59058c2008-08-24 21:49:00 -04006171/**
James Smart3621a712009-04-06 18:47:14 -04006172 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04006173 * @ptr: holder for the timer function associated data.
6174 *
6175 * This routine is invoked by the ELS timer after timeout. It posts the ELS
6176 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
6177 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
6178 * up the worker thread. It is for the worker thread to invoke the routine
6179 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
6180 **/
dea31012005-04-17 16:05:31 -05006181void
6182lpfc_els_timeout(unsigned long ptr)
6183{
James Smart2e0fef82007-06-17 19:56:36 -05006184 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
6185 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04006186 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05006187 unsigned long iflag;
6188
James Smart2e0fef82007-06-17 19:56:36 -05006189 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04006190 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
6191 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05006192 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04006193 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05006194
James Smart5e9d9b82008-06-14 22:52:53 -04006195 if (!tmo_posted)
6196 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05006197 return;
6198}
6199
James Smart2a9bf3d2010-06-07 15:24:45 -04006200
James Smarte59058c2008-08-24 21:49:00 -04006201/**
James Smart3621a712009-04-06 18:47:14 -04006202 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04006203 * @vport: pointer to a virtual N_Port data structure.
6204 *
6205 * This routine is the actual handler function that processes an ELS timeout
6206 * event. It walks the ELS ring to get and abort all the IOCBs (except the
6207 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
6208 * invoking the lpfc_sli_issue_abort_iotag() routine.
6209 **/
dea31012005-04-17 16:05:31 -05006210void
James Smart2e0fef82007-06-17 19:56:36 -05006211lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006212{
James Smart2e0fef82007-06-17 19:56:36 -05006213 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006214 struct lpfc_sli_ring *pring;
6215 struct lpfc_iocbq *tmp_iocb, *piocb;
6216 IOCB_t *cmd = NULL;
6217 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05006218 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05006219 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05006220 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04006221 LIST_HEAD(txcmplq_completions);
6222 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05006223
James Smart2a9bf3d2010-06-07 15:24:45 -04006224
dea31012005-04-17 16:05:31 -05006225 timeout = (uint32_t)(phba->fc_ratov << 1);
6226
6227 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05006228
James Smart2a9bf3d2010-06-07 15:24:45 -04006229 spin_lock_irq(&phba->hbalock);
6230 list_splice_init(&pring->txcmplq, &txcmplq_completions);
6231 spin_unlock_irq(&phba->hbalock);
6232
6233 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05006234 cmd = &piocb->iocb;
6235
James Smart2e0fef82007-06-17 19:56:36 -05006236 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
6237 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
6238 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05006239 continue;
James Smart2e0fef82007-06-17 19:56:36 -05006240
6241 if (piocb->vport != vport)
6242 continue;
6243
dea31012005-04-17 16:05:31 -05006244 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05006245 if (pcmd)
6246 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05006247
James Smart92d7f7b2007-06-17 19:56:38 -05006248 if (els_command == ELS_CMD_FARP ||
6249 els_command == ELS_CMD_FARPR ||
6250 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05006251 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05006252
dea31012005-04-17 16:05:31 -05006253 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05006254 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05006255 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05006256 else
dea31012005-04-17 16:05:31 -05006257 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05006258 continue;
6259 }
6260
James Smart2e0fef82007-06-17 19:56:36 -05006261 remote_ID = 0xffffffff;
6262 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05006263 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05006264 else {
6265 struct lpfc_nodelist *ndlp;
6266 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04006267 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05006268 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05006269 }
James Smart2a9bf3d2010-06-07 15:24:45 -04006270 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05006271 }
James Smart2a9bf3d2010-06-07 15:24:45 -04006272 spin_lock_irq(&phba->hbalock);
6273 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05006274 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04006275
James Smart2a9bf3d2010-06-07 15:24:45 -04006276 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
6277 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6278 "0127 ELS timeout Data: x%x x%x x%x "
6279 "x%x\n", els_command,
6280 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
6281 spin_lock_irq(&phba->hbalock);
6282 list_del_init(&piocb->dlist);
6283 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6284 spin_unlock_irq(&phba->hbalock);
6285 }
6286
James Smart0e9bb8d2013-03-01 16:35:12 -05006287 if (!list_empty(&phba->sli.ring[LPFC_ELS_RING].txcmplq))
James Smart256ec0d2013-04-17 20:14:58 -04006288 mod_timer(&vport->els_tmofunc,
6289 jiffies + msecs_to_jiffies(1000 * timeout));
dea31012005-04-17 16:05:31 -05006290}
6291
James Smarte59058c2008-08-24 21:49:00 -04006292/**
James Smart3621a712009-04-06 18:47:14 -04006293 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04006294 * @vport: pointer to a host virtual N_Port data structure.
6295 *
6296 * This routine is used to clean up all the outstanding ELS commands on a
6297 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
6298 * routine. After that, it walks the ELS transmit queue to remove all the
6299 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
6300 * the IOCBs with a non-NULL completion callback function, the callback
6301 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6302 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
6303 * callback function, the IOCB will simply be released. Finally, it walks
6304 * the ELS transmit completion queue to issue an abort IOCB to any transmit
6305 * completion queue IOCB that is associated with the @vport and is not
6306 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
6307 * part of the discovery state machine) out to HBA by invoking the
6308 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
6309 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
6310 * the IOCBs are aborted when this function returns.
6311 **/
dea31012005-04-17 16:05:31 -05006312void
James Smart2e0fef82007-06-17 19:56:36 -05006313lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006314{
James Smart2534ba72007-04-25 09:52:20 -04006315 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05006316 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04006317 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05006318 struct lpfc_iocbq *tmp_iocb, *piocb;
6319 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006320
6321 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05006322
James Smart2e0fef82007-06-17 19:56:36 -05006323 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006324 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6325 cmd = &piocb->iocb;
6326
6327 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6328 continue;
6329 }
6330
6331 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04006332 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6333 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6334 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6335 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05006336 continue;
dea31012005-04-17 16:05:31 -05006337
James Smart2e0fef82007-06-17 19:56:36 -05006338 if (piocb->vport != vport)
6339 continue;
6340
James Smart2534ba72007-04-25 09:52:20 -04006341 list_move_tail(&piocb->list, &completions);
dea31012005-04-17 16:05:31 -05006342 }
6343
6344 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05006345 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6346 continue;
6347 }
dea31012005-04-17 16:05:31 -05006348
James Smart2e0fef82007-06-17 19:56:36 -05006349 if (piocb->vport != vport)
6350 continue;
6351
James Smart07951072007-04-25 09:51:38 -04006352 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05006353 }
James Smart2e0fef82007-06-17 19:56:36 -05006354 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04006355
James Smarta257bf92009-04-06 18:48:10 -04006356 /* Cancell all the IOCBs from the completions list */
6357 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6358 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04006359
dea31012005-04-17 16:05:31 -05006360 return;
6361}
6362
James Smarte59058c2008-08-24 21:49:00 -04006363/**
James Smart3621a712009-04-06 18:47:14 -04006364 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04006365 * @phba: pointer to lpfc hba data structure.
6366 *
6367 * This routine is used to clean up all the outstanding ELS commands on a
6368 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
6369 * routine. After that, it walks the ELS transmit queue to remove all the
6370 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
6371 * the IOCBs with the completion callback function associated, the callback
6372 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6373 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
6374 * callback function associated, the IOCB will simply be released. Finally,
6375 * it walks the ELS transmit completion queue to issue an abort IOCB to any
6376 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
6377 * management plane IOCBs that are not part of the discovery state machine)
6378 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
6379 **/
James Smart549e55c2007-08-02 11:09:51 -04006380void
6381lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
6382{
6383 LIST_HEAD(completions);
6384 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6385 struct lpfc_iocbq *tmp_iocb, *piocb;
6386 IOCB_t *cmd = NULL;
6387
6388 lpfc_fabric_abort_hba(phba);
6389 spin_lock_irq(&phba->hbalock);
6390 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6391 cmd = &piocb->iocb;
6392 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6393 continue;
6394 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6395 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6396 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6397 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6398 cmd->ulpCommand == CMD_ABORT_XRI_CN)
6399 continue;
6400 list_move_tail(&piocb->list, &completions);
James Smart549e55c2007-08-02 11:09:51 -04006401 }
6402 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6403 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6404 continue;
6405 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6406 }
6407 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04006408
6409 /* Cancel all the IOCBs from the completions list */
6410 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6411 IOERR_SLI_ABORTED);
6412
James Smart549e55c2007-08-02 11:09:51 -04006413 return;
6414}
6415
James Smarte59058c2008-08-24 21:49:00 -04006416/**
James Smart3621a712009-04-06 18:47:14 -04006417 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04006418 * @phba: Pointer to hba context object.
6419 * @cmdiocbp: Pointer to command iocb which reported error.
6420 * @rspiocbp: Pointer to response iocb which reported error.
6421 *
6422 * This function sends an event when there is an ELS command
6423 * failure.
6424 **/
6425void
6426lpfc_send_els_failure_event(struct lpfc_hba *phba,
6427 struct lpfc_iocbq *cmdiocbp,
6428 struct lpfc_iocbq *rspiocbp)
6429{
6430 struct lpfc_vport *vport = cmdiocbp->vport;
6431 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6432 struct lpfc_lsrjt_event lsrjt_event;
6433 struct lpfc_fabric_event_header fabric_event;
6434 struct ls_rjt stat;
6435 struct lpfc_nodelist *ndlp;
6436 uint32_t *pcmd;
6437
6438 ndlp = cmdiocbp->context1;
6439 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6440 return;
6441
6442 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
6443 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
6444 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
6445 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
6446 sizeof(struct lpfc_name));
6447 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
6448 sizeof(struct lpfc_name));
6449 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
6450 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04006451 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04006452 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
6453 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
6454 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
6455 fc_host_post_vendor_event(shost,
6456 fc_get_event_number(),
6457 sizeof(lsrjt_event),
6458 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05006459 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006460 return;
6461 }
6462 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
6463 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
6464 fabric_event.event_type = FC_REG_FABRIC_EVENT;
6465 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
6466 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
6467 else
6468 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
6469 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
6470 sizeof(struct lpfc_name));
6471 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
6472 sizeof(struct lpfc_name));
6473 fc_host_post_vendor_event(shost,
6474 fc_get_event_number(),
6475 sizeof(fabric_event),
6476 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05006477 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006478 return;
6479 }
6480
6481}
6482
6483/**
James Smart3621a712009-04-06 18:47:14 -04006484 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04006485 * @vport: Pointer to vport object.
6486 * @ndlp: Pointer FC node object.
6487 * @cmd: ELS command code.
6488 *
6489 * This function posts an event when there is an incoming
6490 * unsolicited ELS command.
6491 **/
6492static void
6493lpfc_send_els_event(struct lpfc_vport *vport,
6494 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05006495 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04006496{
James Smartddcc50f2008-12-04 22:38:46 -05006497 struct lpfc_els_event_header *els_data = NULL;
6498 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04006499 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6500
James Smartddcc50f2008-12-04 22:38:46 -05006501 if (*payload == ELS_CMD_LOGO) {
6502 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
6503 if (!logo_data) {
6504 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6505 "0148 Failed to allocate memory "
6506 "for LOGO event\n");
6507 return;
6508 }
6509 els_data = &logo_data->header;
6510 } else {
6511 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
6512 GFP_KERNEL);
6513 if (!els_data) {
6514 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6515 "0149 Failed to allocate memory "
6516 "for ELS event\n");
6517 return;
6518 }
6519 }
6520 els_data->event_type = FC_REG_ELS_EVENT;
6521 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04006522 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05006523 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006524 break;
6525 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05006526 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006527 break;
6528 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05006529 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
6530 break;
6531 case ELS_CMD_LOGO:
6532 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
6533 /* Copy the WWPN in the LOGO payload */
6534 memcpy(logo_data->logo_wwpn, &payload[2],
6535 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04006536 break;
6537 default:
Julia Lawalle9161412009-02-08 22:43:19 +01006538 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04006539 return;
6540 }
James Smartddcc50f2008-12-04 22:38:46 -05006541 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
6542 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
6543 if (*payload == ELS_CMD_LOGO) {
6544 fc_host_post_vendor_event(shost,
6545 fc_get_event_number(),
6546 sizeof(struct lpfc_logo_event),
6547 (char *)logo_data,
6548 LPFC_NL_VENDOR_ID);
6549 kfree(logo_data);
6550 } else {
6551 fc_host_post_vendor_event(shost,
6552 fc_get_event_number(),
6553 sizeof(struct lpfc_els_event_header),
6554 (char *)els_data,
6555 LPFC_NL_VENDOR_ID);
6556 kfree(els_data);
6557 }
James Smartea2151b2008-09-07 11:52:10 -04006558
6559 return;
6560}
6561
6562
6563/**
James Smart3621a712009-04-06 18:47:14 -04006564 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04006565 * @phba: pointer to lpfc hba data structure.
6566 * @pring: pointer to a SLI ring.
6567 * @vport: pointer to a host virtual N_Port data structure.
6568 * @elsiocb: pointer to lpfc els command iocb data structure.
6569 *
6570 * This routine is used for processing the IOCB associated with a unsolicited
6571 * event. It first determines whether there is an existing ndlp that matches
6572 * the DID from the unsolicited IOCB. If not, it will create a new one with
6573 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6574 * IOCB is then used to invoke the proper routine and to set up proper state
6575 * of the discovery state machine.
6576 **/
James Smarted957682007-06-17 19:56:37 -05006577static void
6578lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05006579 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05006580{
James Smart87af33f2007-10-27 13:37:43 -04006581 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05006582 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006583 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05006584 uint32_t *payload;
James Smart303f2f92013-01-03 15:43:11 -05006585 uint32_t cmd, did, newnode;
6586 uint8_t rjt_exp, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05006587 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05006588
James Smarte47c9092008-02-08 18:49:26 -05006589 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05006590 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05006591
dea31012005-04-17 16:05:31 -05006592 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05006593 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
6594 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05006595 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04006596 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05006597
James Smart858c9f62007-06-17 19:56:39 -05006598 did = icmd->un.rcvels.remoteID;
6599 if (icmd->ulpStatus) {
6600 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6601 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6602 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05006603 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05006604 }
dea31012005-04-17 16:05:31 -05006605
6606 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05006607 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05006608 goto dropit;
dea31012005-04-17 16:05:31 -05006609
James Smartc8685952009-11-18 15:39:16 -05006610 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05006611 if (vport->load_flag & FC_UNLOADING)
6612 goto dropit;
6613
James Smart92494142011-02-16 12:39:44 -05006614 /* If NPort discovery is delayed drop incoming ELS */
6615 if ((vport->fc_flag & FC_DISC_DELAYED) &&
6616 (cmd != ELS_CMD_PLOGI))
6617 goto dropit;
6618
James Smart2e0fef82007-06-17 19:56:36 -05006619 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006620 if (!ndlp) {
dea31012005-04-17 16:05:31 -05006621 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006622 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05006623 if (!ndlp)
dea31012005-04-17 16:05:31 -05006624 goto dropit;
dea31012005-04-17 16:05:31 -05006625
James Smart2e0fef82007-06-17 19:56:36 -05006626 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04006627 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05006628 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05006629 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05006630 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006631 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6632 ndlp = lpfc_enable_node(vport, ndlp,
6633 NLP_STE_UNUSED_NODE);
6634 if (!ndlp)
6635 goto dropit;
6636 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6637 newnode = 1;
6638 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6639 ndlp->nlp_type |= NLP_FABRIC;
6640 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
6641 /* This is similar to the new node path */
6642 ndlp = lpfc_nlp_get(ndlp);
6643 if (!ndlp)
6644 goto dropit;
6645 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6646 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04006647 }
dea31012005-04-17 16:05:31 -05006648
6649 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05006650
James Smart329f9bc2007-04-25 09:53:01 -04006651 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006652 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05006653
6654 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
6655 cmd &= ELS_CMD_MASK;
6656 }
6657 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006658 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6659 "0112 ELS command x%x received from NPORT x%x "
James Smarte74c03c2013-04-17 20:15:19 -04006660 "Data: x%x x%x x%x x%x\n",
6661 cmd, did, vport->port_state, vport->fc_flag,
6662 vport->fc_myDID, vport->fc_prevDID);
dea31012005-04-17 16:05:31 -05006663 switch (cmd) {
6664 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006665 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6666 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6667 did, vport->port_state, ndlp->nlp_flag);
6668
dea31012005-04-17 16:05:31 -05006669 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05006670 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
James Smarte74c03c2013-04-17 20:15:19 -04006671 if (phba->sli_rev == LPFC_SLI_REV4 &&
6672 (phba->pport->fc_flag & FC_PT2PT)) {
6673 vport->fc_prevDID = vport->fc_myDID;
6674 /* Our DID needs to be updated before registering
6675 * the vfi. This is done in lpfc_rcv_plogi but
6676 * that is called after the reg_vfi.
6677 */
6678 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
6679 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6680 "3312 Remote port assigned DID x%x "
6681 "%x\n", vport->fc_myDID,
6682 vport->fc_prevDID);
6683 }
James Smart858c9f62007-06-17 19:56:39 -05006684
James Smartddcc50f2008-12-04 22:38:46 -05006685 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05006686
6687 /* If Nport discovery is delayed, reject PLOGIs */
6688 if (vport->fc_flag & FC_DISC_DELAYED) {
6689 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05006690 rjt_exp = LSEXP_NOTHING_MORE;
James Smart92494142011-02-16 12:39:44 -05006691 break;
6692 }
James Smarte74c03c2013-04-17 20:15:19 -04006693 shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05006694 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05006695 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6696 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6697 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05006698 rjt_exp = LSEXP_NOTHING_MORE;
James Smart1b32f6a2008-02-08 18:49:39 -05006699 break;
6700 }
6701 /* We get here, and drop thru, if we are PT2PT with
6702 * another NPort and the other side has initiated
6703 * the PLOGI before responding to our FLOGI.
6704 */
James Smarte74c03c2013-04-17 20:15:19 -04006705 if (phba->sli_rev == LPFC_SLI_REV4 &&
6706 (phba->fc_topology_changed ||
6707 vport->fc_myDID != vport->fc_prevDID)) {
6708 lpfc_unregister_fcf_prep(phba);
6709 spin_lock_irq(shost->host_lock);
6710 vport->fc_flag &= ~FC_VFI_REGISTERED;
6711 spin_unlock_irq(shost->host_lock);
6712 phba->fc_topology_changed = 0;
6713 lpfc_issue_reg_vfi(vport);
6714 }
dea31012005-04-17 16:05:31 -05006715 }
James Smart87af33f2007-10-27 13:37:43 -04006716
James Smart87af33f2007-10-27 13:37:43 -04006717 spin_lock_irq(shost->host_lock);
6718 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6719 spin_unlock_irq(shost->host_lock);
6720
James Smart2e0fef82007-06-17 19:56:36 -05006721 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6722 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006723
dea31012005-04-17 16:05:31 -05006724 break;
6725 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006726 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6727 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6728 did, vport->port_state, ndlp->nlp_flag);
6729
dea31012005-04-17 16:05:31 -05006730 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006731 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006732 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006733 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006734 break;
6735 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006736 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6737 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6738 did, vport->port_state, ndlp->nlp_flag);
6739
dea31012005-04-17 16:05:31 -05006740 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006741 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006742 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006743 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05006744 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05006745 break;
6746 }
James Smart2e0fef82007-06-17 19:56:36 -05006747 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006748 break;
6749 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006750 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6751 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6752 did, vport->port_state, ndlp->nlp_flag);
6753
dea31012005-04-17 16:05:31 -05006754 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006755 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006756 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006757 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05006758 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05006759 break;
6760 }
James Smart2e0fef82007-06-17 19:56:36 -05006761 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05006762 break;
6763 case ELS_CMD_RSCN:
6764 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006765 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006766 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006767 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006768 break;
6769 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006770 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6771 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6772 did, vport->port_state, ndlp->nlp_flag);
6773
James Smartddcc50f2008-12-04 22:38:46 -05006774 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006775 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006776 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006777 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05006778 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05006779 break;
6780 }
James Smart2e0fef82007-06-17 19:56:36 -05006781 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6782 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006783 break;
6784 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006785 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6786 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6787 did, vport->port_state, ndlp->nlp_flag);
6788
dea31012005-04-17 16:05:31 -05006789 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006790 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006791 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05006792 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05006793 break;
6794 }
James Smart2e0fef82007-06-17 19:56:36 -05006795 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6796 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006797 break;
6798 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006799 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6800 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6801 did, vport->port_state, ndlp->nlp_flag);
6802
dea31012005-04-17 16:05:31 -05006803 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006804 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006805 break;
6806 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006807 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6808 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6809 did, vport->port_state, ndlp->nlp_flag);
6810
dea31012005-04-17 16:05:31 -05006811 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006812 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006813 break;
6814 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006815 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6816 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6817 did, vport->port_state, ndlp->nlp_flag);
6818
dea31012005-04-17 16:05:31 -05006819 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006820 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006821 break;
dea31012005-04-17 16:05:31 -05006822 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006823 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6824 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6825 did, vport->port_state, ndlp->nlp_flag);
6826
dea31012005-04-17 16:05:31 -05006827 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006828 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006829 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05006830 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05006831 break;
6832 }
James Smart2e0fef82007-06-17 19:56:36 -05006833 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006834 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006835 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006836 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6837 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6838 did, vport->port_state, ndlp->nlp_flag);
6839
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006840 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006841 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006842 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006843 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006844 break;
James Smart12265f62010-10-22 11:05:53 -04006845 case ELS_CMD_RLS:
6846 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6847 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6848 did, vport->port_state, ndlp->nlp_flag);
6849
6850 phba->fc_stat.elsRcvRLS++;
6851 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6852 if (newnode)
6853 lpfc_nlp_put(ndlp);
6854 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006855 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006856 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6857 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6858 did, vport->port_state, ndlp->nlp_flag);
6859
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006860 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006861 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006862 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006863 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006864 break;
6865 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006866 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6867 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6868 did, vport->port_state, ndlp->nlp_flag);
6869
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006870 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006871 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006872 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006873 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006874 break;
dea31012005-04-17 16:05:31 -05006875 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006876 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6877 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6878 did, vport->port_state, ndlp->nlp_flag);
6879
dea31012005-04-17 16:05:31 -05006880 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006881 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006882 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006883 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006884 break;
James Smart12265f62010-10-22 11:05:53 -04006885 case ELS_CMD_RTV:
6886 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6887 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6888 did, vport->port_state, ndlp->nlp_flag);
6889 phba->fc_stat.elsRcvRTV++;
6890 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6891 if (newnode)
6892 lpfc_nlp_put(ndlp);
6893 break;
James Smart5ffc2662009-11-18 15:39:44 -05006894 case ELS_CMD_RRQ:
6895 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6896 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6897 did, vport->port_state, ndlp->nlp_flag);
6898
6899 phba->fc_stat.elsRcvRRQ++;
6900 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6901 if (newnode)
6902 lpfc_nlp_put(ndlp);
6903 break;
James Smart12265f62010-10-22 11:05:53 -04006904 case ELS_CMD_ECHO:
6905 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6906 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6907 did, vport->port_state, ndlp->nlp_flag);
6908
6909 phba->fc_stat.elsRcvECHO++;
6910 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6911 if (newnode)
6912 lpfc_nlp_put(ndlp);
6913 break;
James Smart303f2f92013-01-03 15:43:11 -05006914 case ELS_CMD_REC:
6915 /* receive this due to exchange closed */
6916 rjt_err = LSRJT_UNABLE_TPC;
6917 rjt_exp = LSEXP_INVALID_OX_RX;
6918 break;
dea31012005-04-17 16:05:31 -05006919 default:
James Smart858c9f62007-06-17 19:56:39 -05006920 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6921 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6922 cmd, did, vport->port_state);
6923
dea31012005-04-17 16:05:31 -05006924 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05006925 rjt_err = LSRJT_CMD_UNSUPPORTED;
James Smart303f2f92013-01-03 15:43:11 -05006926 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05006927
6928 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006929 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6930 "0115 Unknown ELS command x%x "
6931 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006932 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006933 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006934 break;
6935 }
6936
6937 /* check if need to LS_RJT received ELS cmd */
6938 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006939 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006940 stat.un.b.lsRjtRsnCode = rjt_err;
James Smart303f2f92013-01-03 15:43:11 -05006941 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
James Smart858c9f62007-06-17 19:56:39 -05006942 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6943 NULL);
dea31012005-04-17 16:05:31 -05006944 }
6945
James Smartd7c255b2008-08-24 21:50:00 -04006946 lpfc_nlp_put(elsiocb->context1);
6947 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006948 return;
6949
6950dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006951 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006952 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6953 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006954 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006955 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006956 phba->fc_stat.elsRcvDrop++;
6957}
6958
James Smarte59058c2008-08-24 21:49:00 -04006959/**
James Smart3621a712009-04-06 18:47:14 -04006960 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006961 * @phba: pointer to lpfc hba data structure.
6962 * @pring: pointer to a SLI ring.
6963 * @elsiocb: pointer to lpfc els iocb data structure.
6964 *
6965 * This routine is used to process an unsolicited event received from a SLI
6966 * (Service Level Interface) ring. The actual processing of the data buffer
6967 * associated with the unsolicited event is done by invoking the routine
6968 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6969 * SLI ring on which the unsolicited event was received.
6970 **/
James Smarted957682007-06-17 19:56:37 -05006971void
6972lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6973 struct lpfc_iocbq *elsiocb)
6974{
6975 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006976 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006977 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006978 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6979 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006980
James Smartd7c255b2008-08-24 21:50:00 -04006981 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006982 elsiocb->context2 = NULL;
6983 elsiocb->context3 = NULL;
6984
6985 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6986 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6987 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
James Smarte3d2b802012-08-14 14:25:43 -04006988 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
6989 IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006990 phba->fc_stat.NoRcvBuf++;
6991 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006992 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006993 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006994 return;
6995 }
6996
James Smart92d7f7b2007-06-17 19:56:38 -05006997 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6998 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6999 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
7000 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
7001 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04007002 else
7003 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04007004 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05007005 }
James Smart6d368e52011-05-24 11:44:12 -04007006
James Smart7f5f3d02008-02-08 18:50:14 -05007007 /* If there are no BDEs associated
7008 * with this IOCB, there is nothing to do.
7009 */
James Smarted957682007-06-17 19:56:37 -05007010 if (icmd->ulpBdeCount == 0)
7011 return;
7012
James Smart7f5f3d02008-02-08 18:50:14 -05007013 /* type of ELS cmd is first 32bit word
7014 * in packet
7015 */
James Smarted957682007-06-17 19:56:37 -05007016 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05007017 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05007018 } else {
7019 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
7020 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05007021 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
7022 paddr);
James Smarted957682007-06-17 19:56:37 -05007023 }
7024
James Smart92d7f7b2007-06-17 19:56:38 -05007025 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
7026 /*
7027 * The different unsolicited event handlers would tell us
7028 * if they are done with "mp" by setting context2 to NULL.
7029 */
dea31012005-04-17 16:05:31 -05007030 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05007031 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
7032 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05007033 }
James Smarted957682007-06-17 19:56:37 -05007034
7035 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05007036 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05007037 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05007038 elsiocb->context2 = bdeBuf2;
7039 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05007040 /* free mp if we are done with it */
7041 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05007042 lpfc_in_buf_free(phba, elsiocb->context2);
7043 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05007044 }
dea31012005-04-17 16:05:31 -05007045 }
dea31012005-04-17 16:05:31 -05007046}
James Smart92d7f7b2007-06-17 19:56:38 -05007047
James Smarte59058c2008-08-24 21:49:00 -04007048/**
James Smart3621a712009-04-06 18:47:14 -04007049 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04007050 * @phba: pointer to lpfc hba data structure.
7051 * @vport: pointer to a virtual N_Port data structure.
7052 *
7053 * This routine issues a Port Login (PLOGI) to the Name Server with
7054 * State Change Request (SCR) for a @vport. This routine will create an
7055 * ndlp for the Name Server associated to the @vport if such node does
7056 * not already exist. The PLOGI to Name Server is issued by invoking the
7057 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
7058 * (FDMI) is configured to the @vport, a FDMI node will be created and
7059 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
7060 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007061void
7062lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
7063{
7064 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
James Smart92494142011-02-16 12:39:44 -05007065 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7066
7067 /*
7068 * If lpfc_delay_discovery parameter is set and the clean address
7069 * bit is cleared and fc fabric parameters chenged, delay FC NPort
7070 * discovery.
7071 */
7072 spin_lock_irq(shost->host_lock);
7073 if (vport->fc_flag & FC_DISC_DELAYED) {
7074 spin_unlock_irq(shost->host_lock);
James Smart18775702013-04-17 20:19:25 -04007075 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
7076 "3334 Delay fc port discovery for %d seconds\n",
7077 phba->fc_ratov);
James Smart92494142011-02-16 12:39:44 -05007078 mod_timer(&vport->delayed_disc_tmo,
James Smart256ec0d2013-04-17 20:14:58 -04007079 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
James Smart92494142011-02-16 12:39:44 -05007080 return;
7081 }
7082 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007083
7084 ndlp = lpfc_findnode_did(vport, NameServer_DID);
7085 if (!ndlp) {
7086 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
7087 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05007088 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05007089 lpfc_disc_start(vport);
7090 return;
7091 }
7092 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007093 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7094 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007095 return;
7096 }
7097 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05007098 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7099 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
7100 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05007101 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05007102 lpfc_disc_start(vport);
7103 return;
7104 }
7105 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7106 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7107 "0348 NameServer login: node freed\n");
7108 return;
7109 }
James Smart92d7f7b2007-06-17 19:56:38 -05007110 }
James Smart58da1ff2008-04-07 10:15:56 -04007111 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05007112
7113 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
7114
7115 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
7116 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007117 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7118 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007119 return;
7120 }
7121
James Smart3de2a652007-08-02 11:09:59 -04007122 if (vport->cfg_fdmi_on) {
James Smart63e801c2010-11-20 23:14:19 -05007123 /* If this is the first time, allocate an ndlp and initialize
7124 * it. Otherwise, make sure the node is enabled and then do the
7125 * login.
7126 */
7127 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
7128 if (!ndlp_fdmi) {
7129 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
7130 GFP_KERNEL);
7131 if (ndlp_fdmi) {
7132 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
7133 ndlp_fdmi->nlp_type |= NLP_FABRIC;
7134 } else
7135 return;
7136 }
7137 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
7138 ndlp_fdmi = lpfc_enable_node(vport,
7139 ndlp_fdmi,
7140 NLP_STE_NPR_NODE);
7141
James Smart92d7f7b2007-06-17 19:56:38 -05007142 if (ndlp_fdmi) {
James Smart58da1ff2008-04-07 10:15:56 -04007143 lpfc_nlp_set_state(vport, ndlp_fdmi,
James Smart63e801c2010-11-20 23:14:19 -05007144 NLP_STE_PLOGI_ISSUE);
7145 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007146 }
7147 }
James Smart92d7f7b2007-06-17 19:56:38 -05007148}
7149
James Smarte59058c2008-08-24 21:49:00 -04007150/**
James Smart3621a712009-04-06 18:47:14 -04007151 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04007152 * @phba: pointer to lpfc hba data structure.
7153 * @pmb: pointer to the driver internal queue element for mailbox command.
7154 *
7155 * This routine is the completion callback function to register new vport
7156 * mailbox command. If the new vport mailbox command completes successfully,
7157 * the fabric registration login shall be performed on physical port (the
7158 * new vport created is actually a physical port, with VPI 0) or the port
7159 * login to Name Server for State Change Request (SCR) will be performed
7160 * on virtual port (real virtual port, with VPI greater than 0).
7161 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007162static void
7163lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7164{
7165 struct lpfc_vport *vport = pmb->vport;
7166 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7167 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04007168 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05007169 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007170
James Smart09372822008-01-11 01:52:54 -05007171 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007172 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05007173 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007174
7175 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04007176 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04007177 "0915 Register VPI failed : Status: x%x"
7178 " upd bit: x%x \n", mb->mbxStatus,
7179 mb->un.varRegVpi.upd);
7180 if (phba->sli_rev == LPFC_SLI_REV4 &&
7181 mb->un.varRegVpi.upd)
7182 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05007183
7184 switch (mb->mbxStatus) {
7185 case 0x11: /* unsupported feature */
7186 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05007187 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05007188 /* giving up on vport registration */
7189 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7190 spin_lock_irq(shost->host_lock);
7191 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
7192 spin_unlock_irq(shost->host_lock);
7193 lpfc_can_disctmo(vport);
7194 break;
James Smart695a8142010-01-26 23:08:03 -05007195 /* If reg_vpi fail with invalid VPI status, re-init VPI */
7196 case 0x20:
7197 spin_lock_irq(shost->host_lock);
7198 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
7199 spin_unlock_irq(shost->host_lock);
7200 lpfc_init_vpi(phba, pmb, vport->vpi);
7201 pmb->vport = vport;
7202 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
7203 rc = lpfc_sli_issue_mbox(phba, pmb,
7204 MBX_NOWAIT);
7205 if (rc == MBX_NOT_FINISHED) {
7206 lpfc_printf_vlog(vport,
7207 KERN_ERR, LOG_MBOX,
7208 "2732 Failed to issue INIT_VPI"
7209 " mailbox command\n");
7210 } else {
7211 lpfc_nlp_put(ndlp);
7212 return;
7213 }
7214
James Smart92d7f7b2007-06-17 19:56:38 -05007215 default:
7216 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04007217 if (phba->sli_rev == LPFC_SLI_REV4)
7218 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007219 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05007220 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007221 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05007222 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04007223 if (vport->port_type == LPFC_PHYSICAL_PORT
7224 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart76a95d72010-11-20 23:11:48 -05007225 lpfc_issue_init_vfi(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05007226 else
7227 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007228 break;
7229 }
James Smart92d7f7b2007-06-17 19:56:38 -05007230 } else {
James Smart695a8142010-01-26 23:08:03 -05007231 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05007232 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05007233 spin_unlock_irq(shost->host_lock);
7234 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04007235 if (phba->sli_rev < LPFC_SLI_REV4)
7236 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05007237 else {
James Smartfc2b9892010-02-26 14:15:29 -05007238 /*
7239 * If the physical port is instantiated using
7240 * FDISC, do not start vport discovery.
7241 */
7242 if (vport->port_state != LPFC_FDISC)
7243 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05007244 lpfc_do_scr_ns_plogi(phba, vport);
7245 }
7246 } else
James Smart92d7f7b2007-06-17 19:56:38 -05007247 lpfc_do_scr_ns_plogi(phba, vport);
7248 }
James Smart38b92ef2010-08-04 16:11:39 -04007249mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05007250 /* Now, we decrement the ndlp reference count held for this
7251 * callback function
7252 */
7253 lpfc_nlp_put(ndlp);
7254
James Smart92d7f7b2007-06-17 19:56:38 -05007255 mempool_free(pmb, phba->mbox_mem_pool);
7256 return;
7257}
7258
James Smarte59058c2008-08-24 21:49:00 -04007259/**
James Smart3621a712009-04-06 18:47:14 -04007260 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04007261 * @phba: pointer to lpfc hba data structure.
7262 * @vport: pointer to a host virtual N_Port data structure.
7263 * @ndlp: pointer to a node-list data structure.
7264 *
7265 * This routine registers the @vport as a new virtual port with a HBA.
7266 * It is done through a registering vpi mailbox command.
7267 **/
James Smart695a8142010-01-26 23:08:03 -05007268void
James Smart92d7f7b2007-06-17 19:56:38 -05007269lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
7270 struct lpfc_nodelist *ndlp)
7271{
James Smart09372822008-01-11 01:52:54 -05007272 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007273 LPFC_MBOXQ_t *mbox;
7274
7275 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7276 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04007277 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05007278 mbox->vport = vport;
7279 mbox->context2 = lpfc_nlp_get(ndlp);
7280 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04007281 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05007282 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05007283 /* mailbox command not success, decrement ndlp
7284 * reference count for this command
7285 */
7286 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007287 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05007288
James Smarte8b62012007-08-02 11:10:09 -04007289 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7290 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05007291 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05007292 }
7293 } else {
James Smarte8b62012007-08-02 11:10:09 -04007294 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7295 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05007296 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05007297 }
James Smartfa4066b2008-01-11 01:53:27 -05007298 return;
7299
7300mbox_err_exit:
7301 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7302 spin_lock_irq(shost->host_lock);
7303 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
7304 spin_unlock_irq(shost->host_lock);
7305 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007306}
7307
James Smarte59058c2008-08-24 21:49:00 -04007308/**
James Smart0c9ab6f2010-02-26 14:15:57 -05007309 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05007310 * @phba: pointer to lpfc hba data structure.
7311 *
James Smart0c9ab6f2010-02-26 14:15:57 -05007312 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05007313 **/
7314void
James Smart0c9ab6f2010-02-26 14:15:57 -05007315lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05007316{
7317 struct lpfc_vport **vports;
7318 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05007319 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05007320 int i;
James Smart695a8142010-01-26 23:08:03 -05007321
7322 /* Treat this failure as linkdown for all vports */
7323 link_state = phba->link_state;
7324 lpfc_linkdown(phba);
7325 phba->link_state = link_state;
7326
7327 vports = lpfc_create_vport_work_array(phba);
7328
7329 if (vports) {
7330 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
7331 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
7332 if (ndlp)
7333 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
7334 lpfc_els_flush_cmd(vports[i]);
7335 }
7336 lpfc_destroy_vport_work_array(phba, vports);
7337 }
James Smart0c9ab6f2010-02-26 14:15:57 -05007338}
7339
7340/**
7341 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
7342 * @phba: pointer to lpfc hba data structure.
7343 *
7344 * This routine abort all pending discovery commands and
7345 * start a timer to retry FLOGI for the physical port
7346 * discovery.
7347 **/
7348void
7349lpfc_retry_pport_discovery(struct lpfc_hba *phba)
7350{
7351 struct lpfc_nodelist *ndlp;
7352 struct Scsi_Host *shost;
7353
7354 /* Cancel the all vports retry delay retry timers */
7355 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05007356
7357 /* If fabric require FLOGI, then re-instantiate physical login */
7358 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
7359 if (!ndlp)
7360 return;
7361
James Smart695a8142010-01-26 23:08:03 -05007362 shost = lpfc_shost_from_vport(phba->pport);
James Smart256ec0d2013-04-17 20:14:58 -04007363 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
James Smart695a8142010-01-26 23:08:03 -05007364 spin_lock_irq(shost->host_lock);
7365 ndlp->nlp_flag |= NLP_DELAY_TMO;
7366 spin_unlock_irq(shost->host_lock);
7367 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
7368 phba->pport->port_state = LPFC_FLOGI;
7369 return;
7370}
7371
7372/**
7373 * lpfc_fabric_login_reqd - Check if FLOGI required.
7374 * @phba: pointer to lpfc hba data structure.
7375 * @cmdiocb: pointer to FDISC command iocb.
7376 * @rspiocb: pointer to FDISC response iocb.
7377 *
7378 * This routine checks if a FLOGI is reguired for FDISC
7379 * to succeed.
7380 **/
7381static int
7382lpfc_fabric_login_reqd(struct lpfc_hba *phba,
7383 struct lpfc_iocbq *cmdiocb,
7384 struct lpfc_iocbq *rspiocb)
7385{
7386
7387 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
7388 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
7389 return 0;
7390 else
7391 return 1;
7392}
7393
7394/**
James Smart3621a712009-04-06 18:47:14 -04007395 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007396 * @phba: pointer to lpfc hba data structure.
7397 * @cmdiocb: pointer to lpfc command iocb data structure.
7398 * @rspiocb: pointer to lpfc response iocb data structure.
7399 *
7400 * This routine is the completion callback function to a Fabric Discover
7401 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
7402 * single threaded, each FDISC completion callback function will reset
7403 * the discovery timer for all vports such that the timers will not get
7404 * unnecessary timeout. The function checks the FDISC IOCB status. If error
7405 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
7406 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
7407 * assigned to the vport has been changed with the completion of the FDISC
7408 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
7409 * are unregistered from the HBA, and then the lpfc_register_new_vport()
7410 * routine is invoked to register new vport with the HBA. Otherwise, the
7411 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
7412 * Server for State Change Request (SCR).
7413 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007414static void
7415lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7416 struct lpfc_iocbq *rspiocb)
7417{
7418 struct lpfc_vport *vport = cmdiocb->vport;
7419 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7420 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
7421 struct lpfc_nodelist *np;
7422 struct lpfc_nodelist *next_np;
7423 IOCB_t *irsp = &rspiocb->iocb;
7424 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05007425 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
7426 struct serv_parm *sp;
7427 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05007428
James Smarte8b62012007-08-02 11:10:09 -04007429 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7430 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
7431 irsp->ulpStatus, irsp->un.ulpWord[4],
7432 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05007433 /* Since all FDISCs are being single threaded, we
7434 * must reset the discovery timer for ALL vports
7435 * waiting to send FDISC when one completes.
7436 */
7437 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
7438 lpfc_set_disctmo(piocb->vport);
7439 }
7440
James Smart858c9f62007-06-17 19:56:39 -05007441 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7442 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
7443 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
7444
James Smart92d7f7b2007-06-17 19:56:38 -05007445 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05007446
7447 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
7448 lpfc_retry_pport_discovery(phba);
7449 goto out;
7450 }
7451
James Smart92d7f7b2007-06-17 19:56:38 -05007452 /* Check for retry */
7453 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
7454 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007455 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04007456 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart6b5151f2012-01-18 16:24:06 -05007457 "0126 FDISC failed. (x%x/x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04007458 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04007459 goto fdisc_failed;
7460 }
James Smartd7c255b2008-08-24 21:50:00 -04007461 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05007462 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04007463 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04007464 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05007465 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04007466 vport->fc_flag |= FC_PUBLIC_LOOP;
7467 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007468
James Smartd7c255b2008-08-24 21:50:00 -04007469 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
7470 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05007471 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
7472 sp = prsp->virt + sizeof(uint32_t);
7473 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
7474 memcpy(&vport->fabric_portname, &sp->portName,
7475 sizeof(struct lpfc_name));
7476 memcpy(&vport->fabric_nodename, &sp->nodeName,
7477 sizeof(struct lpfc_name));
7478 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04007479 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7480 /* If our NportID changed, we need to ensure all
7481 * remaining NPORTs get unreg_login'ed so we can
7482 * issue unreg_vpi.
7483 */
7484 list_for_each_entry_safe(np, next_np,
7485 &vport->fc_nodes, nlp_listp) {
7486 if (!NLP_CHK_NODE_ACT(ndlp) ||
7487 (np->nlp_state != NLP_STE_NPR_NODE) ||
7488 !(np->nlp_flag & NLP_NPR_ADISC))
7489 continue;
James Smart09372822008-01-11 01:52:54 -05007490 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007491 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05007492 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007493 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05007494 }
James Smart78730cf2010-04-06 15:06:30 -04007495 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04007496
7497 if (phba->sli_rev == LPFC_SLI_REV4)
7498 lpfc_sli4_unreg_all_rpis(vport);
7499
James Smartd7c255b2008-08-24 21:50:00 -04007500 lpfc_mbx_unreg_vpi(vport);
7501 spin_lock_irq(shost->host_lock);
7502 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05007503 if (phba->sli_rev == LPFC_SLI_REV4)
7504 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04007505 else
7506 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04007507 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04007508 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
7509 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7510 /*
7511 * Driver needs to re-reg VPI in order for f/w
7512 * to update the MAC address.
7513 */
7514 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04007515 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007516 }
7517
James Smartecfd03c2010-02-12 14:41:27 -05007518 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
7519 lpfc_issue_init_vpi(vport);
7520 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04007521 lpfc_register_new_vport(phba, vport, ndlp);
7522 else
7523 lpfc_do_scr_ns_plogi(phba, vport);
7524 goto out;
7525fdisc_failed:
7526 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7527 /* Cancel discovery timer */
7528 lpfc_can_disctmo(vport);
7529 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007530out:
7531 lpfc_els_free_iocb(phba, cmdiocb);
7532}
7533
James Smarte59058c2008-08-24 21:49:00 -04007534/**
James Smart3621a712009-04-06 18:47:14 -04007535 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007536 * @vport: pointer to a virtual N_Port data structure.
7537 * @ndlp: pointer to a node-list data structure.
7538 * @retry: number of retries to the command IOCB.
7539 *
7540 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7541 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7542 * routine to issue the IOCB, which makes sure only one outstanding fabric
7543 * IOCB will be sent off HBA at any given time.
7544 *
7545 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7546 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7547 * will be stored into the context1 field of the IOCB for the completion
7548 * callback function to the FDISC ELS command.
7549 *
7550 * Return code
7551 * 0 - Successfully issued fdisc iocb command
7552 * 1 - Failed to issue fdisc iocb command
7553 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007554static int
James Smart92d7f7b2007-06-17 19:56:38 -05007555lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7556 uint8_t retry)
7557{
7558 struct lpfc_hba *phba = vport->phba;
7559 IOCB_t *icmd;
7560 struct lpfc_iocbq *elsiocb;
7561 struct serv_parm *sp;
7562 uint8_t *pcmd;
7563 uint16_t cmdsize;
7564 int did = ndlp->nlp_DID;
7565 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007566
James Smart5ffc2662009-11-18 15:39:44 -05007567 vport->port_state = LPFC_FDISC;
James Smart6b5151f2012-01-18 16:24:06 -05007568 vport->fc_myDID = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007569 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
7570 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
7571 ELS_CMD_FDISC);
7572 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05007573 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007574 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7575 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007576 return 1;
7577 }
7578
7579 icmd = &elsiocb->iocb;
7580 icmd->un.elsreq64.myID = 0;
7581 icmd->un.elsreq64.fl = 1;
7582
James Smart73d91e52011-10-10 21:32:10 -04007583 /*
7584 * SLI3 ports require a different context type value than SLI4.
7585 * Catch SLI3 ports here and override the prep.
7586 */
7587 if (phba->sli_rev == LPFC_SLI_REV3) {
James Smartf1126682009-06-10 17:22:44 -04007588 icmd->ulpCt_h = 1;
7589 icmd->ulpCt_l = 0;
7590 }
James Smart92d7f7b2007-06-17 19:56:38 -05007591
7592 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7593 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
7594 pcmd += sizeof(uint32_t); /* CSP Word 1 */
7595 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
7596 sp = (struct serv_parm *) pcmd;
7597 /* Setup CSPs accordingly for Fabric */
7598 sp->cmn.e_d_tov = 0;
7599 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05007600 sp->cmn.virtual_fabric_support = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007601 sp->cls1.classValid = 0;
7602 sp->cls2.seqDelivery = 1;
7603 sp->cls3.seqDelivery = 1;
7604
7605 pcmd += sizeof(uint32_t); /* CSP Word 2 */
7606 pcmd += sizeof(uint32_t); /* CSP Word 3 */
7607 pcmd += sizeof(uint32_t); /* CSP Word 4 */
7608 pcmd += sizeof(uint32_t); /* Port Name */
7609 memcpy(pcmd, &vport->fc_portname, 8);
7610 pcmd += sizeof(uint32_t); /* Node Name */
7611 pcmd += sizeof(uint32_t); /* Node Name */
7612 memcpy(pcmd, &vport->fc_nodename, 8);
7613
7614 lpfc_set_disctmo(vport);
7615
7616 phba->fc_stat.elsXmitFDISC++;
7617 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
7618
James Smart858c9f62007-06-17 19:56:39 -05007619 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7620 "Issue FDISC: did:x%x",
7621 did, 0, 0);
7622
James Smart92d7f7b2007-06-17 19:56:38 -05007623 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
7624 if (rc == IOCB_ERROR) {
7625 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05007626 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007627 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7628 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007629 return 1;
7630 }
7631 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05007632 return 0;
7633}
7634
James Smarte59058c2008-08-24 21:49:00 -04007635/**
James Smart3621a712009-04-06 18:47:14 -04007636 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04007637 * @phba: pointer to lpfc hba data structure.
7638 * @cmdiocb: pointer to lpfc command iocb data structure.
7639 * @rspiocb: pointer to lpfc response iocb data structure.
7640 *
7641 * This routine is the completion callback function to the issuing of a LOGO
7642 * ELS command off a vport. It frees the command IOCB and then decrement the
7643 * reference count held on ndlp for this completion function, indicating that
7644 * the reference to the ndlp is no long needed. Note that the
7645 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7646 * callback function and an additional explicit ndlp reference decrementation
7647 * will trigger the actual release of the ndlp.
7648 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007649static void
7650lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7651 struct lpfc_iocbq *rspiocb)
7652{
7653 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05007654 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05007655 struct lpfc_nodelist *ndlp;
James Smart9589b062011-04-16 11:03:17 -04007656 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05007657
James Smart9589b062011-04-16 11:03:17 -04007658 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05007659 irsp = &rspiocb->iocb;
7660 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7661 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7662 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05007663
7664 lpfc_els_free_iocb(phba, cmdiocb);
7665 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05007666
7667 /* Trigger the release of the ndlp after logo */
7668 lpfc_nlp_put(ndlp);
James Smart9589b062011-04-16 11:03:17 -04007669
7670 /* NPIV LOGO completes to NPort <nlp_DID> */
7671 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7672 "2928 NPIV LOGO completes to NPort x%x "
7673 "Data: x%x x%x x%x x%x\n",
7674 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
7675 irsp->ulpTimeout, vport->num_disc_nodes);
7676
7677 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
7678 spin_lock_irq(shost->host_lock);
7679 vport->fc_flag &= ~FC_FABRIC;
7680 spin_unlock_irq(shost->host_lock);
7681 }
James Smart92d7f7b2007-06-17 19:56:38 -05007682}
7683
James Smarte59058c2008-08-24 21:49:00 -04007684/**
James Smart3621a712009-04-06 18:47:14 -04007685 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04007686 * @vport: pointer to a virtual N_Port data structure.
7687 * @ndlp: pointer to a node-list data structure.
7688 *
7689 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7690 *
7691 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7692 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7693 * will be stored into the context1 field of the IOCB for the completion
7694 * callback function to the LOGO ELS command.
7695 *
7696 * Return codes
7697 * 0 - Successfully issued logo off the @vport
7698 * 1 - Failed to issue logo off the @vport
7699 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007700int
7701lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
7702{
7703 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7704 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007705 IOCB_t *icmd;
7706 struct lpfc_iocbq *elsiocb;
7707 uint8_t *pcmd;
7708 uint16_t cmdsize;
7709
7710 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
7711 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
7712 ELS_CMD_LOGO);
7713 if (!elsiocb)
7714 return 1;
7715
7716 icmd = &elsiocb->iocb;
7717 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7718 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
7719 pcmd += sizeof(uint32_t);
7720
7721 /* Fill in LOGO payload */
7722 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
7723 pcmd += sizeof(uint32_t);
7724 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
7725
James Smart858c9f62007-06-17 19:56:39 -05007726 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7727 "Issue LOGO npiv did:x%x flg:x%x",
7728 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7729
James Smart92d7f7b2007-06-17 19:56:38 -05007730 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7731 spin_lock_irq(shost->host_lock);
7732 ndlp->nlp_flag |= NLP_LOGO_SND;
7733 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04007734 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7735 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05007736 spin_lock_irq(shost->host_lock);
7737 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7738 spin_unlock_irq(shost->host_lock);
7739 lpfc_els_free_iocb(phba, elsiocb);
7740 return 1;
7741 }
7742 return 0;
7743}
7744
James Smarte59058c2008-08-24 21:49:00 -04007745/**
James Smart3621a712009-04-06 18:47:14 -04007746 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04007747 * @ptr: holder for the timer function associated data.
7748 *
7749 * This routine is invoked by the fabric iocb block timer after
7750 * timeout. It posts the fabric iocb block timeout event by setting the
7751 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7752 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7753 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7754 * posted event WORKER_FABRIC_BLOCK_TMO.
7755 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007756void
7757lpfc_fabric_block_timeout(unsigned long ptr)
7758{
7759 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7760 unsigned long iflags;
7761 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007762
James Smart92d7f7b2007-06-17 19:56:38 -05007763 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7764 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7765 if (!tmo_posted)
7766 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7767 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7768
James Smart5e9d9b82008-06-14 22:52:53 -04007769 if (!tmo_posted)
7770 lpfc_worker_wake_up(phba);
7771 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007772}
7773
James Smarte59058c2008-08-24 21:49:00 -04007774/**
James Smart3621a712009-04-06 18:47:14 -04007775 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007776 * @phba: pointer to lpfc hba data structure.
7777 *
7778 * This routine issues one fabric iocb from the driver internal list to
7779 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7780 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7781 * remove one pending fabric iocb from the driver internal list and invokes
7782 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7783 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007784static void
7785lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7786{
7787 struct lpfc_iocbq *iocb;
7788 unsigned long iflags;
7789 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007790 IOCB_t *cmd;
7791
7792repeat:
7793 iocb = NULL;
7794 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007795 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007796 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7797 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7798 list);
7799 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007800 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007801 atomic_inc(&phba->fabric_iocb_count);
7802 }
7803 spin_unlock_irqrestore(&phba->hbalock, iflags);
7804 if (iocb) {
7805 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7806 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7807 iocb->iocb_flag |= LPFC_IO_FABRIC;
7808
James Smart858c9f62007-06-17 19:56:39 -05007809 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7810 "Fabric sched1: ste:x%x",
7811 iocb->vport->port_state, 0, 0);
7812
James Smart3772a992009-05-22 14:50:54 -04007813 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007814
7815 if (ret == IOCB_ERROR) {
7816 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7817 iocb->fabric_iocb_cmpl = NULL;
7818 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7819 cmd = &iocb->iocb;
7820 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7821 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7822 iocb->iocb_cmpl(phba, iocb, iocb);
7823
7824 atomic_dec(&phba->fabric_iocb_count);
7825 goto repeat;
7826 }
7827 }
7828
7829 return;
7830}
7831
James Smarte59058c2008-08-24 21:49:00 -04007832/**
James Smart3621a712009-04-06 18:47:14 -04007833 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007834 * @phba: pointer to lpfc hba data structure.
7835 *
7836 * This routine unblocks the issuing fabric iocb command. The function
7837 * will clear the fabric iocb block bit and then invoke the routine
7838 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7839 * from the driver internal fabric iocb list.
7840 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007841void
7842lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7843{
7844 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7845
7846 lpfc_resume_fabric_iocbs(phba);
7847 return;
7848}
7849
James Smarte59058c2008-08-24 21:49:00 -04007850/**
James Smart3621a712009-04-06 18:47:14 -04007851 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007852 * @phba: pointer to lpfc hba data structure.
7853 *
7854 * This routine blocks the issuing fabric iocb for a specified amount of
7855 * time (currently 100 ms). This is done by set the fabric iocb block bit
7856 * and set up a timeout timer for 100ms. When the block bit is set, no more
7857 * fabric iocb will be issued out of the HBA.
7858 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007859static void
7860lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7861{
7862 int blocked;
7863
7864 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007865 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007866 if (!blocked)
James Smart256ec0d2013-04-17 20:14:58 -04007867 mod_timer(&phba->fabric_block_timer,
7868 jiffies + msecs_to_jiffies(100));
James Smart92d7f7b2007-06-17 19:56:38 -05007869
7870 return;
7871}
7872
James Smarte59058c2008-08-24 21:49:00 -04007873/**
James Smart3621a712009-04-06 18:47:14 -04007874 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007875 * @phba: pointer to lpfc hba data structure.
7876 * @cmdiocb: pointer to lpfc command iocb data structure.
7877 * @rspiocb: pointer to lpfc response iocb data structure.
7878 *
7879 * This routine is the callback function that is put to the fabric iocb's
7880 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7881 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7882 * function first restores and invokes the original iocb's callback function
7883 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7884 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7885 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007886static void
7887lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7888 struct lpfc_iocbq *rspiocb)
7889{
7890 struct ls_rjt stat;
7891
7892 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7893 BUG();
7894
7895 switch (rspiocb->iocb.ulpStatus) {
7896 case IOSTAT_NPORT_RJT:
7897 case IOSTAT_FABRIC_RJT:
7898 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7899 lpfc_block_fabric_iocbs(phba);
7900 }
7901 break;
7902
7903 case IOSTAT_NPORT_BSY:
7904 case IOSTAT_FABRIC_BSY:
7905 lpfc_block_fabric_iocbs(phba);
7906 break;
7907
7908 case IOSTAT_LS_RJT:
7909 stat.un.lsRjtError =
7910 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7911 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7912 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7913 lpfc_block_fabric_iocbs(phba);
7914 break;
7915 }
7916
7917 if (atomic_read(&phba->fabric_iocb_count) == 0)
7918 BUG();
7919
7920 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7921 cmdiocb->fabric_iocb_cmpl = NULL;
7922 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7923 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7924
7925 atomic_dec(&phba->fabric_iocb_count);
7926 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007927 /* Post any pending iocbs to HBA */
7928 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007929 }
7930}
7931
James Smarte59058c2008-08-24 21:49:00 -04007932/**
James Smart3621a712009-04-06 18:47:14 -04007933 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007934 * @phba: pointer to lpfc hba data structure.
7935 * @iocb: pointer to lpfc command iocb data structure.
7936 *
7937 * This routine is used as the top-level API for issuing a fabric iocb command
7938 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7939 * function makes sure that only one fabric bound iocb will be outstanding at
7940 * any given time. As such, this function will first check to see whether there
7941 * is already an outstanding fabric iocb on the wire. If so, it will put the
7942 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7943 * issued later. Otherwise, it will issue the iocb on the wire and update the
7944 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7945 *
7946 * Note, this implementation has a potential sending out fabric IOCBs out of
7947 * order. The problem is caused by the construction of the "ready" boolen does
7948 * not include the condition that the internal fabric IOCB list is empty. As
7949 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7950 * ahead of the fabric IOCBs in the internal list.
7951 *
7952 * Return code
7953 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7954 * IOCB_ERROR - failed to issue fabric iocb
7955 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007956static int
James Smart92d7f7b2007-06-17 19:56:38 -05007957lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7958{
7959 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007960 int ready;
7961 int ret;
7962
7963 if (atomic_read(&phba->fabric_iocb_count) > 1)
7964 BUG();
7965
7966 spin_lock_irqsave(&phba->hbalock, iflags);
7967 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7968 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7969
James Smart7f5f3d02008-02-08 18:50:14 -05007970 if (ready)
7971 /* Increment fabric iocb count to hold the position */
7972 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007973 spin_unlock_irqrestore(&phba->hbalock, iflags);
7974 if (ready) {
7975 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7976 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7977 iocb->iocb_flag |= LPFC_IO_FABRIC;
7978
James Smart858c9f62007-06-17 19:56:39 -05007979 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7980 "Fabric sched2: ste:x%x",
7981 iocb->vport->port_state, 0, 0);
7982
James Smart3772a992009-05-22 14:50:54 -04007983 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007984
7985 if (ret == IOCB_ERROR) {
7986 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7987 iocb->fabric_iocb_cmpl = NULL;
7988 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7989 atomic_dec(&phba->fabric_iocb_count);
7990 }
7991 } else {
7992 spin_lock_irqsave(&phba->hbalock, iflags);
7993 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7994 spin_unlock_irqrestore(&phba->hbalock, iflags);
7995 ret = IOCB_SUCCESS;
7996 }
7997 return ret;
7998}
7999
James Smarte59058c2008-08-24 21:49:00 -04008000/**
James Smart3621a712009-04-06 18:47:14 -04008001 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04008002 * @vport: pointer to a virtual N_Port data structure.
8003 *
8004 * This routine aborts all the IOCBs associated with a @vport from the
8005 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
8006 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
8007 * list, removes each IOCB associated with the @vport off the list, set the
8008 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
8009 * associated with the IOCB.
8010 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01008011static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05008012{
8013 LIST_HEAD(completions);
8014 struct lpfc_hba *phba = vport->phba;
8015 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05008016
8017 spin_lock_irq(&phba->hbalock);
8018 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
8019 list) {
8020
8021 if (piocb->vport != vport)
8022 continue;
8023
8024 list_move_tail(&piocb->list, &completions);
8025 }
8026 spin_unlock_irq(&phba->hbalock);
8027
James Smarta257bf92009-04-06 18:48:10 -04008028 /* Cancel all the IOCBs from the completions list */
8029 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
8030 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05008031}
8032
James Smarte59058c2008-08-24 21:49:00 -04008033/**
James Smart3621a712009-04-06 18:47:14 -04008034 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04008035 * @ndlp: pointer to a node-list data structure.
8036 *
8037 * This routine aborts all the IOCBs associated with an @ndlp from the
8038 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
8039 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
8040 * list, removes each IOCB associated with the @ndlp off the list, set the
8041 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
8042 * associated with the IOCB.
8043 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008044void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
8045{
8046 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04008047 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05008048 struct lpfc_iocbq *tmp_iocb, *piocb;
8049 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05008050
8051 spin_lock_irq(&phba->hbalock);
8052 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
8053 list) {
8054 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
8055
8056 list_move_tail(&piocb->list, &completions);
8057 }
8058 }
8059 spin_unlock_irq(&phba->hbalock);
8060
James Smarta257bf92009-04-06 18:48:10 -04008061 /* Cancel all the IOCBs from the completions list */
8062 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
8063 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05008064}
8065
James Smarte59058c2008-08-24 21:49:00 -04008066/**
James Smart3621a712009-04-06 18:47:14 -04008067 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04008068 * @phba: pointer to lpfc hba data structure.
8069 *
8070 * This routine aborts all the IOCBs currently on the driver internal
8071 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
8072 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
8073 * list, removes IOCBs off the list, set the status feild to
8074 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
8075 * the IOCB.
8076 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008077void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
8078{
8079 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05008080
8081 spin_lock_irq(&phba->hbalock);
8082 list_splice_init(&phba->fabric_iocb_list, &completions);
8083 spin_unlock_irq(&phba->hbalock);
8084
James Smarta257bf92009-04-06 18:48:10 -04008085 /* Cancel all the IOCBs from the completions list */
8086 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
8087 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05008088}
James Smart6fb120a2009-05-22 14:52:59 -04008089
8090/**
James Smart1151e3e2011-02-16 12:39:35 -05008091 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
8092 * @vport: pointer to lpfc vport data structure.
8093 *
8094 * This routine is invoked by the vport cleanup for deletions and the cleanup
8095 * for an ndlp on removal.
8096 **/
8097void
8098lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
8099{
8100 struct lpfc_hba *phba = vport->phba;
8101 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8102 unsigned long iflag = 0;
8103
8104 spin_lock_irqsave(&phba->hbalock, iflag);
8105 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
8106 list_for_each_entry_safe(sglq_entry, sglq_next,
8107 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
8108 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
8109 sglq_entry->ndlp = NULL;
8110 }
8111 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
8112 spin_unlock_irqrestore(&phba->hbalock, iflag);
8113 return;
8114}
8115
8116/**
James Smart6fb120a2009-05-22 14:52:59 -04008117 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
8118 * @phba: pointer to lpfc hba data structure.
8119 * @axri: pointer to the els xri abort wcqe structure.
8120 *
8121 * This routine is invoked by the worker thread to process a SLI4 slow-path
8122 * ELS aborted xri.
8123 **/
8124void
8125lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
8126 struct sli4_wcqe_xri_aborted *axri)
8127{
8128 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05008129 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -04008130 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -05008131
James Smart6fb120a2009-05-22 14:52:59 -04008132 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8133 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05008134 struct lpfc_nodelist *ndlp;
James Smart589a52d2010-07-14 15:30:54 -04008135 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04008136
James Smart0f65ff62010-02-26 14:14:23 -05008137 spin_lock_irqsave(&phba->hbalock, iflag);
8138 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04008139 list_for_each_entry_safe(sglq_entry, sglq_next,
8140 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
8141 if (sglq_entry->sli4_xritag == xri) {
8142 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05008143 ndlp = sglq_entry->ndlp;
8144 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -04008145 list_add_tail(&sglq_entry->list,
8146 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05008147 sglq_entry->state = SGL_FREED;
8148 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04008149 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smartee0f4fe2012-05-09 21:19:14 -04008150 lpfc_set_rrq_active(phba, ndlp,
8151 sglq_entry->sli4_lxritag,
8152 rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04008153
8154 /* Check if TXQ queue needs to be serviced */
James Smart0e9bb8d2013-03-01 16:35:12 -05008155 if (!(list_empty(&pring->txq)))
James Smart589a52d2010-07-14 15:30:54 -04008156 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04008157 return;
8158 }
8159 }
James Smart0f65ff62010-02-26 14:14:23 -05008160 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -04008161 lxri = lpfc_sli4_xri_inrange(phba, xri);
8162 if (lxri == NO_XRI) {
8163 spin_unlock_irqrestore(&phba->hbalock, iflag);
8164 return;
8165 }
8166 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -05008167 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
8168 spin_unlock_irqrestore(&phba->hbalock, iflag);
8169 return;
8170 }
8171 sglq_entry->state = SGL_XRI_ABORTED;
8172 spin_unlock_irqrestore(&phba->hbalock, iflag);
8173 return;
James Smart6fb120a2009-05-22 14:52:59 -04008174}
James Smart086a3452012-08-14 14:25:21 -04008175
8176/* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
8177 * @vport: pointer to virtual port object.
8178 * @ndlp: nodelist pointer for the impacted node.
8179 *
8180 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
8181 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
8182 * the driver is required to send a LOGO to the remote node before it
8183 * attempts to recover its login to the remote node.
8184 */
8185void
8186lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
8187 struct lpfc_nodelist *ndlp)
8188{
8189 struct Scsi_Host *shost;
8190 struct lpfc_hba *phba;
8191 unsigned long flags = 0;
8192
8193 shost = lpfc_shost_from_vport(vport);
8194 phba = vport->phba;
8195 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
8196 lpfc_printf_log(phba, KERN_INFO,
8197 LOG_SLI, "3093 No rport recovery needed. "
8198 "rport in state 0x%x\n", ndlp->nlp_state);
8199 return;
8200 }
8201 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8202 "3094 Start rport recovery on shost id 0x%x "
8203 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
8204 "flags 0x%x\n",
8205 shost->host_no, ndlp->nlp_DID,
8206 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
8207 ndlp->nlp_flag);
8208 /*
8209 * The rport is not responding. Remove the FCP-2 flag to prevent
8210 * an ADISC in the follow-up recovery code.
8211 */
8212 spin_lock_irqsave(shost->host_lock, flags);
8213 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
8214 spin_unlock_irqrestore(shost->host_lock, flags);
8215 lpfc_issue_els_logo(vport, ndlp, 0);
8216 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
8217}
8218