blob: 36bf58ba750ad3d3b13770acda31f9047d5708ad [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 Smartf25e8e72015-04-07 15:07:28 -04004 * Copyright (C) 2004-2015 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 Wellnitzc9f8735b2006-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 Smart88f43a02013-04-17 20:19:44 -0400242 if (elscmd == ELS_CMD_FLOGI)
243 icmd->ulpTimeout = FF_DEF_RATOV * 2;
244 else
245 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500246 } else {
James Smart939723a2012-05-09 21:19:03 -0400247 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
248 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
249 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
250 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
251 icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500252 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
253 }
dea31012005-04-17 16:05:31 -0500254 icmd->ulpBdeCount = 1;
255 icmd->ulpLe = 1;
256 icmd->ulpClass = CLASS3;
257
James Smart939723a2012-05-09 21:19:03 -0400258 /*
259 * If we have NPIV enabled, we want to send ELS traffic by VPI.
260 * For SLI4, since the driver controls VPIs we also want to include
261 * all ELS pt2pt protocol traffic as well.
262 */
263 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
264 ((phba->sli_rev == LPFC_SLI_REV4) &&
265 (vport->fc_flag & FC_PT2PT))) {
James Smart92d7f7b2007-06-17 19:56:38 -0500266
James Smart939723a2012-05-09 21:19:03 -0400267 if (expectRsp) {
268 icmd->un.elsreq64.myID = vport->fc_myDID;
269
270 /* For ELS_REQUEST64_CR, use the VPI by default */
271 icmd->ulpContext = phba->vpi_ids[vport->vpi];
272 }
273
James Smart92d7f7b2007-06-17 19:56:38 -0500274 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500275 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
276 if (elscmd == ELS_CMD_ECHO)
277 icmd->ulpCt_l = 0; /* context = invalid RPI */
278 else
279 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500280 }
281
dea31012005-04-17 16:05:31 -0500282 bpl = (struct ulp_bde64 *) pbuflist->virt;
283 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
284 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
285 bpl->tus.f.bdeSize = cmdSize;
286 bpl->tus.f.bdeFlags = 0;
287 bpl->tus.w = le32_to_cpu(bpl->tus.w);
288
289 if (expectRsp) {
290 bpl++;
291 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
292 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
293 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400294 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500295 bpl->tus.w = le32_to_cpu(bpl->tus.w);
296 }
297
James Smartfa4066b2008-01-11 01:53:27 -0500298 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400299 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500300 if (!elsiocb->context1)
301 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400302 elsiocb->context2 = pcmd;
303 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500304 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500305 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500306 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
307
308 if (prsp) {
309 list_add(&prsp->list, &pcmd->list);
310 }
dea31012005-04-17 16:05:31 -0500311 if (expectRsp) {
312 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400313 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
314 "0116 Xmit ELS command x%x to remote "
James Smarte74c03c2013-04-17 20:15:19 -0400315 "NPORT x%x I/O tag: x%x, port state:x%x"
316 " fc_flag:x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400317 elscmd, did, elsiocb->iotag,
James Smarte74c03c2013-04-17 20:15:19 -0400318 vport->port_state,
319 vport->fc_flag);
dea31012005-04-17 16:05:31 -0500320 } else {
321 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400322 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
323 "0117 Xmit ELS response x%x to remote "
James Smarte74c03c2013-04-17 20:15:19 -0400324 "NPORT x%x I/O tag: x%x, size: x%x "
325 "port_state x%x fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400326 elscmd, ndlp->nlp_DID, elsiocb->iotag,
James Smarte74c03c2013-04-17 20:15:19 -0400327 cmdSize, vport->port_state,
328 vport->fc_flag);
dea31012005-04-17 16:05:31 -0500329 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500330 return elsiocb;
dea31012005-04-17 16:05:31 -0500331
James Smartfa4066b2008-01-11 01:53:27 -0500332els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500333 if (expectRsp)
334 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500335 kfree(pbuflist);
336
337els_iocb_free_prsp_exit:
338 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
339 kfree(prsp);
340
341els_iocb_free_pcmb_exit:
342 kfree(pcmd);
343 lpfc_sli_release_iocbq(phba, elsiocb);
344 return NULL;
345}
dea31012005-04-17 16:05:31 -0500346
James Smarte59058c2008-08-24 21:49:00 -0400347/**
James Smart3621a712009-04-06 18:47:14 -0400348 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400349 * @vport: pointer to a host virtual N_Port data structure.
350 *
351 * This routine issues a fabric registration login for a @vport. An
352 * active ndlp node with Fabric_DID must already exist for this @vport.
353 * The routine invokes two mailbox commands to carry out fabric registration
354 * login through the HBA firmware: the first mailbox command requests the
355 * HBA to perform link configuration for the @vport; and the second mailbox
356 * command requests the HBA to perform the actual fabric registration login
357 * with the @vport.
358 *
359 * Return code
360 * 0 - successfully issued fabric registration login for @vport
361 * -ENXIO -- failed to issue fabric registration login for @vport
362 **/
James Smart3772a992009-05-22 14:50:54 -0400363int
James Smart92d7f7b2007-06-17 19:56:38 -0500364lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
365{
366 struct lpfc_hba *phba = vport->phba;
367 LPFC_MBOXQ_t *mbox;
368 struct lpfc_dmabuf *mp;
369 struct lpfc_nodelist *ndlp;
370 struct serv_parm *sp;
371 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400372 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500373
374 sp = &phba->fc_fabparam;
375 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500376 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400377 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500378 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400379 }
James Smart92d7f7b2007-06-17 19:56:38 -0500380
381 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400382 if (!mbox) {
383 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500384 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400385 }
James Smart92d7f7b2007-06-17 19:56:38 -0500386
387 vport->port_state = LPFC_FABRIC_CFG_LINK;
388 lpfc_config_link(phba, mbox);
389 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
390 mbox->vport = vport;
391
James Smart0b727fe2007-10-27 13:37:25 -0400392 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400393 if (rc == MBX_NOT_FINISHED) {
394 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500395 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400396 }
James Smart92d7f7b2007-06-17 19:56:38 -0500397
398 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400399 if (!mbox) {
400 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500401 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400402 }
James Smart40426292010-12-15 17:58:10 -0500403 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
404 ndlp->nlp_rpi);
James Smart98c9ea52007-10-27 13:37:33 -0400405 if (rc) {
406 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500407 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400408 }
James Smart92d7f7b2007-06-17 19:56:38 -0500409
410 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
411 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500412 /* increment the reference count on ndlp to hold reference
413 * for the callback routine.
414 */
James Smart92d7f7b2007-06-17 19:56:38 -0500415 mbox->context2 = lpfc_nlp_get(ndlp);
416
James Smart0b727fe2007-10-27 13:37:25 -0400417 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400418 if (rc == MBX_NOT_FINISHED) {
419 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500420 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400421 }
James Smart92d7f7b2007-06-17 19:56:38 -0500422
423 return 0;
424
425fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500426 /* decrement the reference count on ndlp just incremented
427 * for the failed mbox command.
428 */
James Smart92d7f7b2007-06-17 19:56:38 -0500429 lpfc_nlp_put(ndlp);
430 mp = (struct lpfc_dmabuf *) mbox->context1;
431 lpfc_mbuf_free(phba, mp->virt, mp->phys);
432 kfree(mp);
433fail_free_mbox:
434 mempool_free(mbox, phba->mbox_mem_pool);
435
436fail:
437 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400438 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400439 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500440 return -ENXIO;
441}
442
James Smarte59058c2008-08-24 21:49:00 -0400443/**
James Smart6fb120a2009-05-22 14:52:59 -0400444 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
445 * @vport: pointer to a host virtual N_Port data structure.
446 *
447 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
James Smart1b511972011-12-13 13:23:09 -0500448 * the @vport. This mailbox command is necessary for SLI4 port only.
James Smart6fb120a2009-05-22 14:52:59 -0400449 *
450 * Return code
451 * 0 - successfully issued REG_VFI for @vport
452 * A failure code otherwise.
453 **/
James Smart1b511972011-12-13 13:23:09 -0500454int
James Smart6fb120a2009-05-22 14:52:59 -0400455lpfc_issue_reg_vfi(struct lpfc_vport *vport)
456{
457 struct lpfc_hba *phba = vport->phba;
458 LPFC_MBOXQ_t *mboxq;
459 struct lpfc_nodelist *ndlp;
460 struct serv_parm *sp;
461 struct lpfc_dmabuf *dmabuf;
462 int rc = 0;
463
464 sp = &phba->fc_fabparam;
James Smart939723a2012-05-09 21:19:03 -0400465 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
James Smart1b511972011-12-13 13:23:09 -0500466 if ((phba->sli_rev == LPFC_SLI_REV4) &&
James Smart939723a2012-05-09 21:19:03 -0400467 !(phba->link_flag & LS_LOOPBACK_MODE) &&
468 !(vport->fc_flag & FC_PT2PT)) {
James Smart1b511972011-12-13 13:23:09 -0500469 ndlp = lpfc_findnode_did(vport, Fabric_DID);
470 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
471 rc = -ENODEV;
472 goto fail;
473 }
James Smart6fb120a2009-05-22 14:52:59 -0400474 }
475
476 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
477 if (!dmabuf) {
478 rc = -ENOMEM;
479 goto fail;
480 }
481 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
482 if (!dmabuf->virt) {
483 rc = -ENOMEM;
484 goto fail_free_dmabuf;
485 }
James Smart6d368e52011-05-24 11:44:12 -0400486
James Smart6fb120a2009-05-22 14:52:59 -0400487 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
488 if (!mboxq) {
489 rc = -ENOMEM;
490 goto fail_free_coherent;
491 }
492 vport->port_state = LPFC_FABRIC_CFG_LINK;
493 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
494 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
James Smartae05ebe2013-03-01 16:35:38 -0500495
James Smart6fb120a2009-05-22 14:52:59 -0400496 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
497 mboxq->vport = vport;
498 mboxq->context1 = dmabuf;
499 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
500 if (rc == MBX_NOT_FINISHED) {
501 rc = -ENXIO;
502 goto fail_free_mbox;
503 }
504 return 0;
505
506fail_free_mbox:
507 mempool_free(mboxq, phba->mbox_mem_pool);
508fail_free_coherent:
509 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
510fail_free_dmabuf:
511 kfree(dmabuf);
512fail:
513 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
514 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
515 "0289 Issue Register VFI failed: Err %d\n", rc);
516 return rc;
517}
518
519/**
James Smart1b511972011-12-13 13:23:09 -0500520 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
521 * @vport: pointer to a host virtual N_Port data structure.
522 *
523 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
524 * the @vport. This mailbox command is necessary for SLI4 port only.
525 *
526 * Return code
527 * 0 - successfully issued REG_VFI for @vport
528 * A failure code otherwise.
529 **/
530int
531lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
532{
533 struct lpfc_hba *phba = vport->phba;
534 struct Scsi_Host *shost;
535 LPFC_MBOXQ_t *mboxq;
536 int rc;
537
538 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
539 if (!mboxq) {
540 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
541 "2556 UNREG_VFI mbox allocation failed"
542 "HBA state x%x\n", phba->pport->port_state);
543 return -ENOMEM;
544 }
545
546 lpfc_unreg_vfi(mboxq, vport);
547 mboxq->vport = vport;
548 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
549
550 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
551 if (rc == MBX_NOT_FINISHED) {
552 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
553 "2557 UNREG_VFI issue mbox failed rc x%x "
554 "HBA state x%x\n",
555 rc, phba->pport->port_state);
556 mempool_free(mboxq, phba->mbox_mem_pool);
557 return -EIO;
558 }
559
560 shost = lpfc_shost_from_vport(vport);
561 spin_lock_irq(shost->host_lock);
562 vport->fc_flag &= ~FC_VFI_REGISTERED;
563 spin_unlock_irq(shost->host_lock);
564 return 0;
565}
566
567/**
James Smart92494142011-02-16 12:39:44 -0500568 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
569 * @vport: pointer to a host virtual N_Port data structure.
570 * @sp: pointer to service parameter data structure.
571 *
572 * This routine is called from FLOGI/FDISC completion handler functions.
573 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
574 * node nodename is changed in the completion service parameter else return
575 * 0. This function also set flag in the vport data structure to delay
576 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
577 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
578 * node nodename is changed in the completion service parameter.
579 *
580 * Return code
581 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
582 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
583 *
584 **/
585static uint8_t
586lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
587 struct serv_parm *sp)
588{
589 uint8_t fabric_param_changed = 0;
590 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
591
592 if ((vport->fc_prevDID != vport->fc_myDID) ||
593 memcmp(&vport->fabric_portname, &sp->portName,
594 sizeof(struct lpfc_name)) ||
595 memcmp(&vport->fabric_nodename, &sp->nodeName,
596 sizeof(struct lpfc_name)))
597 fabric_param_changed = 1;
598
599 /*
600 * Word 1 Bit 31 in common service parameter is overloaded.
601 * Word 1 Bit 31 in FLOGI request is multiple NPort request
602 * Word 1 Bit 31 in FLOGI response is clean address bit
603 *
604 * If fabric parameter is changed and clean address bit is
605 * cleared delay nport discovery if
606 * - vport->fc_prevDID != 0 (not initial discovery) OR
607 * - lpfc_delay_discovery module parameter is set.
608 */
609 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
610 (vport->fc_prevDID || lpfc_delay_discovery)) {
611 spin_lock_irq(shost->host_lock);
612 vport->fc_flag |= FC_DISC_DELAYED;
613 spin_unlock_irq(shost->host_lock);
614 }
615
616 return fabric_param_changed;
617}
618
619
620/**
James Smart3621a712009-04-06 18:47:14 -0400621 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400622 * @vport: pointer to a host virtual N_Port data structure.
623 * @ndlp: pointer to a node-list data structure.
624 * @sp: pointer to service parameter data structure.
625 * @irsp: pointer to the IOCB within the lpfc response IOCB.
626 *
627 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
628 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
629 * port in a fabric topology. It properly sets up the parameters to the @ndlp
630 * from the IOCB response. It also check the newly assigned N_Port ID to the
631 * @vport against the previously assigned N_Port ID. If it is different from
632 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
633 * is invoked on all the remaining nodes with the @vport to unregister the
634 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
635 * is invoked to register login to the fabric.
636 *
637 * Return code
638 * 0 - Success (currently, always return 0)
639 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500640static int
James Smart2e0fef82007-06-17 19:56:36 -0500641lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
642 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500643{
James Smart2e0fef82007-06-17 19:56:36 -0500644 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
645 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500646 struct lpfc_nodelist *np;
647 struct lpfc_nodelist *next_np;
James Smart92494142011-02-16 12:39:44 -0500648 uint8_t fabric_param_changed;
dea31012005-04-17 16:05:31 -0500649
James Smart2e0fef82007-06-17 19:56:36 -0500650 spin_lock_irq(shost->host_lock);
651 vport->fc_flag |= FC_FABRIC;
652 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500653
654 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
655 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
656 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
657
James Smart12265f62010-10-22 11:05:53 -0400658 phba->fc_edtovResol = sp->cmn.edtovResolution;
dea31012005-04-17 16:05:31 -0500659 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
660
James Smart76a95d72010-11-20 23:11:48 -0500661 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500662 spin_lock_irq(shost->host_lock);
663 vport->fc_flag |= FC_PUBLIC_LOOP;
664 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500665 }
666
James Smart2e0fef82007-06-17 19:56:36 -0500667 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500668 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500669 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500670 ndlp->nlp_class_sup = 0;
671 if (sp->cls1.classValid)
672 ndlp->nlp_class_sup |= FC_COS_CLASS1;
673 if (sp->cls2.classValid)
674 ndlp->nlp_class_sup |= FC_COS_CLASS2;
675 if (sp->cls3.classValid)
676 ndlp->nlp_class_sup |= FC_COS_CLASS3;
677 if (sp->cls4.classValid)
678 ndlp->nlp_class_sup |= FC_COS_CLASS4;
679 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
680 sp->cmn.bbRcvSizeLsb;
James Smart92494142011-02-16 12:39:44 -0500681
682 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
683 memcpy(&vport->fabric_portname, &sp->portName,
684 sizeof(struct lpfc_name));
685 memcpy(&vport->fabric_nodename, &sp->nodeName,
686 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500687 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
688
James Smart92d7f7b2007-06-17 19:56:38 -0500689 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
690 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400691 lpfc_printf_vlog(vport, KERN_WARNING,
692 LOG_ELS | LOG_VPORT,
693 "1816 FLOGI NPIV supported, "
694 "response data 0x%x\n",
695 sp->cmn.response_multiple_NPort);
James Smart1b511972011-12-13 13:23:09 -0500696 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500697 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500698 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500699 } else {
700 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400701 to call reg_vnpid atleast for the physcial host */
702 lpfc_printf_vlog(vport, KERN_WARNING,
703 LOG_ELS | LOG_VPORT,
704 "1817 Fabric does not support NPIV "
705 "- configuring single port mode.\n");
James Smart1b511972011-12-13 13:23:09 -0500706 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500707 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500708 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500709 }
710 }
711
James Smartae05ebe2013-03-01 16:35:38 -0500712 /*
713 * For FC we need to do some special processing because of the SLI
714 * Port's default settings of the Common Service Parameters.
715 */
716 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC) {
717 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
718 if ((phba->sli_rev == LPFC_SLI_REV4) && fabric_param_changed)
719 lpfc_unregister_fcf_prep(phba);
720
721 /* This should just update the VFI CSPs*/
722 if (vport->fc_flag & FC_VFI_REGISTERED)
723 lpfc_issue_reg_vfi(vport);
724 }
725
James Smart92494142011-02-16 12:39:44 -0500726 if (fabric_param_changed &&
James Smart92d7f7b2007-06-17 19:56:38 -0500727 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
728
729 /* If our NportID changed, we need to ensure all
730 * remaining NPORTs get unreg_login'ed.
731 */
732 list_for_each_entry_safe(np, next_np,
733 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400734 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500735 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500736 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
737 !(np->nlp_flag & NLP_NPR_ADISC))
738 continue;
739 spin_lock_irq(shost->host_lock);
740 np->nlp_flag &= ~NLP_NPR_ADISC;
741 spin_unlock_irq(shost->host_lock);
742 lpfc_unreg_rpi(vport, np);
743 }
James Smart78730cf2010-04-06 15:06:30 -0400744 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -0400745
James Smart5248a742011-07-22 18:37:06 -0400746 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart5af5eee2010-10-22 11:06:38 -0400747 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500748 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500749 spin_lock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -0500750 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
751 spin_unlock_irq(shost->host_lock);
752 }
James Smart27aa1b72012-05-09 21:18:49 -0400753
754 /*
755 * For SLI3 and SLI4, the VPI needs to be reregistered in
756 * response to this fabric parameter change event.
757 */
758 spin_lock_irq(shost->host_lock);
759 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
760 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -0400761 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
762 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
763 /*
764 * Driver needs to re-reg VPI in order for f/w
765 * to update the MAC address.
766 */
James Smart9589b0622011-04-16 11:03:17 -0400767 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart38b92ef2010-08-04 16:11:39 -0400768 lpfc_register_new_vport(phba, vport, ndlp);
769 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500770 }
771
James Smart6fb120a2009-05-22 14:52:59 -0400772 if (phba->sli_rev < LPFC_SLI_REV4) {
773 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
774 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
775 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
776 lpfc_register_new_vport(phba, vport, ndlp);
777 else
778 lpfc_issue_fabric_reglogin(vport);
779 } else {
780 ndlp->nlp_type |= NLP_FABRIC;
781 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500782 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
783 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400784 lpfc_start_fdiscs(phba);
785 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500786 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500787 lpfc_issue_init_vpi(vport);
James Smart1b511972011-12-13 13:23:09 -0500788 else {
789 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
790 "3135 Need register VFI: (x%x/%x)\n",
791 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -0400792 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -0500793 }
James Smart92d7f7b2007-06-17 19:56:38 -0500794 }
dea31012005-04-17 16:05:31 -0500795 return 0;
dea31012005-04-17 16:05:31 -0500796}
James Smart1b511972011-12-13 13:23:09 -0500797
James Smarte59058c2008-08-24 21:49:00 -0400798/**
James Smart3621a712009-04-06 18:47:14 -0400799 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400800 * @vport: pointer to a host virtual N_Port data structure.
801 * @ndlp: pointer to a node-list data structure.
802 * @sp: pointer to service parameter data structure.
803 *
804 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
805 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
806 * in a point-to-point topology. First, the @vport's N_Port Name is compared
807 * with the received N_Port Name: if the @vport's N_Port Name is greater than
808 * the received N_Port Name lexicographically, this node shall assign local
809 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
810 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
811 * this node shall just wait for the remote node to issue PLOGI and assign
812 * N_Port IDs.
813 *
814 * Return code
815 * 0 - Success
816 * -ENXIO - Fail
817 **/
dea31012005-04-17 16:05:31 -0500818static int
James Smart2e0fef82007-06-17 19:56:36 -0500819lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
820 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500821{
James Smart2e0fef82007-06-17 19:56:36 -0500822 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
823 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500824 LPFC_MBOXQ_t *mbox;
825 int rc;
826
James Smart2e0fef82007-06-17 19:56:36 -0500827 spin_lock_irq(shost->host_lock);
828 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
829 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500830
831 phba->fc_edtov = FF_DEF_EDTOV;
832 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500833 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500834 sizeof(vport->fc_portname));
James Smart2eb68622012-09-29 11:32:27 -0400835 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
836
dea31012005-04-17 16:05:31 -0500837 if (rc >= 0) {
838 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500839 spin_lock_irq(shost->host_lock);
840 vport->fc_flag |= FC_PT2PT_PLOGI;
841 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500842
843 /*
844 * N_Port ID cannot be 0, set our to LocalID the other
845 * side will be RemoteID.
846 */
847
848 /* not equal */
849 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500850 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500851
852 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
853 if (!mbox)
854 goto fail;
855
856 lpfc_config_link(phba, mbox);
857
858 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500859 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400860 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500861 if (rc == MBX_NOT_FINISHED) {
862 mempool_free(mbox, phba->mbox_mem_pool);
863 goto fail;
864 }
James Smart939723a2012-05-09 21:19:03 -0400865
866 /*
867 * For SLI4, the VFI/VPI are registered AFTER the
868 * Nport with the higher WWPN sends the PLOGI with
869 * an assigned NPortId.
870 */
871
872 /* not equal */
873 if ((phba->sli_rev == LPFC_SLI_REV4) && rc)
874 lpfc_issue_reg_vfi(vport);
875
James Smarte47c9092008-02-08 18:49:26 -0500876 /* Decrement ndlp reference count indicating that ndlp can be
877 * safely released when other references to it are done.
878 */
James Smart329f9bc2007-04-25 09:53:01 -0400879 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500880
James Smart2e0fef82007-06-17 19:56:36 -0500881 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500882 if (!ndlp) {
883 /*
884 * Cannot find existing Fabric ndlp, so allocate a
885 * new one
886 */
887 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
888 if (!ndlp)
889 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500890 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500891 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
892 ndlp = lpfc_enable_node(vport, ndlp,
893 NLP_STE_UNUSED_NODE);
894 if(!ndlp)
895 goto fail;
dea31012005-04-17 16:05:31 -0500896 }
897
898 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500899 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500900 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500901 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500902 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500903 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
904 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500905 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500906 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500907 } else
908 /* This side will wait for the PLOGI, decrement ndlp reference
909 * count indicating that ndlp can be released when other
910 * references to it are done.
911 */
James Smart329f9bc2007-04-25 09:53:01 -0400912 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500913
James Smart09372822008-01-11 01:52:54 -0500914 /* If we are pt2pt with another NPort, force NPIV off! */
915 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
916
James Smart2e0fef82007-06-17 19:56:36 -0500917 spin_lock_irq(shost->host_lock);
918 vport->fc_flag |= FC_PT2PT;
919 spin_unlock_irq(shost->host_lock);
James Smarte74c03c2013-04-17 20:15:19 -0400920 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
921 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
922 lpfc_unregister_fcf_prep(phba);
923
924 /* The FC_VFI_REGISTERED flag will get clear in the cmpl
925 * handler for unreg_vfi, but if we don't force the
926 * FC_VFI_REGISTERED flag then the reg_vfi mailbox could be
927 * built with the update bit set instead of just the vp bit to
928 * change the Nport ID. We need to have the vp set and the
929 * Upd cleared on topology changes.
930 */
931 spin_lock_irq(shost->host_lock);
932 vport->fc_flag &= ~FC_VFI_REGISTERED;
933 spin_unlock_irq(shost->host_lock);
934 phba->fc_topology_changed = 0;
935 lpfc_issue_reg_vfi(vport);
936 }
dea31012005-04-17 16:05:31 -0500937
938 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500939 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500940 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500941fail:
dea31012005-04-17 16:05:31 -0500942 return -ENXIO;
943}
944
James Smarte59058c2008-08-24 21:49:00 -0400945/**
James Smart3621a712009-04-06 18:47:14 -0400946 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400947 * @phba: pointer to lpfc hba data structure.
948 * @cmdiocb: pointer to lpfc command iocb data structure.
949 * @rspiocb: pointer to lpfc response iocb data structure.
950 *
951 * This routine is the top-level completion callback function for issuing
952 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
953 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
954 * retry has been made (either immediately or delayed with lpfc_els_retry()
955 * returning 1), the command IOCB will be released and function returned.
956 * If the retry attempt has been given up (possibly reach the maximum
957 * number of retries), one additional decrement of ndlp reference shall be
958 * invoked before going out after releasing the command IOCB. This will
959 * actually release the remote node (Note, lpfc_els_free_iocb() will also
960 * invoke one decrement of ndlp reference count). If no error reported in
961 * the IOCB status, the command Port ID field is used to determine whether
962 * this is a point-to-point topology or a fabric topology: if the Port ID
963 * field is assigned, it is a fabric topology; otherwise, it is a
964 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
965 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
966 * specific topology completion conditions.
967 **/
dea31012005-04-17 16:05:31 -0500968static void
James Smart329f9bc2007-04-25 09:53:01 -0400969lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
970 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500971{
James Smart2e0fef82007-06-17 19:56:36 -0500972 struct lpfc_vport *vport = cmdiocb->vport;
973 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500974 IOCB_t *irsp = &rspiocb->iocb;
975 struct lpfc_nodelist *ndlp = cmdiocb->context1;
976 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
977 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500978 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500979 int rc;
980
981 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500982 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500983 /* One additional decrement on node reference count to
984 * trigger the release of the node
985 */
James Smart329f9bc2007-04-25 09:53:01 -0400986 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500987 goto out;
988 }
989
James Smart858c9f62007-06-17 19:56:39 -0500990 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
991 "FLOGI cmpl: status:x%x/x%x state:x%x",
992 irsp->ulpStatus, irsp->un.ulpWord[4],
993 vport->port_state);
994
dea31012005-04-17 16:05:31 -0500995 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500996 /*
James Smarta93ff372010-10-22 11:06:08 -0400997 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -0500998 * due to new FCF discovery
999 */
1000 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart80c17842012-03-01 22:35:45 -05001001 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1002 if (phba->link_state < LPFC_LINK_UP)
1003 goto stop_rr_fcf_flogi;
1004 if ((phba->fcoe_cvl_eventtag_attn ==
1005 phba->fcoe_cvl_eventtag) &&
1006 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -04001007 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1008 IOERR_SLI_ABORTED))
James Smart80c17842012-03-01 22:35:45 -05001009 goto stop_rr_fcf_flogi;
1010 else
1011 phba->fcoe_cvl_eventtag_attn =
1012 phba->fcoe_cvl_eventtag;
James Smart0c9ab6f2010-02-26 14:15:57 -05001013 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001014 "2611 FLOGI failed on FCF (x%x), "
1015 "status:x%x/x%x, tmo:x%x, perform "
1016 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -04001017 phba->fcf.current_rec.fcf_indx,
1018 irsp->ulpStatus, irsp->un.ulpWord[4],
1019 irsp->ulpTimeout);
James Smart7d791df2011-07-22 18:37:52 -04001020 lpfc_sli4_set_fcf_flogi_fail(phba,
1021 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001022 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -04001023 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1024 if (rc)
1025 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001026 }
1027
James Smart80c17842012-03-01 22:35:45 -05001028stop_rr_fcf_flogi:
James Smart38b92ef2010-08-04 16:11:39 -04001029 /* FLOGI failure */
1030 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1031 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1032 irsp->ulpStatus, irsp->un.ulpWord[4],
1033 irsp->ulpTimeout);
1034
dea31012005-04-17 16:05:31 -05001035 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001036 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001037 goto out;
James Smart2e0fef82007-06-17 19:56:36 -05001038
James Smart76a95d72010-11-20 23:11:48 -05001039 /* FLOGI failure */
1040 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1041 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1042 irsp->ulpStatus, irsp->un.ulpWord[4],
1043 irsp->ulpTimeout);
1044
dea31012005-04-17 16:05:31 -05001045 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -05001046 spin_lock_irq(shost->host_lock);
1047 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1048 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001049
James Smart329f9bc2007-04-25 09:53:01 -04001050 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -05001051 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1052 * alpa map would take too long otherwise.
1053 */
James Smart1b511972011-12-13 13:23:09 -05001054 if (phba->alpa_map[0] == 0)
James Smart3de2a652007-08-02 11:09:59 -04001055 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smartff78d8f2011-12-13 13:21:35 -05001056 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1057 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
James Smarte74c03c2013-04-17 20:15:19 -04001058 (vport->fc_prevDID != vport->fc_myDID) ||
1059 phba->fc_topology_changed)) {
1060 if (vport->fc_flag & FC_VFI_REGISTERED) {
1061 if (phba->fc_topology_changed) {
1062 lpfc_unregister_fcf_prep(phba);
1063 spin_lock_irq(shost->host_lock);
1064 vport->fc_flag &= ~FC_VFI_REGISTERED;
1065 spin_unlock_irq(shost->host_lock);
1066 phba->fc_topology_changed = 0;
1067 } else {
1068 lpfc_sli4_unreg_all_rpis(vport);
1069 }
1070 }
James Smartff78d8f2011-12-13 13:21:35 -05001071 lpfc_issue_reg_vfi(vport);
1072 lpfc_nlp_put(ndlp);
1073 goto out;
dea31012005-04-17 16:05:31 -05001074 }
dea31012005-04-17 16:05:31 -05001075 goto flogifail;
1076 }
James Smart695a8142010-01-26 23:08:03 -05001077 spin_lock_irq(shost->host_lock);
1078 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04001079 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -05001080 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001081
1082 /*
1083 * The FLogI succeeded. Sync the data for the CPU before
1084 * accessing it.
1085 */
1086 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04001087 if (!prsp)
1088 goto out;
dea31012005-04-17 16:05:31 -05001089 sp = prsp->virt + sizeof(uint32_t);
1090
1091 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -04001092 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smart88f43a02013-04-17 20:19:44 -04001093 "0101 FLOGI completes successfully, I/O tag:x%x, "
1094 "Data: x%x x%x x%x x%x x%x x%x\n", cmdiocb->iotag,
James Smarte8b62012007-08-02 11:10:09 -04001095 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
James Smarte74c03c2013-04-17 20:15:19 -04001096 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1097 vport->port_state, vport->fc_flag);
dea31012005-04-17 16:05:31 -05001098
James Smart2e0fef82007-06-17 19:56:36 -05001099 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -05001100 /*
1101 * If Common Service Parameters indicate Nport
1102 * we are point to point, if Fport we are Fabric.
1103 */
1104 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -05001105 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -05001106 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001107 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -04001108 else {
1109 lpfc_printf_vlog(vport, KERN_ERR,
1110 LOG_FIP | LOG_ELS,
1111 "2831 FLOGI response with cleared Fabric "
1112 "bit fcf_index 0x%x "
1113 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1114 "Fabric Name "
1115 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1116 phba->fcf.current_rec.fcf_indx,
1117 phba->fcf.current_rec.switch_name[0],
1118 phba->fcf.current_rec.switch_name[1],
1119 phba->fcf.current_rec.switch_name[2],
1120 phba->fcf.current_rec.switch_name[3],
1121 phba->fcf.current_rec.switch_name[4],
1122 phba->fcf.current_rec.switch_name[5],
1123 phba->fcf.current_rec.switch_name[6],
1124 phba->fcf.current_rec.switch_name[7],
1125 phba->fcf.current_rec.fabric_name[0],
1126 phba->fcf.current_rec.fabric_name[1],
1127 phba->fcf.current_rec.fabric_name[2],
1128 phba->fcf.current_rec.fabric_name[3],
1129 phba->fcf.current_rec.fabric_name[4],
1130 phba->fcf.current_rec.fabric_name[5],
1131 phba->fcf.current_rec.fabric_name[6],
1132 phba->fcf.current_rec.fabric_name[7]);
1133 lpfc_nlp_put(ndlp);
1134 spin_lock_irq(&phba->hbalock);
1135 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001136 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -04001137 spin_unlock_irq(&phba->hbalock);
1138 goto out;
1139 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001140 if (!rc) {
1141 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -04001142 if (phba->hba_flag & HBA_FIP_SUPPORT)
1143 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1144 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001145 "2769 FLOGI to FCF (x%x) "
1146 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -04001147 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001148 spin_lock_irq(&phba->hbalock);
1149 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001150 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -05001151 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001152 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001153 }
dea31012005-04-17 16:05:31 -05001154 }
1155
1156flogifail:
James Smart329f9bc2007-04-25 09:53:01 -04001157 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001158
James Smart858c9f62007-06-17 19:56:39 -05001159 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001160 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001161 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001162
1163 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001164 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001165 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04001166 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1167 IOERR_SLI_ABORTED) &&
1168 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1169 IOERR_SLI_DOWN))) &&
James Smart87af33f2007-10-27 13:37:43 -04001170 (phba->link_state != LPFC_CLEAR_LA)) {
1171 /* If FLOGI failed enable link interrupt. */
1172 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001173 }
dea31012005-04-17 16:05:31 -05001174out:
1175 lpfc_els_free_iocb(phba, cmdiocb);
1176}
1177
James Smarte59058c2008-08-24 21:49:00 -04001178/**
James Smart3621a712009-04-06 18:47:14 -04001179 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001180 * @vport: pointer to a host virtual N_Port data structure.
1181 * @ndlp: pointer to a node-list data structure.
1182 * @retry: number of retries to the command IOCB.
1183 *
1184 * This routine issues a Fabric Login (FLOGI) Request ELS command
1185 * for a @vport. The initiator service parameters are put into the payload
1186 * of the FLOGI Request IOCB and the top-level callback function pointer
1187 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1188 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1189 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1190 *
1191 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1192 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1193 * will be stored into the context1 field of the IOCB for the completion
1194 * callback function to the FLOGI ELS command.
1195 *
1196 * Return code
1197 * 0 - successfully issued flogi iocb for @vport
1198 * 1 - failed to issue flogi iocb for @vport
1199 **/
dea31012005-04-17 16:05:31 -05001200static int
James Smart2e0fef82007-06-17 19:56:36 -05001201lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001202 uint8_t retry)
1203{
James Smart2e0fef82007-06-17 19:56:36 -05001204 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001205 struct serv_parm *sp;
1206 IOCB_t *icmd;
1207 struct lpfc_iocbq *elsiocb;
1208 struct lpfc_sli_ring *pring;
1209 uint8_t *pcmd;
1210 uint16_t cmdsize;
1211 uint32_t tmo;
1212 int rc;
1213
1214 pring = &phba->sli.ring[LPFC_ELS_RING];
1215
James Smart92d7f7b2007-06-17 19:56:38 -05001216 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001217 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1218 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001219
James Smart488d1462006-03-07 15:02:37 -05001220 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001221 return 1;
dea31012005-04-17 16:05:31 -05001222
1223 icmd = &elsiocb->iocb;
1224 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1225
1226 /* For FLOGI request, remainder of payload is service parameters */
1227 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001228 pcmd += sizeof(uint32_t);
1229 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001230 sp = (struct serv_parm *) pcmd;
1231
1232 /* Setup CSPs accordingly for Fabric */
1233 sp->cmn.e_d_tov = 0;
1234 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05001235 sp->cmn.virtual_fabric_support = 0;
dea31012005-04-17 16:05:31 -05001236 sp->cls1.classValid = 0;
dea31012005-04-17 16:05:31 -05001237 if (sp->cmn.fcphLow < FC_PH3)
1238 sp->cmn.fcphLow = FC_PH3;
1239 if (sp->cmn.fcphHigh < FC_PH3)
1240 sp->cmn.fcphHigh = FC_PH3;
1241
James Smartc31098c2011-04-16 11:03:33 -04001242 if (phba->sli_rev == LPFC_SLI_REV4) {
1243 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1244 LPFC_SLI_INTF_IF_TYPE_0) {
1245 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1246 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1247 /* FLOGI needs to be 3 for WQE FCFI */
1248 /* Set the fcfi to the fcfi we registered with */
1249 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1250 }
James Smart0f378872012-10-31 14:45:01 -04001251 /* Can't do SLI4 class2 without support sequence coalescing */
1252 sp->cls2.classValid = 0;
1253 sp->cls2.seqDelivery = 0;
James Smart5248a742011-07-22 18:37:06 -04001254 } else {
James Smart0f378872012-10-31 14:45:01 -04001255 /* Historical, setting sequential-delivery bit for SLI3 */
1256 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1257 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
James Smart5248a742011-07-22 18:37:06 -04001258 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1259 sp->cmn.request_multiple_Nport = 1;
1260 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1261 icmd->ulpCt_h = 1;
1262 icmd->ulpCt_l = 0;
1263 } else
1264 sp->cmn.request_multiple_Nport = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001265 }
1266
James Smart76a95d72010-11-20 23:11:48 -05001267 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001268 icmd->un.elsreq64.myID = 0;
1269 icmd->un.elsreq64.fl = 1;
1270 }
1271
dea31012005-04-17 16:05:31 -05001272 tmo = phba->fc_ratov;
1273 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001274 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001275 phba->fc_ratov = tmo;
1276
1277 phba->fc_stat.elsXmitFLOGI++;
1278 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001279
1280 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1281 "Issue FLOGI: opt:x%x",
1282 phba->sli3_options, 0, 0);
1283
James Smart92d7f7b2007-06-17 19:56:38 -05001284 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001285 if (rc == IOCB_ERROR) {
1286 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001287 return 1;
dea31012005-04-17 16:05:31 -05001288 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001289 return 0;
dea31012005-04-17 16:05:31 -05001290}
1291
James Smarte59058c2008-08-24 21:49:00 -04001292/**
James Smart3621a712009-04-06 18:47:14 -04001293 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001294 * @phba: pointer to lpfc hba data structure.
1295 *
1296 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1297 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1298 * list and issues an abort IOCB commond on each outstanding IOCB that
1299 * contains a active Fabric_DID ndlp. Note that this function is to issue
1300 * the abort IOCB command on all the outstanding IOCBs, thus when this
1301 * function returns, it does not guarantee all the IOCBs are actually aborted.
1302 *
1303 * Return code
Daniel Mack3ad2f3fb2010-02-03 08:01:28 +08001304 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001305 **/
dea31012005-04-17 16:05:31 -05001306int
James Smart2e0fef82007-06-17 19:56:36 -05001307lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001308{
1309 struct lpfc_sli_ring *pring;
1310 struct lpfc_iocbq *iocb, *next_iocb;
1311 struct lpfc_nodelist *ndlp;
1312 IOCB_t *icmd;
1313
1314 /* Abort outstanding I/O on NPort <nlp_DID> */
1315 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001316 "0201 Abort outstanding I/O on NPort x%x\n",
1317 Fabric_DID);
dea31012005-04-17 16:05:31 -05001318
1319 pring = &phba->sli.ring[LPFC_ELS_RING];
1320
1321 /*
1322 * Check the txcmplq for an iocb that matches the nport the driver is
1323 * searching for.
1324 */
James Smart2e0fef82007-06-17 19:56:36 -05001325 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001326 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1327 icmd = &iocb->iocb;
James Smart1b511972011-12-13 13:23:09 -05001328 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
dea31012005-04-17 16:05:31 -05001329 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001330 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1331 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001332 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001333 }
1334 }
James Smart2e0fef82007-06-17 19:56:36 -05001335 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001336
1337 return 0;
1338}
1339
James Smarte59058c2008-08-24 21:49:00 -04001340/**
James Smart3621a712009-04-06 18:47:14 -04001341 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001342 * @vport: pointer to a host virtual N_Port data structure.
1343 *
1344 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1345 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1346 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1347 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1348 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1349 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1350 * @vport.
1351 *
1352 * Return code
1353 * 0 - failed to issue initial flogi for @vport
1354 * 1 - successfully issued initial flogi for @vport
1355 **/
dea31012005-04-17 16:05:31 -05001356int
James Smart2e0fef82007-06-17 19:56:36 -05001357lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001358{
James Smart2e0fef82007-06-17 19:56:36 -05001359 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001360 struct lpfc_nodelist *ndlp;
1361
James Smart98c9ea52007-10-27 13:37:33 -04001362 vport->port_state = LPFC_FLOGI;
1363 lpfc_set_disctmo(vport);
1364
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001365 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001366 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001367 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001368 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001369 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1370 if (!ndlp)
1371 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001372 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001373 /* Set the node type */
1374 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001375 /* Put ndlp onto node list */
1376 lpfc_enqueue_node(vport, ndlp);
1377 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1378 /* re-setup ndlp without removing from node list */
1379 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1380 if (!ndlp)
1381 return 0;
dea31012005-04-17 16:05:31 -05001382 }
James Smart87af33f2007-10-27 13:37:43 -04001383
James Smart5ac6b302010-10-22 11:05:36 -04001384 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001385 /* This decrement of reference count to node shall kick off
1386 * the release of the node.
1387 */
James Smart329f9bc2007-04-25 09:53:01 -04001388 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001389 return 0;
1390 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001391 return 1;
dea31012005-04-17 16:05:31 -05001392}
1393
James Smarte59058c2008-08-24 21:49:00 -04001394/**
James Smart3621a712009-04-06 18:47:14 -04001395 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001396 * @vport: pointer to a host virtual N_Port data structure.
1397 *
1398 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1399 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1400 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1401 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1402 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1403 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1404 * @vport.
1405 *
1406 * Return code
1407 * 0 - failed to issue initial fdisc for @vport
1408 * 1 - successfully issued initial fdisc for @vport
1409 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001410int
1411lpfc_initial_fdisc(struct lpfc_vport *vport)
1412{
1413 struct lpfc_hba *phba = vport->phba;
1414 struct lpfc_nodelist *ndlp;
1415
1416 /* First look for the Fabric ndlp */
1417 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1418 if (!ndlp) {
1419 /* Cannot find existing Fabric ndlp, so allocate a new one */
1420 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1421 if (!ndlp)
1422 return 0;
1423 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001424 /* Put ndlp onto node list */
1425 lpfc_enqueue_node(vport, ndlp);
1426 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1427 /* re-setup ndlp without removing from node list */
1428 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1429 if (!ndlp)
1430 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001431 }
James Smarte47c9092008-02-08 18:49:26 -05001432
James Smart92d7f7b2007-06-17 19:56:38 -05001433 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001434 /* decrement node reference count to trigger the release of
1435 * the node.
1436 */
James Smart92d7f7b2007-06-17 19:56:38 -05001437 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001438 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001439 }
1440 return 1;
1441}
James Smart87af33f2007-10-27 13:37:43 -04001442
James Smarte59058c2008-08-24 21:49:00 -04001443/**
James Smart3621a712009-04-06 18:47:14 -04001444 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001445 * @vport: pointer to a host virtual N_Port data structure.
1446 *
1447 * This routine checks whether there are more remaining Port Logins
1448 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1449 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1450 * to issue ELS PLOGIs up to the configured discover threads with the
1451 * @vport (@vport->cfg_discovery_threads). The function also decrement
1452 * the @vport's num_disc_node by 1 if it is not already 0.
1453 **/
James Smart87af33f2007-10-27 13:37:43 -04001454void
James Smart2e0fef82007-06-17 19:56:36 -05001455lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001456{
1457 int sentplogi;
1458
James Smart2e0fef82007-06-17 19:56:36 -05001459 if (vport->num_disc_nodes)
1460 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001461
1462 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001463 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1464 "0232 Continue discovery with %d PLOGIs to go "
1465 "Data: x%x x%x x%x\n",
1466 vport->num_disc_nodes, vport->fc_plogi_cnt,
1467 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001468 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001469 if (vport->fc_flag & FC_NLP_MORE)
1470 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1471 sentplogi = lpfc_els_disc_plogi(vport);
1472
dea31012005-04-17 16:05:31 -05001473 return;
1474}
1475
James Smarte59058c2008-08-24 21:49:00 -04001476/**
James Smart3621a712009-04-06 18:47:14 -04001477 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001478 * @phba: pointer to lpfc hba data structure.
1479 * @prsp: pointer to response IOCB payload.
1480 * @ndlp: pointer to a node-list data structure.
1481 *
1482 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1483 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1484 * The following cases are considered N_Port confirmed:
1485 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1486 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1487 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1488 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1489 * 1) if there is a node on vport list other than the @ndlp with the same
1490 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1491 * on that node to release the RPI associated with the node; 2) if there is
1492 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1493 * into, a new node shall be allocated (or activated). In either case, the
1494 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1495 * be released and the new_ndlp shall be put on to the vport node list and
1496 * its pointer returned as the confirmed node.
1497 *
1498 * Note that before the @ndlp got "released", the keepDID from not-matching
1499 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1500 * of the @ndlp. This is because the release of @ndlp is actually to put it
1501 * into an inactive state on the vport node list and the vport node list
1502 * management algorithm does not allow two node with a same DID.
1503 *
1504 * Return code
1505 * pointer to the PLOGI N_Port @ndlp
1506 **/
James Smart488d1462006-03-07 15:02:37 -05001507static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001508lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001509 struct lpfc_nodelist *ndlp)
1510{
James Smart2e0fef82007-06-17 19:56:36 -05001511 struct lpfc_vport *vport = ndlp->vport;
James Smart953ceed2015-05-22 10:42:37 -04001512 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05001513 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001514 struct lpfc_rport_data *rdata;
1515 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001516 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001517 uint8_t name[sizeof(struct lpfc_name)];
James Smarte5abba42015-05-21 13:55:27 -04001518 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
James Smart953ceed2015-05-22 10:42:37 -04001519 uint16_t keep_nlp_state;
James Smart38b92ef2010-08-04 16:11:39 -04001520 int put_node;
1521 int put_rport;
James Smartcff261f2013-12-17 20:29:47 -05001522 unsigned long *active_rrqs_xri_bitmap = NULL;
James Smart488d1462006-03-07 15:02:37 -05001523
James Smart2fb9bd82006-12-02 13:33:57 -05001524 /* Fabric nodes can have the same WWPN so we don't bother searching
1525 * by WWPN. Just return the ndlp that was given to us.
1526 */
1527 if (ndlp->nlp_type & NLP_FABRIC)
1528 return ndlp;
1529
James Smart92d7f7b2007-06-17 19:56:38 -05001530 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001531 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001532
James Smart685f0bf2007-04-25 09:53:08 -04001533 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001534 * we have for that ndlp. If not, we have some work to do.
1535 */
James Smart2e0fef82007-06-17 19:56:36 -05001536 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001537
James Smarte47c9092008-02-08 18:49:26 -05001538 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001539 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001540 if (phba->sli_rev == LPFC_SLI_REV4) {
1541 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1542 GFP_KERNEL);
1543 if (active_rrqs_xri_bitmap)
1544 memset(active_rrqs_xri_bitmap, 0,
1545 phba->cfg_rrq_xri_bitmap_sz);
1546 }
James Smart488d1462006-03-07 15:02:37 -05001547
James Smart34f5ad82012-08-03 12:35:03 -04001548 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1549 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1550 ndlp, ndlp->nlp_DID, new_ndlp);
1551
James Smart488d1462006-03-07 15:02:37 -05001552 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001553 rc = memcmp(&ndlp->nlp_portname, name,
1554 sizeof(struct lpfc_name));
James Smartcff261f2013-12-17 20:29:47 -05001555 if (!rc) {
1556 if (active_rrqs_xri_bitmap)
1557 mempool_free(active_rrqs_xri_bitmap,
1558 phba->active_rrq_pool);
James Smart92795652006-07-06 15:50:02 -04001559 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001560 }
James Smart488d1462006-03-07 15:02:37 -05001561 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
James Smartcff261f2013-12-17 20:29:47 -05001562 if (!new_ndlp) {
1563 if (active_rrqs_xri_bitmap)
1564 mempool_free(active_rrqs_xri_bitmap,
1565 phba->active_rrq_pool);
James Smart488d1462006-03-07 15:02:37 -05001566 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001567 }
James Smart2e0fef82007-06-17 19:56:36 -05001568 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001569 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001570 rc = memcmp(&ndlp->nlp_portname, name,
1571 sizeof(struct lpfc_name));
James Smartcff261f2013-12-17 20:29:47 -05001572 if (!rc) {
1573 if (active_rrqs_xri_bitmap)
1574 mempool_free(active_rrqs_xri_bitmap,
1575 phba->active_rrq_pool);
James Smart58da1ff2008-04-07 10:15:56 -04001576 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001577 }
James Smarte47c9092008-02-08 18:49:26 -05001578 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1579 NLP_STE_UNUSED_NODE);
James Smartcff261f2013-12-17 20:29:47 -05001580 if (!new_ndlp) {
1581 if (active_rrqs_xri_bitmap)
1582 mempool_free(active_rrqs_xri_bitmap,
1583 phba->active_rrq_pool);
James Smarte47c9092008-02-08 18:49:26 -05001584 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001585 }
James Smart58da1ff2008-04-07 10:15:56 -04001586 keepDID = new_ndlp->nlp_DID;
James Smartcff261f2013-12-17 20:29:47 -05001587 if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap)
1588 memcpy(active_rrqs_xri_bitmap,
1589 new_ndlp->active_rrqs_xri_bitmap,
1590 phba->cfg_rrq_xri_bitmap_sz);
James Smart19ca7602010-11-20 23:11:55 -05001591 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001592 keepDID = new_ndlp->nlp_DID;
James Smartcff261f2013-12-17 20:29:47 -05001593 if (phba->sli_rev == LPFC_SLI_REV4 &&
1594 active_rrqs_xri_bitmap)
1595 memcpy(active_rrqs_xri_bitmap,
1596 new_ndlp->active_rrqs_xri_bitmap,
1597 phba->cfg_rrq_xri_bitmap_sz);
James Smart19ca7602010-11-20 23:11:55 -05001598 }
James Smart488d1462006-03-07 15:02:37 -05001599
James Smart2e0fef82007-06-17 19:56:36 -05001600 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001601 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001602 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001603 if (phba->sli_rev == LPFC_SLI_REV4)
James Smartcff261f2013-12-17 20:29:47 -05001604 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1605 ndlp->active_rrqs_xri_bitmap,
1606 phba->cfg_rrq_xri_bitmap_sz);
James Smart0ff10d42008-01-11 01:52:36 -05001607
James Smart953ceed2015-05-22 10:42:37 -04001608 spin_lock_irq(shost->host_lock);
James Smarte5abba42015-05-21 13:55:27 -04001609 keep_nlp_flag = new_ndlp->nlp_flag;
1610 new_ndlp->nlp_flag = ndlp->nlp_flag;
1611 ndlp->nlp_flag = keep_nlp_flag;
James Smart953ceed2015-05-22 10:42:37 -04001612 spin_unlock_irq(shost->host_lock);
James Smart0ff10d42008-01-11 01:52:36 -05001613
James Smart953ceed2015-05-22 10:42:37 -04001614 /* Set nlp_states accordingly */
1615 keep_nlp_state = new_ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001616 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001617
James Smart2e0fef82007-06-17 19:56:36 -05001618 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001619 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1620 /* The new_ndlp is replacing ndlp totally, so we need
1621 * to put ndlp on UNUSED list and try to free it.
1622 */
James Smart34f5ad82012-08-03 12:35:03 -04001623 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1624 "3179 PLOGI confirm NEW: %x %x\n",
1625 new_ndlp->nlp_DID, keepDID);
James Smart0ff10d42008-01-11 01:52:36 -05001626
1627 /* Fix up the rport accordingly */
1628 rport = ndlp->rport;
1629 if (rport) {
1630 rdata = rport->dd_data;
1631 if (rdata->pnode == ndlp) {
James Smart466e8402015-05-21 13:55:28 -04001632 /* break the link before dropping the ref */
James Smart0ff10d42008-01-11 01:52:36 -05001633 ndlp->rport = NULL;
James Smart466e8402015-05-21 13:55:28 -04001634 lpfc_nlp_put(ndlp);
James Smart0ff10d42008-01-11 01:52:36 -05001635 rdata->pnode = lpfc_nlp_get(new_ndlp);
1636 new_ndlp->rport = rport;
1637 }
1638 new_ndlp->nlp_type = ndlp->nlp_type;
1639 }
James Smart58da1ff2008-04-07 10:15:56 -04001640 /* We shall actually free the ndlp with both nlp_DID and
1641 * nlp_portname fields equals 0 to avoid any ndlp on the
1642 * nodelist never to be used.
1643 */
1644 if (ndlp->nlp_DID == 0) {
1645 spin_lock_irq(&phba->ndlp_lock);
1646 NLP_SET_FREE_REQ(ndlp);
1647 spin_unlock_irq(&phba->ndlp_lock);
1648 }
James Smart0ff10d42008-01-11 01:52:36 -05001649
James Smart58da1ff2008-04-07 10:15:56 -04001650 /* Two ndlps cannot have the same did on the nodelist */
1651 ndlp->nlp_DID = keepDID;
James Smartcff261f2013-12-17 20:29:47 -05001652 if (phba->sli_rev == LPFC_SLI_REV4 &&
1653 active_rrqs_xri_bitmap)
1654 memcpy(ndlp->active_rrqs_xri_bitmap,
1655 active_rrqs_xri_bitmap,
1656 phba->cfg_rrq_xri_bitmap_sz);
James Smarte5abba42015-05-21 13:55:27 -04001657
1658 if (!NLP_CHK_NODE_ACT(ndlp))
1659 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001660 }
James Smart92795652006-07-06 15:50:02 -04001661 else {
James Smart34f5ad82012-08-03 12:35:03 -04001662 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1663 "3180 PLOGI confirm SWAP: %x %x\n",
1664 new_ndlp->nlp_DID, keepDID);
1665
James Smart2e0fef82007-06-17 19:56:36 -05001666 lpfc_unreg_rpi(vport, ndlp);
James Smart34f5ad82012-08-03 12:35:03 -04001667
James Smart58da1ff2008-04-07 10:15:56 -04001668 /* Two ndlps cannot have the same did */
1669 ndlp->nlp_DID = keepDID;
James Smartcff261f2013-12-17 20:29:47 -05001670 if (phba->sli_rev == LPFC_SLI_REV4 &&
1671 active_rrqs_xri_bitmap)
1672 memcpy(ndlp->active_rrqs_xri_bitmap,
1673 active_rrqs_xri_bitmap,
1674 phba->cfg_rrq_xri_bitmap_sz);
James Smart34f5ad82012-08-03 12:35:03 -04001675
James Smart953ceed2015-05-22 10:42:37 -04001676 /* Since we are switching over to the new_ndlp,
1677 * reset the old ndlp state
James Smart34f5ad82012-08-03 12:35:03 -04001678 */
1679 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1680 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
James Smart953ceed2015-05-22 10:42:37 -04001681 keep_nlp_state = NLP_STE_NPR_NODE;
1682 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
James Smart34f5ad82012-08-03 12:35:03 -04001683
James Smart38b92ef2010-08-04 16:11:39 -04001684 /* Fix up the rport accordingly */
1685 rport = ndlp->rport;
1686 if (rport) {
1687 rdata = rport->dd_data;
1688 put_node = rdata->pnode != NULL;
1689 put_rport = ndlp->rport != NULL;
1690 rdata->pnode = NULL;
1691 ndlp->rport = NULL;
1692 if (put_node)
1693 lpfc_nlp_put(ndlp);
1694 if (put_rport)
1695 put_device(&rport->dev);
1696 }
James Smart92795652006-07-06 15:50:02 -04001697 }
James Smartcff261f2013-12-17 20:29:47 -05001698 if (phba->sli_rev == LPFC_SLI_REV4 &&
1699 active_rrqs_xri_bitmap)
1700 mempool_free(active_rrqs_xri_bitmap,
1701 phba->active_rrq_pool);
James Smart488d1462006-03-07 15:02:37 -05001702 return new_ndlp;
1703}
1704
James Smarte59058c2008-08-24 21:49:00 -04001705/**
James Smart3621a712009-04-06 18:47:14 -04001706 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001707 * @vport: pointer to a host virtual N_Port data structure.
1708 *
1709 * This routine checks whether more Registration State Change
1710 * Notifications (RSCNs) came in while the discovery state machine was in
1711 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1712 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1713 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1714 * handling the RSCNs.
1715 **/
James Smart87af33f2007-10-27 13:37:43 -04001716void
1717lpfc_end_rscn(struct lpfc_vport *vport)
1718{
1719 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1720
1721 if (vport->fc_flag & FC_RSCN_MODE) {
1722 /*
1723 * Check to see if more RSCNs came in while we were
1724 * processing this one.
1725 */
1726 if (vport->fc_rscn_id_cnt ||
1727 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1728 lpfc_els_handle_rscn(vport);
1729 else {
1730 spin_lock_irq(shost->host_lock);
1731 vport->fc_flag &= ~FC_RSCN_MODE;
1732 spin_unlock_irq(shost->host_lock);
1733 }
1734 }
1735}
1736
James Smarte59058c2008-08-24 21:49:00 -04001737/**
James Smart19ca7602010-11-20 23:11:55 -05001738 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1739 * @phba: pointer to lpfc hba data structure.
1740 * @cmdiocb: pointer to lpfc command iocb data structure.
1741 * @rspiocb: pointer to lpfc response iocb data structure.
1742 *
1743 * This routine will call the clear rrq function to free the rrq and
1744 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1745 * exist then the clear_rrq is still called because the rrq needs to
1746 * be freed.
1747 **/
1748
1749static void
1750lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1751 struct lpfc_iocbq *rspiocb)
1752{
1753 struct lpfc_vport *vport = cmdiocb->vport;
1754 IOCB_t *irsp;
1755 struct lpfc_nodelist *ndlp;
1756 struct lpfc_node_rrq *rrq;
1757
1758 /* we pass cmdiocb to state machine which needs rspiocb as well */
1759 rrq = cmdiocb->context_un.rrq;
1760 cmdiocb->context_un.rsp_iocb = rspiocb;
1761
1762 irsp = &rspiocb->iocb;
1763 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1764 "RRQ cmpl: status:x%x/x%x did:x%x",
1765 irsp->ulpStatus, irsp->un.ulpWord[4],
1766 irsp->un.elsreq64.remoteID);
1767
1768 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1769 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1770 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1771 "2882 RRQ completes to NPort x%x "
1772 "with no ndlp. Data: x%x x%x x%x\n",
1773 irsp->un.elsreq64.remoteID,
1774 irsp->ulpStatus, irsp->un.ulpWord[4],
1775 irsp->ulpIoTag);
1776 goto out;
1777 }
1778
1779 /* rrq completes to NPort <nlp_DID> */
1780 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1781 "2880 RRQ completes to NPort x%x "
1782 "Data: x%x x%x x%x x%x x%x\n",
1783 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1784 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1785
1786 if (irsp->ulpStatus) {
1787 /* Check for retry */
1788 /* RRQ failed Don't print the vport to vport rjts */
1789 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1790 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1791 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1792 (phba)->pport->cfg_log_verbose & LOG_ELS)
1793 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1794 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1795 ndlp->nlp_DID, irsp->ulpStatus,
1796 irsp->un.ulpWord[4]);
1797 }
1798out:
1799 if (rrq)
1800 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1801 lpfc_els_free_iocb(phba, cmdiocb);
1802 return;
1803}
1804/**
James Smart3621a712009-04-06 18:47:14 -04001805 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001806 * @phba: pointer to lpfc hba data structure.
1807 * @cmdiocb: pointer to lpfc command iocb data structure.
1808 * @rspiocb: pointer to lpfc response iocb data structure.
1809 *
1810 * This routine is the completion callback function for issuing the Port
1811 * Login (PLOGI) command. For PLOGI completion, there must be an active
1812 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001813 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001814 * ignored and command IOCB released. The PLOGI response IOCB status is
1815 * checked for error conditons. If there is error status reported, PLOGI
1816 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1817 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1818 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1819 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1820 * there are additional N_Port nodes with the vport that need to perform
1821 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1822 * PLOGIs.
1823 **/
dea31012005-04-17 16:05:31 -05001824static void
James Smart2e0fef82007-06-17 19:56:36 -05001825lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1826 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001827{
James Smart2e0fef82007-06-17 19:56:36 -05001828 struct lpfc_vport *vport = cmdiocb->vport;
1829 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001830 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001831 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001832 struct lpfc_dmabuf *prsp;
James Smarteb016562014-09-03 12:58:06 -04001833 int disc, rc;
dea31012005-04-17 16:05:31 -05001834
dea31012005-04-17 16:05:31 -05001835 /* we pass cmdiocb to state machine which needs rspiocb as well */
1836 cmdiocb->context_un.rsp_iocb = rspiocb;
1837
1838 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001839 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1840 "PLOGI cmpl: status:x%x/x%x did:x%x",
1841 irsp->ulpStatus, irsp->un.ulpWord[4],
1842 irsp->un.elsreq64.remoteID);
1843
James Smart2e0fef82007-06-17 19:56:36 -05001844 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001845 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001846 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1847 "0136 PLOGI completes to NPort x%x "
1848 "with no ndlp. Data: x%x x%x x%x\n",
1849 irsp->un.elsreq64.remoteID,
1850 irsp->ulpStatus, irsp->un.ulpWord[4],
1851 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001852 goto out;
James Smarted957682007-06-17 19:56:37 -05001853 }
dea31012005-04-17 16:05:31 -05001854
1855 /* Since ndlp can be freed in the disc state machine, note if this node
1856 * is being used during discovery.
1857 */
James Smart2e0fef82007-06-17 19:56:36 -05001858 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001859 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001860 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001861 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001862 rc = 0;
1863
1864 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001865 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1866 "0102 PLOGI completes to NPort x%x "
1867 "Data: x%x x%x x%x x%x x%x\n",
1868 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1869 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001870 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001871 if (lpfc_els_chk_latt(vport)) {
1872 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001873 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001874 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001875 goto out;
1876 }
1877
dea31012005-04-17 16:05:31 -05001878 if (irsp->ulpStatus) {
1879 /* Check for retry */
1880 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1881 /* ELS command is being retried */
1882 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001883 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001884 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001885 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001886 }
1887 goto out;
1888 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001889 /* PLOGI failed Don't print the vport to vport rjts */
1890 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1891 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1892 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1893 (phba)->pport->cfg_log_verbose & LOG_ELS)
1894 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001895 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1896 ndlp->nlp_DID, irsp->ulpStatus,
1897 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001898 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001899 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001900 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001901 else
James Smart2e0fef82007-06-17 19:56:36 -05001902 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001903 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001904 } else {
1905 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001906 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001907 cmdiocb->context2)->list.next,
1908 struct lpfc_dmabuf, list);
1909 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001910 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001911 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001912 }
1913
James Smart2e0fef82007-06-17 19:56:36 -05001914 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001915 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001916 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001917
James Smart2e0fef82007-06-17 19:56:36 -05001918 if (vport->num_disc_nodes == 0) {
1919 spin_lock_irq(shost->host_lock);
1920 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1921 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001922
James Smart2e0fef82007-06-17 19:56:36 -05001923 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001924 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001925 }
1926 }
1927
1928out:
1929 lpfc_els_free_iocb(phba, cmdiocb);
1930 return;
1931}
1932
James Smarte59058c2008-08-24 21:49:00 -04001933/**
James Smart3621a712009-04-06 18:47:14 -04001934 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001935 * @vport: pointer to a host virtual N_Port data structure.
1936 * @did: destination port identifier.
1937 * @retry: number of retries to the command IOCB.
1938 *
1939 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1940 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1941 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1942 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1943 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1944 *
1945 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1946 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1947 * will be stored into the context1 field of the IOCB for the completion
1948 * callback function to the PLOGI ELS command.
1949 *
1950 * Return code
1951 * 0 - Successfully issued a plogi for @vport
1952 * 1 - failed to issue a plogi for @vport
1953 **/
dea31012005-04-17 16:05:31 -05001954int
James Smart2e0fef82007-06-17 19:56:36 -05001955lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001956{
James Smart2e0fef82007-06-17 19:56:36 -05001957 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001958 struct serv_parm *sp;
1959 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001960 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001961 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001962 struct lpfc_sli *psli;
1963 uint8_t *pcmd;
1964 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001965 int ret;
dea31012005-04-17 16:05:31 -05001966
1967 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001968
James Smart98c9ea52007-10-27 13:37:33 -04001969 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001970 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1971 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001972
James Smarte47c9092008-02-08 18:49:26 -05001973 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001974 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001975 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001976 ELS_CMD_PLOGI);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001977 if (!elsiocb)
1978 return 1;
dea31012005-04-17 16:05:31 -05001979
1980 icmd = &elsiocb->iocb;
1981 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1982
1983 /* For PLOGI request, remainder of payload is service parameters */
1984 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001985 pcmd += sizeof(uint32_t);
1986 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001987 sp = (struct serv_parm *) pcmd;
1988
James Smart5ac6b302010-10-22 11:05:36 -04001989 /*
1990 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1991 * to device on remote loops work.
1992 */
1993 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1994 sp->cmn.altBbCredit = 1;
1995
dea31012005-04-17 16:05:31 -05001996 if (sp->cmn.fcphLow < FC_PH_4_3)
1997 sp->cmn.fcphLow = FC_PH_4_3;
1998
1999 if (sp->cmn.fcphHigh < FC_PH3)
2000 sp->cmn.fcphHigh = FC_PH3;
2001
James Smart858c9f62007-06-17 19:56:39 -05002002 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2003 "Issue PLOGI: did:x%x",
2004 did, 0, 0);
2005
dea31012005-04-17 16:05:31 -05002006 phba->fc_stat.elsXmitPLOGI++;
2007 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04002008 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002009
2010 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002011 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002012 return 1;
dea31012005-04-17 16:05:31 -05002013 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002014 return 0;
dea31012005-04-17 16:05:31 -05002015}
2016
James Smarte59058c2008-08-24 21:49:00 -04002017/**
James Smart3621a712009-04-06 18:47:14 -04002018 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04002019 * @phba: pointer to lpfc hba data structure.
2020 * @cmdiocb: pointer to lpfc command iocb data structure.
2021 * @rspiocb: pointer to lpfc response iocb data structure.
2022 *
2023 * This routine is the completion callback function for a Process Login
2024 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2025 * status. If there is error status reported, PRLI retry shall be attempted
2026 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2027 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2028 * ndlp to mark the PRLI completion.
2029 **/
dea31012005-04-17 16:05:31 -05002030static void
James Smart2e0fef82007-06-17 19:56:36 -05002031lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2032 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002033{
James Smart2e0fef82007-06-17 19:56:36 -05002034 struct lpfc_vport *vport = cmdiocb->vport;
2035 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002036 IOCB_t *irsp;
2037 struct lpfc_sli *psli;
2038 struct lpfc_nodelist *ndlp;
2039
2040 psli = &phba->sli;
2041 /* we pass cmdiocb to state machine which needs rspiocb as well */
2042 cmdiocb->context_un.rsp_iocb = rspiocb;
2043
2044 irsp = &(rspiocb->iocb);
2045 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05002046 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002047 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002048 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002049
James Smart858c9f62007-06-17 19:56:39 -05002050 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2051 "PRLI cmpl: status:x%x/x%x did:x%x",
2052 irsp->ulpStatus, irsp->un.ulpWord[4],
2053 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002054 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002055 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2056 "0103 PRLI completes to NPort x%x "
2057 "Data: x%x x%x x%x x%x\n",
2058 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2059 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002060
James Smart2e0fef82007-06-17 19:56:36 -05002061 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05002062 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002063 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002064 goto out;
2065
2066 if (irsp->ulpStatus) {
2067 /* Check for retry */
2068 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2069 /* ELS command is being retried */
2070 goto out;
2071 }
2072 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05002073 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2074 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
2075 ndlp->nlp_DID, irsp->ulpStatus,
2076 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002077 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002078 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002079 goto out;
James Smarte47c9092008-02-08 18:49:26 -05002080 else
James Smart2e0fef82007-06-17 19:56:36 -05002081 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002082 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05002083 } else
dea31012005-04-17 16:05:31 -05002084 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002085 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002086 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05002087out:
2088 lpfc_els_free_iocb(phba, cmdiocb);
2089 return;
2090}
2091
James Smarte59058c2008-08-24 21:49:00 -04002092/**
James Smart3621a712009-04-06 18:47:14 -04002093 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04002094 * @vport: pointer to a host virtual N_Port data structure.
2095 * @ndlp: pointer to a node-list data structure.
2096 * @retry: number of retries to the command IOCB.
2097 *
2098 * This routine issues a Process Login (PRLI) ELS command for the
2099 * @vport. The PRLI service parameters are set up in the payload of the
2100 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2101 * is put to the IOCB completion callback func field before invoking the
2102 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2103 *
2104 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2105 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2106 * will be stored into the context1 field of the IOCB for the completion
2107 * callback function to the PRLI ELS command.
2108 *
2109 * Return code
2110 * 0 - successfully issued prli iocb command for @vport
2111 * 1 - failed to issue prli iocb command for @vport
2112 **/
dea31012005-04-17 16:05:31 -05002113int
James Smart2e0fef82007-06-17 19:56:36 -05002114lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002115 uint8_t retry)
2116{
James Smart2e0fef82007-06-17 19:56:36 -05002117 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2118 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002119 PRLI *npr;
2120 IOCB_t *icmd;
2121 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002122 uint8_t *pcmd;
2123 uint16_t cmdsize;
2124
James Smart92d7f7b2007-06-17 19:56:38 -05002125 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05002126 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2127 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05002128 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002129 return 1;
dea31012005-04-17 16:05:31 -05002130
2131 icmd = &elsiocb->iocb;
2132 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2133
2134 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05002135 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05002136 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05002137 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002138
2139 /* For PRLI, remainder of payload is PRLI parameter page */
2140 npr = (PRLI *) pcmd;
2141 /*
2142 * If our firmware version is 3.20 or later,
2143 * set the following bits for FC-TAPE support.
2144 */
2145 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2146 npr->ConfmComplAllowed = 1;
2147 npr->Retry = 1;
2148 npr->TaskRetryIdReq = 1;
2149 }
2150 npr->estabImagePair = 1;
2151 npr->readXferRdyDis = 1;
James Smart3cb01c52013-07-15 18:35:04 -04002152 if (vport->cfg_first_burst_size)
2153 npr->writeXferRdyDis = 1;
dea31012005-04-17 16:05:31 -05002154
2155 /* For FCP support */
2156 npr->prliType = PRLI_FCP_TYPE;
2157 npr->initiatorFunc = 1;
2158
James Smart858c9f62007-06-17 19:56:39 -05002159 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2160 "Issue PRLI: did:x%x",
2161 ndlp->nlp_DID, 0, 0);
2162
dea31012005-04-17 16:05:31 -05002163 phba->fc_stat.elsXmitPRLI++;
2164 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05002165 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002166 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002167 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002168 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2169 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002170 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002171 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002172 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002173 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002174 return 1;
dea31012005-04-17 16:05:31 -05002175 }
James Smart2e0fef82007-06-17 19:56:36 -05002176 vport->fc_prli_sent++;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002177 return 0;
dea31012005-04-17 16:05:31 -05002178}
2179
James Smarte59058c2008-08-24 21:49:00 -04002180/**
James Smart3621a712009-04-06 18:47:14 -04002181 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04002182 * @vport: pointer to a host virtual N_Port data structure.
2183 *
2184 * This routine performs Registration State Change Notification (RSCN)
2185 * discovery for a @vport. If the @vport's node port recovery count is not
2186 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2187 * the nodes that need recovery. If none of the PLOGI were needed through
2188 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2189 * invoked to check and handle possible more RSCN came in during the period
2190 * of processing the current ones.
2191 **/
2192static void
2193lpfc_rscn_disc(struct lpfc_vport *vport)
2194{
2195 lpfc_can_disctmo(vport);
2196
2197 /* RSCN discovery */
2198 /* go thru NPR nodes and issue ELS PLOGIs */
2199 if (vport->fc_npr_cnt)
2200 if (lpfc_els_disc_plogi(vport))
2201 return;
2202
2203 lpfc_end_rscn(vport);
2204}
2205
2206/**
James Smart3621a712009-04-06 18:47:14 -04002207 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002208 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2209 *
2210 * This function is called when the final ADISC is completed during discovery.
2211 * This function handles clearing link attention or issuing reg_vpi depending
2212 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2213 * discovery.
2214 * This function is called with no locks held.
2215 **/
2216static void
2217lpfc_adisc_done(struct lpfc_vport *vport)
2218{
2219 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2220 struct lpfc_hba *phba = vport->phba;
2221
2222 /*
2223 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2224 * and continue discovery.
2225 */
2226 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002227 !(vport->fc_flag & FC_RSCN_MODE) &&
2228 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smartd454c912014-12-30 12:08:58 -05002229 /* The ADISCs are complete. Doesn't matter if they
2230 * succeeded or failed because the ADISC completion
2231 * routine guarantees to call the state machine and
2232 * the RPI is either unregistered (failed ADISC response)
2233 * or the RPI is still valid and the node is marked
2234 * mapped for a target. The exchanges should be in the
2235 * correct state. This code is specific to SLI3.
2236 */
2237 lpfc_issue_clear_la(phba, vport);
James Smart90160e02008-08-24 21:49:45 -04002238 lpfc_issue_reg_vpi(phba, vport);
2239 return;
2240 }
2241 /*
2242 * For SLI2, we need to set port_state to READY
2243 * and continue discovery.
2244 */
2245 if (vport->port_state < LPFC_VPORT_READY) {
2246 /* If we get here, there is nothing to ADISC */
James Smart85c0f172015-04-07 15:07:12 -04002247 lpfc_issue_clear_la(phba, vport);
James Smart90160e02008-08-24 21:49:45 -04002248 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2249 vport->num_disc_nodes = 0;
2250 /* go thru NPR list, issue ELS PLOGIs */
2251 if (vport->fc_npr_cnt)
2252 lpfc_els_disc_plogi(vport);
2253 if (!vport->num_disc_nodes) {
2254 spin_lock_irq(shost->host_lock);
2255 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2256 spin_unlock_irq(shost->host_lock);
2257 lpfc_can_disctmo(vport);
2258 lpfc_end_rscn(vport);
2259 }
2260 }
2261 vport->port_state = LPFC_VPORT_READY;
2262 } else
2263 lpfc_rscn_disc(vport);
2264}
2265
2266/**
James Smart3621a712009-04-06 18:47:14 -04002267 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002268 * @vport: pointer to a host virtual N_Port data structure.
2269 *
2270 * This routine determines whether there are more ndlps on a @vport
2271 * node list need to have Address Discover (ADISC) issued. If so, it will
2272 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2273 * remaining nodes which need to have ADISC sent.
2274 **/
James Smart0ff10d42008-01-11 01:52:36 -05002275void
James Smart2e0fef82007-06-17 19:56:36 -05002276lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002277{
James Smart2e0fef82007-06-17 19:56:36 -05002278 if (vport->num_disc_nodes)
2279 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002280 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002281 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2282 "0210 Continue discovery with %d ADISCs to go "
2283 "Data: x%x x%x x%x\n",
2284 vport->num_disc_nodes, vport->fc_adisc_cnt,
2285 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002286 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002287 if (vport->fc_flag & FC_NLP_MORE) {
2288 lpfc_set_disctmo(vport);
2289 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smarteb016562014-09-03 12:58:06 -04002290 lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002291 }
James Smart90160e02008-08-24 21:49:45 -04002292 if (!vport->num_disc_nodes)
2293 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002294 return;
2295}
2296
James Smarte59058c2008-08-24 21:49:00 -04002297/**
James Smart3621a712009-04-06 18:47:14 -04002298 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002299 * @phba: pointer to lpfc hba data structure.
2300 * @cmdiocb: pointer to lpfc command iocb data structure.
2301 * @rspiocb: pointer to lpfc response iocb data structure.
2302 *
2303 * This routine is the completion function for issuing the Address Discover
2304 * (ADISC) command. It first checks to see whether link went down during
2305 * the discovery process. If so, the node will be marked as node port
2306 * recovery for issuing discover IOCB by the link attention handler and
2307 * exit. Otherwise, the response status is checked. If error was reported
2308 * in the response status, the ADISC command shall be retried by invoking
2309 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2310 * the response status, the state machine is invoked to set transition
2311 * with respect to NLP_EVT_CMPL_ADISC event.
2312 **/
dea31012005-04-17 16:05:31 -05002313static void
James Smart2e0fef82007-06-17 19:56:36 -05002314lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2315 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002316{
James Smart2e0fef82007-06-17 19:56:36 -05002317 struct lpfc_vport *vport = cmdiocb->vport;
2318 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002319 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002320 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002321 int disc;
dea31012005-04-17 16:05:31 -05002322
2323 /* we pass cmdiocb to state machine which needs rspiocb as well */
2324 cmdiocb->context_un.rsp_iocb = rspiocb;
2325
2326 irsp = &(rspiocb->iocb);
2327 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002328
James Smart858c9f62007-06-17 19:56:39 -05002329 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2330 "ADISC cmpl: status:x%x/x%x did:x%x",
2331 irsp->ulpStatus, irsp->un.ulpWord[4],
2332 ndlp->nlp_DID);
2333
dea31012005-04-17 16:05:31 -05002334 /* Since ndlp can be freed in the disc state machine, note if this node
2335 * is being used during discovery.
2336 */
James Smart2e0fef82007-06-17 19:56:36 -05002337 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002338 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002339 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002340 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002341 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002342 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2343 "0104 ADISC completes to NPort x%x "
2344 "Data: x%x x%x x%x x%x x%x\n",
2345 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2346 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002347 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002348 if (lpfc_els_chk_latt(vport)) {
2349 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002350 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002351 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002352 goto out;
2353 }
2354
2355 if (irsp->ulpStatus) {
2356 /* Check for retry */
2357 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2358 /* ELS command is being retried */
2359 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002360 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002361 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002362 spin_unlock_irq(shost->host_lock);
2363 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002364 }
2365 goto out;
2366 }
2367 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002368 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2369 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2370 ndlp->nlp_DID, irsp->ulpStatus,
2371 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002372 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002373 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002374 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002375 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002376 } else
dea31012005-04-17 16:05:31 -05002377 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002378 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002379 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002380
James Smart90160e02008-08-24 21:49:45 -04002381 /* Check to see if there are more ADISCs to be sent */
2382 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002383 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002384out:
2385 lpfc_els_free_iocb(phba, cmdiocb);
2386 return;
2387}
2388
James Smarte59058c2008-08-24 21:49:00 -04002389/**
James Smart3621a712009-04-06 18:47:14 -04002390 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002391 * @vport: pointer to a virtual N_Port data structure.
2392 * @ndlp: pointer to a node-list data structure.
2393 * @retry: number of retries to the command IOCB.
2394 *
2395 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2396 * @vport. It prepares the payload of the ADISC ELS command, updates the
2397 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2398 * to issue the ADISC ELS command.
2399 *
2400 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2401 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2402 * will be stored into the context1 field of the IOCB for the completion
2403 * callback function to the ADISC ELS command.
2404 *
2405 * Return code
2406 * 0 - successfully issued adisc
2407 * 1 - failed to issue adisc
2408 **/
dea31012005-04-17 16:05:31 -05002409int
James Smart2e0fef82007-06-17 19:56:36 -05002410lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002411 uint8_t retry)
2412{
James Smart2e0fef82007-06-17 19:56:36 -05002413 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2414 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002415 ADISC *ap;
2416 IOCB_t *icmd;
2417 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002418 uint8_t *pcmd;
2419 uint16_t cmdsize;
2420
James Smart92d7f7b2007-06-17 19:56:38 -05002421 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002422 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2423 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002424 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002425 return 1;
dea31012005-04-17 16:05:31 -05002426
2427 icmd = &elsiocb->iocb;
2428 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2429
2430 /* For ADISC request, remainder of payload is service parameters */
2431 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002432 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002433
2434 /* Fill in ADISC payload */
2435 ap = (ADISC *) pcmd;
2436 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002437 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2438 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002439 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002440
James Smart858c9f62007-06-17 19:56:39 -05002441 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2442 "Issue ADISC: did:x%x",
2443 ndlp->nlp_DID, 0, 0);
2444
dea31012005-04-17 16:05:31 -05002445 phba->fc_stat.elsXmitADISC++;
2446 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002447 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002448 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002449 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002450 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2451 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002452 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002453 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002454 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002455 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002456 return 1;
dea31012005-04-17 16:05:31 -05002457 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002458 return 0;
dea31012005-04-17 16:05:31 -05002459}
2460
James Smarte59058c2008-08-24 21:49:00 -04002461/**
James Smart3621a712009-04-06 18:47:14 -04002462 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002463 * @phba: pointer to lpfc hba data structure.
2464 * @cmdiocb: pointer to lpfc command iocb data structure.
2465 * @rspiocb: pointer to lpfc response iocb data structure.
2466 *
2467 * This routine is the completion function for issuing the ELS Logout (LOGO)
2468 * command. If no error status was reported from the LOGO response, the
2469 * state machine of the associated ndlp shall be invoked for transition with
2470 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2471 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2472 **/
dea31012005-04-17 16:05:31 -05002473static void
James Smart2e0fef82007-06-17 19:56:36 -05002474lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2475 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002476{
James Smart2e0fef82007-06-17 19:56:36 -05002477 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2478 struct lpfc_vport *vport = ndlp->vport;
2479 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002480 IOCB_t *irsp;
2481 struct lpfc_sli *psli;
James Smart92494142011-02-16 12:39:44 -05002482 struct lpfcMboxq *mbox;
James Smart086a3452012-08-14 14:25:21 -04002483 unsigned long flags;
2484 uint32_t skip_recovery = 0;
dea31012005-04-17 16:05:31 -05002485
2486 psli = &phba->sli;
2487 /* we pass cmdiocb to state machine which needs rspiocb as well */
2488 cmdiocb->context_un.rsp_iocb = rspiocb;
2489
2490 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002491 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002492 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002493 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002494
James Smart858c9f62007-06-17 19:56:39 -05002495 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2496 "LOGO cmpl: status:x%x/x%x did:x%x",
2497 irsp->ulpStatus, irsp->un.ulpWord[4],
2498 ndlp->nlp_DID);
James Smart086a3452012-08-14 14:25:21 -04002499
dea31012005-04-17 16:05:31 -05002500 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002501 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2502 "0105 LOGO completes to NPort x%x "
2503 "Data: x%x x%x x%x x%x\n",
2504 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2505 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002506
James Smart086a3452012-08-14 14:25:21 -04002507 if (lpfc_els_chk_latt(vport)) {
2508 skip_recovery = 1;
2509 goto out;
2510 }
2511
2512 /* Check to see if link went down during discovery */
James Smart92d7f7b2007-06-17 19:56:38 -05002513 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2514 /* NLP_EVT_DEVICE_RM should unregister the RPI
2515 * which should abort all outstanding IOs.
2516 */
2517 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2518 NLP_EVT_DEVICE_RM);
James Smart086a3452012-08-14 14:25:21 -04002519 skip_recovery = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002520 goto out;
2521 }
2522
dea31012005-04-17 16:05:31 -05002523 if (irsp->ulpStatus) {
2524 /* Check for retry */
James Smart086a3452012-08-14 14:25:21 -04002525 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
dea31012005-04-17 16:05:31 -05002526 /* ELS command is being retried */
James Smart086a3452012-08-14 14:25:21 -04002527 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002528 goto out;
James Smart086a3452012-08-14 14:25:21 -04002529 }
dea31012005-04-17 16:05:31 -05002530 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002531 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2532 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2533 ndlp->nlp_DID, irsp->ulpStatus,
2534 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002535 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart086a3452012-08-14 14:25:21 -04002536 if (lpfc_error_lost_link(irsp)) {
2537 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002538 goto out;
James Smart086a3452012-08-14 14:25:21 -04002539 }
2540 }
2541
2542 /* Call state machine. This will unregister the rpi if needed. */
2543 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2544
dea31012005-04-17 16:05:31 -05002545out:
2546 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92494142011-02-16 12:39:44 -05002547 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2548 if ((vport->fc_flag & FC_PT2PT) &&
2549 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2550 phba->pport->fc_myDID = 0;
2551 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2552 if (mbox) {
2553 lpfc_config_link(phba, mbox);
2554 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2555 mbox->vport = vport;
2556 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2557 MBX_NOT_FINISHED) {
2558 mempool_free(mbox, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04002559 skip_recovery = 1;
James Smart92494142011-02-16 12:39:44 -05002560 }
2561 }
2562 }
James Smart086a3452012-08-14 14:25:21 -04002563
2564 /*
2565 * If the node is a target, the handling attempts to recover the port.
2566 * For any other port type, the rpi is unregistered as an implicit
2567 * LOGO.
2568 */
2569 if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) {
2570 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2571 spin_lock_irqsave(shost->host_lock, flags);
2572 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2573 spin_unlock_irqrestore(shost->host_lock, flags);
2574
2575 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2576 "3187 LOGO completes to NPort x%x: Start "
2577 "Recovery Data: x%x x%x x%x x%x\n",
2578 ndlp->nlp_DID, irsp->ulpStatus,
2579 irsp->un.ulpWord[4], irsp->ulpTimeout,
2580 vport->num_disc_nodes);
2581 lpfc_disc_start(vport);
2582 }
dea31012005-04-17 16:05:31 -05002583 return;
2584}
2585
James Smarte59058c2008-08-24 21:49:00 -04002586/**
James Smart3621a712009-04-06 18:47:14 -04002587 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002588 * @vport: pointer to a virtual N_Port data structure.
2589 * @ndlp: pointer to a node-list data structure.
2590 * @retry: number of retries to the command IOCB.
2591 *
2592 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2593 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2594 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2595 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2596 *
2597 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2598 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2599 * will be stored into the context1 field of the IOCB for the completion
2600 * callback function to the LOGO ELS command.
2601 *
2602 * Return code
2603 * 0 - successfully issued logo
2604 * 1 - failed to issue logo
2605 **/
dea31012005-04-17 16:05:31 -05002606int
James Smart2e0fef82007-06-17 19:56:36 -05002607lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002608 uint8_t retry)
2609{
James Smart2e0fef82007-06-17 19:56:36 -05002610 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2611 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002612 IOCB_t *icmd;
2613 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002614 uint8_t *pcmd;
2615 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002616 int rc;
dea31012005-04-17 16:05:31 -05002617
James Smart98c9ea52007-10-27 13:37:33 -04002618 spin_lock_irq(shost->host_lock);
2619 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2620 spin_unlock_irq(shost->host_lock);
2621 return 0;
2622 }
2623 spin_unlock_irq(shost->host_lock);
2624
James Smart92d7f7b2007-06-17 19:56:38 -05002625 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002626 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2627 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002628 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002629 return 1;
dea31012005-04-17 16:05:31 -05002630
2631 icmd = &elsiocb->iocb;
2632 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2633 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002634 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002635
2636 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002637 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002638 pcmd += sizeof(uint32_t);
2639 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002640
James Smart858c9f62007-06-17 19:56:39 -05002641 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2642 "Issue LOGO: did:x%x",
2643 ndlp->nlp_DID, 0, 0);
2644
James Smart086a3452012-08-14 14:25:21 -04002645 /*
2646 * If we are issuing a LOGO, we may try to recover the remote NPort
2647 * by issuing a PLOGI later. Even though we issue ELS cmds by the
2648 * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
2649 * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
2650 * for that ELS cmd. To avoid this situation, lets get rid of the
2651 * RPI right now, before any ELS cmds are sent.
2652 */
2653 spin_lock_irq(shost->host_lock);
2654 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
2655 spin_unlock_irq(shost->host_lock);
2656 if (lpfc_unreg_rpi(vport, ndlp)) {
2657 lpfc_els_free_iocb(phba, elsiocb);
2658 return 0;
2659 }
2660
dea31012005-04-17 16:05:31 -05002661 phba->fc_stat.elsXmitLOGO++;
2662 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002663 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002664 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart086a3452012-08-14 14:25:21 -04002665 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
James Smart2e0fef82007-06-17 19:56:36 -05002666 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002667 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002668
2669 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002670 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002671 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002672 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002673 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002674 return 1;
dea31012005-04-17 16:05:31 -05002675 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002676 return 0;
dea31012005-04-17 16:05:31 -05002677}
2678
James Smarte59058c2008-08-24 21:49:00 -04002679/**
James Smart3621a712009-04-06 18:47:14 -04002680 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002681 * @phba: pointer to lpfc hba data structure.
2682 * @cmdiocb: pointer to lpfc command iocb data structure.
2683 * @rspiocb: pointer to lpfc response iocb data structure.
2684 *
2685 * This routine is a generic completion callback function for ELS commands.
2686 * Specifically, it is the callback function which does not need to perform
2687 * any command specific operations. It is currently used by the ELS command
2688 * issuing routines for the ELS State Change Request (SCR),
2689 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2690 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2691 * certain debug loggings, this callback function simply invokes the
2692 * lpfc_els_chk_latt() routine to check whether link went down during the
2693 * discovery process.
2694 **/
dea31012005-04-17 16:05:31 -05002695static void
James Smart2e0fef82007-06-17 19:56:36 -05002696lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2697 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002698{
James Smart2e0fef82007-06-17 19:56:36 -05002699 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002700 IOCB_t *irsp;
2701
2702 irsp = &rspiocb->iocb;
2703
James Smart858c9f62007-06-17 19:56:39 -05002704 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2705 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2706 irsp->ulpStatus, irsp->un.ulpWord[4],
2707 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002708 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002709 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2710 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2711 irsp->ulpIoTag, irsp->ulpStatus,
2712 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002713 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002714 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002715 lpfc_els_free_iocb(phba, cmdiocb);
2716 return;
2717}
2718
James Smarte59058c2008-08-24 21:49:00 -04002719/**
James Smart3621a712009-04-06 18:47:14 -04002720 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002721 * @vport: pointer to a host virtual N_Port data structure.
2722 * @nportid: N_Port identifier to the remote node.
2723 * @retry: number of retries to the command IOCB.
2724 *
2725 * This routine issues a State Change Request (SCR) to a fabric node
2726 * on a @vport. The remote node @nportid is passed into the function. It
2727 * first search the @vport node list to find the matching ndlp. If no such
2728 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2729 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2730 * routine is invoked to send the SCR IOCB.
2731 *
2732 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2733 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2734 * will be stored into the context1 field of the IOCB for the completion
2735 * callback function to the SCR ELS command.
2736 *
2737 * Return code
2738 * 0 - Successfully issued scr command
2739 * 1 - Failed to issue scr command
2740 **/
dea31012005-04-17 16:05:31 -05002741int
James Smart2e0fef82007-06-17 19:56:36 -05002742lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002743{
James Smart2e0fef82007-06-17 19:56:36 -05002744 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002745 IOCB_t *icmd;
2746 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002747 struct lpfc_sli *psli;
2748 uint8_t *pcmd;
2749 uint16_t cmdsize;
2750 struct lpfc_nodelist *ndlp;
2751
2752 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002753 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002754
James Smarte47c9092008-02-08 18:49:26 -05002755 ndlp = lpfc_findnode_did(vport, nportid);
2756 if (!ndlp) {
2757 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2758 if (!ndlp)
2759 return 1;
2760 lpfc_nlp_init(vport, ndlp, nportid);
2761 lpfc_enqueue_node(vport, ndlp);
2762 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2763 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2764 if (!ndlp)
2765 return 1;
2766 }
dea31012005-04-17 16:05:31 -05002767
James Smart2e0fef82007-06-17 19:56:36 -05002768 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2769 ndlp->nlp_DID, ELS_CMD_SCR);
2770
James Smart488d1462006-03-07 15:02:37 -05002771 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002772 /* This will trigger the release of the node just
2773 * allocated
2774 */
James Smart329f9bc2007-04-25 09:53:01 -04002775 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002776 return 1;
dea31012005-04-17 16:05:31 -05002777 }
2778
2779 icmd = &elsiocb->iocb;
2780 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2781
2782 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002783 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002784
2785 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002786 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002787 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2788
James Smart858c9f62007-06-17 19:56:39 -05002789 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2790 "Issue SCR: did:x%x",
2791 ndlp->nlp_DID, 0, 0);
2792
dea31012005-04-17 16:05:31 -05002793 phba->fc_stat.elsXmitSCR++;
2794 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002795 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2796 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002797 /* The additional lpfc_nlp_put will cause the following
2798 * lpfc_els_free_iocb routine to trigger the rlease of
2799 * the node.
2800 */
James Smart329f9bc2007-04-25 09:53:01 -04002801 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002802 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002803 return 1;
dea31012005-04-17 16:05:31 -05002804 }
James Smartfa4066b2008-01-11 01:53:27 -05002805 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2806 * trigger the release of node.
2807 */
James Smartcff261f2013-12-17 20:29:47 -05002808
James Smart329f9bc2007-04-25 09:53:01 -04002809 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002810 return 0;
dea31012005-04-17 16:05:31 -05002811}
2812
James Smarte59058c2008-08-24 21:49:00 -04002813/**
James Smart3621a712009-04-06 18:47:14 -04002814 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002815 * @vport: pointer to a host virtual N_Port data structure.
2816 * @nportid: N_Port identifier to the remote node.
2817 * @retry: number of retries to the command IOCB.
2818 *
2819 * This routine issues a Fibre Channel Address Resolution Response
2820 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2821 * is passed into the function. It first search the @vport node list to find
2822 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2823 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2824 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2825 *
2826 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2827 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2828 * will be stored into the context1 field of the IOCB for the completion
2829 * callback function to the PARPR ELS command.
2830 *
2831 * Return code
2832 * 0 - Successfully issued farpr command
2833 * 1 - Failed to issue farpr command
2834 **/
dea31012005-04-17 16:05:31 -05002835static int
James Smart2e0fef82007-06-17 19:56:36 -05002836lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002837{
James Smart2e0fef82007-06-17 19:56:36 -05002838 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002839 IOCB_t *icmd;
2840 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002841 struct lpfc_sli *psli;
2842 FARP *fp;
2843 uint8_t *pcmd;
2844 uint32_t *lp;
2845 uint16_t cmdsize;
2846 struct lpfc_nodelist *ondlp;
2847 struct lpfc_nodelist *ndlp;
2848
2849 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002850 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002851
James Smarte47c9092008-02-08 18:49:26 -05002852 ndlp = lpfc_findnode_did(vport, nportid);
2853 if (!ndlp) {
2854 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2855 if (!ndlp)
2856 return 1;
2857 lpfc_nlp_init(vport, ndlp, nportid);
2858 lpfc_enqueue_node(vport, ndlp);
2859 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2860 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2861 if (!ndlp)
2862 return 1;
2863 }
James Smart2e0fef82007-06-17 19:56:36 -05002864
2865 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2866 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002867 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002868 /* This will trigger the release of the node just
2869 * allocated
2870 */
James Smart329f9bc2007-04-25 09:53:01 -04002871 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002872 return 1;
dea31012005-04-17 16:05:31 -05002873 }
2874
2875 icmd = &elsiocb->iocb;
2876 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2877
2878 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002879 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002880
2881 /* Fill in FARPR payload */
2882 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002883 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002884 lp = (uint32_t *) pcmd;
2885 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002886 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002887 fp->Rflags = 0;
2888 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2889
James Smart92d7f7b2007-06-17 19:56:38 -05002890 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2891 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002892 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002893 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002894 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002895 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002896 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002897 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002898 }
2899
James Smart858c9f62007-06-17 19:56:39 -05002900 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2901 "Issue FARPR: did:x%x",
2902 ndlp->nlp_DID, 0, 0);
2903
dea31012005-04-17 16:05:31 -05002904 phba->fc_stat.elsXmitFARPR++;
2905 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002906 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2907 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002908 /* The additional lpfc_nlp_put will cause the following
2909 * lpfc_els_free_iocb routine to trigger the release of
2910 * the node.
2911 */
James Smart329f9bc2007-04-25 09:53:01 -04002912 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002913 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002914 return 1;
dea31012005-04-17 16:05:31 -05002915 }
James Smartfa4066b2008-01-11 01:53:27 -05002916 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2917 * trigger the release of the node.
2918 */
James Smart329f9bc2007-04-25 09:53:01 -04002919 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002920 return 0;
dea31012005-04-17 16:05:31 -05002921}
2922
James Smarte59058c2008-08-24 21:49:00 -04002923/**
James Smart3621a712009-04-06 18:47:14 -04002924 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002925 * @vport: pointer to a host virtual N_Port data structure.
2926 * @nlp: pointer to a node-list data structure.
2927 *
2928 * This routine cancels the timer with a delayed IOCB-command retry for
2929 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2930 * removes the ELS retry event if it presents. In addition, if the
2931 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2932 * commands are sent for the @vport's nodes that require issuing discovery
2933 * ADISC.
2934 **/
dea31012005-04-17 16:05:31 -05002935void
James Smart2e0fef82007-06-17 19:56:36 -05002936lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002937{
James Smart2e0fef82007-06-17 19:56:36 -05002938 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002939 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002940
James Smart0d2b6b82008-06-14 22:52:47 -04002941 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2942 return;
James Smart2e0fef82007-06-17 19:56:36 -05002943 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002944 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002945 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002946 del_timer_sync(&nlp->nlp_delayfunc);
2947 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002948 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002949 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002950 /* Decrement nlp reference count held for the delayed retry */
2951 evtp = &nlp->els_retry_evt;
2952 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2953 }
James Smartfdcebe22006-03-07 15:04:01 -05002954 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002955 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002956 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002957 spin_unlock_irq(shost->host_lock);
2958 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002959 if (vport->port_state < LPFC_VPORT_READY) {
2960 /* Check if there are more ADISCs to be sent */
2961 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002962 } else {
2963 /* Check if there are more PLOGIs to be sent */
2964 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002965 if (vport->num_disc_nodes == 0) {
2966 spin_lock_irq(shost->host_lock);
2967 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2968 spin_unlock_irq(shost->host_lock);
2969 lpfc_can_disctmo(vport);
2970 lpfc_end_rscn(vport);
2971 }
James Smartfdcebe22006-03-07 15:04:01 -05002972 }
2973 }
2974 }
2975 return;
2976}
2977
James Smarte59058c2008-08-24 21:49:00 -04002978/**
James Smart3621a712009-04-06 18:47:14 -04002979 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002980 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2981 *
2982 * This routine is invoked by the ndlp delayed-function timer to check
2983 * whether there is any pending ELS retry event(s) with the node. If not, it
2984 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2985 * adds the delayed events to the HBA work list and invokes the
2986 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2987 * event. Note that lpfc_nlp_get() is called before posting the event to
2988 * the work list to hold reference count of ndlp so that it guarantees the
2989 * reference to ndlp will still be available when the worker thread gets
2990 * to the event associated with the ndlp.
2991 **/
James Smartfdcebe22006-03-07 15:04:01 -05002992void
dea31012005-04-17 16:05:31 -05002993lpfc_els_retry_delay(unsigned long ptr)
2994{
James Smart2e0fef82007-06-17 19:56:36 -05002995 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2996 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002997 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002998 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002999 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05003000
James Smart92d7f7b2007-06-17 19:56:38 -05003001 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003002 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003003 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003004 return;
3005 }
3006
James Smartfa4066b2008-01-11 01:53:27 -05003007 /* We need to hold the node by incrementing the reference
3008 * count until the queued work is done
3009 */
3010 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04003011 if (evtp->evt_arg1) {
3012 evtp->evt = LPFC_EVT_ELS_RETRY;
3013 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05003014 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04003015 }
James Smart92d7f7b2007-06-17 19:56:38 -05003016 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003017 return;
3018}
3019
James Smarte59058c2008-08-24 21:49:00 -04003020/**
James Smart3621a712009-04-06 18:47:14 -04003021 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04003022 * @ndlp: pointer to a node-list data structure.
3023 *
3024 * This routine is the worker-thread handler for processing the @ndlp delayed
3025 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3026 * the last ELS command from the associated ndlp and invokes the proper ELS
3027 * function according to the delayed ELS command to retry the command.
3028 **/
dea31012005-04-17 16:05:31 -05003029void
3030lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3031{
James Smart2e0fef82007-06-17 19:56:36 -05003032 struct lpfc_vport *vport = ndlp->vport;
3033 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarteb016562014-09-03 12:58:06 -04003034 uint32_t cmd, retry;
dea31012005-04-17 16:05:31 -05003035
James Smart2e0fef82007-06-17 19:56:36 -05003036 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003037 cmd = ndlp->nlp_last_elscmd;
3038 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05003039
3040 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05003041 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003042 return;
3043 }
3044
3045 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003046 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05003047 /*
3048 * If a discovery event readded nlp_delayfunc after timer
3049 * firing and before processing the timer, cancel the
3050 * nlp_delayfunc.
3051 */
3052 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05003053 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04003054 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05003055
3056 switch (cmd) {
3057 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003058 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05003059 break;
3060 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003061 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003062 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003063 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003064 }
dea31012005-04-17 16:05:31 -05003065 break;
3066 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05003067 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003068 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003069 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003070 }
dea31012005-04-17 16:05:31 -05003071 break;
3072 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05003073 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003074 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003075 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003076 }
dea31012005-04-17 16:05:31 -05003077 break;
3078 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05003079 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003080 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04003081 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003082 }
dea31012005-04-17 16:05:31 -05003083 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003084 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05003085 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3086 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05003087 break;
dea31012005-04-17 16:05:31 -05003088 }
3089 return;
3090}
3091
James Smarte59058c2008-08-24 21:49:00 -04003092/**
James Smart3621a712009-04-06 18:47:14 -04003093 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04003094 * @phba: pointer to lpfc hba data structure.
3095 * @cmdiocb: pointer to lpfc command iocb data structure.
3096 * @rspiocb: pointer to lpfc response iocb data structure.
3097 *
3098 * This routine makes a retry decision on an ELS command IOCB, which has
3099 * failed. The following ELS IOCBs use this function for retrying the command
3100 * when previously issued command responsed with error status: FLOGI, PLOGI,
3101 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3102 * returned error status, it makes the decision whether a retry shall be
3103 * issued for the command, and whether a retry shall be made immediately or
3104 * delayed. In the former case, the corresponding ELS command issuing-function
3105 * is called to retry the command. In the later case, the ELS command shall
3106 * be posted to the ndlp delayed event and delayed function timer set to the
3107 * ndlp for the delayed command issusing.
3108 *
3109 * Return code
3110 * 0 - No retry of els command is made
3111 * 1 - Immediate or delayed retry of els command is made
3112 **/
dea31012005-04-17 16:05:31 -05003113static int
James Smart2e0fef82007-06-17 19:56:36 -05003114lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3115 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003116{
James Smart2e0fef82007-06-17 19:56:36 -05003117 struct lpfc_vport *vport = cmdiocb->vport;
3118 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3119 IOCB_t *irsp = &rspiocb->iocb;
3120 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3121 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05003122 uint32_t *elscmd;
3123 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05003124 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04003125 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003126 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05003127 uint32_t did;
dea31012005-04-17 16:05:31 -05003128
James Smart488d1462006-03-07 15:02:37 -05003129
dea31012005-04-17 16:05:31 -05003130 /* Note: context2 may be 0 for internal driver abort
3131 * of delays ELS command.
3132 */
3133
3134 if (pcmd && pcmd->virt) {
3135 elscmd = (uint32_t *) (pcmd->virt);
3136 cmd = *elscmd++;
3137 }
3138
James Smarte47c9092008-02-08 18:49:26 -05003139 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05003140 did = ndlp->nlp_DID;
3141 else {
3142 /* We should only hit this case for retrying PLOGI */
3143 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003144 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05003145 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3146 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05003147 return 1;
3148 }
3149
James Smart858c9f62007-06-17 19:56:39 -05003150 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3151 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3152 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3153
dea31012005-04-17 16:05:31 -05003154 switch (irsp->ulpStatus) {
3155 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05003156 break;
James Smart1151e3e2011-02-16 12:39:35 -05003157 case IOSTAT_REMOTE_STOP:
3158 if (phba->sli_rev == LPFC_SLI_REV4) {
3159 /* This IO was aborted by the target, we don't
3160 * know the rxid and because we did not send the
3161 * ABTS we cannot generate and RRQ.
3162 */
3163 lpfc_set_rrq_active(phba, ndlp,
James Smartee0f4fe2012-05-09 21:19:14 -04003164 cmdiocb->sli4_lxritag, 0, 0);
James Smart1151e3e2011-02-16 12:39:35 -05003165 }
3166 break;
dea31012005-04-17 16:05:31 -05003167 case IOSTAT_LOCAL_REJECT:
James Smarte3d2b802012-08-14 14:25:43 -04003168 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
dea31012005-04-17 16:05:31 -05003169 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05003170 if (cmd == ELS_CMD_FLOGI) {
3171 if (PCI_DEVICE_ID_HORNET ==
3172 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05003173 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05003174 phba->pport->fc_myDID = 0;
3175 phba->alpa_map[0] = 0;
3176 phba->alpa_map[1] = 0;
3177 }
3178 }
James Smart2e0fef82007-06-17 19:56:36 -05003179 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003180 delay = 1000;
dea31012005-04-17 16:05:31 -05003181 retry = 1;
3182 break;
3183
James Smart92d7f7b2007-06-17 19:56:38 -05003184 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05003185 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3186 "0124 Retry illegal cmd x%x "
3187 "retry:x%x delay:x%x\n",
3188 cmd, cmdiocb->retry, delay);
3189 retry = 1;
3190 /* All command's retry policy */
3191 maxretry = 8;
3192 if (cmdiocb->retry > 2)
3193 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05003194 break;
3195
dea31012005-04-17 16:05:31 -05003196 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04003197 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05003198 retry = 1;
3199 if (cmdiocb->retry > 100)
3200 delay = 100;
3201 maxretry = 250;
3202 break;
3203
3204 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05003205 delay = 100;
dea31012005-04-17 16:05:31 -05003206 retry = 1;
3207 break;
3208
James Smart858c9f62007-06-17 19:56:39 -05003209 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05003210 case IOERR_INVALID_RPI:
James Smart5b5b36a2013-01-03 15:43:19 -05003211 if (cmd == ELS_CMD_PLOGI &&
3212 did == NameServer_DID) {
3213 /* Continue forever if plogi to */
3214 /* the nameserver fails */
3215 maxretry = 0;
3216 delay = 100;
3217 }
dea31012005-04-17 16:05:31 -05003218 retry = 1;
3219 break;
3220 }
3221 break;
3222
3223 case IOSTAT_NPORT_RJT:
3224 case IOSTAT_FABRIC_RJT:
3225 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3226 retry = 1;
3227 break;
3228 }
3229 break;
3230
3231 case IOSTAT_NPORT_BSY:
3232 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04003233 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05003234 retry = 1;
3235 break;
3236
3237 case IOSTAT_LS_RJT:
3238 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3239 /* Added for Vendor specifc support
3240 * Just keep retrying for these Rsn / Exp codes
3241 */
3242 switch (stat.un.b.lsRjtRsnCode) {
3243 case LSRJT_UNABLE_TPC:
3244 if (stat.un.b.lsRjtRsnCodeExp ==
3245 LSEXP_CMD_IN_PROGRESS) {
3246 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003247 delay = 1000;
dea31012005-04-17 16:05:31 -05003248 maxretry = 48;
3249 }
3250 retry = 1;
3251 break;
3252 }
James Smartffc95492010-06-07 15:23:17 -04003253 if (stat.un.b.lsRjtRsnCodeExp ==
3254 LSEXP_CANT_GIVE_DATA) {
3255 if (cmd == ELS_CMD_PLOGI) {
3256 delay = 1000;
3257 maxretry = 48;
3258 }
3259 retry = 1;
3260 break;
3261 }
James Smart4c1b64b2012-09-29 11:31:11 -04003262 if ((cmd == ELS_CMD_PLOGI) ||
3263 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003264 delay = 1000;
dea31012005-04-17 16:05:31 -05003265 maxretry = lpfc_max_els_tries + 1;
3266 retry = 1;
3267 break;
3268 }
James Smart92d7f7b2007-06-17 19:56:38 -05003269 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3270 (cmd == ELS_CMD_FDISC) &&
3271 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04003272 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3273 "0125 FDISC Failed (x%x). "
3274 "Fabric out of resources\n",
3275 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003276 lpfc_vport_set_state(vport,
3277 FC_VPORT_NO_FABRIC_RSCS);
3278 }
dea31012005-04-17 16:05:31 -05003279 break;
3280
3281 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003282 if ((cmd == ELS_CMD_PLOGI) ||
3283 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003284 delay = 1000;
dea31012005-04-17 16:05:31 -05003285 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003286 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003287 /* FDISC retry policy */
3288 maxretry = 48;
3289 if (cmdiocb->retry >= 32)
3290 delay = 1000;
dea31012005-04-17 16:05:31 -05003291 }
3292 retry = 1;
3293 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003294
3295 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05003296 /* There are some cases where switches return this
3297 * error when they are not ready and should be returning
3298 * Logical Busy. We should delay every time.
3299 */
3300 if (cmd == ELS_CMD_FDISC &&
3301 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3302 maxretry = 3;
3303 delay = 1000;
3304 retry = 1;
3305 break;
3306 }
James Smart92d7f7b2007-06-17 19:56:38 -05003307 case LSRJT_PROTOCOL_ERR:
3308 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3309 (cmd == ELS_CMD_FDISC) &&
3310 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3311 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3312 ) {
James Smarte8b62012007-08-02 11:10:09 -04003313 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04003314 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04003315 "Fabric Detected Bad WWN\n",
3316 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003317 lpfc_vport_set_state(vport,
3318 FC_VPORT_FABRIC_REJ_WWN);
3319 }
3320 break;
dea31012005-04-17 16:05:31 -05003321 }
3322 break;
3323
3324 case IOSTAT_INTERMED_RSP:
3325 case IOSTAT_BA_RJT:
3326 break;
3327
3328 default:
3329 break;
3330 }
3331
James Smart488d1462006-03-07 15:02:37 -05003332 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05003333 retry = 1;
dea31012005-04-17 16:05:31 -05003334
James Smartdf9e1b52011-12-13 13:22:17 -05003335 if ((cmd == ELS_CMD_FLOGI) &&
James Smart76a95d72010-11-20 23:11:48 -05003336 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05003337 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003338 /* FLOGI retry policy */
3339 retry = 1;
James Smartdf9e1b52011-12-13 13:22:17 -05003340 /* retry FLOGI forever */
James Smart6eae4302015-04-07 15:07:23 -04003341 if (phba->link_flag != LS_LOOPBACK_MODE)
3342 maxretry = 0;
3343 else
3344 maxretry = 2;
3345
James Smart6669f9b2009-10-02 15:16:45 -04003346 if (cmdiocb->retry >= 100)
3347 delay = 5000;
3348 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04003349 delay = 1000;
James Smartdf9e1b52011-12-13 13:22:17 -05003350 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3351 /* retry FDISCs every second up to devloss */
3352 retry = 1;
3353 maxretry = vport->cfg_devloss_tmo;
3354 delay = 1000;
James Smart98c9ea52007-10-27 13:37:33 -04003355 }
3356
James Smart6669f9b2009-10-02 15:16:45 -04003357 cmdiocb->retry++;
3358 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003359 phba->fc_stat.elsRetryExceeded++;
3360 retry = 0;
3361 }
3362
James Smarted957682007-06-17 19:56:37 -05003363 if ((vport->load_flag & FC_UNLOADING) != 0)
3364 retry = 0;
3365
dea31012005-04-17 16:05:31 -05003366 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003367 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3368 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3369 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3370 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3371 "2849 Stop retry ELS command "
3372 "x%x to remote NPORT x%x, "
3373 "Data: x%x x%x\n", cmd, did,
3374 cmdiocb->retry, delay);
3375 return 0;
3376 }
3377 }
dea31012005-04-17 16:05:31 -05003378
3379 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003380 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3381 "0107 Retry ELS command x%x to remote "
3382 "NPORT x%x Data: x%x x%x\n",
3383 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003384
James Smart858c9f62007-06-17 19:56:39 -05003385 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3386 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04003387 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3388 IOERR_NO_RESOURCES))) {
James Smart858c9f62007-06-17 19:56:39 -05003389 /* Don't reset timer for no resources */
3390
dea31012005-04-17 16:05:31 -05003391 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003392 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003393 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003394 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003395 }
3396
3397 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003398 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003399 phba->fc_stat.elsDelayRetry++;
3400 ndlp->nlp_retry = cmdiocb->retry;
3401
James Smart92d7f7b2007-06-17 19:56:38 -05003402 /* delay is specified in milliseconds */
3403 mod_timer(&ndlp->nlp_delayfunc,
3404 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003405 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003406 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003407 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003408
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003409 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05003410 if (cmd == ELS_CMD_PRLI)
3411 lpfc_nlp_set_state(vport, ndlp,
James Smart4c1b64b2012-09-29 11:31:11 -04003412 NLP_STE_PRLI_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003413 else
3414 lpfc_nlp_set_state(vport, ndlp,
3415 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003416 ndlp->nlp_last_elscmd = cmd;
3417
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003418 return 1;
dea31012005-04-17 16:05:31 -05003419 }
3420 switch (cmd) {
3421 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003422 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003423 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003424 case ELS_CMD_FDISC:
3425 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3426 return 1;
dea31012005-04-17 16:05:31 -05003427 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003428 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003429 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003430 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003431 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003432 }
James Smart2e0fef82007-06-17 19:56:36 -05003433 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003434 return 1;
dea31012005-04-17 16:05:31 -05003435 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003436 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003437 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3438 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003439 return 1;
dea31012005-04-17 16:05:31 -05003440 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003441 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003442 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3443 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003444 return 1;
dea31012005-04-17 16:05:31 -05003445 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003446 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04003447 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003448 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003449 return 1;
dea31012005-04-17 16:05:31 -05003450 }
3451 }
dea31012005-04-17 16:05:31 -05003452 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003453 if (logerr) {
3454 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3455 "0137 No retry ELS command x%x to remote "
3456 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3457 cmd, did, irsp->ulpStatus,
3458 irsp->un.ulpWord[4]);
3459 }
3460 else {
3461 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003462 "0108 No retry ELS command x%x to remote "
3463 "NPORT x%x Retried:%d Error:x%x/%x\n",
3464 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3465 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003466 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003467 return 0;
dea31012005-04-17 16:05:31 -05003468}
3469
James Smarte59058c2008-08-24 21:49:00 -04003470/**
James Smart3621a712009-04-06 18:47:14 -04003471 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003472 * @phba: pointer to lpfc hba data structure.
3473 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3474 *
3475 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3476 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3477 * checks to see whether there is a lpfc DMA buffer associated with the
3478 * response of the command IOCB. If so, it will be released before releasing
3479 * the lpfc DMA buffer associated with the IOCB itself.
3480 *
3481 * Return code
3482 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3483 **/
James Smart09372822008-01-11 01:52:54 -05003484static int
James Smart87af33f2007-10-27 13:37:43 -04003485lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3486{
3487 struct lpfc_dmabuf *buf_ptr;
3488
James Smarte59058c2008-08-24 21:49:00 -04003489 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003490 if (!list_empty(&buf_ptr1->list)) {
3491 list_remove_head(&buf_ptr1->list, buf_ptr,
3492 struct lpfc_dmabuf,
3493 list);
3494 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3495 kfree(buf_ptr);
3496 }
3497 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3498 kfree(buf_ptr1);
3499 return 0;
3500}
3501
James Smarte59058c2008-08-24 21:49:00 -04003502/**
James Smart3621a712009-04-06 18:47:14 -04003503 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003504 * @phba: pointer to lpfc hba data structure.
3505 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3506 *
3507 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3508 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3509 * pool.
3510 *
3511 * Return code
3512 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3513 **/
James Smart09372822008-01-11 01:52:54 -05003514static int
James Smart87af33f2007-10-27 13:37:43 -04003515lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3516{
3517 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3518 kfree(buf_ptr);
3519 return 0;
3520}
3521
James Smarte59058c2008-08-24 21:49:00 -04003522/**
James Smart3621a712009-04-06 18:47:14 -04003523 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003524 * @phba: pointer to lpfc hba data structure.
3525 * @elsiocb: pointer to lpfc els command iocb data structure.
3526 *
3527 * This routine frees a command IOCB and its associated resources. The
3528 * command IOCB data structure contains the reference to various associated
3529 * resources, these fields must be set to NULL if the associated reference
3530 * not present:
3531 * context1 - reference to ndlp
3532 * context2 - reference to cmd
3533 * context2->next - reference to rsp
3534 * context3 - reference to bpl
3535 *
3536 * It first properly decrements the reference count held on ndlp for the
3537 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3538 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3539 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3540 * adds the DMA buffer the @phba data structure for the delayed release.
3541 * If reference to the Buffer Pointer List (BPL) is present, the
3542 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3543 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3544 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3545 *
3546 * Return code
3547 * 0 - Success (currently, always return 0)
3548 **/
James Smart87af33f2007-10-27 13:37:43 -04003549int
James Smart329f9bc2007-04-25 09:53:01 -04003550lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003551{
3552 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003553 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003554
James Smarta8adb832007-10-27 13:37:53 -04003555 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3556 if (ndlp) {
3557 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3558 lpfc_nlp_put(ndlp);
3559
3560 /* If the ndlp is not being used by another discovery
3561 * thread, free it.
3562 */
3563 if (!lpfc_nlp_not_used(ndlp)) {
3564 /* If ndlp is being used by another discovery
3565 * thread, just clear NLP_DEFER_RM
3566 */
3567 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3568 }
3569 }
3570 else
3571 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003572 elsiocb->context1 = NULL;
3573 }
dea31012005-04-17 16:05:31 -05003574 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3575 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003576 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3577 /* Firmware could still be in progress of DMAing
3578 * payload, so don't free data buffer till after
3579 * a hbeat.
3580 */
3581 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3582 buf_ptr = elsiocb->context2;
3583 elsiocb->context2 = NULL;
3584 if (buf_ptr) {
3585 buf_ptr1 = NULL;
3586 spin_lock_irq(&phba->hbalock);
3587 if (!list_empty(&buf_ptr->list)) {
3588 list_remove_head(&buf_ptr->list,
3589 buf_ptr1, struct lpfc_dmabuf,
3590 list);
3591 INIT_LIST_HEAD(&buf_ptr1->list);
3592 list_add_tail(&buf_ptr1->list,
3593 &phba->elsbuf);
3594 phba->elsbuf_cnt++;
3595 }
3596 INIT_LIST_HEAD(&buf_ptr->list);
3597 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3598 phba->elsbuf_cnt++;
3599 spin_unlock_irq(&phba->hbalock);
3600 }
3601 } else {
3602 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3603 lpfc_els_free_data(phba, buf_ptr1);
3604 }
dea31012005-04-17 16:05:31 -05003605 }
3606
3607 if (elsiocb->context3) {
3608 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003609 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003610 }
James Bottomley604a3e32005-10-29 10:28:33 -05003611 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003612 return 0;
3613}
3614
James Smarte59058c2008-08-24 21:49:00 -04003615/**
James Smart3621a712009-04-06 18:47:14 -04003616 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003617 * @phba: pointer to lpfc hba data structure.
3618 * @cmdiocb: pointer to lpfc command iocb data structure.
3619 * @rspiocb: pointer to lpfc response iocb data structure.
3620 *
3621 * This routine is the completion callback function to the Logout (LOGO)
3622 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3623 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3624 * release the ndlp if it has the last reference remaining (reference count
3625 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3626 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3627 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3628 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3629 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3630 * IOCB data structure.
3631 **/
dea31012005-04-17 16:05:31 -05003632static void
James Smart2e0fef82007-06-17 19:56:36 -05003633lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3634 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003635{
James Smart2e0fef82007-06-17 19:56:36 -05003636 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3637 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003638 IOCB_t *irsp;
3639
3640 irsp = &rspiocb->iocb;
3641 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3642 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3643 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003644 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003645 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3646 "0109 ACC to LOGO completes to NPort x%x "
3647 "Data: x%x x%x x%x\n",
3648 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3649 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003650
3651 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3652 /* NPort Recovery mode or node is just allocated */
3653 if (!lpfc_nlp_not_used(ndlp)) {
3654 /* If the ndlp is being used by another discovery
3655 * thread, just unregister the RPI.
3656 */
3657 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003658 } else {
3659 /* Indicate the node has already released, should
3660 * not reference to it from within lpfc_els_free_iocb.
3661 */
3662 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003663 }
dea31012005-04-17 16:05:31 -05003664 }
James Smart73d91e52011-10-10 21:32:10 -04003665
3666 /*
3667 * The driver received a LOGO from the rport and has ACK'd it.
James Smartdf9e1b52011-12-13 13:22:17 -05003668 * At this point, the driver is done so release the IOCB
James Smart73d91e52011-10-10 21:32:10 -04003669 */
dea31012005-04-17 16:05:31 -05003670 lpfc_els_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05003671}
3672
James Smarte59058c2008-08-24 21:49:00 -04003673/**
James Smart3621a712009-04-06 18:47:14 -04003674 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003675 * @phba: pointer to lpfc hba data structure.
3676 * @pmb: pointer to the driver internal queue element for mailbox command.
3677 *
3678 * This routine is the completion callback function for unregister default
3679 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3680 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3681 * decrements the ndlp reference count held for this completion callback
3682 * function. After that, it invokes the lpfc_nlp_not_used() to check
3683 * whether there is only one reference left on the ndlp. If so, it will
3684 * perform one more decrement and trigger the release of the ndlp.
3685 **/
James Smart858c9f62007-06-17 19:56:39 -05003686void
3687lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3688{
3689 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3690 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3691
3692 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003693 pmb->context2 = NULL;
3694
James Smart858c9f62007-06-17 19:56:39 -05003695 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3696 kfree(mp);
3697 mempool_free(pmb, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04003698 if (ndlp) {
James Smartbe6bb942015-04-07 15:07:22 -04003699 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3700 "0006 rpi%x DID:%x flg:%x %d map:%x %p\n",
3701 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3702 atomic_read(&ndlp->kref.refcount),
3703 ndlp->nlp_usg_map, ndlp);
James Smart086a3452012-08-14 14:25:21 -04003704 if (NLP_CHK_NODE_ACT(ndlp)) {
3705 lpfc_nlp_put(ndlp);
3706 /* This is the end of the default RPI cleanup logic for
3707 * this ndlp. If no other discovery threads are using
3708 * this ndlp, free all resources associated with it.
3709 */
3710 lpfc_nlp_not_used(ndlp);
3711 } else {
3712 lpfc_drop_node(ndlp->vport, ndlp);
3713 }
James Smarta8adb832007-10-27 13:37:53 -04003714 }
James Smart3772a992009-05-22 14:50:54 -04003715
James Smart858c9f62007-06-17 19:56:39 -05003716 return;
3717}
3718
James Smarte59058c2008-08-24 21:49:00 -04003719/**
James Smart3621a712009-04-06 18:47:14 -04003720 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003721 * @phba: pointer to lpfc hba data structure.
3722 * @cmdiocb: pointer to lpfc command iocb data structure.
3723 * @rspiocb: pointer to lpfc response iocb data structure.
3724 *
3725 * This routine is the completion callback function for ELS Response IOCB
3726 * command. In normal case, this callback function just properly sets the
3727 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3728 * field in the command IOCB is not NULL, the referred mailbox command will
3729 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3730 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3731 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3732 * routine shall be invoked trying to release the ndlp if no other threads
3733 * are currently referring it.
3734 **/
dea31012005-04-17 16:05:31 -05003735static void
James Smart858c9f62007-06-17 19:56:39 -05003736lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003737 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003738{
James Smart2e0fef82007-06-17 19:56:36 -05003739 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3740 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3741 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003742 IOCB_t *irsp;
3743 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003744 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003745 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003746 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003747
James Smart33ccf8d2006-08-17 11:57:58 -04003748 irsp = &rspiocb->iocb;
3749
dea31012005-04-17 16:05:31 -05003750 if (cmdiocb->context_un.mbox)
3751 mbox = cmdiocb->context_un.mbox;
3752
James Smartfa4066b2008-01-11 01:53:27 -05003753 /* First determine if this is a LS_RJT cmpl. Note, this callback
3754 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3755 */
James Smart87af33f2007-10-27 13:37:43 -04003756 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003757 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3758 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003759 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3fb2010-02-03 08:01:28 +08003760 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003761 */
3762 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3763 ls_rjt = 1;
3764 }
3765
dea31012005-04-17 16:05:31 -05003766 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003767 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003768 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003769 mp = (struct lpfc_dmabuf *) mbox->context1;
3770 if (mp) {
3771 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3772 kfree(mp);
3773 }
James Smart329f9bc2007-04-25 09:53:01 -04003774 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003775 }
James Smart58da1ff2008-04-07 10:15:56 -04003776 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3777 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003778 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003779 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003780 /* Indicate the node has already released,
3781 * should not reference to it from within
3782 * the routine lpfc_els_free_iocb.
3783 */
3784 cmdiocb->context1 = NULL;
3785 }
dea31012005-04-17 16:05:31 -05003786 goto out;
3787 }
3788
James Smart858c9f62007-06-17 19:56:39 -05003789 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003790 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003791 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003792 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003793 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003794 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3795 "0110 ELS response tag x%x completes "
3796 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3797 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3798 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3799 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3800 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003801 if (mbox) {
3802 if ((rspiocb->iocb.ulpStatus == 0)
3803 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003804 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003805 /* Increment reference count to ndlp to hold the
3806 * reference to ndlp for the callback function.
3807 */
James Smart329f9bc2007-04-25 09:53:01 -04003808 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003809 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003810 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3811 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3812 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3813 }
3814 else {
3815 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3816 ndlp->nlp_prev_state = ndlp->nlp_state;
3817 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003818 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003819 }
James Smart0b727fe2007-10-27 13:37:25 -04003820 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003821 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003822 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003823 else
3824 /* Decrement the ndlp reference count we
3825 * set for this failed mailbox command.
3826 */
3827 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003828
3829 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3830 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3831 "0138 ELS rsp: Cannot issue reg_login for x%x "
3832 "Data: x%x x%x x%x\n",
3833 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3834 ndlp->nlp_rpi);
3835
James Smartfa4066b2008-01-11 01:53:27 -05003836 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003837 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003838 /* Indicate node has already been released,
3839 * should not reference to it from within
3840 * the routine lpfc_els_free_iocb.
3841 */
3842 cmdiocb->context1 = NULL;
3843 }
dea31012005-04-17 16:05:31 -05003844 } else {
James Smart858c9f62007-06-17 19:56:39 -05003845 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3846 if (!lpfc_error_lost_link(irsp) &&
3847 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003848 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003849 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003850 /* Indicate node has already been
3851 * released, should not reference
3852 * to it from within the routine
3853 * lpfc_els_free_iocb.
3854 */
3855 cmdiocb->context1 = NULL;
3856 }
dea31012005-04-17 16:05:31 -05003857 }
3858 }
James Smart14691152006-12-02 13:34:28 -05003859 mp = (struct lpfc_dmabuf *) mbox->context1;
3860 if (mp) {
3861 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3862 kfree(mp);
3863 }
3864 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003865 }
3866out:
James Smart58da1ff2008-04-07 10:15:56 -04003867 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003868 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003869 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003870 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003871
3872 /* If the node is not being used by another discovery thread,
3873 * and we are sending a reject, we are done with it.
3874 * Release driver reference count here and free associated
3875 * resources.
3876 */
3877 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003878 if (lpfc_nlp_not_used(ndlp))
3879 /* Indicate node has already been released,
3880 * should not reference to it from within
3881 * the routine lpfc_els_free_iocb.
3882 */
3883 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003884 }
James Smart87af33f2007-10-27 13:37:43 -04003885
dea31012005-04-17 16:05:31 -05003886 lpfc_els_free_iocb(phba, cmdiocb);
3887 return;
3888}
3889
James Smarte59058c2008-08-24 21:49:00 -04003890/**
James Smart3621a712009-04-06 18:47:14 -04003891 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003892 * @vport: pointer to a host virtual N_Port data structure.
3893 * @flag: the els command code to be accepted.
3894 * @oldiocb: pointer to the original lpfc command iocb data structure.
3895 * @ndlp: pointer to a node-list data structure.
3896 * @mbox: pointer to the driver internal queue element for mailbox command.
3897 *
3898 * This routine prepares and issues an Accept (ACC) response IOCB
3899 * command. It uses the @flag to properly set up the IOCB field for the
3900 * specific ACC response command to be issued and invokes the
3901 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3902 * @mbox pointer is passed in, it will be put into the context_un.mbox
3903 * field of the IOCB for the completion callback function to issue the
3904 * mailbox command to the HBA later when callback is invoked.
3905 *
3906 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3907 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3908 * will be stored into the context1 field of the IOCB for the completion
3909 * callback function to the corresponding response ELS IOCB command.
3910 *
3911 * Return code
3912 * 0 - Successfully issued acc response
3913 * 1 - Failed to issue acc response
3914 **/
dea31012005-04-17 16:05:31 -05003915int
James Smart2e0fef82007-06-17 19:56:36 -05003916lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3917 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003918 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003919{
James Smart2e0fef82007-06-17 19:56:36 -05003920 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3921 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003922 IOCB_t *icmd;
3923 IOCB_t *oldcmd;
3924 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003925 struct lpfc_sli *psli;
3926 uint8_t *pcmd;
3927 uint16_t cmdsize;
3928 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003929 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003930
3931 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003932 oldcmd = &oldiocb->iocb;
3933
3934 switch (flag) {
3935 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003936 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003937 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3938 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003939 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003940 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003941 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003942 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003943 return 1;
dea31012005-04-17 16:05:31 -05003944 }
James Smart2e0fef82007-06-17 19:56:36 -05003945
dea31012005-04-17 16:05:31 -05003946 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003947 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3948 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003949 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3950 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003951 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003952
3953 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3954 "Issue ACC: did:x%x flg:x%x",
3955 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003956 break;
3957 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003958 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003959 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3960 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003961 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003962 return 1;
James Smart488d1462006-03-07 15:02:37 -05003963
dea31012005-04-17 16:05:31 -05003964 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003965 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3966 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003967 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3968
3969 if (mbox)
3970 elsiocb->context_un.mbox = mbox;
3971
3972 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003973 pcmd += sizeof(uint32_t);
3974 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003975
3976 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3977 "Issue ACC PLOGI: did:x%x flg:x%x",
3978 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003979 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003980 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003981 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003982 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003983 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3984 if (!elsiocb)
3985 return 1;
3986
3987 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003988 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3989 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04003990 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3991
3992 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003993 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003994 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3995 els_pkt_ptr = (ELS_PKT *) pcmd;
3996 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003997
3998 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3999 "Issue ACC PRLO: did:x%x flg:x%x",
4000 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04004001 break;
dea31012005-04-17 16:05:31 -05004002 default:
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004003 return 1;
dea31012005-04-17 16:05:31 -05004004 }
dea31012005-04-17 16:05:31 -05004005 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004006 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4007 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
James Smarte6446432012-05-09 21:16:42 -04004008 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
4009 "fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04004010 elsiocb->iotag, elsiocb->iocb.ulpContext,
4011 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
James Smarte6446432012-05-09 21:16:42 -04004012 ndlp->nlp_rpi, vport->fc_flag);
dea31012005-04-17 16:05:31 -05004013 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05004014 spin_lock_irq(shost->host_lock);
James Smart7c5e5182015-05-22 10:42:43 -04004015 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4016 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4017 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05004018 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004019 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4020 } else {
James Smart858c9f62007-06-17 19:56:39 -05004021 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004022 }
4023
4024 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004025 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004026 if (rc == IOCB_ERROR) {
4027 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004028 return 1;
dea31012005-04-17 16:05:31 -05004029 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004030 return 0;
dea31012005-04-17 16:05:31 -05004031}
4032
James Smarte59058c2008-08-24 21:49:00 -04004033/**
James Smart3621a712009-04-06 18:47:14 -04004034 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004035 * @vport: pointer to a virtual N_Port data structure.
4036 * @rejectError:
4037 * @oldiocb: pointer to the original lpfc command iocb data structure.
4038 * @ndlp: pointer to a node-list data structure.
4039 * @mbox: pointer to the driver internal queue element for mailbox command.
4040 *
4041 * This routine prepares and issue an Reject (RJT) response IOCB
4042 * command. If a @mbox pointer is passed in, it will be put into the
4043 * context_un.mbox field of the IOCB for the completion callback function
4044 * to issue to the HBA later.
4045 *
4046 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4047 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4048 * will be stored into the context1 field of the IOCB for the completion
4049 * callback function to the reject response ELS IOCB command.
4050 *
4051 * Return code
4052 * 0 - Successfully issued reject response
4053 * 1 - Failed to issue reject response
4054 **/
dea31012005-04-17 16:05:31 -05004055int
James Smart2e0fef82007-06-17 19:56:36 -05004056lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05004057 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4058 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05004059{
James Smart2e0fef82007-06-17 19:56:36 -05004060 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004061 IOCB_t *icmd;
4062 IOCB_t *oldcmd;
4063 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004064 struct lpfc_sli *psli;
4065 uint8_t *pcmd;
4066 uint16_t cmdsize;
4067 int rc;
4068
4069 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05004070 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05004071 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4072 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05004073 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004074 return 1;
dea31012005-04-17 16:05:31 -05004075
4076 icmd = &elsiocb->iocb;
4077 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004078 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4079 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05004080 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4081
4082 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05004083 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004084 *((uint32_t *) (pcmd)) = rejectError;
4085
James Smart51ef4c22007-08-02 11:10:31 -04004086 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05004087 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05004088
dea31012005-04-17 16:05:31 -05004089 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004090 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4091 "0129 Xmit ELS RJT x%x response tag x%x "
4092 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4093 "rpi x%x\n",
4094 rejectError, elsiocb->iotag,
4095 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4096 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004097 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4098 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4099 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4100
dea31012005-04-17 16:05:31 -05004101 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05004102 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004103 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04004104
dea31012005-04-17 16:05:31 -05004105 if (rc == IOCB_ERROR) {
4106 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004107 return 1;
dea31012005-04-17 16:05:31 -05004108 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004109 return 0;
dea31012005-04-17 16:05:31 -05004110}
4111
James Smarte59058c2008-08-24 21:49:00 -04004112/**
James Smart3621a712009-04-06 18:47:14 -04004113 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004114 * @vport: pointer to a virtual N_Port data structure.
4115 * @oldiocb: pointer to the original lpfc command iocb data structure.
4116 * @ndlp: pointer to a node-list data structure.
4117 *
4118 * This routine prepares and issues an Accept (ACC) response to Address
4119 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4120 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4121 *
4122 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4123 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4124 * will be stored into the context1 field of the IOCB for the completion
4125 * callback function to the ADISC Accept response ELS IOCB command.
4126 *
4127 * Return code
4128 * 0 - Successfully issued acc adisc response
4129 * 1 - Failed to issue adisc acc response
4130 **/
dea31012005-04-17 16:05:31 -05004131int
James Smart2e0fef82007-06-17 19:56:36 -05004132lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4133 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004134{
James Smart2e0fef82007-06-17 19:56:36 -05004135 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004136 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05004137 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004138 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004139 uint8_t *pcmd;
4140 uint16_t cmdsize;
4141 int rc;
4142
James Smart92d7f7b2007-06-17 19:56:38 -05004143 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05004144 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4145 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004146 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004147 return 1;
dea31012005-04-17 16:05:31 -05004148
dea31012005-04-17 16:05:31 -05004149 icmd = &elsiocb->iocb;
4150 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004151 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4152 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04004153
4154 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004155 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4156 "0130 Xmit ADISC ACC response iotag x%x xri: "
4157 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4158 elsiocb->iotag, elsiocb->iocb.ulpContext,
4159 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4160 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004161 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4162
4163 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004164 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004165
4166 ap = (ADISC *) (pcmd);
4167 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05004168 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4169 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05004170 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05004171
James Smart858c9f62007-06-17 19:56:39 -05004172 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4173 "Issue ACC ADISC: did:x%x flg:x%x",
4174 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4175
dea31012005-04-17 16:05:31 -05004176 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004177 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004178 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004179 if (rc == IOCB_ERROR) {
4180 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004181 return 1;
dea31012005-04-17 16:05:31 -05004182 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004183 return 0;
dea31012005-04-17 16:05:31 -05004184}
4185
James Smarte59058c2008-08-24 21:49:00 -04004186/**
James Smart3621a712009-04-06 18:47:14 -04004187 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004188 * @vport: pointer to a virtual N_Port data structure.
4189 * @oldiocb: pointer to the original lpfc command iocb data structure.
4190 * @ndlp: pointer to a node-list data structure.
4191 *
4192 * This routine prepares and issues an Accept (ACC) response to Process
4193 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4194 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4195 *
4196 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4197 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4198 * will be stored into the context1 field of the IOCB for the completion
4199 * callback function to the PRLI Accept response ELS IOCB command.
4200 *
4201 * Return code
4202 * 0 - Successfully issued acc prli response
4203 * 1 - Failed to issue acc prli response
4204 **/
dea31012005-04-17 16:05:31 -05004205int
James Smart2e0fef82007-06-17 19:56:36 -05004206lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04004207 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004208{
James Smart2e0fef82007-06-17 19:56:36 -05004209 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004210 PRLI *npr;
4211 lpfc_vpd_t *vpd;
4212 IOCB_t *icmd;
4213 IOCB_t *oldcmd;
4214 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004215 struct lpfc_sli *psli;
4216 uint8_t *pcmd;
4217 uint16_t cmdsize;
4218 int rc;
4219
4220 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05004221
James Smart92d7f7b2007-06-17 19:56:38 -05004222 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05004223 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05004224 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004225 if (!elsiocb)
4226 return 1;
dea31012005-04-17 16:05:31 -05004227
dea31012005-04-17 16:05:31 -05004228 icmd = &elsiocb->iocb;
4229 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004230 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4231 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4232
James Smart5b8bd0c2007-04-25 09:52:49 -04004233 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004234 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4235 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4236 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4237 elsiocb->iotag, elsiocb->iocb.ulpContext,
4238 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4239 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004240 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4241
4242 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05004243 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004244
4245 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05004246 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05004247
4248 npr = (PRLI *) pcmd;
4249 vpd = &phba->vpd;
4250 /*
James Smart0d2b6b82008-06-14 22:52:47 -04004251 * If the remote port is a target and our firmware version is 3.20 or
4252 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05004253 */
James Smart0d2b6b82008-06-14 22:52:47 -04004254 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4255 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05004256 npr->ConfmComplAllowed = 1;
4257 npr->Retry = 1;
4258 npr->TaskRetryIdReq = 1;
4259 }
4260
4261 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4262 npr->estabImagePair = 1;
4263 npr->readXferRdyDis = 1;
4264 npr->ConfmComplAllowed = 1;
4265
4266 npr->prliType = PRLI_FCP_TYPE;
4267 npr->initiatorFunc = 1;
4268
James Smart858c9f62007-06-17 19:56:39 -05004269 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4270 "Issue ACC PRLI: did:x%x flg:x%x",
4271 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4272
dea31012005-04-17 16:05:31 -05004273 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004274 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004275
James Smart3772a992009-05-22 14:50:54 -04004276 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004277 if (rc == IOCB_ERROR) {
4278 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004279 return 1;
dea31012005-04-17 16:05:31 -05004280 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004281 return 0;
dea31012005-04-17 16:05:31 -05004282}
4283
James Smarte59058c2008-08-24 21:49:00 -04004284/**
James Smart3621a712009-04-06 18:47:14 -04004285 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004286 * @vport: pointer to a virtual N_Port data structure.
4287 * @format: rnid command format.
4288 * @oldiocb: pointer to the original lpfc command iocb data structure.
4289 * @ndlp: pointer to a node-list data structure.
4290 *
4291 * This routine issues a Request Node Identification Data (RNID) Accept
4292 * (ACC) response. It constructs the RNID ACC response command according to
4293 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4294 * issue the response. Note that this command does not need to hold the ndlp
4295 * reference count for the callback. So, the ndlp reference count taken by
4296 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4297 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4298 * there is no ndlp reference available.
4299 *
4300 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4301 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4302 * will be stored into the context1 field of the IOCB for the completion
4303 * callback function. However, for the RNID Accept Response ELS command,
4304 * this is undone later by this routine after the IOCB is allocated.
4305 *
4306 * Return code
4307 * 0 - Successfully issued acc rnid response
4308 * 1 - Failed to issue acc rnid response
4309 **/
dea31012005-04-17 16:05:31 -05004310static int
James Smart2e0fef82007-06-17 19:56:36 -05004311lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004312 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004313{
James Smart2e0fef82007-06-17 19:56:36 -05004314 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004315 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004316 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004317 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004318 struct lpfc_sli *psli;
4319 uint8_t *pcmd;
4320 uint16_t cmdsize;
4321 int rc;
4322
4323 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05004324 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4325 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004326 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004327 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004328
James Smart2e0fef82007-06-17 19:56:36 -05004329 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4330 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004331 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004332 return 1;
dea31012005-04-17 16:05:31 -05004333
dea31012005-04-17 16:05:31 -05004334 icmd = &elsiocb->iocb;
4335 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004336 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4337 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4338
James Smart5b8bd0c2007-04-25 09:52:49 -04004339 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004340 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4341 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4342 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004343 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004344 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004345 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004346
James Smart92d7f7b2007-06-17 19:56:38 -05004347 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004348 rn = (RNID *) (pcmd);
4349 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004350 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4351 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4352 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004353 switch (format) {
4354 case 0:
4355 rn->SpecificLen = 0;
4356 break;
4357 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004358 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004359 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004360 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004361 rn->un.topologyDisc.unitType = RNID_HBA;
4362 rn->un.topologyDisc.physPort = 0;
4363 rn->un.topologyDisc.attachedNodes = 0;
4364 break;
4365 default:
4366 rn->CommonLen = 0;
4367 rn->SpecificLen = 0;
4368 break;
4369 }
4370
James Smart858c9f62007-06-17 19:56:39 -05004371 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4372 "Issue ACC RNID: did:x%x flg:x%x",
4373 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4374
dea31012005-04-17 16:05:31 -05004375 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004376 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004377
James Smart3772a992009-05-22 14:50:54 -04004378 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004379 if (rc == IOCB_ERROR) {
4380 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004381 return 1;
dea31012005-04-17 16:05:31 -05004382 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004383 return 0;
dea31012005-04-17 16:05:31 -05004384}
4385
James Smarte59058c2008-08-24 21:49:00 -04004386/**
James Smart19ca7602010-11-20 23:11:55 -05004387 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4388 * @vport: pointer to a virtual N_Port data structure.
4389 * @iocb: pointer to the lpfc command iocb data structure.
4390 * @ndlp: pointer to a node-list data structure.
4391 *
4392 * Return
4393 **/
4394static void
4395lpfc_els_clear_rrq(struct lpfc_vport *vport,
4396 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4397{
4398 struct lpfc_hba *phba = vport->phba;
4399 uint8_t *pcmd;
4400 struct RRQ *rrq;
4401 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004402 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004403 struct lpfc_node_rrq *prrq;
4404
4405
4406 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4407 pcmd += sizeof(uint32_t);
4408 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004409 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b0622011-04-16 11:03:17 -04004410 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05004411
4412 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4413 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4414 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004415 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b0622011-04-16 11:03:17 -04004416 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05004417 rxid,
4418 iocb->iotag, iocb->iocb.ulpContext);
4419
4420 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4421 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4422 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004423 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b0622011-04-16 11:03:17 -04004424 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05004425 else
4426 xri = rxid;
4427 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004428 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004429 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004430 return;
4431}
4432
4433/**
James Smart12265f62010-10-22 11:05:53 -04004434 * lpfc_els_rsp_echo_acc - Issue echo acc response
4435 * @vport: pointer to a virtual N_Port data structure.
4436 * @data: pointer to echo data to return in the accept.
4437 * @oldiocb: pointer to the original lpfc command iocb data structure.
4438 * @ndlp: pointer to a node-list data structure.
4439 *
4440 * Return code
4441 * 0 - Successfully issued acc echo response
4442 * 1 - Failed to issue acc echo response
4443 **/
4444static int
4445lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4446 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4447{
4448 struct lpfc_hba *phba = vport->phba;
4449 struct lpfc_iocbq *elsiocb;
4450 struct lpfc_sli *psli;
4451 uint8_t *pcmd;
4452 uint16_t cmdsize;
4453 int rc;
4454
4455 psli = &phba->sli;
4456 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4457
James Smartbf086112011-08-21 21:48:13 -04004458 /* The accumulated length can exceed the BPL_SIZE. For
4459 * now, use this as the limit
4460 */
4461 if (cmdsize > LPFC_BPL_SIZE)
4462 cmdsize = LPFC_BPL_SIZE;
James Smart12265f62010-10-22 11:05:53 -04004463 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4464 ndlp->nlp_DID, ELS_CMD_ACC);
4465 if (!elsiocb)
4466 return 1;
4467
James Smart7851fe22011-07-22 18:36:52 -04004468 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4469 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4470
James Smart12265f62010-10-22 11:05:53 -04004471 /* Xmit ECHO ACC response tag <ulpIoTag> */
4472 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4473 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4474 elsiocb->iotag, elsiocb->iocb.ulpContext);
4475 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4476 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4477 pcmd += sizeof(uint32_t);
4478 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4479
4480 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4481 "Issue ACC ECHO: did:x%x flg:x%x",
4482 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4483
4484 phba->fc_stat.elsXmitACC++;
4485 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart12265f62010-10-22 11:05:53 -04004486
4487 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4488 if (rc == IOCB_ERROR) {
4489 lpfc_els_free_iocb(phba, elsiocb);
4490 return 1;
4491 }
4492 return 0;
4493}
4494
4495/**
James Smart3621a712009-04-06 18:47:14 -04004496 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004497 * @vport: pointer to a host virtual N_Port data structure.
4498 *
4499 * This routine issues Address Discover (ADISC) ELS commands to those
4500 * N_Ports which are in node port recovery state and ADISC has not been issued
4501 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4502 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4503 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4504 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4505 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4506 * IOCBs quit for later pick up. On the other hand, after walking through
4507 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4508 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4509 * no more ADISC need to be sent.
4510 *
4511 * Return code
4512 * The number of N_Ports with adisc issued.
4513 **/
dea31012005-04-17 16:05:31 -05004514int
James Smart2e0fef82007-06-17 19:56:36 -05004515lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004516{
James Smart2e0fef82007-06-17 19:56:36 -05004517 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004518 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004519 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004520
James Smart685f0bf2007-04-25 09:53:08 -04004521 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004522 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004523 if (!NLP_CHK_NODE_ACT(ndlp))
4524 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004525 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4526 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4527 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004528 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004529 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004530 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004531 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004532 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4533 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004534 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004535 vport->num_disc_nodes++;
4536 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004537 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004538 spin_lock_irq(shost->host_lock);
4539 vport->fc_flag |= FC_NLP_MORE;
4540 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004541 break;
dea31012005-04-17 16:05:31 -05004542 }
4543 }
4544 }
4545 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004546 spin_lock_irq(shost->host_lock);
4547 vport->fc_flag &= ~FC_NLP_MORE;
4548 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004549 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004550 return sentadisc;
dea31012005-04-17 16:05:31 -05004551}
4552
James Smarte59058c2008-08-24 21:49:00 -04004553/**
James Smart3621a712009-04-06 18:47:14 -04004554 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004555 * @vport: pointer to a host virtual N_Port data structure.
4556 *
4557 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4558 * which are in node port recovery state, with a @vport. Each time an ELS
4559 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4560 * the per @vport number of discover count (num_disc_nodes) shall be
4561 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4562 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4563 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4564 * later pick up. On the other hand, after walking through all the ndlps with
4565 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4566 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4567 * PLOGI need to be sent.
4568 *
4569 * Return code
4570 * The number of N_Ports with plogi issued.
4571 **/
dea31012005-04-17 16:05:31 -05004572int
James Smart2e0fef82007-06-17 19:56:36 -05004573lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004574{
James Smart2e0fef82007-06-17 19:56:36 -05004575 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004576 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004577 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004578
James Smart2e0fef82007-06-17 19:56:36 -05004579 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4580 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004581 if (!NLP_CHK_NODE_ACT(ndlp))
4582 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004583 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
James Smart8b017a32015-05-21 13:55:18 -04004584 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4585 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4586 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
James Smart685f0bf2007-04-25 09:53:08 -04004587 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004588 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4589 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004590 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004591 vport->num_disc_nodes++;
4592 if (vport->num_disc_nodes >=
James Smart8b017a32015-05-21 13:55:18 -04004593 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004594 spin_lock_irq(shost->host_lock);
4595 vport->fc_flag |= FC_NLP_MORE;
4596 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004597 break;
dea31012005-04-17 16:05:31 -05004598 }
4599 }
4600 }
James Smart87af33f2007-10-27 13:37:43 -04004601 if (sentplogi) {
4602 lpfc_set_disctmo(vport);
4603 }
4604 else {
James Smart2e0fef82007-06-17 19:56:36 -05004605 spin_lock_irq(shost->host_lock);
4606 vport->fc_flag &= ~FC_NLP_MORE;
4607 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004608 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004609 return sentplogi;
dea31012005-04-17 16:05:31 -05004610}
4611
James Smart86478872015-05-21 13:55:21 -04004612void
4613lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
4614 uint32_t word0)
4615{
4616
4617 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
4618 desc->payload.els_req = word0;
4619 desc->length = cpu_to_be32(sizeof(desc->payload));
4620}
4621
4622void
4623lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
4624 uint8_t *page_a0, uint8_t *page_a2)
4625{
4626 uint16_t wavelength;
4627 uint16_t temperature;
4628 uint16_t rx_power;
4629 uint16_t tx_bias;
4630 uint16_t tx_power;
4631 uint16_t vcc;
4632 uint16_t flag = 0;
4633 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
4634 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
4635
4636 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
4637
4638 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
4639 &page_a0[SSF_TRANSCEIVER_CODE_B4];
4640 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
4641 &page_a0[SSF_TRANSCEIVER_CODE_B5];
4642
4643 if ((trasn_code_byte4->fc_sw_laser) ||
4644 (trasn_code_byte5->fc_sw_laser_sl) ||
4645 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
4646 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
4647 } else if (trasn_code_byte4->fc_lw_laser) {
4648 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
4649 page_a0[SSF_WAVELENGTH_B0];
4650 if (wavelength == SFP_WAVELENGTH_LC1310)
4651 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
4652 if (wavelength == SFP_WAVELENGTH_LL1550)
4653 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
4654 }
4655 /* check if its SFP+ */
4656 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
4657 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
4658 << SFP_FLAG_CT_SHIFT;
4659
4660 /* check if its OPTICAL */
4661 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
4662 SFP_FLAG_IS_OPTICAL_PORT : 0)
4663 << SFP_FLAG_IS_OPTICAL_SHIFT;
4664
4665 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
4666 page_a2[SFF_TEMPERATURE_B0]);
4667 vcc = (page_a2[SFF_VCC_B1] << 8 |
4668 page_a2[SFF_VCC_B0]);
4669 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
4670 page_a2[SFF_TXPOWER_B0]);
4671 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
4672 page_a2[SFF_TX_BIAS_CURRENT_B0]);
4673 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
4674 page_a2[SFF_RXPOWER_B0]);
4675 desc->sfp_info.temperature = cpu_to_be16(temperature);
4676 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
4677 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
4678 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
4679 desc->sfp_info.vcc = cpu_to_be16(vcc);
4680
4681 desc->sfp_info.flags = cpu_to_be16(flag);
4682 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
4683}
4684
4685void
4686lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
4687 READ_LNK_VAR *stat)
4688{
4689 uint32_t type;
4690
4691 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
4692
4693 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
4694
4695 desc->info.port_type = cpu_to_be32(type);
4696
4697 desc->info.link_status.link_failure_cnt =
4698 cpu_to_be32(stat->linkFailureCnt);
4699 desc->info.link_status.loss_of_synch_cnt =
4700 cpu_to_be32(stat->lossSyncCnt);
4701 desc->info.link_status.loss_of_signal_cnt =
4702 cpu_to_be32(stat->lossSignalCnt);
4703 desc->info.link_status.primitive_seq_proto_err =
4704 cpu_to_be32(stat->primSeqErrCnt);
4705 desc->info.link_status.invalid_trans_word =
4706 cpu_to_be32(stat->invalidXmitWord);
4707 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
4708
4709 desc->length = cpu_to_be32(sizeof(desc->info));
4710}
4711
4712void
4713lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
4714{
4715 uint16_t rdp_cap = 0;
4716 uint16_t rdp_speed;
4717
4718 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
4719
4720 switch (phba->sli4_hba.link_state.speed) {
4721 case LPFC_FC_LA_SPEED_1G:
4722 rdp_speed = RDP_PS_1GB;
4723 break;
4724 case LPFC_FC_LA_SPEED_2G:
4725 rdp_speed = RDP_PS_2GB;
4726 break;
4727 case LPFC_FC_LA_SPEED_4G:
4728 rdp_speed = RDP_PS_4GB;
4729 break;
4730 case LPFC_FC_LA_SPEED_8G:
4731 rdp_speed = RDP_PS_8GB;
4732 break;
4733 case LPFC_FC_LA_SPEED_10G:
4734 rdp_speed = RDP_PS_10GB;
4735 break;
4736 case LPFC_FC_LA_SPEED_16G:
4737 rdp_speed = RDP_PS_16GB;
4738 break;
4739 case LPFC_FC_LA_SPEED_32G:
4740 rdp_speed = RDP_PS_32GB;
4741 break;
4742 default:
4743 rdp_speed = RDP_PS_UNKNOWN;
4744 break;
4745 }
4746
4747 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
4748
4749 if (phba->lmt & LMT_16Gb)
4750 rdp_cap |= RDP_PS_16GB;
4751 if (phba->lmt & LMT_10Gb)
4752 rdp_cap |= RDP_PS_10GB;
4753 if (phba->lmt & LMT_8Gb)
4754 rdp_cap |= RDP_PS_8GB;
4755 if (phba->lmt & LMT_4Gb)
4756 rdp_cap |= RDP_PS_4GB;
4757 if (phba->lmt & LMT_2Gb)
4758 rdp_cap |= RDP_PS_2GB;
4759 if (phba->lmt & LMT_1Gb)
4760 rdp_cap |= RDP_PS_1GB;
4761
4762 if (rdp_cap == 0)
4763 rdp_cap = RDP_CAP_UNKNOWN;
4764
4765 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
4766 desc->length = cpu_to_be32(sizeof(desc->info));
4767}
4768
4769void
4770lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
4771 struct lpfc_hba *phba)
4772{
4773
4774 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
4775
4776 memcpy(desc->port_names.wwnn, phba->wwnn,
4777 sizeof(desc->port_names.wwnn));
4778
4779 memcpy(desc->port_names.wwpn, &phba->wwpn,
4780 sizeof(desc->port_names.wwpn));
4781
4782 desc->length = cpu_to_be32(sizeof(desc->port_names));
4783}
4784
4785void
4786lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
4787 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4788{
4789
4790 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
4791 if (vport->fc_flag & FC_FABRIC) {
4792 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
4793 sizeof(desc->port_names.wwnn));
4794
4795 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
4796 sizeof(desc->port_names.wwpn));
4797 } else { /* Point to Point */
4798 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
4799 sizeof(desc->port_names.wwnn));
4800
4801 memcpy(desc->port_names.wwnn, &ndlp->nlp_portname,
4802 sizeof(desc->port_names.wwpn));
4803 }
4804
4805 desc->length = cpu_to_be32(sizeof(desc->port_names));
4806}
4807
4808void
4809lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
4810 int status)
4811{
4812 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
4813 struct lpfc_vport *vport = ndlp->vport;
4814 struct lpfc_iocbq *elsiocb;
4815 IOCB_t *icmd;
4816 uint8_t *pcmd;
4817 struct ls_rjt *stat;
4818 struct fc_rdp_res_frame *rdp_res;
4819 uint32_t cmdsize;
4820 int rc;
4821
4822 if (status != SUCCESS)
4823 goto error;
4824 cmdsize = sizeof(struct fc_rdp_res_frame);
4825
4826 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
4827 lpfc_max_els_tries, rdp_context->ndlp,
4828 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
4829 lpfc_nlp_put(ndlp);
4830 if (!elsiocb)
4831 goto free_rdp_context;
4832
4833 icmd = &elsiocb->iocb;
4834 icmd->ulpContext = rdp_context->rx_id;
4835 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
4836
4837 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4838 "2171 Xmit RDP response tag x%x xri x%x, "
4839 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
4840 elsiocb->iotag, elsiocb->iocb.ulpContext,
4841 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4842 ndlp->nlp_rpi);
4843 rdp_res = (struct fc_rdp_res_frame *)
4844 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4845 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4846 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
4847 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4848
4849 /* For RDP payload */
4850 lpfc_rdp_res_link_service(&rdp_res->link_service_desc, ELS_CMD_RDP);
4851
4852 lpfc_rdp_res_sfp_desc(&rdp_res->sfp_desc,
4853 rdp_context->page_a0, rdp_context->page_a2);
4854 lpfc_rdp_res_speed(&rdp_res->portspeed_desc, phba);
4855 lpfc_rdp_res_link_error(&rdp_res->link_error_desc,
4856 &rdp_context->link_stat);
4857 lpfc_rdp_res_diag_port_names(&rdp_res->diag_port_names_desc, phba);
4858 lpfc_rdp_res_attach_port_names(&rdp_res->attached_port_names_desc,
4859 vport, ndlp);
4860 rdp_res->length = cpu_to_be32(RDP_DESC_PAYLOAD_SIZE);
4861
4862 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4863
4864 phba->fc_stat.elsXmitACC++;
4865 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4866 if (rc == IOCB_ERROR)
4867 lpfc_els_free_iocb(phba, elsiocb);
4868
4869 kfree(rdp_context);
4870
4871 return;
4872error:
4873 cmdsize = 2 * sizeof(uint32_t);
4874 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
4875 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
4876 lpfc_nlp_put(ndlp);
4877 if (!elsiocb)
4878 goto free_rdp_context;
4879
4880 icmd = &elsiocb->iocb;
4881 icmd->ulpContext = rdp_context->rx_id;
4882 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
4883 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4884
4885 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4886 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
4887 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4888
4889 phba->fc_stat.elsXmitLSRJT++;
4890 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4891 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4892
4893 if (rc == IOCB_ERROR)
4894 lpfc_els_free_iocb(phba, elsiocb);
4895free_rdp_context:
4896 kfree(rdp_context);
4897}
4898
4899int
4900lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
4901{
4902 LPFC_MBOXQ_t *mbox = NULL;
4903 int rc;
4904
4905 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4906 if (!mbox) {
4907 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
4908 "7105 failed to allocate mailbox memory");
4909 return 1;
4910 }
4911
4912 if (lpfc_sli4_dump_page_a0(phba, mbox))
4913 goto prep_mbox_fail;
4914 mbox->vport = rdp_context->ndlp->vport;
4915 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
4916 mbox->context2 = (struct lpfc_rdp_context *) rdp_context;
4917 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4918 if (rc == MBX_NOT_FINISHED)
4919 goto issue_mbox_fail;
4920
4921 return 0;
4922
4923prep_mbox_fail:
4924issue_mbox_fail:
4925 mempool_free(mbox, phba->mbox_mem_pool);
4926 return 1;
4927}
4928
4929/*
4930 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
4931 * @vport: pointer to a host virtual N_Port data structure.
4932 * @cmdiocb: pointer to lpfc command iocb data structure.
4933 * @ndlp: pointer to a node-list data structure.
4934 *
4935 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
4936 * IOCB. First, the payload of the unsolicited RDP is checked.
4937 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
4938 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
4939 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
4940 * gather all data and send RDP response.
4941 *
4942 * Return code
4943 * 0 - Sent the acc response
4944 * 1 - Sent the reject response.
4945 */
4946static int
4947lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4948 struct lpfc_nodelist *ndlp)
4949{
4950 struct lpfc_hba *phba = vport->phba;
4951 struct lpfc_dmabuf *pcmd;
4952 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
4953 struct fc_rdp_req_frame *rdp_req;
4954 struct lpfc_rdp_context *rdp_context;
4955 IOCB_t *cmd = NULL;
4956 struct ls_rjt stat;
4957
4958 if (phba->sli_rev < LPFC_SLI_REV4 ||
4959 (bf_get(lpfc_sli_intf_if_type,
4960 &phba->sli4_hba.sli_intf) !=
4961 LPFC_SLI_INTF_IF_TYPE_2)) {
4962 rjt_err = LSRJT_UNABLE_TPC;
4963 rjt_expl = LSEXP_REQ_UNSUPPORTED;
4964 goto error;
4965 }
4966
4967 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
4968 rjt_err = LSRJT_UNABLE_TPC;
4969 rjt_expl = LSEXP_REQ_UNSUPPORTED;
4970 goto error;
4971 }
4972
4973 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4974 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
4975
4976
4977 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4978 "2422 ELS RDP Request "
4979 "dec len %d tag x%x port_id %d len %d\n",
4980 be32_to_cpu(rdp_req->rdp_des_length),
4981 be32_to_cpu(rdp_req->nport_id_desc.tag),
4982 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
4983 be32_to_cpu(rdp_req->nport_id_desc.length));
4984
4985 if (sizeof(struct fc_rdp_nport_desc) !=
4986 be32_to_cpu(rdp_req->rdp_des_length))
4987 goto rjt_logerr;
4988 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
4989 goto rjt_logerr;
4990 if (RDP_NPORT_ID_SIZE !=
4991 be32_to_cpu(rdp_req->nport_id_desc.length))
4992 goto rjt_logerr;
4993 rdp_context = kmalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
4994 if (!rdp_context) {
4995 rjt_err = LSRJT_UNABLE_TPC;
4996 goto error;
4997 }
4998
4999 memset(rdp_context, 0, sizeof(struct lpfc_rdp_context));
5000 cmd = &cmdiocb->iocb;
5001 rdp_context->ndlp = lpfc_nlp_get(ndlp);
5002 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
5003 rdp_context->rx_id = cmd->ulpContext;
5004 rdp_context->cmpl = lpfc_els_rdp_cmpl;
5005 if (lpfc_get_rdp_info(phba, rdp_context)) {
5006 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
5007 "2423 Unable to send mailbox");
5008 kfree(rdp_context);
5009 rjt_err = LSRJT_UNABLE_TPC;
5010 lpfc_nlp_put(ndlp);
5011 goto error;
5012 }
5013
5014 return 0;
5015
5016rjt_logerr:
5017 rjt_err = LSRJT_LOGICAL_ERR;
5018
5019error:
5020 memset(&stat, 0, sizeof(stat));
5021 stat.un.b.lsRjtRsnCode = rjt_err;
5022 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
5023 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5024 return 1;
5025}
5026
5027
James Smart8b017a32015-05-21 13:55:18 -04005028static void
5029lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5030{
5031 MAILBOX_t *mb;
5032 IOCB_t *icmd;
5033 uint8_t *pcmd;
5034 struct lpfc_iocbq *elsiocb;
5035 struct lpfc_nodelist *ndlp;
5036 struct ls_rjt *stat;
James Smart481ad962015-05-22 10:42:35 -04005037 union lpfc_sli4_cfg_shdr *shdr;
James Smart8b017a32015-05-21 13:55:18 -04005038 struct lpfc_lcb_context *lcb_context;
5039 struct fc_lcb_res_frame *lcb_res;
James Smart481ad962015-05-22 10:42:35 -04005040 uint32_t cmdsize, shdr_status, shdr_add_status;
James Smart8b017a32015-05-21 13:55:18 -04005041 int rc;
5042
5043 mb = &pmb->u.mb;
James Smart8b017a32015-05-21 13:55:18 -04005044 lcb_context = (struct lpfc_lcb_context *)pmb->context1;
5045 ndlp = lcb_context->ndlp;
5046 pmb->context1 = NULL;
5047 pmb->context2 = NULL;
5048
James Smart481ad962015-05-22 10:42:35 -04005049 shdr = (union lpfc_sli4_cfg_shdr *)
5050 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
5051 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5052 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5053
5054 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
5055 "0194 SET_BEACON_CONFIG mailbox "
5056 "completed with status x%x add_status x%x,"
5057 " mbx status x%x\n",
5058 shdr_status, shdr_add_status, mb->mbxStatus);
5059
5060 if (mb->mbxStatus && !(shdr_status &&
5061 shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)) {
James Smart8b017a32015-05-21 13:55:18 -04005062 mempool_free(pmb, phba->mbox_mem_pool);
5063 goto error;
5064 }
5065
5066 mempool_free(pmb, phba->mbox_mem_pool);
James Smart8b017a32015-05-21 13:55:18 -04005067 cmdsize = sizeof(struct fc_lcb_res_frame);
5068 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5069 lpfc_max_els_tries, ndlp,
5070 ndlp->nlp_DID, ELS_CMD_ACC);
5071
5072 /* Decrement the ndlp reference count from previous mbox command */
5073 lpfc_nlp_put(ndlp);
5074
5075 if (!elsiocb)
5076 goto free_lcb_context;
5077
5078 lcb_res = (struct fc_lcb_res_frame *)
5079 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5080
5081 icmd = &elsiocb->iocb;
5082 icmd->ulpContext = lcb_context->rx_id;
5083 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5084
5085 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5086 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
5087 lcb_res->lcb_sub_command = lcb_context->sub_command;
5088 lcb_res->lcb_type = lcb_context->type;
5089 lcb_res->lcb_frequency = lcb_context->frequency;
5090 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5091 phba->fc_stat.elsXmitACC++;
5092 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5093 if (rc == IOCB_ERROR)
5094 lpfc_els_free_iocb(phba, elsiocb);
5095
5096 kfree(lcb_context);
5097 return;
5098
5099error:
5100 cmdsize = sizeof(struct fc_lcb_res_frame);
5101 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5102 lpfc_max_els_tries, ndlp,
5103 ndlp->nlp_DID, ELS_CMD_LS_RJT);
5104 lpfc_nlp_put(ndlp);
5105 if (!elsiocb)
5106 goto free_lcb_context;
5107
5108 icmd = &elsiocb->iocb;
5109 icmd->ulpContext = lcb_context->rx_id;
5110 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5111 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5112
5113 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
5114 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5115 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5116
5117 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5118 phba->fc_stat.elsXmitLSRJT++;
5119 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5120 if (rc == IOCB_ERROR)
5121 lpfc_els_free_iocb(phba, elsiocb);
5122free_lcb_context:
5123 kfree(lcb_context);
5124}
5125
5126static int
5127lpfc_sli4_set_beacon(struct lpfc_vport *vport,
5128 struct lpfc_lcb_context *lcb_context,
5129 uint32_t beacon_state)
5130{
5131 struct lpfc_hba *phba = vport->phba;
5132 LPFC_MBOXQ_t *mbox = NULL;
5133 uint32_t len;
5134 int rc;
5135
5136 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5137 if (!mbox)
5138 return 1;
5139
5140 len = sizeof(struct lpfc_mbx_set_beacon_config) -
5141 sizeof(struct lpfc_sli4_cfg_mhdr);
5142 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5143 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
5144 LPFC_SLI4_MBX_EMBED);
5145 mbox->context1 = (void *)lcb_context;
5146 mbox->vport = phba->pport;
5147 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
5148 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
5149 phba->sli4_hba.physical_port);
5150 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
5151 beacon_state);
5152 bf_set(lpfc_mbx_set_beacon_port_type, &mbox->u.mqe.un.beacon_config, 1);
5153 bf_set(lpfc_mbx_set_beacon_duration, &mbox->u.mqe.un.beacon_config, 0);
5154 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5155 if (rc == MBX_NOT_FINISHED) {
5156 mempool_free(mbox, phba->mbox_mem_pool);
5157 return 1;
5158 }
5159
5160 return 0;
5161}
5162
5163
5164/**
5165 * lpfc_els_rcv_lcb - Process an unsolicited LCB
5166 * @vport: pointer to a host virtual N_Port data structure.
5167 * @cmdiocb: pointer to lpfc command iocb data structure.
5168 * @ndlp: pointer to a node-list data structure.
5169 *
5170 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
5171 * First, the payload of the unsolicited LCB is checked.
5172 * Then based on Subcommand beacon will either turn on or off.
5173 *
5174 * Return code
5175 * 0 - Sent the acc response
5176 * 1 - Sent the reject response.
5177 **/
5178static int
5179lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5180 struct lpfc_nodelist *ndlp)
5181{
5182 struct lpfc_hba *phba = vport->phba;
5183 struct lpfc_dmabuf *pcmd;
5184 IOCB_t *icmd;
5185 uint8_t *lp;
5186 struct fc_lcb_request_frame *beacon;
5187 struct lpfc_lcb_context *lcb_context;
5188 uint8_t state, rjt_err;
5189 struct ls_rjt stat;
5190
5191 icmd = &cmdiocb->iocb;
5192 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
5193 lp = (uint8_t *)pcmd->virt;
5194 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
5195
5196 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5197 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
5198 "type x%x frequency %x duration x%x\n",
5199 lp[0], lp[1], lp[2],
5200 beacon->lcb_command,
5201 beacon->lcb_sub_command,
5202 beacon->lcb_type,
5203 beacon->lcb_frequency,
5204 be16_to_cpu(beacon->lcb_duration));
5205
5206 if (phba->sli_rev < LPFC_SLI_REV4 ||
5207 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
5208 LPFC_SLI_INTF_IF_TYPE_2)) {
5209 rjt_err = LSRJT_CMD_UNSUPPORTED;
5210 goto rjt;
5211 }
5212 lcb_context = kmalloc(sizeof(struct lpfc_lcb_context), GFP_KERNEL);
5213
5214 if (phba->hba_flag & HBA_FCOE_MODE) {
5215 rjt_err = LSRJT_CMD_UNSUPPORTED;
5216 goto rjt;
5217 }
5218 if (beacon->lcb_frequency == 0) {
5219 rjt_err = LSRJT_CMD_UNSUPPORTED;
5220 goto rjt;
5221 }
5222 if ((beacon->lcb_type != LPFC_LCB_GREEN) &&
5223 (beacon->lcb_type != LPFC_LCB_AMBER)) {
5224 rjt_err = LSRJT_CMD_UNSUPPORTED;
5225 goto rjt;
5226 }
5227 if ((beacon->lcb_sub_command != LPFC_LCB_ON) &&
5228 (beacon->lcb_sub_command != LPFC_LCB_OFF)) {
5229 rjt_err = LSRJT_CMD_UNSUPPORTED;
5230 goto rjt;
5231 }
5232 if ((beacon->lcb_sub_command == LPFC_LCB_ON) &&
5233 (beacon->lcb_type != LPFC_LCB_GREEN) &&
5234 (beacon->lcb_type != LPFC_LCB_AMBER)) {
5235 rjt_err = LSRJT_CMD_UNSUPPORTED;
5236 goto rjt;
5237 }
5238 if (be16_to_cpu(beacon->lcb_duration) != 0) {
5239 rjt_err = LSRJT_CMD_UNSUPPORTED;
5240 goto rjt;
5241 }
5242
5243 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
5244 lcb_context->sub_command = beacon->lcb_sub_command;
5245 lcb_context->type = beacon->lcb_type;
5246 lcb_context->frequency = beacon->lcb_frequency;
5247 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
5248 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
5249 lcb_context->ndlp = lpfc_nlp_get(ndlp);
5250 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
5251 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
5252 LOG_ELS, "0193 failed to send mail box");
5253 lpfc_nlp_put(ndlp);
5254 rjt_err = LSRJT_UNABLE_TPC;
5255 goto rjt;
5256 }
5257 return 0;
5258rjt:
5259 memset(&stat, 0, sizeof(stat));
5260 stat.un.b.lsRjtRsnCode = rjt_err;
5261 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5262 return 1;
5263}
5264
5265
James Smarte59058c2008-08-24 21:49:00 -04005266/**
James Smart3621a712009-04-06 18:47:14 -04005267 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04005268 * @vport: pointer to a host virtual N_Port data structure.
5269 *
5270 * This routine cleans up any Registration State Change Notification
5271 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
5272 * @vport together with the host_lock is used to prevent multiple thread
5273 * trying to access the RSCN array on a same @vport at the same time.
5274 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005275void
James Smart2e0fef82007-06-17 19:56:36 -05005276lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005277{
James Smart2e0fef82007-06-17 19:56:36 -05005278 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5279 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005280 int i;
5281
James Smart7f5f3d02008-02-08 18:50:14 -05005282 spin_lock_irq(shost->host_lock);
5283 if (vport->fc_rscn_flush) {
5284 /* Another thread is walking fc_rscn_id_list on this vport */
5285 spin_unlock_irq(shost->host_lock);
5286 return;
5287 }
5288 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
5289 vport->fc_rscn_flush = 1;
5290 spin_unlock_irq(shost->host_lock);
5291
James Smart2e0fef82007-06-17 19:56:36 -05005292 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05005293 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05005294 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05005295 }
James Smart2e0fef82007-06-17 19:56:36 -05005296 spin_lock_irq(shost->host_lock);
5297 vport->fc_rscn_id_cnt = 0;
5298 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
5299 spin_unlock_irq(shost->host_lock);
5300 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05005301 /* Indicate we are done walking this fc_rscn_id_list */
5302 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05005303}
5304
James Smarte59058c2008-08-24 21:49:00 -04005305/**
James Smart3621a712009-04-06 18:47:14 -04005306 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04005307 * @vport: pointer to a host virtual N_Port data structure.
5308 * @did: remote destination port identifier.
5309 *
5310 * This routine checks whether there is any pending Registration State
5311 * Configuration Notification (RSCN) to a @did on @vport.
5312 *
5313 * Return code
5314 * None zero - The @did matched with a pending rscn
5315 * 0 - not able to match @did with a pending rscn
5316 **/
dea31012005-04-17 16:05:31 -05005317int
James Smart2e0fef82007-06-17 19:56:36 -05005318lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05005319{
5320 D_ID ns_did;
5321 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05005322 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05005323 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05005324 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005325
5326 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05005327
5328 /* Never match fabric nodes for RSCNs */
5329 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05005330 return 0;
dea31012005-04-17 16:05:31 -05005331
5332 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05005333 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005334 return did;
dea31012005-04-17 16:05:31 -05005335
James Smart7f5f3d02008-02-08 18:50:14 -05005336 spin_lock_irq(shost->host_lock);
5337 if (vport->fc_rscn_flush) {
5338 /* Another thread is walking fc_rscn_id_list on this vport */
5339 spin_unlock_irq(shost->host_lock);
5340 return 0;
5341 }
5342 /* Indicate we are walking fc_rscn_id_list on this vport */
5343 vport->fc_rscn_flush = 1;
5344 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05005345 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05005346 lp = vport->fc_rscn_id_list[i]->virt;
5347 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5348 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05005349 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05005350 rscn_did.un.word = be32_to_cpu(*lp++);
5351 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05005352 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
5353 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04005354 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5355 && (ns_did.un.b.area == rscn_did.un.b.area)
5356 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05005357 goto return_did_out;
dea31012005-04-17 16:05:31 -05005358 break;
James Smarteaf15d52008-12-04 22:39:29 -05005359 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05005360 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5361 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05005362 goto return_did_out;
dea31012005-04-17 16:05:31 -05005363 break;
James Smarteaf15d52008-12-04 22:39:29 -05005364 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05005365 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05005366 goto return_did_out;
dea31012005-04-17 16:05:31 -05005367 break;
James Smarteaf15d52008-12-04 22:39:29 -05005368 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05005369 goto return_did_out;
dea31012005-04-17 16:05:31 -05005370 }
5371 }
James Smart92d7f7b2007-06-17 19:56:38 -05005372 }
James Smart7f5f3d02008-02-08 18:50:14 -05005373 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5374 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005375 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05005376return_did_out:
5377 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5378 vport->fc_rscn_flush = 0;
5379 return did;
dea31012005-04-17 16:05:31 -05005380}
5381
James Smarte59058c2008-08-24 21:49:00 -04005382/**
James Smart3621a712009-04-06 18:47:14 -04005383 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04005384 * @vport: pointer to a host virtual N_Port data structure.
5385 *
5386 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
5387 * state machine for a @vport's nodes that are with pending RSCN (Registration
5388 * State Change Notification).
5389 *
5390 * Return code
5391 * 0 - Successful (currently alway return 0)
5392 **/
dea31012005-04-17 16:05:31 -05005393static int
James Smart2e0fef82007-06-17 19:56:36 -05005394lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005395{
James Smart685f0bf2007-04-25 09:53:08 -04005396 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05005397
James Smart0d2b6b82008-06-14 22:52:47 -04005398 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05005399 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005400 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04005401 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
5402 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05005403 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005404 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04005405 NLP_EVT_DEVICE_RECOVERY);
5406 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05005407 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005408 return 0;
dea31012005-04-17 16:05:31 -05005409}
5410
James Smarte59058c2008-08-24 21:49:00 -04005411/**
James Smart3621a712009-04-06 18:47:14 -04005412 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05005413 * @vport: pointer to a host virtual N_Port data structure.
5414 * @cmdiocb: pointer to lpfc command iocb data structure.
5415 *
5416 * lpfc_send_rscn_event sends an RSCN netlink event to management
5417 * applications.
5418 */
5419static void
5420lpfc_send_rscn_event(struct lpfc_vport *vport,
5421 struct lpfc_iocbq *cmdiocb)
5422{
5423 struct lpfc_dmabuf *pcmd;
5424 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5425 uint32_t *payload_ptr;
5426 uint32_t payload_len;
5427 struct lpfc_rscn_event_header *rscn_event_data;
5428
5429 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5430 payload_ptr = (uint32_t *) pcmd->virt;
5431 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
5432
5433 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
5434 payload_len, GFP_KERNEL);
5435 if (!rscn_event_data) {
5436 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5437 "0147 Failed to allocate memory for RSCN event\n");
5438 return;
5439 }
5440 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
5441 rscn_event_data->payload_length = payload_len;
5442 memcpy(rscn_event_data->rscn_payload, payload_ptr,
5443 payload_len);
5444
5445 fc_host_post_vendor_event(shost,
5446 fc_get_event_number(),
5447 sizeof(struct lpfc_els_event_header) + payload_len,
5448 (char *)rscn_event_data,
5449 LPFC_NL_VENDOR_ID);
5450
5451 kfree(rscn_event_data);
5452}
5453
5454/**
James Smart3621a712009-04-06 18:47:14 -04005455 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04005456 * @vport: pointer to a host virtual N_Port data structure.
5457 * @cmdiocb: pointer to lpfc command iocb data structure.
5458 * @ndlp: pointer to a node-list data structure.
5459 *
5460 * This routine processes an unsolicited RSCN (Registration State Change
5461 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
5462 * to invoke fc_host_post_event() routine to the FC transport layer. If the
5463 * discover state machine is about to begin discovery, it just accepts the
5464 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
5465 * contains N_Port IDs for other vports on this HBA, it just accepts the
5466 * RSCN and ignore processing it. If the state machine is in the recovery
5467 * state, the fc_rscn_id_list of this @vport is walked and the
5468 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
5469 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
5470 * routine is invoked to handle the RSCN event.
5471 *
5472 * Return code
5473 * 0 - Just sent the acc response
5474 * 1 - Sent the acc response and waited for name server completion
5475 **/
dea31012005-04-17 16:05:31 -05005476static int
James Smart2e0fef82007-06-17 19:56:36 -05005477lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04005478 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005479{
James Smart2e0fef82007-06-17 19:56:36 -05005480 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5481 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005482 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05005483 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05005484 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05005485 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05005486 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05005487 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04005488 int i;
dea31012005-04-17 16:05:31 -05005489
5490 icmd = &cmdiocb->iocb;
5491 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5492 lp = (uint32_t *) pcmd->virt;
5493
James Smart92d7f7b2007-06-17 19:56:38 -05005494 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5495 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05005496 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04005497 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5498 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05005499 vport->fc_flag, payload_len, *lp,
5500 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05005501
5502 /* Send an RSCN event to the management application */
5503 lpfc_send_rscn_event(vport, cmdiocb);
5504
James Smartd2873e42006-08-18 17:46:43 -04005505 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05005506 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04005507 FCH_EVT_RSCN, lp[i]);
5508
dea31012005-04-17 16:05:31 -05005509 /* If we are about to begin discovery, just ACC the RSCN.
5510 * Discovery processing will satisfy it.
5511 */
James Smart2e0fef82007-06-17 19:56:36 -05005512 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05005513 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5514 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
5515 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
5516
James Smart51ef4c22007-08-02 11:10:31 -04005517 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005518 return 0;
dea31012005-04-17 16:05:31 -05005519 }
5520
James Smart92d7f7b2007-06-17 19:56:38 -05005521 /* If this RSCN just contains NPortIDs for other vports on this HBA,
5522 * just ACC and ignore it.
5523 */
5524 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04005525 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05005526 i = payload_len;
5527 datap = lp;
5528 while (i > 0) {
5529 nportid = *datap++;
5530 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
5531 i -= sizeof(uint32_t);
5532 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04005533 if (lpfc_find_vport_by_did(phba, nportid))
5534 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05005535 }
5536 if (rscn_id == hba_id) {
5537 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04005538 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04005539 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04005540 "Data: x%x x%x x%x x%x\n",
5541 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05005542 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05005543 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5544 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
5545 ndlp->nlp_DID, vport->port_state,
5546 ndlp->nlp_flag);
5547
James Smart92d7f7b2007-06-17 19:56:38 -05005548 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04005549 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05005550 return 0;
5551 }
5552 }
5553
James Smart7f5f3d02008-02-08 18:50:14 -05005554 spin_lock_irq(shost->host_lock);
5555 if (vport->fc_rscn_flush) {
5556 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05005557 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05005558 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04005559 /* Send back ACC */
5560 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05005561 return 0;
5562 }
5563 /* Indicate we are walking fc_rscn_id_list on this vport */
5564 vport->fc_rscn_flush = 1;
5565 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005566 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05005567 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05005568 /* If we are already processing an RSCN, save the received
5569 * RSCN payload buffer, cmdiocb->context2 to process later.
5570 */
James Smart2e0fef82007-06-17 19:56:36 -05005571 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05005572 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5573 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
5574 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
5575
James Smart09372822008-01-11 01:52:54 -05005576 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005577 vport->fc_flag |= FC_RSCN_DEFERRED;
5578 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05005579 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05005580 vport->fc_flag |= FC_RSCN_MODE;
5581 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005582 if (rscn_cnt) {
5583 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
5584 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
5585 }
5586 if ((rscn_cnt) &&
5587 (payload_len + length <= LPFC_BPL_SIZE)) {
5588 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05005589 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05005590 memcpy(((uint8_t *)cmd) + length, lp,
5591 payload_len);
5592 } else {
5593 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
5594 vport->fc_rscn_id_cnt++;
5595 /* If we zero, cmdiocb->context2, the calling
5596 * routine will not try to free it.
5597 */
5598 cmdiocb->context2 = NULL;
5599 }
dea31012005-04-17 16:05:31 -05005600 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04005601 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5602 "0235 Deferred RSCN "
5603 "Data: x%x x%x x%x\n",
5604 vport->fc_rscn_id_cnt, vport->fc_flag,
5605 vport->port_state);
dea31012005-04-17 16:05:31 -05005606 } else {
James Smart2e0fef82007-06-17 19:56:36 -05005607 vport->fc_flag |= FC_RSCN_DISCOVERY;
5608 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005609 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04005610 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5611 "0234 ReDiscovery RSCN "
5612 "Data: x%x x%x x%x\n",
5613 vport->fc_rscn_id_cnt, vport->fc_flag,
5614 vport->port_state);
dea31012005-04-17 16:05:31 -05005615 }
James Smart7f5f3d02008-02-08 18:50:14 -05005616 /* Indicate we are done walking fc_rscn_id_list on this vport */
5617 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05005618 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04005619 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005620 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05005621 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05005622 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005623 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05005624 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005625 return 0;
dea31012005-04-17 16:05:31 -05005626 }
James Smart858c9f62007-06-17 19:56:39 -05005627 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5628 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
5629 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
5630
James Smart2e0fef82007-06-17 19:56:36 -05005631 spin_lock_irq(shost->host_lock);
5632 vport->fc_flag |= FC_RSCN_MODE;
5633 spin_unlock_irq(shost->host_lock);
5634 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05005635 /* Indicate we are done walking fc_rscn_id_list on this vport */
5636 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05005637 /*
5638 * If we zero, cmdiocb->context2, the calling routine will
5639 * not try to free it.
5640 */
5641 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005642 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05005643 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04005644 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005645 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05005646 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05005647 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05005648}
5649
James Smarte59058c2008-08-24 21:49:00 -04005650/**
James Smart3621a712009-04-06 18:47:14 -04005651 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04005652 * @vport: pointer to a host virtual N_Port data structure.
5653 *
5654 * This routine handles the Registration State Configuration Notification
5655 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
5656 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
5657 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
5658 * NameServer shall be issued. If CT command to the NameServer fails to be
5659 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
5660 * RSCN activities with the @vport.
5661 *
5662 * Return code
5663 * 0 - Cleaned up rscn on the @vport
5664 * 1 - Wait for plogi to name server before proceed
5665 **/
dea31012005-04-17 16:05:31 -05005666int
James Smart2e0fef82007-06-17 19:56:36 -05005667lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005668{
5669 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05005670 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005671
James Smart92d7f7b2007-06-17 19:56:38 -05005672 /* Ignore RSCN if the port is being torn down. */
5673 if (vport->load_flag & FC_UNLOADING) {
5674 lpfc_els_flush_rscn(vport);
5675 return 0;
5676 }
5677
dea31012005-04-17 16:05:31 -05005678 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05005679 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05005680
5681 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04005682 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5683 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
5684 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
5685 vport->port_state);
dea31012005-04-17 16:05:31 -05005686
5687 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05005688 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05005689 vport->num_disc_nodes = 0;
5690
James Smart2e0fef82007-06-17 19:56:36 -05005691 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005692 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
5693 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05005694 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05005695 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05005696 /* Wait for NameServer query cmpl before we can
5697 continue */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005698 return 1;
dea31012005-04-17 16:05:31 -05005699 } else {
5700 /* If login to NameServer does not exist, issue one */
5701 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05005702 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005703 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05005704 /* Wait for NameServer login cmpl before we can
5705 continue */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005706 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05005707
James Smarte47c9092008-02-08 18:49:26 -05005708 if (ndlp) {
5709 ndlp = lpfc_enable_node(vport, ndlp,
5710 NLP_STE_PLOGI_ISSUE);
5711 if (!ndlp) {
5712 lpfc_els_flush_rscn(vport);
5713 return 0;
5714 }
5715 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05005716 } else {
James Smarte47c9092008-02-08 18:49:26 -05005717 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5718 if (!ndlp) {
5719 lpfc_els_flush_rscn(vport);
5720 return 0;
5721 }
James Smart2e0fef82007-06-17 19:56:36 -05005722 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005723 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005724 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05005725 }
James Smarte47c9092008-02-08 18:49:26 -05005726 ndlp->nlp_type |= NLP_FABRIC;
5727 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
5728 /* Wait for NameServer login cmpl before we can
5729 * continue
5730 */
5731 return 1;
dea31012005-04-17 16:05:31 -05005732 }
5733
James Smart2e0fef82007-06-17 19:56:36 -05005734 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005735 return 0;
dea31012005-04-17 16:05:31 -05005736}
5737
James Smarte59058c2008-08-24 21:49:00 -04005738/**
James Smart3621a712009-04-06 18:47:14 -04005739 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04005740 * @vport: pointer to a host virtual N_Port data structure.
5741 * @cmdiocb: pointer to lpfc command iocb data structure.
5742 * @ndlp: pointer to a node-list data structure.
5743 *
5744 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
5745 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
5746 * point topology. As an unsolicited FLOGI should not be received in a loop
5747 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
5748 * lpfc_check_sparm() routine is invoked to check the parameters in the
5749 * unsolicited FLOGI. If parameters validation failed, the routine
5750 * lpfc_els_rsp_reject() shall be called with reject reason code set to
5751 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
5752 * FLOGI shall be compared with the Port WWN of the @vport to determine who
5753 * will initiate PLOGI. The higher lexicographical value party shall has
5754 * higher priority (as the winning port) and will initiate PLOGI and
5755 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
5756 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
5757 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
5758 *
5759 * Return code
5760 * 0 - Successfully processed the unsolicited flogi
5761 * 1 - Failed to process the unsolicited flogi
5762 **/
dea31012005-04-17 16:05:31 -05005763static int
James Smart2e0fef82007-06-17 19:56:36 -05005764lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04005765 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005766{
James Smart2e0fef82007-06-17 19:56:36 -05005767 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5768 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005769 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5770 uint32_t *lp = (uint32_t *) pcmd->virt;
5771 IOCB_t *icmd = &cmdiocb->iocb;
5772 struct serv_parm *sp;
5773 LPFC_MBOXQ_t *mbox;
5774 struct ls_rjt stat;
5775 uint32_t cmd, did;
5776 int rc;
James Smarte74c03c2013-04-17 20:15:19 -04005777 uint32_t fc_flag = 0;
5778 uint32_t port_state = 0;
dea31012005-04-17 16:05:31 -05005779
5780 cmd = *lp++;
5781 sp = (struct serv_parm *) lp;
5782
5783 /* FLOGI received */
5784
James Smart2e0fef82007-06-17 19:56:36 -05005785 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05005786
James Smart76a95d72010-11-20 23:11:48 -05005787 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05005788 /* We should never receive a FLOGI in loop mode, ignore it */
5789 did = icmd->un.elsreq64.remoteID;
5790
5791 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
5792 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04005793 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5794 "0113 An FLOGI ELS command x%x was "
5795 "received from DID x%x in Loop Mode\n",
5796 cmd, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005797 return 1;
dea31012005-04-17 16:05:31 -05005798 }
5799
James Smart341af102010-01-26 23:07:37 -05005800 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05005801 /* For a FLOGI we accept, then if our portname is greater
5802 * then the remote portname we initiate Nport login.
5803 */
5804
James Smart2e0fef82007-06-17 19:56:36 -05005805 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05005806 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05005807
5808 if (!rc) {
James Smart1b511972011-12-13 13:23:09 -05005809 if (phba->sli_rev < LPFC_SLI_REV4) {
5810 mbox = mempool_alloc(phba->mbox_mem_pool,
5811 GFP_KERNEL);
5812 if (!mbox)
5813 return 1;
5814 lpfc_linkdown(phba);
5815 lpfc_init_link(phba, mbox,
5816 phba->cfg_topology,
5817 phba->cfg_link_speed);
5818 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
5819 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5820 mbox->vport = vport;
5821 rc = lpfc_sli_issue_mbox(phba, mbox,
5822 MBX_NOWAIT);
5823 lpfc_set_loopback_flag(phba);
5824 if (rc == MBX_NOT_FINISHED)
5825 mempool_free(mbox, phba->mbox_mem_pool);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005826 return 1;
James Smart1b511972011-12-13 13:23:09 -05005827 } else {
5828 /* abort the flogi coming back to ourselves
5829 * due to external loopback on the port.
5830 */
5831 lpfc_els_abort_flogi(phba);
5832 return 0;
dea31012005-04-17 16:05:31 -05005833 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005834 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05005835 spin_lock_irq(shost->host_lock);
5836 vport->fc_flag |= FC_PT2PT_PLOGI;
5837 spin_unlock_irq(shost->host_lock);
James Smart939723a2012-05-09 21:19:03 -04005838
5839 /* If we have the high WWPN we can assign our own
5840 * myDID; otherwise, we have to WAIT for a PLOGI
5841 * from the remote NPort to find out what it
5842 * will be.
5843 */
James Smarte6446432012-05-09 21:16:42 -04005844 vport->fc_myDID = PT2PT_LocalID;
James Smarte74c03c2013-04-17 20:15:19 -04005845 } else
5846 vport->fc_myDID = PT2PT_RemoteID;
James Smart939723a2012-05-09 21:19:03 -04005847
5848 /*
5849 * The vport state should go to LPFC_FLOGI only
5850 * AFTER we issue a FLOGI, not receive one.
5851 */
James Smart2e0fef82007-06-17 19:56:36 -05005852 spin_lock_irq(shost->host_lock);
James Smarte74c03c2013-04-17 20:15:19 -04005853 fc_flag = vport->fc_flag;
5854 port_state = vport->port_state;
James Smart2e0fef82007-06-17 19:56:36 -05005855 vport->fc_flag |= FC_PT2PT;
5856 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
5857 spin_unlock_irq(shost->host_lock);
James Smarte74c03c2013-04-17 20:15:19 -04005858 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5859 "3311 Rcv Flogi PS x%x new PS x%x "
5860 "fc_flag x%x new fc_flag x%x\n",
5861 port_state, vport->port_state,
5862 fc_flag, vport->fc_flag);
James Smart939723a2012-05-09 21:19:03 -04005863
5864 /*
5865 * We temporarily set fc_myDID to make it look like we are
5866 * a Fabric. This is done just so we end up with the right
5867 * did / sid on the FLOGI ACC rsp.
5868 */
5869 did = vport->fc_myDID;
5870 vport->fc_myDID = Fabric_DID;
5871
dea31012005-04-17 16:05:31 -05005872 } else {
5873 /* Reject this request because invalid parameters */
5874 stat.un.b.lsRjtRsvd0 = 0;
5875 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5876 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
5877 stat.un.b.vendorUnique = 0;
James Smart939723a2012-05-09 21:19:03 -04005878
5879 /*
5880 * We temporarily set fc_myDID to make it look like we are
5881 * a Fabric. This is done just so we end up with the right
5882 * did / sid on the FLOGI LS_RJT rsp.
5883 */
5884 did = vport->fc_myDID;
5885 vport->fc_myDID = Fabric_DID;
5886
James Smart858c9f62007-06-17 19:56:39 -05005887 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5888 NULL);
James Smart939723a2012-05-09 21:19:03 -04005889
5890 /* Now lets put fc_myDID back to what its supposed to be */
5891 vport->fc_myDID = did;
5892
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005893 return 1;
dea31012005-04-17 16:05:31 -05005894 }
5895
5896 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04005897 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005898
James Smart939723a2012-05-09 21:19:03 -04005899 /* Now lets put fc_myDID back to what its supposed to be */
5900 vport->fc_myDID = did;
5901
James Smarte6446432012-05-09 21:16:42 -04005902 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
James Smart939723a2012-05-09 21:19:03 -04005903
James Smarte6446432012-05-09 21:16:42 -04005904 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5905 if (!mbox)
5906 goto fail;
5907
5908 lpfc_config_link(phba, mbox);
5909
5910 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5911 mbox->vport = vport;
5912 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5913 if (rc == MBX_NOT_FINISHED) {
5914 mempool_free(mbox, phba->mbox_mem_pool);
5915 goto fail;
5916 }
5917 }
5918
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005919 return 0;
James Smarte6446432012-05-09 21:16:42 -04005920fail:
5921 return 1;
dea31012005-04-17 16:05:31 -05005922}
5923
James Smarte59058c2008-08-24 21:49:00 -04005924/**
James Smart3621a712009-04-06 18:47:14 -04005925 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04005926 * @vport: pointer to a host virtual N_Port data structure.
5927 * @cmdiocb: pointer to lpfc command iocb data structure.
5928 * @ndlp: pointer to a node-list data structure.
5929 *
5930 * This routine processes Request Node Identification Data (RNID) IOCB
5931 * received as an ELS unsolicited event. Only when the RNID specified format
5932 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
5933 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
5934 * Accept (ACC) the RNID ELS command. All the other RNID formats are
5935 * rejected by invoking the lpfc_els_rsp_reject() routine.
5936 *
5937 * Return code
5938 * 0 - Successfully processed rnid iocb (currently always return 0)
5939 **/
dea31012005-04-17 16:05:31 -05005940static int
James Smart2e0fef82007-06-17 19:56:36 -05005941lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5942 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005943{
5944 struct lpfc_dmabuf *pcmd;
5945 uint32_t *lp;
5946 IOCB_t *icmd;
5947 RNID *rn;
5948 struct ls_rjt stat;
James Smarteb016562014-09-03 12:58:06 -04005949 uint32_t cmd;
dea31012005-04-17 16:05:31 -05005950
5951 icmd = &cmdiocb->iocb;
dea31012005-04-17 16:05:31 -05005952 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5953 lp = (uint32_t *) pcmd->virt;
5954
5955 cmd = *lp++;
5956 rn = (RNID *) lp;
5957
5958 /* RNID received */
5959
5960 switch (rn->Format) {
5961 case 0:
5962 case RNID_TOPOLOGY_DISC:
5963 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05005964 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005965 break;
5966 default:
5967 /* Reject this request because format not supported */
5968 stat.un.b.lsRjtRsvd0 = 0;
5969 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5970 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5971 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005972 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5973 NULL);
dea31012005-04-17 16:05:31 -05005974 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005975 return 0;
dea31012005-04-17 16:05:31 -05005976}
5977
James Smarte59058c2008-08-24 21:49:00 -04005978/**
James Smart12265f62010-10-22 11:05:53 -04005979 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
5980 * @vport: pointer to a host virtual N_Port data structure.
5981 * @cmdiocb: pointer to lpfc command iocb data structure.
5982 * @ndlp: pointer to a node-list data structure.
5983 *
5984 * Return code
5985 * 0 - Successfully processed echo iocb (currently always return 0)
5986 **/
5987static int
5988lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5989 struct lpfc_nodelist *ndlp)
5990{
5991 uint8_t *pcmd;
5992
5993 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
5994
5995 /* skip over first word of echo command to find echo data */
5996 pcmd += sizeof(uint32_t);
5997
5998 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
5999 return 0;
6000}
6001
6002/**
James Smart3621a712009-04-06 18:47:14 -04006003 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04006004 * @vport: pointer to a host virtual N_Port data structure.
6005 * @cmdiocb: pointer to lpfc command iocb data structure.
6006 * @ndlp: pointer to a node-list data structure.
6007 *
6008 * This routine processes a Link Incident Report Registration(LIRR) IOCB
6009 * received as an ELS unsolicited event. Currently, this function just invokes
6010 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
6011 *
6012 * Return code
6013 * 0 - Successfully processed lirr iocb (currently always return 0)
6014 **/
dea31012005-04-17 16:05:31 -05006015static int
James Smart2e0fef82007-06-17 19:56:36 -05006016lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6017 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006018{
6019 struct ls_rjt stat;
6020
6021 /* For now, unconditionally reject this command */
6022 stat.un.b.lsRjtRsvd0 = 0;
6023 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6024 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6025 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05006026 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006027 return 0;
6028}
6029
James Smarte59058c2008-08-24 21:49:00 -04006030/**
James Smart5ffc2662009-11-18 15:39:44 -05006031 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
6032 * @vport: pointer to a host virtual N_Port data structure.
6033 * @cmdiocb: pointer to lpfc command iocb data structure.
6034 * @ndlp: pointer to a node-list data structure.
6035 *
6036 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
6037 * received as an ELS unsolicited event. A request to RRQ shall only
6038 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
6039 * Nx_Port N_Port_ID of the target Exchange is the same as the
6040 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
6041 * not accepted, an LS_RJT with reason code "Unable to perform
6042 * command request" and reason code explanation "Invalid Originator
6043 * S_ID" shall be returned. For now, we just unconditionally accept
6044 * RRQ from the target.
6045 **/
6046static void
6047lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6048 struct lpfc_nodelist *ndlp)
6049{
6050 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05006051 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6052 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05006053}
6054
6055/**
James Smart12265f62010-10-22 11:05:53 -04006056 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6057 * @phba: pointer to lpfc hba data structure.
6058 * @pmb: pointer to the driver internal queue element for mailbox command.
6059 *
6060 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6061 * mailbox command. This callback function is to actually send the Accept
6062 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6063 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6064 * mailbox command, constructs the RPS response with the link statistics
6065 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6066 * response to the RPS.
6067 *
6068 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6069 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6070 * will be stored into the context1 field of the IOCB for the completion
6071 * callback function to the RPS Accept Response ELS IOCB command.
6072 *
6073 **/
6074static void
6075lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6076{
6077 MAILBOX_t *mb;
6078 IOCB_t *icmd;
6079 struct RLS_RSP *rls_rsp;
6080 uint8_t *pcmd;
6081 struct lpfc_iocbq *elsiocb;
6082 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04006083 uint16_t oxid;
6084 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04006085 uint32_t cmdsize;
6086
6087 mb = &pmb->u.mb;
6088
6089 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04006090 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6091 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
James Smart12265f62010-10-22 11:05:53 -04006092 pmb->context1 = NULL;
6093 pmb->context2 = NULL;
6094
6095 if (mb->mbxStatus) {
6096 mempool_free(pmb, phba->mbox_mem_pool);
6097 return;
6098 }
6099
6100 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
James Smart12265f62010-10-22 11:05:53 -04006101 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6102 lpfc_max_els_tries, ndlp,
6103 ndlp->nlp_DID, ELS_CMD_ACC);
6104
6105 /* Decrement the ndlp reference count from previous mbox command */
6106 lpfc_nlp_put(ndlp);
6107
James Smart37db57e2012-05-09 21:17:16 -04006108 if (!elsiocb) {
6109 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04006110 return;
James Smart37db57e2012-05-09 21:17:16 -04006111 }
James Smart12265f62010-10-22 11:05:53 -04006112
6113 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04006114 icmd->ulpContext = rxid;
6115 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04006116
6117 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6118 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6119 pcmd += sizeof(uint32_t); /* Skip past command */
6120 rls_rsp = (struct RLS_RSP *)pcmd;
6121
6122 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6123 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6124 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6125 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6126 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6127 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
James Smart37db57e2012-05-09 21:17:16 -04006128 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04006129 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6130 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6131 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
6132 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6133 elsiocb->iotag, elsiocb->iocb.ulpContext,
6134 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6135 ndlp->nlp_rpi);
6136 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6137 phba->fc_stat.elsXmitACC++;
6138 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6139 lpfc_els_free_iocb(phba, elsiocb);
6140}
6141
6142/**
James Smart3621a712009-04-06 18:47:14 -04006143 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04006144 * @phba: pointer to lpfc hba data structure.
6145 * @pmb: pointer to the driver internal queue element for mailbox command.
6146 *
6147 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6148 * mailbox command. This callback function is to actually send the Accept
6149 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6150 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6151 * mailbox command, constructs the RPS response with the link statistics
6152 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6153 * response to the RPS.
6154 *
6155 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6156 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6157 * will be stored into the context1 field of the IOCB for the completion
6158 * callback function to the RPS Accept Response ELS IOCB command.
6159 *
6160 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05006161static void
James Smart329f9bc2007-04-25 09:53:01 -04006162lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006163{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006164 MAILBOX_t *mb;
6165 IOCB_t *icmd;
6166 RPS_RSP *rps_rsp;
6167 uint8_t *pcmd;
6168 struct lpfc_iocbq *elsiocb;
6169 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04006170 uint16_t status;
6171 uint16_t oxid;
6172 uint16_t rxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006173 uint32_t cmdsize;
6174
James Smart04c68492009-05-22 14:52:52 -04006175 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006176
6177 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04006178 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6179 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
Randy Dunlap041976f2006-06-25 01:58:51 -07006180 pmb->context1 = NULL;
6181 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006182
6183 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04006184 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006185 return;
6186 }
6187
6188 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04006189 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05006190 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6191 lpfc_max_els_tries, ndlp,
6192 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05006193
6194 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04006195 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05006196
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006197 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006198 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006199
6200 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04006201 icmd->ulpContext = rxid;
6202 icmd->unsli3.rcvsli3.ox_id = oxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006203
6204 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6205 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05006206 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006207 rps_rsp = (RPS_RSP *)pcmd;
6208
James Smart76a95d72010-11-20 23:11:48 -05006209 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006210 status = 0x10;
6211 else
6212 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05006213 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006214 status |= 0x4;
6215
6216 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05006217 rps_rsp->portStatus = cpu_to_be16(status);
6218 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6219 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6220 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6221 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6222 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6223 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006224 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04006225 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6226 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
6227 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6228 elsiocb->iotag, elsiocb->iocb.ulpContext,
6229 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6230 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05006231 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006232 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04006233 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006234 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006235 return;
6236}
6237
James Smarte59058c2008-08-24 21:49:00 -04006238/**
James Smart12265f62010-10-22 11:05:53 -04006239 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
6240 * @vport: pointer to a host virtual N_Port data structure.
6241 * @cmdiocb: pointer to lpfc command iocb data structure.
6242 * @ndlp: pointer to a node-list data structure.
6243 *
6244 * This routine processes Read Port Status (RPL) IOCB received as an
6245 * ELS unsolicited event. It first checks the remote port state. If the
6246 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6247 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6248 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6249 * for reading the HBA link statistics. It is for the callback function,
6250 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
6251 * to actually sending out RPL Accept (ACC) response.
6252 *
6253 * Return codes
6254 * 0 - Successfully processed rls iocb (currently always return 0)
6255 **/
6256static int
6257lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6258 struct lpfc_nodelist *ndlp)
6259{
6260 struct lpfc_hba *phba = vport->phba;
6261 LPFC_MBOXQ_t *mbox;
6262 struct lpfc_dmabuf *pcmd;
6263 struct ls_rjt stat;
6264
6265 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6266 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6267 /* reject the unsolicited RPS request and done with it */
6268 goto reject_out;
6269
6270 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6271
6272 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6273 if (mbox) {
6274 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04006275 mbox->context1 = (void *)((unsigned long)
6276 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6277 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart12265f62010-10-22 11:05:53 -04006278 mbox->context2 = lpfc_nlp_get(ndlp);
6279 mbox->vport = vport;
6280 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
6281 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6282 != MBX_NOT_FINISHED)
6283 /* Mbox completion will send ELS Response */
6284 return 0;
6285 /* Decrement reference count used for the failed mbox
6286 * command.
6287 */
6288 lpfc_nlp_put(ndlp);
6289 mempool_free(mbox, phba->mbox_mem_pool);
6290 }
6291reject_out:
6292 /* issue rejection response */
6293 stat.un.b.lsRjtRsvd0 = 0;
6294 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6295 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6296 stat.un.b.vendorUnique = 0;
6297 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6298 return 0;
6299}
6300
6301/**
6302 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
6303 * @vport: pointer to a host virtual N_Port data structure.
6304 * @cmdiocb: pointer to lpfc command iocb data structure.
6305 * @ndlp: pointer to a node-list data structure.
6306 *
6307 * This routine processes Read Timout Value (RTV) IOCB received as an
6308 * ELS unsolicited event. It first checks the remote port state. If the
6309 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6310 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6311 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
6312 * Value (RTV) unsolicited IOCB event.
6313 *
6314 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6315 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6316 * will be stored into the context1 field of the IOCB for the completion
6317 * callback function to the RPS Accept Response ELS IOCB command.
6318 *
6319 * Return codes
6320 * 0 - Successfully processed rtv iocb (currently always return 0)
6321 **/
6322static int
6323lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6324 struct lpfc_nodelist *ndlp)
6325{
6326 struct lpfc_hba *phba = vport->phba;
6327 struct ls_rjt stat;
6328 struct RTV_RSP *rtv_rsp;
6329 uint8_t *pcmd;
6330 struct lpfc_iocbq *elsiocb;
6331 uint32_t cmdsize;
6332
6333
6334 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6335 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6336 /* reject the unsolicited RPS request and done with it */
6337 goto reject_out;
6338
6339 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
6340 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6341 lpfc_max_els_tries, ndlp,
6342 ndlp->nlp_DID, ELS_CMD_ACC);
6343
6344 if (!elsiocb)
6345 return 1;
6346
6347 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6348 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6349 pcmd += sizeof(uint32_t); /* Skip past command */
6350
6351 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04006352 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
6353 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04006354
6355 rtv_rsp = (struct RTV_RSP *)pcmd;
6356
6357 /* populate RTV payload */
6358 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
6359 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
6360 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
6361 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
6362 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
6363
6364 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6365 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6366 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
6367 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
6368 "Data: x%x x%x x%x\n",
6369 elsiocb->iotag, elsiocb->iocb.ulpContext,
6370 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6371 ndlp->nlp_rpi,
6372 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
6373 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6374 phba->fc_stat.elsXmitACC++;
6375 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6376 lpfc_els_free_iocb(phba, elsiocb);
6377 return 0;
6378
6379reject_out:
6380 /* issue rejection response */
6381 stat.un.b.lsRjtRsvd0 = 0;
6382 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6383 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6384 stat.un.b.vendorUnique = 0;
6385 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6386 return 0;
6387}
6388
6389/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04006390 * @vport: pointer to a host virtual N_Port data structure.
6391 * @cmdiocb: pointer to lpfc command iocb data structure.
6392 * @ndlp: pointer to a node-list data structure.
6393 *
6394 * This routine processes Read Port Status (RPS) IOCB received as an
6395 * ELS unsolicited event. It first checks the remote port state. If the
6396 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6397 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
6398 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6399 * for reading the HBA link statistics. It is for the callback function,
6400 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
6401 * to actually sending out RPS Accept (ACC) response.
6402 *
6403 * Return codes
6404 * 0 - Successfully processed rps iocb (currently always return 0)
6405 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006406static int
James Smart2e0fef82007-06-17 19:56:36 -05006407lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6408 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006409{
James Smart2e0fef82007-06-17 19:56:36 -05006410 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006411 uint32_t *lp;
6412 uint8_t flag;
6413 LPFC_MBOXQ_t *mbox;
6414 struct lpfc_dmabuf *pcmd;
6415 RPS *rps;
6416 struct ls_rjt stat;
6417
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05006418 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04006419 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6420 /* reject the unsolicited RPS request and done with it */
6421 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006422
6423 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6424 lp = (uint32_t *) pcmd->virt;
6425 flag = (be32_to_cpu(*lp++) & 0xf);
6426 rps = (RPS *) lp;
6427
6428 if ((flag == 0) ||
6429 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05006430 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05006431 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05006432
James Smart92d7f7b2007-06-17 19:56:38 -05006433 printk("Fix me....\n");
6434 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05006435 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6436 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006437 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04006438 mbox->context1 = (void *)((unsigned long)
6439 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6440 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart329f9bc2007-04-25 09:53:01 -04006441 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006442 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006443 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05006444 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04006445 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006446 /* Mbox completion will send ELS Response */
6447 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05006448 /* Decrement reference count used for the failed mbox
6449 * command.
6450 */
James Smart329f9bc2007-04-25 09:53:01 -04006451 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006452 mempool_free(mbox, phba->mbox_mem_pool);
6453 }
6454 }
James Smart90160e02008-08-24 21:49:45 -04006455
6456reject_out:
6457 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006458 stat.un.b.lsRjtRsvd0 = 0;
6459 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6460 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6461 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05006462 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006463 return 0;
6464}
6465
James Smart19ca7602010-11-20 23:11:55 -05006466/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
6467 * @vport: pointer to a host virtual N_Port data structure.
6468 * @ndlp: pointer to a node-list data structure.
6469 * @did: DID of the target.
6470 * @rrq: Pointer to the rrq struct.
6471 *
6472 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
6473 * Successful the the completion handler will clear the RRQ.
6474 *
6475 * Return codes
6476 * 0 - Successfully sent rrq els iocb.
6477 * 1 - Failed to send rrq els iocb.
6478 **/
6479static int
6480lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6481 uint32_t did, struct lpfc_node_rrq *rrq)
6482{
6483 struct lpfc_hba *phba = vport->phba;
6484 struct RRQ *els_rrq;
6485 IOCB_t *icmd;
6486 struct lpfc_iocbq *elsiocb;
6487 uint8_t *pcmd;
6488 uint16_t cmdsize;
6489 int ret;
6490
6491
6492 if (ndlp != rrq->ndlp)
6493 ndlp = rrq->ndlp;
6494 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6495 return 1;
6496
6497 /* If ndlp is not NULL, we will bump the reference count on it */
6498 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
6499 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
6500 ELS_CMD_RRQ);
6501 if (!elsiocb)
6502 return 1;
6503
6504 icmd = &elsiocb->iocb;
6505 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6506
6507 /* For RRQ request, remainder of payload is Exchange IDs */
6508 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
6509 pcmd += sizeof(uint32_t);
6510 els_rrq = (struct RRQ *) pcmd;
6511
James Smartee0f4fe2012-05-09 21:19:14 -04006512 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
James Smart19ca7602010-11-20 23:11:55 -05006513 bf_set(rrq_rxid, els_rrq, rrq->rxid);
6514 bf_set(rrq_did, els_rrq, vport->fc_myDID);
6515 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
6516 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
6517
6518
6519 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6520 "Issue RRQ: did:x%x",
6521 did, rrq->xritag, rrq->rxid);
6522 elsiocb->context_un.rrq = rrq;
6523 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
6524 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6525
6526 if (ret == IOCB_ERROR) {
6527 lpfc_els_free_iocb(phba, elsiocb);
6528 return 1;
6529 }
6530 return 0;
6531}
6532
6533/**
6534 * lpfc_send_rrq - Sends ELS RRQ if needed.
6535 * @phba: pointer to lpfc hba data structure.
6536 * @rrq: pointer to the active rrq.
6537 *
6538 * This routine will call the lpfc_issue_els_rrq if the rrq is
6539 * still active for the xri. If this function returns a failure then
6540 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
6541 *
6542 * Returns 0 Success.
6543 * 1 Failure.
6544 **/
6545int
6546lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
6547{
6548 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
6549 rrq->nlp_DID);
6550 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
6551 return lpfc_issue_els_rrq(rrq->vport, ndlp,
6552 rrq->nlp_DID, rrq);
6553 else
6554 return 1;
6555}
6556
James Smarte59058c2008-08-24 21:49:00 -04006557/**
James Smart3621a712009-04-06 18:47:14 -04006558 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04006559 * @vport: pointer to a host virtual N_Port data structure.
6560 * @cmdsize: size of the ELS command.
6561 * @oldiocb: pointer to the original lpfc command iocb data structure.
6562 * @ndlp: pointer to a node-list data structure.
6563 *
6564 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
6565 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
6566 *
6567 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6568 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6569 * will be stored into the context1 field of the IOCB for the completion
6570 * callback function to the RPL Accept Response ELS command.
6571 *
6572 * Return code
6573 * 0 - Successfully issued ACC RPL ELS command
6574 * 1 - Failed to issue ACC RPL ELS command
6575 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05006576static int
James Smart2e0fef82007-06-17 19:56:36 -05006577lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
6578 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006579{
James Smart2e0fef82007-06-17 19:56:36 -05006580 struct lpfc_hba *phba = vport->phba;
6581 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006582 RPL_RSP rpl_rsp;
6583 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006584 uint8_t *pcmd;
6585
James Smart2e0fef82007-06-17 19:56:36 -05006586 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
6587 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006588
James Smart488d1462006-03-07 15:02:37 -05006589 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006590 return 1;
James Smart488d1462006-03-07 15:02:37 -05006591
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006592 icmd = &elsiocb->iocb;
6593 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04006594 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
6595 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006596
6597 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6598 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05006599 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006600 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
6601 pcmd += sizeof(uint16_t);
6602
6603 /* Setup the RPL ACC payload */
6604 rpl_rsp.listLen = be32_to_cpu(1);
6605 rpl_rsp.index = 0;
6606 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05006607 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
6608 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006609 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006610 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006611 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04006612 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6613 "0120 Xmit ELS RPL ACC response tag x%x "
6614 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
6615 "rpi x%x\n",
6616 elsiocb->iotag, elsiocb->iocb.ulpContext,
6617 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6618 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05006619 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006620 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04006621 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6622 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006623 lpfc_els_free_iocb(phba, elsiocb);
6624 return 1;
6625 }
6626 return 0;
6627}
6628
James Smarte59058c2008-08-24 21:49:00 -04006629/**
James Smart3621a712009-04-06 18:47:14 -04006630 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04006631 * @vport: pointer to a host virtual N_Port data structure.
6632 * @cmdiocb: pointer to lpfc command iocb data structure.
6633 * @ndlp: pointer to a node-list data structure.
6634 *
6635 * This routine processes Read Port List (RPL) IOCB received as an ELS
6636 * unsolicited event. It first checks the remote port state. If the remote
6637 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
6638 * invokes the lpfc_els_rsp_reject() routine to send reject response.
6639 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
6640 * to accept the RPL.
6641 *
6642 * Return code
6643 * 0 - Successfully processed rpl iocb (currently always return 0)
6644 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006645static int
James Smart2e0fef82007-06-17 19:56:36 -05006646lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6647 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006648{
6649 struct lpfc_dmabuf *pcmd;
6650 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006651 uint32_t maxsize;
6652 uint16_t cmdsize;
6653 RPL *rpl;
6654 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05006655
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05006656 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6657 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04006658 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006659 stat.un.b.lsRjtRsvd0 = 0;
6660 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6661 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6662 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05006663 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
6664 NULL);
James Smart90160e02008-08-24 21:49:45 -04006665 /* rejected the unsolicited RPL request and done with it */
6666 return 0;
dea31012005-04-17 16:05:31 -05006667 }
6668
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006669 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6670 lp = (uint32_t *) pcmd->virt;
6671 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006672 maxsize = be32_to_cpu(rpl->maxsize);
6673
6674 /* We support only one port */
6675 if ((rpl->index == 0) &&
6676 ((maxsize == 0) ||
6677 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
6678 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05006679 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006680 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
6681 }
James Smart2e0fef82007-06-17 19:56:36 -05006682 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05006683
6684 return 0;
6685}
6686
James Smarte59058c2008-08-24 21:49:00 -04006687/**
James Smart3621a712009-04-06 18:47:14 -04006688 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04006689 * @vport: pointer to a virtual N_Port data structure.
6690 * @cmdiocb: pointer to lpfc command iocb data structure.
6691 * @ndlp: pointer to a node-list data structure.
6692 *
6693 * This routine processes Fibre Channel Address Resolution Protocol
6694 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
6695 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
6696 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
6697 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
6698 * remote PortName is compared against the FC PortName stored in the @vport
6699 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
6700 * compared against the FC NodeName stored in the @vport data structure.
6701 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
6702 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
6703 * invoked to send out FARP Response to the remote node. Before sending the
6704 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
6705 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
6706 * routine is invoked to log into the remote port first.
6707 *
6708 * Return code
6709 * 0 - Either the FARP Match Mode not supported or successfully processed
6710 **/
dea31012005-04-17 16:05:31 -05006711static int
James Smart2e0fef82007-06-17 19:56:36 -05006712lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6713 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006714{
6715 struct lpfc_dmabuf *pcmd;
6716 uint32_t *lp;
6717 IOCB_t *icmd;
6718 FARP *fp;
6719 uint32_t cmd, cnt, did;
6720
6721 icmd = &cmdiocb->iocb;
6722 did = icmd->un.elsreq64.remoteID;
6723 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6724 lp = (uint32_t *) pcmd->virt;
6725
6726 cmd = *lp++;
6727 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05006728 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04006729 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6730 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05006731 /* We will only support match on WWPN or WWNN */
6732 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006733 return 0;
dea31012005-04-17 16:05:31 -05006734 }
6735
6736 cnt = 0;
6737 /* If this FARP command is searching for my portname */
6738 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05006739 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05006740 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05006741 cnt = 1;
6742 }
6743
6744 /* If this FARP command is searching for my nodename */
6745 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05006746 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05006747 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05006748 cnt = 1;
6749 }
6750
6751 if (cnt) {
6752 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
6753 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
6754 /* Log back into the node before sending the FARP. */
6755 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006756 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05006757 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04006758 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05006759 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05006760 }
6761
6762 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05006763 if (fp->Rflags & FARP_REQUEST_FARPR)
6764 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05006765 }
6766 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006767 return 0;
dea31012005-04-17 16:05:31 -05006768}
6769
James Smarte59058c2008-08-24 21:49:00 -04006770/**
James Smart3621a712009-04-06 18:47:14 -04006771 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04006772 * @vport: pointer to a host virtual N_Port data structure.
6773 * @cmdiocb: pointer to lpfc command iocb data structure.
6774 * @ndlp: pointer to a node-list data structure.
6775 *
6776 * This routine processes Fibre Channel Address Resolution Protocol
6777 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
6778 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
6779 * the FARP response request.
6780 *
6781 * Return code
6782 * 0 - Successfully processed FARPR IOCB (currently always return 0)
6783 **/
dea31012005-04-17 16:05:31 -05006784static int
James Smart2e0fef82007-06-17 19:56:36 -05006785lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6786 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006787{
6788 struct lpfc_dmabuf *pcmd;
6789 uint32_t *lp;
6790 IOCB_t *icmd;
6791 uint32_t cmd, did;
6792
6793 icmd = &cmdiocb->iocb;
6794 did = icmd->un.elsreq64.remoteID;
6795 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6796 lp = (uint32_t *) pcmd->virt;
6797
6798 cmd = *lp++;
6799 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04006800 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6801 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05006802 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04006803 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006804
6805 return 0;
6806}
6807
James Smarte59058c2008-08-24 21:49:00 -04006808/**
James Smart3621a712009-04-06 18:47:14 -04006809 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04006810 * @vport: pointer to a host virtual N_Port data structure.
6811 * @cmdiocb: pointer to lpfc command iocb data structure.
6812 * @fan_ndlp: pointer to a node-list data structure.
6813 *
6814 * This routine processes a Fabric Address Notification (FAN) IOCB
6815 * command received as an ELS unsolicited event. The FAN ELS command will
6816 * only be processed on a physical port (i.e., the @vport represents the
6817 * physical port). The fabric NodeName and PortName from the FAN IOCB are
6818 * compared against those in the phba data structure. If any of those is
6819 * different, the lpfc_initial_flogi() routine is invoked to initialize
6820 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
6821 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
6822 * is invoked to register login to the fabric.
6823 *
6824 * Return code
6825 * 0 - Successfully processed fan iocb (currently always return 0).
6826 **/
dea31012005-04-17 16:05:31 -05006827static int
James Smart2e0fef82007-06-17 19:56:36 -05006828lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6829 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05006830{
James Smart2e0fef82007-06-17 19:56:36 -05006831 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04006832 uint32_t *lp;
6833 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006834
James Smart0d2b6b82008-06-14 22:52:47 -04006835 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
6836 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
6837 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006838 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04006839 if ((vport == phba->pport) &&
6840 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006841 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04006842 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006843 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04006844 sizeof(struct lpfc_name)))) {
6845 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05006846 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04006847 } else {
6848 /* FAN verified - skip FLOGI */
6849 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04006850 if (phba->sli_rev < LPFC_SLI_REV4)
6851 lpfc_issue_fabric_reglogin(vport);
James Smart1b511972011-12-13 13:23:09 -05006852 else {
6853 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6854 "3138 Need register VFI: (x%x/%x)\n",
6855 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -04006856 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -05006857 }
dea31012005-04-17 16:05:31 -05006858 }
dea31012005-04-17 16:05:31 -05006859 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006860 return 0;
dea31012005-04-17 16:05:31 -05006861}
6862
James Smarte59058c2008-08-24 21:49:00 -04006863/**
James Smart3621a712009-04-06 18:47:14 -04006864 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04006865 * @ptr: holder for the timer function associated data.
6866 *
6867 * This routine is invoked by the ELS timer after timeout. It posts the ELS
6868 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
6869 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
6870 * up the worker thread. It is for the worker thread to invoke the routine
6871 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
6872 **/
dea31012005-04-17 16:05:31 -05006873void
6874lpfc_els_timeout(unsigned long ptr)
6875{
James Smart2e0fef82007-06-17 19:56:36 -05006876 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
6877 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04006878 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05006879 unsigned long iflag;
6880
James Smart2e0fef82007-06-17 19:56:36 -05006881 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04006882 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
James Smart06918ac2014-02-20 09:57:57 -05006883 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
James Smart2e0fef82007-06-17 19:56:36 -05006884 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04006885 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05006886
James Smart06918ac2014-02-20 09:57:57 -05006887 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
James Smart5e9d9b82008-06-14 22:52:53 -04006888 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05006889 return;
6890}
6891
James Smart2a9bf3d2010-06-07 15:24:45 -04006892
James Smarte59058c2008-08-24 21:49:00 -04006893/**
James Smart3621a712009-04-06 18:47:14 -04006894 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04006895 * @vport: pointer to a virtual N_Port data structure.
6896 *
6897 * This routine is the actual handler function that processes an ELS timeout
6898 * event. It walks the ELS ring to get and abort all the IOCBs (except the
6899 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
6900 * invoking the lpfc_sli_issue_abort_iotag() routine.
6901 **/
dea31012005-04-17 16:05:31 -05006902void
James Smart2e0fef82007-06-17 19:56:36 -05006903lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006904{
James Smart2e0fef82007-06-17 19:56:36 -05006905 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006906 struct lpfc_sli_ring *pring;
6907 struct lpfc_iocbq *tmp_iocb, *piocb;
6908 IOCB_t *cmd = NULL;
6909 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05006910 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05006911 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05006912 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04006913 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05006914
James Smart2a9bf3d2010-06-07 15:24:45 -04006915
dea31012005-04-17 16:05:31 -05006916 timeout = (uint32_t)(phba->fc_ratov << 1);
6917
6918 pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart06918ac2014-02-20 09:57:57 -05006919 if ((phba->pport->load_flag & FC_UNLOADING))
6920 return;
James Smart2a9bf3d2010-06-07 15:24:45 -04006921 spin_lock_irq(&phba->hbalock);
James Smart0976e1a2013-12-17 20:29:36 -05006922 if (phba->sli_rev == LPFC_SLI_REV4)
6923 spin_lock(&pring->ring_lock);
James Smart2a9bf3d2010-06-07 15:24:45 -04006924
James Smart06918ac2014-02-20 09:57:57 -05006925 if ((phba->pport->load_flag & FC_UNLOADING)) {
6926 if (phba->sli_rev == LPFC_SLI_REV4)
6927 spin_unlock(&pring->ring_lock);
6928 spin_unlock_irq(&phba->hbalock);
6929 return;
6930 }
6931
James Smart0976e1a2013-12-17 20:29:36 -05006932 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05006933 cmd = &piocb->iocb;
6934
James Smart2e0fef82007-06-17 19:56:36 -05006935 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
6936 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
6937 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05006938 continue;
James Smart2e0fef82007-06-17 19:56:36 -05006939
6940 if (piocb->vport != vport)
6941 continue;
6942
dea31012005-04-17 16:05:31 -05006943 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05006944 if (pcmd)
6945 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05006946
James Smart92d7f7b2007-06-17 19:56:38 -05006947 if (els_command == ELS_CMD_FARP ||
6948 els_command == ELS_CMD_FARPR ||
6949 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05006950 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05006951
dea31012005-04-17 16:05:31 -05006952 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05006953 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05006954 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05006955 else
dea31012005-04-17 16:05:31 -05006956 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05006957 continue;
6958 }
6959
James Smart2e0fef82007-06-17 19:56:36 -05006960 remote_ID = 0xffffffff;
6961 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05006962 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05006963 else {
6964 struct lpfc_nodelist *ndlp;
6965 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04006966 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05006967 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05006968 }
James Smart2a9bf3d2010-06-07 15:24:45 -04006969 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05006970 }
James Smart0976e1a2013-12-17 20:29:36 -05006971 if (phba->sli_rev == LPFC_SLI_REV4)
6972 spin_unlock(&pring->ring_lock);
James Smart2e0fef82007-06-17 19:56:36 -05006973 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04006974
James Smart2a9bf3d2010-06-07 15:24:45 -04006975 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
James Smart15026c92013-12-17 20:30:09 -05006976 cmd = &piocb->iocb;
James Smart2a9bf3d2010-06-07 15:24:45 -04006977 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6978 "0127 ELS timeout Data: x%x x%x x%x "
6979 "x%x\n", els_command,
6980 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
6981 spin_lock_irq(&phba->hbalock);
6982 list_del_init(&piocb->dlist);
6983 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6984 spin_unlock_irq(&phba->hbalock);
6985 }
6986
James Smart0e9bb8d2013-03-01 16:35:12 -05006987 if (!list_empty(&phba->sli.ring[LPFC_ELS_RING].txcmplq))
James Smart06918ac2014-02-20 09:57:57 -05006988 if (!(phba->pport->load_flag & FC_UNLOADING))
6989 mod_timer(&vport->els_tmofunc,
6990 jiffies + msecs_to_jiffies(1000 * timeout));
dea31012005-04-17 16:05:31 -05006991}
6992
James Smarte59058c2008-08-24 21:49:00 -04006993/**
James Smart3621a712009-04-06 18:47:14 -04006994 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04006995 * @vport: pointer to a host virtual N_Port data structure.
6996 *
6997 * This routine is used to clean up all the outstanding ELS commands on a
6998 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
6999 * routine. After that, it walks the ELS transmit queue to remove all the
7000 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
7001 * the IOCBs with a non-NULL completion callback function, the callback
7002 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7003 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
7004 * callback function, the IOCB will simply be released. Finally, it walks
7005 * the ELS transmit completion queue to issue an abort IOCB to any transmit
7006 * completion queue IOCB that is associated with the @vport and is not
7007 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
7008 * part of the discovery state machine) out to HBA by invoking the
7009 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
7010 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
7011 * the IOCBs are aborted when this function returns.
7012 **/
dea31012005-04-17 16:05:31 -05007013void
James Smart2e0fef82007-06-17 19:56:36 -05007014lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05007015{
James Smart0976e1a2013-12-17 20:29:36 -05007016 LIST_HEAD(abort_list);
James Smart2e0fef82007-06-17 19:56:36 -05007017 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04007018 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05007019 struct lpfc_iocbq *tmp_iocb, *piocb;
7020 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05007021
7022 lpfc_fabric_abort_vport(vport);
James Smart0976e1a2013-12-17 20:29:36 -05007023 /*
7024 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
7025 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
7026 * ultimately grabs the ring_lock, the driver must splice the list into
7027 * a working list and release the locks before calling the abort.
7028 */
7029 spin_lock_irq(&phba->hbalock);
7030 if (phba->sli_rev == LPFC_SLI_REV4)
7031 spin_lock(&pring->ring_lock);
7032
7033 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7034 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
7035 continue;
7036
7037 if (piocb->vport != vport)
7038 continue;
7039 list_add_tail(&piocb->dlist, &abort_list);
7040 }
7041 if (phba->sli_rev == LPFC_SLI_REV4)
7042 spin_unlock(&pring->ring_lock);
7043 spin_unlock_irq(&phba->hbalock);
7044 /* Abort each iocb on the aborted list and remove the dlist links. */
7045 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7046 spin_lock_irq(&phba->hbalock);
7047 list_del_init(&piocb->dlist);
7048 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7049 spin_unlock_irq(&phba->hbalock);
7050 }
7051 if (!list_empty(&abort_list))
7052 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7053 "3387 abort list for txq not empty\n");
7054 INIT_LIST_HEAD(&abort_list);
dea31012005-04-17 16:05:31 -05007055
James Smart2e0fef82007-06-17 19:56:36 -05007056 spin_lock_irq(&phba->hbalock);
James Smart0976e1a2013-12-17 20:29:36 -05007057 if (phba->sli_rev == LPFC_SLI_REV4)
7058 spin_lock(&pring->ring_lock);
7059
dea31012005-04-17 16:05:31 -05007060 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
7061 cmd = &piocb->iocb;
7062
7063 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
7064 continue;
7065 }
7066
7067 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04007068 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
7069 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
7070 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
7071 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05007072 continue;
dea31012005-04-17 16:05:31 -05007073
James Smart2e0fef82007-06-17 19:56:36 -05007074 if (piocb->vport != vport)
7075 continue;
7076
James Smart0976e1a2013-12-17 20:29:36 -05007077 list_del_init(&piocb->list);
7078 list_add_tail(&piocb->list, &abort_list);
dea31012005-04-17 16:05:31 -05007079 }
James Smart0976e1a2013-12-17 20:29:36 -05007080 if (phba->sli_rev == LPFC_SLI_REV4)
7081 spin_unlock(&pring->ring_lock);
James Smart2e0fef82007-06-17 19:56:36 -05007082 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04007083
James Smarta257bf92009-04-06 18:48:10 -04007084 /* Cancell all the IOCBs from the completions list */
James Smart0976e1a2013-12-17 20:29:36 -05007085 lpfc_sli_cancel_iocbs(phba, &abort_list,
7086 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04007087
dea31012005-04-17 16:05:31 -05007088 return;
7089}
7090
James Smarte59058c2008-08-24 21:49:00 -04007091/**
James Smart3621a712009-04-06 18:47:14 -04007092 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04007093 * @phba: pointer to lpfc hba data structure.
7094 *
7095 * This routine is used to clean up all the outstanding ELS commands on a
7096 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
7097 * routine. After that, it walks the ELS transmit queue to remove all the
7098 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
7099 * the IOCBs with the completion callback function associated, the callback
7100 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7101 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
7102 * callback function associated, the IOCB will simply be released. Finally,
7103 * it walks the ELS transmit completion queue to issue an abort IOCB to any
7104 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
7105 * management plane IOCBs that are not part of the discovery state machine)
7106 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
7107 **/
James Smart549e55c2007-08-02 11:09:51 -04007108void
7109lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
7110{
James Smart0976e1a2013-12-17 20:29:36 -05007111 struct lpfc_vport *vport;
7112 list_for_each_entry(vport, &phba->port_list, listentry)
7113 lpfc_els_flush_cmd(vport);
James Smarta257bf92009-04-06 18:48:10 -04007114
James Smart549e55c2007-08-02 11:09:51 -04007115 return;
7116}
7117
James Smarte59058c2008-08-24 21:49:00 -04007118/**
James Smart3621a712009-04-06 18:47:14 -04007119 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04007120 * @phba: Pointer to hba context object.
7121 * @cmdiocbp: Pointer to command iocb which reported error.
7122 * @rspiocbp: Pointer to response iocb which reported error.
7123 *
7124 * This function sends an event when there is an ELS command
7125 * failure.
7126 **/
7127void
7128lpfc_send_els_failure_event(struct lpfc_hba *phba,
7129 struct lpfc_iocbq *cmdiocbp,
7130 struct lpfc_iocbq *rspiocbp)
7131{
7132 struct lpfc_vport *vport = cmdiocbp->vport;
7133 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7134 struct lpfc_lsrjt_event lsrjt_event;
7135 struct lpfc_fabric_event_header fabric_event;
7136 struct ls_rjt stat;
7137 struct lpfc_nodelist *ndlp;
7138 uint32_t *pcmd;
7139
7140 ndlp = cmdiocbp->context1;
7141 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7142 return;
7143
7144 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
7145 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
7146 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
7147 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
7148 sizeof(struct lpfc_name));
7149 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
7150 sizeof(struct lpfc_name));
7151 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
7152 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04007153 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04007154 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
7155 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
7156 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
7157 fc_host_post_vendor_event(shost,
7158 fc_get_event_number(),
7159 sizeof(lsrjt_event),
7160 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05007161 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04007162 return;
7163 }
7164 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
7165 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
7166 fabric_event.event_type = FC_REG_FABRIC_EVENT;
7167 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
7168 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
7169 else
7170 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
7171 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
7172 sizeof(struct lpfc_name));
7173 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
7174 sizeof(struct lpfc_name));
7175 fc_host_post_vendor_event(shost,
7176 fc_get_event_number(),
7177 sizeof(fabric_event),
7178 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05007179 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04007180 return;
7181 }
7182
7183}
7184
7185/**
James Smart3621a712009-04-06 18:47:14 -04007186 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04007187 * @vport: Pointer to vport object.
7188 * @ndlp: Pointer FC node object.
7189 * @cmd: ELS command code.
7190 *
7191 * This function posts an event when there is an incoming
7192 * unsolicited ELS command.
7193 **/
7194static void
7195lpfc_send_els_event(struct lpfc_vport *vport,
7196 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05007197 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04007198{
James Smartddcc50f2008-12-04 22:38:46 -05007199 struct lpfc_els_event_header *els_data = NULL;
7200 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04007201 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7202
James Smartddcc50f2008-12-04 22:38:46 -05007203 if (*payload == ELS_CMD_LOGO) {
7204 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
7205 if (!logo_data) {
7206 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7207 "0148 Failed to allocate memory "
7208 "for LOGO event\n");
7209 return;
7210 }
7211 els_data = &logo_data->header;
7212 } else {
7213 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
7214 GFP_KERNEL);
7215 if (!els_data) {
7216 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7217 "0149 Failed to allocate memory "
7218 "for ELS event\n");
7219 return;
7220 }
7221 }
7222 els_data->event_type = FC_REG_ELS_EVENT;
7223 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04007224 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05007225 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04007226 break;
7227 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05007228 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04007229 break;
7230 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05007231 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
7232 break;
7233 case ELS_CMD_LOGO:
7234 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
7235 /* Copy the WWPN in the LOGO payload */
7236 memcpy(logo_data->logo_wwpn, &payload[2],
7237 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04007238 break;
7239 default:
Julia Lawalle9161412009-02-08 22:43:19 +01007240 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04007241 return;
7242 }
James Smartddcc50f2008-12-04 22:38:46 -05007243 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
7244 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
7245 if (*payload == ELS_CMD_LOGO) {
7246 fc_host_post_vendor_event(shost,
7247 fc_get_event_number(),
7248 sizeof(struct lpfc_logo_event),
7249 (char *)logo_data,
7250 LPFC_NL_VENDOR_ID);
7251 kfree(logo_data);
7252 } else {
7253 fc_host_post_vendor_event(shost,
7254 fc_get_event_number(),
7255 sizeof(struct lpfc_els_event_header),
7256 (char *)els_data,
7257 LPFC_NL_VENDOR_ID);
7258 kfree(els_data);
7259 }
James Smartea2151b2008-09-07 11:52:10 -04007260
7261 return;
7262}
7263
7264
7265/**
James Smart3621a712009-04-06 18:47:14 -04007266 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04007267 * @phba: pointer to lpfc hba data structure.
7268 * @pring: pointer to a SLI ring.
7269 * @vport: pointer to a host virtual N_Port data structure.
7270 * @elsiocb: pointer to lpfc els command iocb data structure.
7271 *
7272 * This routine is used for processing the IOCB associated with a unsolicited
7273 * event. It first determines whether there is an existing ndlp that matches
7274 * the DID from the unsolicited IOCB. If not, it will create a new one with
7275 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
7276 * IOCB is then used to invoke the proper routine and to set up proper state
7277 * of the discovery state machine.
7278 **/
James Smarted957682007-06-17 19:56:37 -05007279static void
7280lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05007281 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05007282{
James Smart87af33f2007-10-27 13:37:43 -04007283 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05007284 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05007285 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05007286 uint32_t *payload;
James Smart303f2f92013-01-03 15:43:11 -05007287 uint32_t cmd, did, newnode;
7288 uint8_t rjt_exp, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05007289 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05007290
James Smarte47c9092008-02-08 18:49:26 -05007291 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05007292 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05007293
dea31012005-04-17 16:05:31 -05007294 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007295 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
7296 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05007297 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04007298 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05007299
James Smart858c9f62007-06-17 19:56:39 -05007300 did = icmd->un.rcvels.remoteID;
7301 if (icmd->ulpStatus) {
7302 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7303 "RCV Unsol ELS: status:x%x/x%x did:x%x",
7304 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05007305 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05007306 }
dea31012005-04-17 16:05:31 -05007307
7308 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05007309 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05007310 goto dropit;
dea31012005-04-17 16:05:31 -05007311
James Smartc8685952009-11-18 15:39:16 -05007312 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05007313 if (vport->load_flag & FC_UNLOADING)
7314 goto dropit;
7315
James Smart92494142011-02-16 12:39:44 -05007316 /* If NPort discovery is delayed drop incoming ELS */
7317 if ((vport->fc_flag & FC_DISC_DELAYED) &&
7318 (cmd != ELS_CMD_PLOGI))
7319 goto dropit;
7320
James Smart2e0fef82007-06-17 19:56:36 -05007321 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007322 if (!ndlp) {
dea31012005-04-17 16:05:31 -05007323 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007324 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05007325 if (!ndlp)
dea31012005-04-17 16:05:31 -05007326 goto dropit;
dea31012005-04-17 16:05:31 -05007327
James Smart2e0fef82007-06-17 19:56:36 -05007328 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04007329 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05007330 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05007331 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05007332 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04007333 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7334 ndlp = lpfc_enable_node(vport, ndlp,
7335 NLP_STE_UNUSED_NODE);
7336 if (!ndlp)
7337 goto dropit;
7338 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7339 newnode = 1;
7340 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7341 ndlp->nlp_type |= NLP_FABRIC;
7342 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
7343 /* This is similar to the new node path */
7344 ndlp = lpfc_nlp_get(ndlp);
7345 if (!ndlp)
7346 goto dropit;
7347 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7348 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04007349 }
dea31012005-04-17 16:05:31 -05007350
7351 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05007352
James Smart12838e72014-09-03 12:57:19 -04007353 /*
7354 * Do not process any unsolicited ELS commands
7355 * if the ndlp is in DEV_LOSS
7356 */
James Smart466e8402015-05-21 13:55:28 -04007357 shost = lpfc_shost_from_vport(vport);
7358 spin_lock_irq(shost->host_lock);
7359 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
7360 spin_unlock_irq(shost->host_lock);
James Smart12838e72014-09-03 12:57:19 -04007361 goto dropit;
James Smart466e8402015-05-21 13:55:28 -04007362 }
7363 spin_unlock_irq(shost->host_lock);
James Smart12838e72014-09-03 12:57:19 -04007364
James Smart329f9bc2007-04-25 09:53:01 -04007365 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05007366 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05007367
7368 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
7369 cmd &= ELS_CMD_MASK;
7370 }
7371 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04007372 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7373 "0112 ELS command x%x received from NPORT x%x "
James Smarte74c03c2013-04-17 20:15:19 -04007374 "Data: x%x x%x x%x x%x\n",
7375 cmd, did, vport->port_state, vport->fc_flag,
7376 vport->fc_myDID, vport->fc_prevDID);
dea31012005-04-17 16:05:31 -05007377 switch (cmd) {
7378 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05007379 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7380 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
7381 did, vport->port_state, ndlp->nlp_flag);
7382
dea31012005-04-17 16:05:31 -05007383 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05007384 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
James Smarte74c03c2013-04-17 20:15:19 -04007385 if (phba->sli_rev == LPFC_SLI_REV4 &&
7386 (phba->pport->fc_flag & FC_PT2PT)) {
7387 vport->fc_prevDID = vport->fc_myDID;
7388 /* Our DID needs to be updated before registering
7389 * the vfi. This is done in lpfc_rcv_plogi but
7390 * that is called after the reg_vfi.
7391 */
7392 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
7393 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7394 "3312 Remote port assigned DID x%x "
7395 "%x\n", vport->fc_myDID,
7396 vport->fc_prevDID);
7397 }
James Smart858c9f62007-06-17 19:56:39 -05007398
James Smartddcc50f2008-12-04 22:38:46 -05007399 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05007400
7401 /* If Nport discovery is delayed, reject PLOGIs */
7402 if (vport->fc_flag & FC_DISC_DELAYED) {
7403 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007404 rjt_exp = LSEXP_NOTHING_MORE;
James Smart92494142011-02-16 12:39:44 -05007405 break;
7406 }
James Smart858c9f62007-06-17 19:56:39 -05007407 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05007408 if (!(phba->pport->fc_flag & FC_PT2PT) ||
7409 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
7410 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007411 rjt_exp = LSEXP_NOTHING_MORE;
James Smart1b32f6a2008-02-08 18:49:39 -05007412 break;
7413 }
7414 /* We get here, and drop thru, if we are PT2PT with
7415 * another NPort and the other side has initiated
7416 * the PLOGI before responding to our FLOGI.
7417 */
James Smarte74c03c2013-04-17 20:15:19 -04007418 if (phba->sli_rev == LPFC_SLI_REV4 &&
7419 (phba->fc_topology_changed ||
7420 vport->fc_myDID != vport->fc_prevDID)) {
7421 lpfc_unregister_fcf_prep(phba);
7422 spin_lock_irq(shost->host_lock);
7423 vport->fc_flag &= ~FC_VFI_REGISTERED;
7424 spin_unlock_irq(shost->host_lock);
7425 phba->fc_topology_changed = 0;
7426 lpfc_issue_reg_vfi(vport);
7427 }
dea31012005-04-17 16:05:31 -05007428 }
James Smart87af33f2007-10-27 13:37:43 -04007429
James Smart87af33f2007-10-27 13:37:43 -04007430 spin_lock_irq(shost->host_lock);
7431 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
7432 spin_unlock_irq(shost->host_lock);
7433
James Smart2e0fef82007-06-17 19:56:36 -05007434 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7435 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05007436
dea31012005-04-17 16:05:31 -05007437 break;
7438 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05007439 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7440 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
7441 did, vport->port_state, ndlp->nlp_flag);
7442
dea31012005-04-17 16:05:31 -05007443 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04007444 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007445 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007446 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05007447 break;
7448 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05007449 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7450 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
7451 did, vport->port_state, ndlp->nlp_flag);
7452
dea31012005-04-17 16:05:31 -05007453 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05007454 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05007455 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007456 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007457 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007458 break;
7459 }
James Smart2e0fef82007-06-17 19:56:36 -05007460 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05007461 break;
7462 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05007463 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7464 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
7465 did, vport->port_state, ndlp->nlp_flag);
7466
dea31012005-04-17 16:05:31 -05007467 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05007468 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05007469 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007470 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007471 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007472 break;
7473 }
James Smart2e0fef82007-06-17 19:56:36 -05007474 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05007475 break;
James Smart8b017a32015-05-21 13:55:18 -04007476 case ELS_CMD_LCB:
7477 phba->fc_stat.elsRcvLCB++;
7478 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
7479 break;
James Smart86478872015-05-21 13:55:21 -04007480 case ELS_CMD_RDP:
7481 phba->fc_stat.elsRcvRDP++;
7482 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
7483 break;
dea31012005-04-17 16:05:31 -05007484 case ELS_CMD_RSCN:
7485 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04007486 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007487 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007488 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05007489 break;
7490 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05007491 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7492 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
7493 did, vport->port_state, ndlp->nlp_flag);
7494
James Smartddcc50f2008-12-04 22:38:46 -05007495 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05007496 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05007497 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007498 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007499 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007500 break;
7501 }
James Smart2e0fef82007-06-17 19:56:36 -05007502 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7503 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05007504 break;
7505 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05007506 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7507 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
7508 did, vport->port_state, ndlp->nlp_flag);
7509
dea31012005-04-17 16:05:31 -05007510 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05007511 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007512 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007513 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007514 break;
7515 }
James Smart2e0fef82007-06-17 19:56:36 -05007516 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7517 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05007518 break;
7519 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05007520 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7521 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
7522 did, vport->port_state, ndlp->nlp_flag);
7523
dea31012005-04-17 16:05:31 -05007524 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05007525 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05007526 break;
7527 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05007528 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7529 "RCV FARP: did:x%x/ste:x%x flg:x%x",
7530 did, vport->port_state, ndlp->nlp_flag);
7531
dea31012005-04-17 16:05:31 -05007532 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05007533 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05007534 break;
7535 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05007536 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7537 "RCV FAN: did:x%x/ste:x%x flg:x%x",
7538 did, vport->port_state, ndlp->nlp_flag);
7539
dea31012005-04-17 16:05:31 -05007540 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05007541 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05007542 break;
dea31012005-04-17 16:05:31 -05007543 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05007544 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7545 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
7546 did, vport->port_state, ndlp->nlp_flag);
7547
dea31012005-04-17 16:05:31 -05007548 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05007549 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007550 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007551 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007552 break;
7553 }
James Smart2e0fef82007-06-17 19:56:36 -05007554 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05007555 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007556 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05007557 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7558 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
7559 did, vport->port_state, ndlp->nlp_flag);
7560
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007561 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05007562 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007563 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007564 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007565 break;
James Smart12265f62010-10-22 11:05:53 -04007566 case ELS_CMD_RLS:
7567 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7568 "RCV RLS: did:x%x/ste:x%x flg:x%x",
7569 did, vport->port_state, ndlp->nlp_flag);
7570
7571 phba->fc_stat.elsRcvRLS++;
7572 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
7573 if (newnode)
7574 lpfc_nlp_put(ndlp);
7575 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007576 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05007577 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7578 "RCV RPS: did:x%x/ste:x%x flg:x%x",
7579 did, vport->port_state, ndlp->nlp_flag);
7580
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007581 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05007582 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007583 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007584 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007585 break;
7586 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05007587 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7588 "RCV RPL: did:x%x/ste:x%x flg:x%x",
7589 did, vport->port_state, ndlp->nlp_flag);
7590
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007591 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05007592 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007593 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007594 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007595 break;
dea31012005-04-17 16:05:31 -05007596 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05007597 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7598 "RCV RNID: did:x%x/ste:x%x flg:x%x",
7599 did, vport->port_state, ndlp->nlp_flag);
7600
dea31012005-04-17 16:05:31 -05007601 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05007602 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007603 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007604 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05007605 break;
James Smart12265f62010-10-22 11:05:53 -04007606 case ELS_CMD_RTV:
7607 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7608 "RCV RTV: did:x%x/ste:x%x flg:x%x",
7609 did, vport->port_state, ndlp->nlp_flag);
7610 phba->fc_stat.elsRcvRTV++;
7611 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
7612 if (newnode)
7613 lpfc_nlp_put(ndlp);
7614 break;
James Smart5ffc2662009-11-18 15:39:44 -05007615 case ELS_CMD_RRQ:
7616 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7617 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
7618 did, vport->port_state, ndlp->nlp_flag);
7619
7620 phba->fc_stat.elsRcvRRQ++;
7621 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
7622 if (newnode)
7623 lpfc_nlp_put(ndlp);
7624 break;
James Smart12265f62010-10-22 11:05:53 -04007625 case ELS_CMD_ECHO:
7626 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7627 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
7628 did, vport->port_state, ndlp->nlp_flag);
7629
7630 phba->fc_stat.elsRcvECHO++;
7631 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
7632 if (newnode)
7633 lpfc_nlp_put(ndlp);
7634 break;
James Smart303f2f92013-01-03 15:43:11 -05007635 case ELS_CMD_REC:
7636 /* receive this due to exchange closed */
7637 rjt_err = LSRJT_UNABLE_TPC;
7638 rjt_exp = LSEXP_INVALID_OX_RX;
7639 break;
dea31012005-04-17 16:05:31 -05007640 default:
James Smart858c9f62007-06-17 19:56:39 -05007641 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7642 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
7643 cmd, did, vport->port_state);
7644
dea31012005-04-17 16:05:31 -05007645 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05007646 rjt_err = LSRJT_CMD_UNSUPPORTED;
James Smart303f2f92013-01-03 15:43:11 -05007647 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007648
7649 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04007650 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7651 "0115 Unknown ELS command x%x "
7652 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04007653 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007654 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05007655 break;
7656 }
7657
7658 /* check if need to LS_RJT received ELS cmd */
7659 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05007660 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05007661 stat.un.b.lsRjtRsnCode = rjt_err;
James Smart303f2f92013-01-03 15:43:11 -05007662 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
James Smart858c9f62007-06-17 19:56:39 -05007663 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
7664 NULL);
dea31012005-04-17 16:05:31 -05007665 }
7666
James Smartd7c255b2008-08-24 21:50:00 -04007667 lpfc_nlp_put(elsiocb->context1);
7668 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05007669 return;
7670
7671dropit:
James Smart98c9ea52007-10-27 13:37:33 -04007672 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04007673 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7674 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05007675 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04007676 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05007677 phba->fc_stat.elsRcvDrop++;
7678}
7679
James Smarte59058c2008-08-24 21:49:00 -04007680/**
James Smart3621a712009-04-06 18:47:14 -04007681 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04007682 * @phba: pointer to lpfc hba data structure.
7683 * @pring: pointer to a SLI ring.
7684 * @elsiocb: pointer to lpfc els iocb data structure.
7685 *
7686 * This routine is used to process an unsolicited event received from a SLI
7687 * (Service Level Interface) ring. The actual processing of the data buffer
7688 * associated with the unsolicited event is done by invoking the routine
7689 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
7690 * SLI ring on which the unsolicited event was received.
7691 **/
James Smarted957682007-06-17 19:56:37 -05007692void
7693lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7694 struct lpfc_iocbq *elsiocb)
7695{
7696 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05007697 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05007698 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05007699 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
7700 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05007701
James Smartd7c255b2008-08-24 21:50:00 -04007702 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05007703 elsiocb->context2 = NULL;
7704 elsiocb->context3 = NULL;
7705
7706 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
7707 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
7708 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
James Smarte3d2b802012-08-14 14:25:43 -04007709 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
7710 IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05007711 phba->fc_stat.NoRcvBuf++;
7712 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05007713 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04007714 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05007715 return;
7716 }
7717
James Smart92d7f7b2007-06-17 19:56:38 -05007718 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
7719 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
7720 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
7721 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
7722 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04007723 else
7724 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04007725 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05007726 }
James Smart6d368e52011-05-24 11:44:12 -04007727
James Smart7f5f3d02008-02-08 18:50:14 -05007728 /* If there are no BDEs associated
7729 * with this IOCB, there is nothing to do.
7730 */
James Smarted957682007-06-17 19:56:37 -05007731 if (icmd->ulpBdeCount == 0)
7732 return;
7733
James Smart7f5f3d02008-02-08 18:50:14 -05007734 /* type of ELS cmd is first 32bit word
7735 * in packet
7736 */
James Smarted957682007-06-17 19:56:37 -05007737 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05007738 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05007739 } else {
7740 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
7741 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05007742 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
7743 paddr);
James Smarted957682007-06-17 19:56:37 -05007744 }
7745
James Smart92d7f7b2007-06-17 19:56:38 -05007746 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
7747 /*
7748 * The different unsolicited event handlers would tell us
7749 * if they are done with "mp" by setting context2 to NULL.
7750 */
dea31012005-04-17 16:05:31 -05007751 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05007752 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
7753 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05007754 }
James Smarted957682007-06-17 19:56:37 -05007755
7756 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05007757 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05007758 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05007759 elsiocb->context2 = bdeBuf2;
7760 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05007761 /* free mp if we are done with it */
7762 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05007763 lpfc_in_buf_free(phba, elsiocb->context2);
7764 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05007765 }
dea31012005-04-17 16:05:31 -05007766 }
dea31012005-04-17 16:05:31 -05007767}
James Smart92d7f7b2007-06-17 19:56:38 -05007768
James Smarte59058c2008-08-24 21:49:00 -04007769/**
James Smart3621a712009-04-06 18:47:14 -04007770 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04007771 * @phba: pointer to lpfc hba data structure.
7772 * @vport: pointer to a virtual N_Port data structure.
7773 *
7774 * This routine issues a Port Login (PLOGI) to the Name Server with
7775 * State Change Request (SCR) for a @vport. This routine will create an
7776 * ndlp for the Name Server associated to the @vport if such node does
7777 * not already exist. The PLOGI to Name Server is issued by invoking the
7778 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
7779 * (FDMI) is configured to the @vport, a FDMI node will be created and
7780 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
7781 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007782void
7783lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
7784{
7785 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
James Smart92494142011-02-16 12:39:44 -05007786 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7787
7788 /*
7789 * If lpfc_delay_discovery parameter is set and the clean address
7790 * bit is cleared and fc fabric parameters chenged, delay FC NPort
7791 * discovery.
7792 */
7793 spin_lock_irq(shost->host_lock);
7794 if (vport->fc_flag & FC_DISC_DELAYED) {
7795 spin_unlock_irq(shost->host_lock);
James Smart18775702013-04-17 20:19:25 -04007796 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
7797 "3334 Delay fc port discovery for %d seconds\n",
7798 phba->fc_ratov);
James Smart92494142011-02-16 12:39:44 -05007799 mod_timer(&vport->delayed_disc_tmo,
James Smart256ec0d2013-04-17 20:14:58 -04007800 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
James Smart92494142011-02-16 12:39:44 -05007801 return;
7802 }
7803 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007804
7805 ndlp = lpfc_findnode_did(vport, NameServer_DID);
7806 if (!ndlp) {
7807 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
7808 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05007809 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05007810 lpfc_disc_start(vport);
7811 return;
7812 }
7813 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007814 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7815 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007816 return;
7817 }
7818 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05007819 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7820 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
7821 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05007822 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05007823 lpfc_disc_start(vport);
7824 return;
7825 }
7826 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7827 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7828 "0348 NameServer login: node freed\n");
7829 return;
7830 }
James Smart92d7f7b2007-06-17 19:56:38 -05007831 }
James Smart58da1ff2008-04-07 10:15:56 -04007832 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05007833
7834 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
7835
7836 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
7837 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007838 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7839 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007840 return;
7841 }
7842
James Smart76b2c342015-04-07 15:07:19 -04007843 if (vport->cfg_fdmi_on & LPFC_FDMI_SUPPORT) {
James Smart63e801c2010-11-20 23:14:19 -05007844 /* If this is the first time, allocate an ndlp and initialize
7845 * it. Otherwise, make sure the node is enabled and then do the
7846 * login.
7847 */
7848 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
7849 if (!ndlp_fdmi) {
7850 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
7851 GFP_KERNEL);
7852 if (ndlp_fdmi) {
7853 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
7854 ndlp_fdmi->nlp_type |= NLP_FABRIC;
7855 } else
7856 return;
7857 }
7858 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
7859 ndlp_fdmi = lpfc_enable_node(vport,
7860 ndlp_fdmi,
7861 NLP_STE_NPR_NODE);
7862
James Smart92d7f7b2007-06-17 19:56:38 -05007863 if (ndlp_fdmi) {
James Smart58da1ff2008-04-07 10:15:56 -04007864 lpfc_nlp_set_state(vport, ndlp_fdmi,
James Smart63e801c2010-11-20 23:14:19 -05007865 NLP_STE_PLOGI_ISSUE);
7866 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007867 }
7868 }
James Smart92d7f7b2007-06-17 19:56:38 -05007869}
7870
James Smarte59058c2008-08-24 21:49:00 -04007871/**
James Smart3621a712009-04-06 18:47:14 -04007872 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04007873 * @phba: pointer to lpfc hba data structure.
7874 * @pmb: pointer to the driver internal queue element for mailbox command.
7875 *
7876 * This routine is the completion callback function to register new vport
7877 * mailbox command. If the new vport mailbox command completes successfully,
7878 * the fabric registration login shall be performed on physical port (the
7879 * new vport created is actually a physical port, with VPI 0) or the port
7880 * login to Name Server for State Change Request (SCR) will be performed
7881 * on virtual port (real virtual port, with VPI greater than 0).
7882 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007883static void
7884lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7885{
7886 struct lpfc_vport *vport = pmb->vport;
7887 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7888 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04007889 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05007890 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007891
James Smart09372822008-01-11 01:52:54 -05007892 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007893 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05007894 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007895
7896 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04007897 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04007898 "0915 Register VPI failed : Status: x%x"
7899 " upd bit: x%x \n", mb->mbxStatus,
7900 mb->un.varRegVpi.upd);
7901 if (phba->sli_rev == LPFC_SLI_REV4 &&
7902 mb->un.varRegVpi.upd)
7903 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05007904
7905 switch (mb->mbxStatus) {
7906 case 0x11: /* unsupported feature */
7907 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05007908 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05007909 /* giving up on vport registration */
7910 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7911 spin_lock_irq(shost->host_lock);
7912 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
7913 spin_unlock_irq(shost->host_lock);
7914 lpfc_can_disctmo(vport);
7915 break;
James Smart695a8142010-01-26 23:08:03 -05007916 /* If reg_vpi fail with invalid VPI status, re-init VPI */
7917 case 0x20:
7918 spin_lock_irq(shost->host_lock);
7919 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
7920 spin_unlock_irq(shost->host_lock);
7921 lpfc_init_vpi(phba, pmb, vport->vpi);
7922 pmb->vport = vport;
7923 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
7924 rc = lpfc_sli_issue_mbox(phba, pmb,
7925 MBX_NOWAIT);
7926 if (rc == MBX_NOT_FINISHED) {
7927 lpfc_printf_vlog(vport,
7928 KERN_ERR, LOG_MBOX,
7929 "2732 Failed to issue INIT_VPI"
7930 " mailbox command\n");
7931 } else {
7932 lpfc_nlp_put(ndlp);
7933 return;
7934 }
7935
James Smart92d7f7b2007-06-17 19:56:38 -05007936 default:
7937 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04007938 if (phba->sli_rev == LPFC_SLI_REV4)
7939 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007940 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05007941 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007942 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05007943 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04007944 if (vport->port_type == LPFC_PHYSICAL_PORT
7945 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart76a95d72010-11-20 23:11:48 -05007946 lpfc_issue_init_vfi(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05007947 else
7948 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007949 break;
7950 }
James Smart92d7f7b2007-06-17 19:56:38 -05007951 } else {
James Smart695a8142010-01-26 23:08:03 -05007952 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05007953 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05007954 spin_unlock_irq(shost->host_lock);
7955 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04007956 if (phba->sli_rev < LPFC_SLI_REV4)
7957 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05007958 else {
James Smartfc2b9892010-02-26 14:15:29 -05007959 /*
7960 * If the physical port is instantiated using
7961 * FDISC, do not start vport discovery.
7962 */
7963 if (vport->port_state != LPFC_FDISC)
7964 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05007965 lpfc_do_scr_ns_plogi(phba, vport);
7966 }
7967 } else
James Smart92d7f7b2007-06-17 19:56:38 -05007968 lpfc_do_scr_ns_plogi(phba, vport);
7969 }
James Smart38b92ef2010-08-04 16:11:39 -04007970mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05007971 /* Now, we decrement the ndlp reference count held for this
7972 * callback function
7973 */
7974 lpfc_nlp_put(ndlp);
7975
James Smart92d7f7b2007-06-17 19:56:38 -05007976 mempool_free(pmb, phba->mbox_mem_pool);
7977 return;
7978}
7979
James Smarte59058c2008-08-24 21:49:00 -04007980/**
James Smart3621a712009-04-06 18:47:14 -04007981 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04007982 * @phba: pointer to lpfc hba data structure.
7983 * @vport: pointer to a host virtual N_Port data structure.
7984 * @ndlp: pointer to a node-list data structure.
7985 *
7986 * This routine registers the @vport as a new virtual port with a HBA.
7987 * It is done through a registering vpi mailbox command.
7988 **/
James Smart695a8142010-01-26 23:08:03 -05007989void
James Smart92d7f7b2007-06-17 19:56:38 -05007990lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
7991 struct lpfc_nodelist *ndlp)
7992{
James Smart09372822008-01-11 01:52:54 -05007993 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007994 LPFC_MBOXQ_t *mbox;
7995
7996 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7997 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04007998 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05007999 mbox->vport = vport;
8000 mbox->context2 = lpfc_nlp_get(ndlp);
8001 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04008002 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05008003 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05008004 /* mailbox command not success, decrement ndlp
8005 * reference count for this command
8006 */
8007 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05008008 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05008009
James Smarte8b62012007-08-02 11:10:09 -04008010 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8011 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05008012 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05008013 }
8014 } else {
James Smarte8b62012007-08-02 11:10:09 -04008015 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8016 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05008017 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05008018 }
James Smartfa4066b2008-01-11 01:53:27 -05008019 return;
8020
8021mbox_err_exit:
8022 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8023 spin_lock_irq(shost->host_lock);
8024 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
8025 spin_unlock_irq(shost->host_lock);
8026 return;
James Smart92d7f7b2007-06-17 19:56:38 -05008027}
8028
James Smarte59058c2008-08-24 21:49:00 -04008029/**
James Smart0c9ab6f2010-02-26 14:15:57 -05008030 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05008031 * @phba: pointer to lpfc hba data structure.
8032 *
James Smart0c9ab6f2010-02-26 14:15:57 -05008033 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05008034 **/
8035void
James Smart0c9ab6f2010-02-26 14:15:57 -05008036lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05008037{
8038 struct lpfc_vport **vports;
8039 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05008040 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05008041 int i;
James Smart695a8142010-01-26 23:08:03 -05008042
8043 /* Treat this failure as linkdown for all vports */
8044 link_state = phba->link_state;
8045 lpfc_linkdown(phba);
8046 phba->link_state = link_state;
8047
8048 vports = lpfc_create_vport_work_array(phba);
8049
8050 if (vports) {
8051 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
8052 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
8053 if (ndlp)
8054 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
8055 lpfc_els_flush_cmd(vports[i]);
8056 }
8057 lpfc_destroy_vport_work_array(phba, vports);
8058 }
James Smart0c9ab6f2010-02-26 14:15:57 -05008059}
8060
8061/**
8062 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
8063 * @phba: pointer to lpfc hba data structure.
8064 *
8065 * This routine abort all pending discovery commands and
8066 * start a timer to retry FLOGI for the physical port
8067 * discovery.
8068 **/
8069void
8070lpfc_retry_pport_discovery(struct lpfc_hba *phba)
8071{
8072 struct lpfc_nodelist *ndlp;
8073 struct Scsi_Host *shost;
8074
8075 /* Cancel the all vports retry delay retry timers */
8076 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05008077
8078 /* If fabric require FLOGI, then re-instantiate physical login */
8079 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
8080 if (!ndlp)
8081 return;
8082
James Smart695a8142010-01-26 23:08:03 -05008083 shost = lpfc_shost_from_vport(phba->pport);
James Smart256ec0d2013-04-17 20:14:58 -04008084 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
James Smart695a8142010-01-26 23:08:03 -05008085 spin_lock_irq(shost->host_lock);
8086 ndlp->nlp_flag |= NLP_DELAY_TMO;
8087 spin_unlock_irq(shost->host_lock);
8088 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
8089 phba->pport->port_state = LPFC_FLOGI;
8090 return;
8091}
8092
8093/**
8094 * lpfc_fabric_login_reqd - Check if FLOGI required.
8095 * @phba: pointer to lpfc hba data structure.
8096 * @cmdiocb: pointer to FDISC command iocb.
8097 * @rspiocb: pointer to FDISC response iocb.
8098 *
8099 * This routine checks if a FLOGI is reguired for FDISC
8100 * to succeed.
8101 **/
8102static int
8103lpfc_fabric_login_reqd(struct lpfc_hba *phba,
8104 struct lpfc_iocbq *cmdiocb,
8105 struct lpfc_iocbq *rspiocb)
8106{
8107
8108 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
8109 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
8110 return 0;
8111 else
8112 return 1;
8113}
8114
8115/**
James Smart3621a712009-04-06 18:47:14 -04008116 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04008117 * @phba: pointer to lpfc hba data structure.
8118 * @cmdiocb: pointer to lpfc command iocb data structure.
8119 * @rspiocb: pointer to lpfc response iocb data structure.
8120 *
8121 * This routine is the completion callback function to a Fabric Discover
8122 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
8123 * single threaded, each FDISC completion callback function will reset
8124 * the discovery timer for all vports such that the timers will not get
8125 * unnecessary timeout. The function checks the FDISC IOCB status. If error
8126 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
8127 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
8128 * assigned to the vport has been changed with the completion of the FDISC
8129 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
8130 * are unregistered from the HBA, and then the lpfc_register_new_vport()
8131 * routine is invoked to register new vport with the HBA. Otherwise, the
8132 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
8133 * Server for State Change Request (SCR).
8134 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008135static void
8136lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8137 struct lpfc_iocbq *rspiocb)
8138{
8139 struct lpfc_vport *vport = cmdiocb->vport;
8140 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8141 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
8142 struct lpfc_nodelist *np;
8143 struct lpfc_nodelist *next_np;
8144 IOCB_t *irsp = &rspiocb->iocb;
8145 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05008146 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
8147 struct serv_parm *sp;
8148 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05008149
James Smarte8b62012007-08-02 11:10:09 -04008150 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8151 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
8152 irsp->ulpStatus, irsp->un.ulpWord[4],
8153 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05008154 /* Since all FDISCs are being single threaded, we
8155 * must reset the discovery timer for ALL vports
8156 * waiting to send FDISC when one completes.
8157 */
8158 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
8159 lpfc_set_disctmo(piocb->vport);
8160 }
8161
James Smart858c9f62007-06-17 19:56:39 -05008162 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8163 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
8164 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
8165
James Smart92d7f7b2007-06-17 19:56:38 -05008166 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05008167
8168 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
8169 lpfc_retry_pport_discovery(phba);
8170 goto out;
8171 }
8172
James Smart92d7f7b2007-06-17 19:56:38 -05008173 /* Check for retry */
8174 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
8175 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05008176 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04008177 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart6b5151f2012-01-18 16:24:06 -05008178 "0126 FDISC failed. (x%x/x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04008179 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04008180 goto fdisc_failed;
8181 }
James Smartd7c255b2008-08-24 21:50:00 -04008182 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05008183 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04008184 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04008185 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05008186 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04008187 vport->fc_flag |= FC_PUBLIC_LOOP;
8188 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008189
James Smartd7c255b2008-08-24 21:50:00 -04008190 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
8191 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05008192 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04008193 if (!prsp)
8194 goto out;
James Smart92494142011-02-16 12:39:44 -05008195 sp = prsp->virt + sizeof(uint32_t);
8196 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
8197 memcpy(&vport->fabric_portname, &sp->portName,
8198 sizeof(struct lpfc_name));
8199 memcpy(&vport->fabric_nodename, &sp->nodeName,
8200 sizeof(struct lpfc_name));
8201 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04008202 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8203 /* If our NportID changed, we need to ensure all
8204 * remaining NPORTs get unreg_login'ed so we can
8205 * issue unreg_vpi.
8206 */
8207 list_for_each_entry_safe(np, next_np,
8208 &vport->fc_nodes, nlp_listp) {
8209 if (!NLP_CHK_NODE_ACT(ndlp) ||
8210 (np->nlp_state != NLP_STE_NPR_NODE) ||
8211 !(np->nlp_flag & NLP_NPR_ADISC))
8212 continue;
James Smart09372822008-01-11 01:52:54 -05008213 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04008214 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05008215 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04008216 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05008217 }
James Smart78730cf2010-04-06 15:06:30 -04008218 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04008219
8220 if (phba->sli_rev == LPFC_SLI_REV4)
8221 lpfc_sli4_unreg_all_rpis(vport);
8222
James Smartd7c255b2008-08-24 21:50:00 -04008223 lpfc_mbx_unreg_vpi(vport);
8224 spin_lock_irq(shost->host_lock);
8225 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05008226 if (phba->sli_rev == LPFC_SLI_REV4)
8227 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04008228 else
8229 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04008230 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04008231 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
8232 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8233 /*
8234 * Driver needs to re-reg VPI in order for f/w
8235 * to update the MAC address.
8236 */
8237 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04008238 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05008239 }
8240
James Smartecfd03c2010-02-12 14:41:27 -05008241 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
8242 lpfc_issue_init_vpi(vport);
8243 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04008244 lpfc_register_new_vport(phba, vport, ndlp);
8245 else
8246 lpfc_do_scr_ns_plogi(phba, vport);
8247 goto out;
8248fdisc_failed:
James Smartc84163d2015-05-21 13:55:22 -04008249 if (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS)
8250 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smartd7c255b2008-08-24 21:50:00 -04008251 /* Cancel discovery timer */
8252 lpfc_can_disctmo(vport);
8253 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05008254out:
8255 lpfc_els_free_iocb(phba, cmdiocb);
8256}
8257
James Smarte59058c2008-08-24 21:49:00 -04008258/**
James Smart3621a712009-04-06 18:47:14 -04008259 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04008260 * @vport: pointer to a virtual N_Port data structure.
8261 * @ndlp: pointer to a node-list data structure.
8262 * @retry: number of retries to the command IOCB.
8263 *
8264 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
8265 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
8266 * routine to issue the IOCB, which makes sure only one outstanding fabric
8267 * IOCB will be sent off HBA at any given time.
8268 *
8269 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8270 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8271 * will be stored into the context1 field of the IOCB for the completion
8272 * callback function to the FDISC ELS command.
8273 *
8274 * Return code
8275 * 0 - Successfully issued fdisc iocb command
8276 * 1 - Failed to issue fdisc iocb command
8277 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01008278static int
James Smart92d7f7b2007-06-17 19:56:38 -05008279lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
8280 uint8_t retry)
8281{
8282 struct lpfc_hba *phba = vport->phba;
8283 IOCB_t *icmd;
8284 struct lpfc_iocbq *elsiocb;
8285 struct serv_parm *sp;
8286 uint8_t *pcmd;
8287 uint16_t cmdsize;
8288 int did = ndlp->nlp_DID;
8289 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05008290
James Smart5ffc2662009-11-18 15:39:44 -05008291 vport->port_state = LPFC_FDISC;
James Smart6b5151f2012-01-18 16:24:06 -05008292 vport->fc_myDID = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05008293 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
8294 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
8295 ELS_CMD_FDISC);
8296 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05008297 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04008298 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8299 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05008300 return 1;
8301 }
8302
8303 icmd = &elsiocb->iocb;
8304 icmd->un.elsreq64.myID = 0;
8305 icmd->un.elsreq64.fl = 1;
8306
James Smart73d91e52011-10-10 21:32:10 -04008307 /*
8308 * SLI3 ports require a different context type value than SLI4.
8309 * Catch SLI3 ports here and override the prep.
8310 */
8311 if (phba->sli_rev == LPFC_SLI_REV3) {
James Smartf1126682009-06-10 17:22:44 -04008312 icmd->ulpCt_h = 1;
8313 icmd->ulpCt_l = 0;
8314 }
James Smart92d7f7b2007-06-17 19:56:38 -05008315
8316 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8317 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
8318 pcmd += sizeof(uint32_t); /* CSP Word 1 */
8319 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
8320 sp = (struct serv_parm *) pcmd;
8321 /* Setup CSPs accordingly for Fabric */
8322 sp->cmn.e_d_tov = 0;
8323 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05008324 sp->cmn.virtual_fabric_support = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05008325 sp->cls1.classValid = 0;
8326 sp->cls2.seqDelivery = 1;
8327 sp->cls3.seqDelivery = 1;
8328
8329 pcmd += sizeof(uint32_t); /* CSP Word 2 */
8330 pcmd += sizeof(uint32_t); /* CSP Word 3 */
8331 pcmd += sizeof(uint32_t); /* CSP Word 4 */
8332 pcmd += sizeof(uint32_t); /* Port Name */
8333 memcpy(pcmd, &vport->fc_portname, 8);
8334 pcmd += sizeof(uint32_t); /* Node Name */
8335 pcmd += sizeof(uint32_t); /* Node Name */
8336 memcpy(pcmd, &vport->fc_nodename, 8);
8337
8338 lpfc_set_disctmo(vport);
8339
8340 phba->fc_stat.elsXmitFDISC++;
8341 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
8342
James Smart858c9f62007-06-17 19:56:39 -05008343 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8344 "Issue FDISC: did:x%x",
8345 did, 0, 0);
8346
James Smart92d7f7b2007-06-17 19:56:38 -05008347 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
8348 if (rc == IOCB_ERROR) {
8349 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05008350 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04008351 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8352 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05008353 return 1;
8354 }
8355 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05008356 return 0;
8357}
8358
James Smarte59058c2008-08-24 21:49:00 -04008359/**
James Smart3621a712009-04-06 18:47:14 -04008360 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04008361 * @phba: pointer to lpfc hba data structure.
8362 * @cmdiocb: pointer to lpfc command iocb data structure.
8363 * @rspiocb: pointer to lpfc response iocb data structure.
8364 *
8365 * This routine is the completion callback function to the issuing of a LOGO
8366 * ELS command off a vport. It frees the command IOCB and then decrement the
8367 * reference count held on ndlp for this completion function, indicating that
8368 * the reference to the ndlp is no long needed. Note that the
8369 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
8370 * callback function and an additional explicit ndlp reference decrementation
8371 * will trigger the actual release of the ndlp.
8372 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008373static void
8374lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8375 struct lpfc_iocbq *rspiocb)
8376{
8377 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05008378 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05008379 struct lpfc_nodelist *ndlp;
James Smart9589b0622011-04-16 11:03:17 -04008380 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05008381
James Smart9589b0622011-04-16 11:03:17 -04008382 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05008383 irsp = &rspiocb->iocb;
8384 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8385 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
8386 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05008387
8388 lpfc_els_free_iocb(phba, cmdiocb);
8389 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05008390
8391 /* Trigger the release of the ndlp after logo */
8392 lpfc_nlp_put(ndlp);
James Smart9589b0622011-04-16 11:03:17 -04008393
8394 /* NPIV LOGO completes to NPort <nlp_DID> */
8395 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8396 "2928 NPIV LOGO completes to NPort x%x "
8397 "Data: x%x x%x x%x x%x\n",
8398 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
8399 irsp->ulpTimeout, vport->num_disc_nodes);
8400
8401 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
8402 spin_lock_irq(shost->host_lock);
James Smart73dc0db2015-05-22 10:42:36 -04008403 vport->fc_flag &= ~FC_NDISC_ACTIVE;
James Smart9589b0622011-04-16 11:03:17 -04008404 vport->fc_flag &= ~FC_FABRIC;
8405 spin_unlock_irq(shost->host_lock);
James Smart73dc0db2015-05-22 10:42:36 -04008406 lpfc_can_disctmo(vport);
James Smart9589b0622011-04-16 11:03:17 -04008407 }
James Smart92d7f7b2007-06-17 19:56:38 -05008408}
8409
James Smarte59058c2008-08-24 21:49:00 -04008410/**
James Smart3621a712009-04-06 18:47:14 -04008411 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04008412 * @vport: pointer to a virtual N_Port data structure.
8413 * @ndlp: pointer to a node-list data structure.
8414 *
8415 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
8416 *
8417 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8418 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8419 * will be stored into the context1 field of the IOCB for the completion
8420 * callback function to the LOGO ELS command.
8421 *
8422 * Return codes
8423 * 0 - Successfully issued logo off the @vport
8424 * 1 - Failed to issue logo off the @vport
8425 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008426int
8427lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
8428{
8429 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8430 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05008431 IOCB_t *icmd;
8432 struct lpfc_iocbq *elsiocb;
8433 uint8_t *pcmd;
8434 uint16_t cmdsize;
8435
8436 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
8437 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
8438 ELS_CMD_LOGO);
8439 if (!elsiocb)
8440 return 1;
8441
8442 icmd = &elsiocb->iocb;
8443 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8444 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
8445 pcmd += sizeof(uint32_t);
8446
8447 /* Fill in LOGO payload */
8448 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
8449 pcmd += sizeof(uint32_t);
8450 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
8451
James Smart858c9f62007-06-17 19:56:39 -05008452 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8453 "Issue LOGO npiv did:x%x flg:x%x",
8454 ndlp->nlp_DID, ndlp->nlp_flag, 0);
8455
James Smart92d7f7b2007-06-17 19:56:38 -05008456 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
8457 spin_lock_irq(shost->host_lock);
8458 ndlp->nlp_flag |= NLP_LOGO_SND;
8459 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04008460 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
8461 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05008462 spin_lock_irq(shost->host_lock);
8463 ndlp->nlp_flag &= ~NLP_LOGO_SND;
8464 spin_unlock_irq(shost->host_lock);
8465 lpfc_els_free_iocb(phba, elsiocb);
8466 return 1;
8467 }
8468 return 0;
8469}
8470
James Smarte59058c2008-08-24 21:49:00 -04008471/**
James Smart3621a712009-04-06 18:47:14 -04008472 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04008473 * @ptr: holder for the timer function associated data.
8474 *
8475 * This routine is invoked by the fabric iocb block timer after
8476 * timeout. It posts the fabric iocb block timeout event by setting the
8477 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
8478 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
8479 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
8480 * posted event WORKER_FABRIC_BLOCK_TMO.
8481 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008482void
8483lpfc_fabric_block_timeout(unsigned long ptr)
8484{
8485 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
8486 unsigned long iflags;
8487 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04008488
James Smart92d7f7b2007-06-17 19:56:38 -05008489 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
8490 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
8491 if (!tmo_posted)
8492 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
8493 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
8494
James Smart5e9d9b82008-06-14 22:52:53 -04008495 if (!tmo_posted)
8496 lpfc_worker_wake_up(phba);
8497 return;
James Smart92d7f7b2007-06-17 19:56:38 -05008498}
8499
James Smarte59058c2008-08-24 21:49:00 -04008500/**
James Smart3621a712009-04-06 18:47:14 -04008501 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04008502 * @phba: pointer to lpfc hba data structure.
8503 *
8504 * This routine issues one fabric iocb from the driver internal list to
8505 * the HBA. It first checks whether it's ready to issue one fabric iocb to
8506 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
8507 * remove one pending fabric iocb from the driver internal list and invokes
8508 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
8509 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008510static void
8511lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
8512{
8513 struct lpfc_iocbq *iocb;
8514 unsigned long iflags;
8515 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05008516 IOCB_t *cmd;
8517
8518repeat:
8519 iocb = NULL;
8520 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05008521 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05008522 if (atomic_read(&phba->fabric_iocb_count) == 0) {
8523 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
8524 list);
8525 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05008526 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05008527 atomic_inc(&phba->fabric_iocb_count);
8528 }
8529 spin_unlock_irqrestore(&phba->hbalock, iflags);
8530 if (iocb) {
8531 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
8532 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
8533 iocb->iocb_flag |= LPFC_IO_FABRIC;
8534
James Smart858c9f62007-06-17 19:56:39 -05008535 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
8536 "Fabric sched1: ste:x%x",
8537 iocb->vport->port_state, 0, 0);
8538
James Smart3772a992009-05-22 14:50:54 -04008539 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05008540
8541 if (ret == IOCB_ERROR) {
8542 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
8543 iocb->fabric_iocb_cmpl = NULL;
8544 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
8545 cmd = &iocb->iocb;
8546 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
8547 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
8548 iocb->iocb_cmpl(phba, iocb, iocb);
8549
8550 atomic_dec(&phba->fabric_iocb_count);
8551 goto repeat;
8552 }
8553 }
8554
8555 return;
8556}
8557
James Smarte59058c2008-08-24 21:49:00 -04008558/**
James Smart3621a712009-04-06 18:47:14 -04008559 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04008560 * @phba: pointer to lpfc hba data structure.
8561 *
8562 * This routine unblocks the issuing fabric iocb command. The function
8563 * will clear the fabric iocb block bit and then invoke the routine
8564 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
8565 * from the driver internal fabric iocb list.
8566 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008567void
8568lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
8569{
8570 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
8571
8572 lpfc_resume_fabric_iocbs(phba);
8573 return;
8574}
8575
James Smarte59058c2008-08-24 21:49:00 -04008576/**
James Smart3621a712009-04-06 18:47:14 -04008577 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04008578 * @phba: pointer to lpfc hba data structure.
8579 *
8580 * This routine blocks the issuing fabric iocb for a specified amount of
8581 * time (currently 100 ms). This is done by set the fabric iocb block bit
8582 * and set up a timeout timer for 100ms. When the block bit is set, no more
8583 * fabric iocb will be issued out of the HBA.
8584 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008585static void
8586lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
8587{
8588 int blocked;
8589
8590 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05008591 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05008592 if (!blocked)
James Smart256ec0d2013-04-17 20:14:58 -04008593 mod_timer(&phba->fabric_block_timer,
8594 jiffies + msecs_to_jiffies(100));
James Smart92d7f7b2007-06-17 19:56:38 -05008595
8596 return;
8597}
8598
James Smarte59058c2008-08-24 21:49:00 -04008599/**
James Smart3621a712009-04-06 18:47:14 -04008600 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04008601 * @phba: pointer to lpfc hba data structure.
8602 * @cmdiocb: pointer to lpfc command iocb data structure.
8603 * @rspiocb: pointer to lpfc response iocb data structure.
8604 *
8605 * This routine is the callback function that is put to the fabric iocb's
8606 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
8607 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
8608 * function first restores and invokes the original iocb's callback function
8609 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
8610 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
8611 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008612static void
8613lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8614 struct lpfc_iocbq *rspiocb)
8615{
8616 struct ls_rjt stat;
8617
8618 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
8619 BUG();
8620
8621 switch (rspiocb->iocb.ulpStatus) {
8622 case IOSTAT_NPORT_RJT:
8623 case IOSTAT_FABRIC_RJT:
8624 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
8625 lpfc_block_fabric_iocbs(phba);
8626 }
8627 break;
8628
8629 case IOSTAT_NPORT_BSY:
8630 case IOSTAT_FABRIC_BSY:
8631 lpfc_block_fabric_iocbs(phba);
8632 break;
8633
8634 case IOSTAT_LS_RJT:
8635 stat.un.lsRjtError =
8636 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
8637 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
8638 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
8639 lpfc_block_fabric_iocbs(phba);
8640 break;
8641 }
8642
8643 if (atomic_read(&phba->fabric_iocb_count) == 0)
8644 BUG();
8645
8646 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
8647 cmdiocb->fabric_iocb_cmpl = NULL;
8648 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
8649 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
8650
8651 atomic_dec(&phba->fabric_iocb_count);
8652 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05008653 /* Post any pending iocbs to HBA */
8654 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05008655 }
8656}
8657
James Smarte59058c2008-08-24 21:49:00 -04008658/**
James Smart3621a712009-04-06 18:47:14 -04008659 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04008660 * @phba: pointer to lpfc hba data structure.
8661 * @iocb: pointer to lpfc command iocb data structure.
8662 *
8663 * This routine is used as the top-level API for issuing a fabric iocb command
8664 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
8665 * function makes sure that only one fabric bound iocb will be outstanding at
8666 * any given time. As such, this function will first check to see whether there
8667 * is already an outstanding fabric iocb on the wire. If so, it will put the
8668 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
8669 * issued later. Otherwise, it will issue the iocb on the wire and update the
8670 * fabric iocb count it indicate that there is one fabric iocb on the wire.
8671 *
8672 * Note, this implementation has a potential sending out fabric IOCBs out of
8673 * order. The problem is caused by the construction of the "ready" boolen does
8674 * not include the condition that the internal fabric IOCB list is empty. As
8675 * such, it is possible a fabric IOCB issued by this routine might be "jump"
8676 * ahead of the fabric IOCBs in the internal list.
8677 *
8678 * Return code
8679 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
8680 * IOCB_ERROR - failed to issue fabric iocb
8681 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01008682static int
James Smart92d7f7b2007-06-17 19:56:38 -05008683lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
8684{
8685 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05008686 int ready;
8687 int ret;
8688
8689 if (atomic_read(&phba->fabric_iocb_count) > 1)
8690 BUG();
8691
8692 spin_lock_irqsave(&phba->hbalock, iflags);
8693 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
8694 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
8695
James Smart7f5f3d02008-02-08 18:50:14 -05008696 if (ready)
8697 /* Increment fabric iocb count to hold the position */
8698 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05008699 spin_unlock_irqrestore(&phba->hbalock, iflags);
8700 if (ready) {
8701 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
8702 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
8703 iocb->iocb_flag |= LPFC_IO_FABRIC;
8704
James Smart858c9f62007-06-17 19:56:39 -05008705 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
8706 "Fabric sched2: ste:x%x",
8707 iocb->vport->port_state, 0, 0);
8708
James Smart3772a992009-05-22 14:50:54 -04008709 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05008710
8711 if (ret == IOCB_ERROR) {
8712 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
8713 iocb->fabric_iocb_cmpl = NULL;
8714 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
8715 atomic_dec(&phba->fabric_iocb_count);
8716 }
8717 } else {
8718 spin_lock_irqsave(&phba->hbalock, iflags);
8719 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
8720 spin_unlock_irqrestore(&phba->hbalock, iflags);
8721 ret = IOCB_SUCCESS;
8722 }
8723 return ret;
8724}
8725
James Smarte59058c2008-08-24 21:49:00 -04008726/**
James Smart3621a712009-04-06 18:47:14 -04008727 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04008728 * @vport: pointer to a virtual N_Port data structure.
8729 *
8730 * This routine aborts all the IOCBs associated with a @vport from the
8731 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
8732 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
8733 * list, removes each IOCB associated with the @vport off the list, set the
8734 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
8735 * associated with the IOCB.
8736 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01008737static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05008738{
8739 LIST_HEAD(completions);
8740 struct lpfc_hba *phba = vport->phba;
8741 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05008742
8743 spin_lock_irq(&phba->hbalock);
8744 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
8745 list) {
8746
8747 if (piocb->vport != vport)
8748 continue;
8749
8750 list_move_tail(&piocb->list, &completions);
8751 }
8752 spin_unlock_irq(&phba->hbalock);
8753
James Smarta257bf92009-04-06 18:48:10 -04008754 /* Cancel all the IOCBs from the completions list */
8755 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
8756 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05008757}
8758
James Smarte59058c2008-08-24 21:49:00 -04008759/**
James Smart3621a712009-04-06 18:47:14 -04008760 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04008761 * @ndlp: pointer to a node-list data structure.
8762 *
8763 * This routine aborts all the IOCBs associated with an @ndlp from the
8764 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
8765 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
8766 * list, removes each IOCB associated with the @ndlp off the list, set the
8767 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
8768 * associated with the IOCB.
8769 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008770void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
8771{
8772 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04008773 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05008774 struct lpfc_iocbq *tmp_iocb, *piocb;
8775 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05008776
8777 spin_lock_irq(&phba->hbalock);
8778 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
8779 list) {
8780 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
8781
8782 list_move_tail(&piocb->list, &completions);
8783 }
8784 }
8785 spin_unlock_irq(&phba->hbalock);
8786
James Smarta257bf92009-04-06 18:48:10 -04008787 /* Cancel all the IOCBs from the completions list */
8788 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
8789 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05008790}
8791
James Smarte59058c2008-08-24 21:49:00 -04008792/**
James Smart3621a712009-04-06 18:47:14 -04008793 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04008794 * @phba: pointer to lpfc hba data structure.
8795 *
8796 * This routine aborts all the IOCBs currently on the driver internal
8797 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
8798 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
8799 * list, removes IOCBs off the list, set the status feild to
8800 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
8801 * the IOCB.
8802 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008803void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
8804{
8805 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05008806
8807 spin_lock_irq(&phba->hbalock);
8808 list_splice_init(&phba->fabric_iocb_list, &completions);
8809 spin_unlock_irq(&phba->hbalock);
8810
James Smarta257bf92009-04-06 18:48:10 -04008811 /* Cancel all the IOCBs from the completions list */
8812 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
8813 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05008814}
James Smart6fb120a2009-05-22 14:52:59 -04008815
8816/**
James Smart1151e3e2011-02-16 12:39:35 -05008817 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
8818 * @vport: pointer to lpfc vport data structure.
8819 *
8820 * This routine is invoked by the vport cleanup for deletions and the cleanup
8821 * for an ndlp on removal.
8822 **/
8823void
8824lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
8825{
8826 struct lpfc_hba *phba = vport->phba;
8827 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8828 unsigned long iflag = 0;
8829
8830 spin_lock_irqsave(&phba->hbalock, iflag);
8831 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
8832 list_for_each_entry_safe(sglq_entry, sglq_next,
8833 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
8834 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
8835 sglq_entry->ndlp = NULL;
8836 }
8837 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
8838 spin_unlock_irqrestore(&phba->hbalock, iflag);
8839 return;
8840}
8841
8842/**
James Smart6fb120a2009-05-22 14:52:59 -04008843 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
8844 * @phba: pointer to lpfc hba data structure.
8845 * @axri: pointer to the els xri abort wcqe structure.
8846 *
8847 * This routine is invoked by the worker thread to process a SLI4 slow-path
8848 * ELS aborted xri.
8849 **/
8850void
8851lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
8852 struct sli4_wcqe_xri_aborted *axri)
8853{
8854 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05008855 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -04008856 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -05008857
James Smart6fb120a2009-05-22 14:52:59 -04008858 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8859 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05008860 struct lpfc_nodelist *ndlp;
James Smart589a52d2010-07-14 15:30:54 -04008861 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04008862
James Smart0f65ff62010-02-26 14:14:23 -05008863 spin_lock_irqsave(&phba->hbalock, iflag);
8864 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04008865 list_for_each_entry_safe(sglq_entry, sglq_next,
8866 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
8867 if (sglq_entry->sli4_xritag == xri) {
8868 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05008869 ndlp = sglq_entry->ndlp;
8870 sglq_entry->ndlp = NULL;
James Smartdafe8ce2014-09-03 12:56:40 -04008871 spin_lock(&pring->ring_lock);
James Smart6fb120a2009-05-22 14:52:59 -04008872 list_add_tail(&sglq_entry->list,
8873 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05008874 sglq_entry->state = SGL_FREED;
James Smartdafe8ce2014-09-03 12:56:40 -04008875 spin_unlock(&pring->ring_lock);
James Smart0f65ff62010-02-26 14:14:23 -05008876 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04008877 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smartee0f4fe2012-05-09 21:19:14 -04008878 lpfc_set_rrq_active(phba, ndlp,
8879 sglq_entry->sli4_lxritag,
8880 rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04008881
8882 /* Check if TXQ queue needs to be serviced */
James Smart0e9bb8d2013-03-01 16:35:12 -05008883 if (!(list_empty(&pring->txq)))
James Smart589a52d2010-07-14 15:30:54 -04008884 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04008885 return;
8886 }
8887 }
James Smart0f65ff62010-02-26 14:14:23 -05008888 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -04008889 lxri = lpfc_sli4_xri_inrange(phba, xri);
8890 if (lxri == NO_XRI) {
8891 spin_unlock_irqrestore(&phba->hbalock, iflag);
8892 return;
8893 }
James Smartdafe8ce2014-09-03 12:56:40 -04008894 spin_lock(&pring->ring_lock);
James Smart7851fe22011-07-22 18:36:52 -04008895 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -05008896 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
James Smartdafe8ce2014-09-03 12:56:40 -04008897 spin_unlock(&pring->ring_lock);
James Smart0f65ff62010-02-26 14:14:23 -05008898 spin_unlock_irqrestore(&phba->hbalock, iflag);
8899 return;
8900 }
8901 sglq_entry->state = SGL_XRI_ABORTED;
James Smartdafe8ce2014-09-03 12:56:40 -04008902 spin_unlock(&pring->ring_lock);
James Smart0f65ff62010-02-26 14:14:23 -05008903 spin_unlock_irqrestore(&phba->hbalock, iflag);
8904 return;
James Smart6fb120a2009-05-22 14:52:59 -04008905}
James Smart086a3452012-08-14 14:25:21 -04008906
8907/* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
8908 * @vport: pointer to virtual port object.
8909 * @ndlp: nodelist pointer for the impacted node.
8910 *
8911 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
8912 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
8913 * the driver is required to send a LOGO to the remote node before it
8914 * attempts to recover its login to the remote node.
8915 */
8916void
8917lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
8918 struct lpfc_nodelist *ndlp)
8919{
8920 struct Scsi_Host *shost;
8921 struct lpfc_hba *phba;
8922 unsigned long flags = 0;
8923
8924 shost = lpfc_shost_from_vport(vport);
8925 phba = vport->phba;
8926 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
8927 lpfc_printf_log(phba, KERN_INFO,
8928 LOG_SLI, "3093 No rport recovery needed. "
8929 "rport in state 0x%x\n", ndlp->nlp_state);
8930 return;
8931 }
8932 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8933 "3094 Start rport recovery on shost id 0x%x "
8934 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
8935 "flags 0x%x\n",
8936 shost->host_no, ndlp->nlp_DID,
8937 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
8938 ndlp->nlp_flag);
8939 /*
8940 * The rport is not responding. Remove the FCP-2 flag to prevent
8941 * an ADISC in the follow-up recovery code.
8942 */
8943 spin_lock_irqsave(shost->host_lock, flags);
8944 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
8945 spin_unlock_irqrestore(shost->host_lock, flags);
8946 lpfc_issue_els_logo(vport, ndlp, 0);
8947 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
8948}
8949