blob: a712f15bc88cfb48841c29ad5b1dde326e15df7d [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 Smart145e5a82020-01-27 16:23:12 -08004 * Copyright (C) 2017-2020 Broadcom. All Rights Reserved. The term *
James Smart4ae2ebd2018-06-26 08:24:31 -07005 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
James Smart50611572016-03-31 14:12:34 -07006 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * EMULEX and SLI are trademarks of Emulex. *
James Smartd080abe2017-02-12 13:52:39 -08008 * www.broadcom.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04009 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -050010 * *
11 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040012 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
dea31012005-04-17 16:05:31 -050022 *******************************************************************/
James Smart09372822008-01-11 01:52:54 -050023/* See Fibre Channel protocol T11 FC-LS for details */
dea31012005-04-17 16:05:31 -050024#include <linux/blkdev.h>
25#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050027#include <linux/interrupt.h>
28
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040029#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050030#include <scsi/scsi_device.h>
31#include <scsi/scsi_host.h>
32#include <scsi/scsi_transport_fc.h>
James Smartf60cb932019-05-14 14:58:05 -070033#include <uapi/scsi/fc/fc_fs.h>
34#include <uapi/scsi/fc/fc_els.h>
dea31012005-04-17 16:05:31 -050035
James Smartda0436e2009-05-22 14:51:39 -040036#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_hw.h"
38#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040039#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040040#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050041#include "lpfc_disc.h"
42#include "lpfc_scsi.h"
43#include "lpfc.h"
44#include "lpfc_logmsg.h"
45#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050046#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050047#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050048
49static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
50 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050051static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
52 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010053static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
54static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
55 struct lpfc_nodelist *ndlp, uint8_t retry);
56static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
57 struct lpfc_iocbq *iocb);
James Smart92d7f7b2007-06-17 19:56:38 -050058
dea31012005-04-17 16:05:31 -050059static int lpfc_max_els_tries = 3;
60
James Smarte59058c2008-08-24 21:49:00 -040061/**
James Smart3621a712009-04-06 18:47:14 -040062 * lpfc_els_chk_latt - Check host link attention event for a vport
James Smarte59058c2008-08-24 21:49:00 -040063 * @vport: pointer to a host virtual N_Port data structure.
64 *
65 * This routine checks whether there is an outstanding host link
66 * attention event during the discovery process with the @vport. It is done
67 * by reading the HBA's Host Attention (HA) register. If there is any host
68 * link attention events during this @vport's discovery process, the @vport
69 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
70 * be issued if the link state is not already in host link cleared state,
71 * and a return code shall indicate whether the host link attention event
72 * had happened.
73 *
74 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
75 * state in LPFC_VPORT_READY, the request for checking host link attention
76 * event will be ignored and a return code shall indicate no host link
77 * attention event had happened.
78 *
79 * Return codes
80 * 0 - no host link attention event happened
81 * 1 - host link attention event happened
82 **/
James Smart858c9f62007-06-17 19:56:39 -050083int
James Smart2e0fef82007-06-17 19:56:36 -050084lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050085{
James Smart2e0fef82007-06-17 19:56:36 -050086 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
87 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050088 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050089
James Smart2e0fef82007-06-17 19:56:36 -050090 if (vport->port_state >= LPFC_VPORT_READY ||
James Smart3772a992009-05-22 14:50:54 -040091 phba->link_state == LPFC_LINK_DOWN ||
92 phba->sli_rev > LPFC_SLI_REV3)
dea31012005-04-17 16:05:31 -050093 return 0;
94
95 /* Read the HBA Host Attention Register */
James Smart9940b972011-03-11 16:06:12 -050096 if (lpfc_readl(phba->HAregaddr, &ha_copy))
97 return 1;
dea31012005-04-17 16:05:31 -050098
99 if (!(ha_copy & HA_LATT))
100 return 0;
101
102 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -0400103 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
104 "0237 Pending Link Event during "
105 "Discovery: State x%x\n",
106 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500107
108 /* CLEAR_LA should re-enable link attention events and
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300109 * we should then immediately take a LATT event. The
dea31012005-04-17 16:05:31 -0500110 * LATT processing should call lpfc_linkdown() which
111 * will cleanup any left over in-progress discovery
112 * events.
113 */
James Smart2e0fef82007-06-17 19:56:36 -0500114 spin_lock_irq(shost->host_lock);
115 vport->fc_flag |= FC_ABORT_DISCOVERY;
116 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500117
James Smart92d7f7b2007-06-17 19:56:38 -0500118 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500119 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500120
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500121 return 1;
dea31012005-04-17 16:05:31 -0500122}
123
James Smarte59058c2008-08-24 21:49:00 -0400124/**
James Smart3621a712009-04-06 18:47:14 -0400125 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400126 * @vport: pointer to a host virtual N_Port data structure.
127 * @expectRsp: flag indicating whether response is expected.
128 * @cmdSize: size of the ELS command.
129 * @retry: number of retries to the command IOCB when it fails.
130 * @ndlp: pointer to a node-list data structure.
131 * @did: destination identifier.
132 * @elscmd: the ELS command code.
133 *
134 * This routine is used for allocating a lpfc-IOCB data structure from
135 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
136 * passed into the routine for discovery state machine to issue an Extended
137 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
138 * and preparation routine that is used by all the discovery state machine
139 * routines and the ELS command-specific fields will be later set up by
140 * the individual discovery machine routines after calling this routine
141 * allocating and preparing a generic IOCB data structure. It fills in the
142 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
143 * payload and response payload (if expected). The reference count on the
144 * ndlp is incremented by 1 and the reference to the ndlp is put into
145 * context1 of the IOCB data structure for this IOCB to hold the ndlp
146 * reference for the command's callback function to access later.
147 *
148 * Return code
149 * Pointer to the newly allocated/prepared els iocb data structure
150 * NULL - when els iocb data structure allocation/preparation failed
151 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400152struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500153lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
154 uint16_t cmdSize, uint8_t retry,
155 struct lpfc_nodelist *ndlp, uint32_t did,
156 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500157{
James Smart2e0fef82007-06-17 19:56:36 -0500158 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400159 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500160 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
161 struct ulp_bde64 *bpl;
162 IOCB_t *icmd;
163
dea31012005-04-17 16:05:31 -0500164
James Smart2e0fef82007-06-17 19:56:36 -0500165 if (!lpfc_is_link_up(phba))
166 return NULL;
dea31012005-04-17 16:05:31 -0500167
dea31012005-04-17 16:05:31 -0500168 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400169 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500170
171 if (elsiocb == NULL)
172 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500173
James Smart0c287582009-06-10 17:22:56 -0400174 /*
175 * If this command is for fabric controller and HBA running
176 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
177 */
178 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400179 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400180 ((elscmd == ELS_CMD_FLOGI) ||
181 (elscmd == ELS_CMD_FDISC) ||
182 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500183 switch (elscmd) {
184 case ELS_CMD_FLOGI:
James Smartf0d9bcc2010-10-22 11:07:09 -0400185 elsiocb->iocb_flag |=
186 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500187 & LPFC_FIP_ELS_ID_MASK);
188 break;
189 case ELS_CMD_FDISC:
James Smartf0d9bcc2010-10-22 11:07:09 -0400190 elsiocb->iocb_flag |=
191 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500192 & LPFC_FIP_ELS_ID_MASK);
193 break;
194 case ELS_CMD_LOGO:
James Smartf0d9bcc2010-10-22 11:07:09 -0400195 elsiocb->iocb_flag |=
196 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500197 & LPFC_FIP_ELS_ID_MASK);
198 break;
199 }
James Smart0c287582009-06-10 17:22:56 -0400200 else
James Smartc8685952009-11-18 15:39:16 -0500201 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400202
dea31012005-04-17 16:05:31 -0500203 icmd = &elsiocb->iocb;
204
205 /* fill in BDEs for command */
206 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400207 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
208 if (pcmd)
209 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500210 if (!pcmd || !pcmd->virt)
211 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500212
213 INIT_LIST_HEAD(&pcmd->list);
214
215 /* Allocate buffer for response payload */
216 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500217 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500218 if (prsp)
219 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
220 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500221 if (!prsp || !prsp->virt)
222 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500223 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500224 } else
dea31012005-04-17 16:05:31 -0500225 prsp = NULL;
dea31012005-04-17 16:05:31 -0500226
227 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500228 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500229 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500230 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
231 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500232 if (!pbuflist || !pbuflist->virt)
233 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500234
235 INIT_LIST_HEAD(&pbuflist->list);
236
dea31012005-04-17 16:05:31 -0500237 if (expectRsp) {
James Smart939723a2012-05-09 21:19:03 -0400238 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
239 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
240 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart92d7f7b2007-06-17 19:56:38 -0500241 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
James Smart939723a2012-05-09 21:19:03 -0400242
243 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500244 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart88f43a02013-04-17 20:19:44 -0400245 if (elscmd == ELS_CMD_FLOGI)
246 icmd->ulpTimeout = FF_DEF_RATOV * 2;
James Smart30e196c2018-10-23 13:41:03 -0700247 else if (elscmd == ELS_CMD_LOGO)
248 icmd->ulpTimeout = phba->fc_ratov;
James Smart88f43a02013-04-17 20:19:44 -0400249 else
250 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500251 } else {
James Smart939723a2012-05-09 21:19:03 -0400252 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
253 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
254 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
255 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
256 icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500257 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
258 }
dea31012005-04-17 16:05:31 -0500259 icmd->ulpBdeCount = 1;
260 icmd->ulpLe = 1;
261 icmd->ulpClass = CLASS3;
262
James Smart939723a2012-05-09 21:19:03 -0400263 /*
264 * If we have NPIV enabled, we want to send ELS traffic by VPI.
265 * For SLI4, since the driver controls VPIs we also want to include
266 * all ELS pt2pt protocol traffic as well.
267 */
268 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
269 ((phba->sli_rev == LPFC_SLI_REV4) &&
270 (vport->fc_flag & FC_PT2PT))) {
James Smart92d7f7b2007-06-17 19:56:38 -0500271
James Smart939723a2012-05-09 21:19:03 -0400272 if (expectRsp) {
273 icmd->un.elsreq64.myID = vport->fc_myDID;
274
275 /* For ELS_REQUEST64_CR, use the VPI by default */
276 icmd->ulpContext = phba->vpi_ids[vport->vpi];
277 }
278
James Smart92d7f7b2007-06-17 19:56:38 -0500279 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500280 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
281 if (elscmd == ELS_CMD_ECHO)
282 icmd->ulpCt_l = 0; /* context = invalid RPI */
283 else
284 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500285 }
286
dea31012005-04-17 16:05:31 -0500287 bpl = (struct ulp_bde64 *) pbuflist->virt;
288 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
289 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
290 bpl->tus.f.bdeSize = cmdSize;
291 bpl->tus.f.bdeFlags = 0;
292 bpl->tus.w = le32_to_cpu(bpl->tus.w);
293
294 if (expectRsp) {
295 bpl++;
296 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
297 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
298 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400299 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500300 bpl->tus.w = le32_to_cpu(bpl->tus.w);
301 }
302
James Smartfa4066b2008-01-11 01:53:27 -0500303 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400304 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500305 if (!elsiocb->context1)
306 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400307 elsiocb->context2 = pcmd;
308 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500309 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500310 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500311 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
312
313 if (prsp) {
314 list_add(&prsp->list, &pcmd->list);
315 }
dea31012005-04-17 16:05:31 -0500316 if (expectRsp) {
317 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400318 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
319 "0116 Xmit ELS command x%x to remote "
James Smartdea16bd2018-11-29 16:09:30 -0800320 "NPORT x%x I/O tag: x%x, port state:x%x "
321 "rpi x%x fc_flag:x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400322 elscmd, did, elsiocb->iotag,
James Smartdea16bd2018-11-29 16:09:30 -0800323 vport->port_state, ndlp->nlp_rpi,
James Smarte74c03c2013-04-17 20:15:19 -0400324 vport->fc_flag);
dea31012005-04-17 16:05:31 -0500325 } else {
326 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400327 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
328 "0117 Xmit ELS response x%x to remote "
James Smarte74c03c2013-04-17 20:15:19 -0400329 "NPORT x%x I/O tag: x%x, size: x%x "
James Smartdea16bd2018-11-29 16:09:30 -0800330 "port_state x%x rpi x%x fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400331 elscmd, ndlp->nlp_DID, elsiocb->iotag,
James Smarte74c03c2013-04-17 20:15:19 -0400332 cmdSize, vport->port_state,
James Smartdea16bd2018-11-29 16:09:30 -0800333 ndlp->nlp_rpi, vport->fc_flag);
dea31012005-04-17 16:05:31 -0500334 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500335 return elsiocb;
dea31012005-04-17 16:05:31 -0500336
James Smartfa4066b2008-01-11 01:53:27 -0500337els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500338 if (expectRsp)
339 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500340 kfree(pbuflist);
341
342els_iocb_free_prsp_exit:
343 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
344 kfree(prsp);
345
346els_iocb_free_pcmb_exit:
347 kfree(pcmd);
348 lpfc_sli_release_iocbq(phba, elsiocb);
349 return NULL;
350}
dea31012005-04-17 16:05:31 -0500351
James Smarte59058c2008-08-24 21:49:00 -0400352/**
James Smart3621a712009-04-06 18:47:14 -0400353 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400354 * @vport: pointer to a host virtual N_Port data structure.
355 *
356 * This routine issues a fabric registration login for a @vport. An
357 * active ndlp node with Fabric_DID must already exist for this @vport.
358 * The routine invokes two mailbox commands to carry out fabric registration
359 * login through the HBA firmware: the first mailbox command requests the
360 * HBA to perform link configuration for the @vport; and the second mailbox
361 * command requests the HBA to perform the actual fabric registration login
362 * with the @vport.
363 *
364 * Return code
365 * 0 - successfully issued fabric registration login for @vport
366 * -ENXIO -- failed to issue fabric registration login for @vport
367 **/
James Smart3772a992009-05-22 14:50:54 -0400368int
James Smart92d7f7b2007-06-17 19:56:38 -0500369lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
370{
371 struct lpfc_hba *phba = vport->phba;
372 LPFC_MBOXQ_t *mbox;
373 struct lpfc_dmabuf *mp;
374 struct lpfc_nodelist *ndlp;
375 struct serv_parm *sp;
376 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400377 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500378
379 sp = &phba->fc_fabparam;
380 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500381 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400382 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500383 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400384 }
James Smart92d7f7b2007-06-17 19:56:38 -0500385
386 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400387 if (!mbox) {
388 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500389 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400390 }
James Smart92d7f7b2007-06-17 19:56:38 -0500391
392 vport->port_state = LPFC_FABRIC_CFG_LINK;
393 lpfc_config_link(phba, mbox);
394 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
395 mbox->vport = vport;
396
James Smart0b727fe2007-10-27 13:37:25 -0400397 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400398 if (rc == MBX_NOT_FINISHED) {
399 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500400 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400401 }
James Smart92d7f7b2007-06-17 19:56:38 -0500402
403 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400404 if (!mbox) {
405 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500406 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400407 }
James Smart40426292010-12-15 17:58:10 -0500408 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
409 ndlp->nlp_rpi);
James Smart98c9ea52007-10-27 13:37:33 -0400410 if (rc) {
411 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500412 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400413 }
James Smart92d7f7b2007-06-17 19:56:38 -0500414
415 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
416 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500417 /* increment the reference count on ndlp to hold reference
418 * for the callback routine.
419 */
James Smart3e1f0712018-11-29 16:09:29 -0800420 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500421
James Smart0b727fe2007-10-27 13:37:25 -0400422 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400423 if (rc == MBX_NOT_FINISHED) {
424 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500425 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400426 }
James Smart92d7f7b2007-06-17 19:56:38 -0500427
428 return 0;
429
430fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500431 /* decrement the reference count on ndlp just incremented
432 * for the failed mbox command.
433 */
James Smart92d7f7b2007-06-17 19:56:38 -0500434 lpfc_nlp_put(ndlp);
James Smart3e1f0712018-11-29 16:09:29 -0800435 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
James Smart92d7f7b2007-06-17 19:56:38 -0500436 lpfc_mbuf_free(phba, mp->virt, mp->phys);
437 kfree(mp);
438fail_free_mbox:
439 mempool_free(mbox, phba->mbox_mem_pool);
440
441fail:
442 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400443 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400444 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500445 return -ENXIO;
446}
447
James Smarte59058c2008-08-24 21:49:00 -0400448/**
James Smart6fb120a2009-05-22 14:52:59 -0400449 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
450 * @vport: pointer to a host virtual N_Port data structure.
451 *
452 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
James Smart1b511972011-12-13 13:23:09 -0500453 * the @vport. This mailbox command is necessary for SLI4 port only.
James Smart6fb120a2009-05-22 14:52:59 -0400454 *
455 * Return code
456 * 0 - successfully issued REG_VFI for @vport
457 * A failure code otherwise.
458 **/
James Smart1b511972011-12-13 13:23:09 -0500459int
James Smart6fb120a2009-05-22 14:52:59 -0400460lpfc_issue_reg_vfi(struct lpfc_vport *vport)
461{
462 struct lpfc_hba *phba = vport->phba;
James Smartd6de08c2015-12-16 18:11:53 -0500463 LPFC_MBOXQ_t *mboxq = NULL;
James Smart6fb120a2009-05-22 14:52:59 -0400464 struct lpfc_nodelist *ndlp;
James Smartd6de08c2015-12-16 18:11:53 -0500465 struct lpfc_dmabuf *dmabuf = NULL;
James Smart6fb120a2009-05-22 14:52:59 -0400466 int rc = 0;
467
James Smart939723a2012-05-09 21:19:03 -0400468 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
James Smart1b511972011-12-13 13:23:09 -0500469 if ((phba->sli_rev == LPFC_SLI_REV4) &&
James Smart939723a2012-05-09 21:19:03 -0400470 !(phba->link_flag & LS_LOOPBACK_MODE) &&
471 !(vport->fc_flag & FC_PT2PT)) {
James Smart1b511972011-12-13 13:23:09 -0500472 ndlp = lpfc_findnode_did(vport, Fabric_DID);
473 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
474 rc = -ENODEV;
475 goto fail;
476 }
James Smart6fb120a2009-05-22 14:52:59 -0400477 }
478
James Smart6fb120a2009-05-22 14:52:59 -0400479 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
480 if (!mboxq) {
481 rc = -ENOMEM;
James Smartd6de08c2015-12-16 18:11:53 -0500482 goto fail;
James Smart6fb120a2009-05-22 14:52:59 -0400483 }
James Smartd6de08c2015-12-16 18:11:53 -0500484
485 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
486 if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
487 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
488 if (!dmabuf) {
489 rc = -ENOMEM;
490 goto fail;
491 }
492 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
493 if (!dmabuf->virt) {
494 rc = -ENOMEM;
495 goto fail;
496 }
497 memcpy(dmabuf->virt, &phba->fc_fabparam,
498 sizeof(struct serv_parm));
499 }
500
James Smart6fb120a2009-05-22 14:52:59 -0400501 vport->port_state = LPFC_FABRIC_CFG_LINK;
James Smartd6de08c2015-12-16 18:11:53 -0500502 if (dmabuf)
503 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
504 else
505 lpfc_reg_vfi(mboxq, vport, 0);
James Smartae05ebe2013-03-01 16:35:38 -0500506
James Smart6fb120a2009-05-22 14:52:59 -0400507 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
508 mboxq->vport = vport;
James Smart3e1f0712018-11-29 16:09:29 -0800509 mboxq->ctx_buf = dmabuf;
James Smart6fb120a2009-05-22 14:52:59 -0400510 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
511 if (rc == MBX_NOT_FINISHED) {
512 rc = -ENXIO;
James Smartd6de08c2015-12-16 18:11:53 -0500513 goto fail;
James Smart6fb120a2009-05-22 14:52:59 -0400514 }
515 return 0;
516
James Smart6fb120a2009-05-22 14:52:59 -0400517fail:
James Smartd6de08c2015-12-16 18:11:53 -0500518 if (mboxq)
519 mempool_free(mboxq, phba->mbox_mem_pool);
520 if (dmabuf) {
521 if (dmabuf->virt)
522 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
523 kfree(dmabuf);
524 }
525
James Smart6fb120a2009-05-22 14:52:59 -0400526 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
527 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
528 "0289 Issue Register VFI failed: Err %d\n", rc);
529 return rc;
530}
531
532/**
James Smart1b511972011-12-13 13:23:09 -0500533 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
534 * @vport: pointer to a host virtual N_Port data structure.
535 *
536 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
537 * the @vport. This mailbox command is necessary for SLI4 port only.
538 *
539 * Return code
540 * 0 - successfully issued REG_VFI for @vport
541 * A failure code otherwise.
542 **/
543int
544lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
545{
546 struct lpfc_hba *phba = vport->phba;
547 struct Scsi_Host *shost;
548 LPFC_MBOXQ_t *mboxq;
549 int rc;
550
551 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
552 if (!mboxq) {
553 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
554 "2556 UNREG_VFI mbox allocation failed"
555 "HBA state x%x\n", phba->pport->port_state);
556 return -ENOMEM;
557 }
558
559 lpfc_unreg_vfi(mboxq, vport);
560 mboxq->vport = vport;
561 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
562
563 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
564 if (rc == MBX_NOT_FINISHED) {
565 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
566 "2557 UNREG_VFI issue mbox failed rc x%x "
567 "HBA state x%x\n",
568 rc, phba->pport->port_state);
569 mempool_free(mboxq, phba->mbox_mem_pool);
570 return -EIO;
571 }
572
573 shost = lpfc_shost_from_vport(vport);
574 spin_lock_irq(shost->host_lock);
575 vport->fc_flag &= ~FC_VFI_REGISTERED;
576 spin_unlock_irq(shost->host_lock);
577 return 0;
578}
579
580/**
James Smart92494142011-02-16 12:39:44 -0500581 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
582 * @vport: pointer to a host virtual N_Port data structure.
583 * @sp: pointer to service parameter data structure.
584 *
585 * This routine is called from FLOGI/FDISC completion handler functions.
586 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
587 * node nodename is changed in the completion service parameter else return
588 * 0. This function also set flag in the vport data structure to delay
589 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
590 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
591 * node nodename is changed in the completion service parameter.
592 *
593 * Return code
594 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
595 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
596 *
597 **/
598static uint8_t
599lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
600 struct serv_parm *sp)
601{
James Smart8eb8b962016-07-06 12:36:08 -0700602 struct lpfc_hba *phba = vport->phba;
James Smart92494142011-02-16 12:39:44 -0500603 uint8_t fabric_param_changed = 0;
604 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
605
606 if ((vport->fc_prevDID != vport->fc_myDID) ||
607 memcmp(&vport->fabric_portname, &sp->portName,
608 sizeof(struct lpfc_name)) ||
609 memcmp(&vport->fabric_nodename, &sp->nodeName,
James Smartaeb3c812017-04-21 16:05:02 -0700610 sizeof(struct lpfc_name)) ||
611 (vport->vport_flag & FAWWPN_PARAM_CHG)) {
James Smart92494142011-02-16 12:39:44 -0500612 fabric_param_changed = 1;
James Smartaeb3c812017-04-21 16:05:02 -0700613 vport->vport_flag &= ~FAWWPN_PARAM_CHG;
614 }
James Smart92494142011-02-16 12:39:44 -0500615 /*
616 * Word 1 Bit 31 in common service parameter is overloaded.
617 * Word 1 Bit 31 in FLOGI request is multiple NPort request
618 * Word 1 Bit 31 in FLOGI response is clean address bit
619 *
620 * If fabric parameter is changed and clean address bit is
621 * cleared delay nport discovery if
622 * - vport->fc_prevDID != 0 (not initial discovery) OR
623 * - lpfc_delay_discovery module parameter is set.
624 */
625 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
James Smart8eb8b962016-07-06 12:36:08 -0700626 (vport->fc_prevDID || phba->cfg_delay_discovery)) {
James Smart92494142011-02-16 12:39:44 -0500627 spin_lock_irq(shost->host_lock);
628 vport->fc_flag |= FC_DISC_DELAYED;
629 spin_unlock_irq(shost->host_lock);
630 }
631
632 return fabric_param_changed;
633}
634
635
636/**
James Smart3621a712009-04-06 18:47:14 -0400637 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400638 * @vport: pointer to a host virtual N_Port data structure.
639 * @ndlp: pointer to a node-list data structure.
640 * @sp: pointer to service parameter data structure.
641 * @irsp: pointer to the IOCB within the lpfc response IOCB.
642 *
643 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
644 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
645 * port in a fabric topology. It properly sets up the parameters to the @ndlp
646 * from the IOCB response. It also check the newly assigned N_Port ID to the
647 * @vport against the previously assigned N_Port ID. If it is different from
648 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
649 * is invoked on all the remaining nodes with the @vport to unregister the
650 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
651 * is invoked to register login to the fabric.
652 *
653 * Return code
654 * 0 - Success (currently, always return 0)
655 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500656static int
James Smart2e0fef82007-06-17 19:56:36 -0500657lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
658 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500659{
James Smart2e0fef82007-06-17 19:56:36 -0500660 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
661 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500662 struct lpfc_nodelist *np;
663 struct lpfc_nodelist *next_np;
James Smart92494142011-02-16 12:39:44 -0500664 uint8_t fabric_param_changed;
dea31012005-04-17 16:05:31 -0500665
James Smart2e0fef82007-06-17 19:56:36 -0500666 spin_lock_irq(shost->host_lock);
667 vport->fc_flag |= FC_FABRIC;
668 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500669
670 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
671 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
672 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
673
James Smart12265f62010-10-22 11:05:53 -0400674 phba->fc_edtovResol = sp->cmn.edtovResolution;
dea31012005-04-17 16:05:31 -0500675 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
676
James Smart76a95d72010-11-20 23:11:48 -0500677 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500678 spin_lock_irq(shost->host_lock);
679 vport->fc_flag |= FC_PUBLIC_LOOP;
680 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500681 }
682
James Smart2e0fef82007-06-17 19:56:36 -0500683 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500684 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500685 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500686 ndlp->nlp_class_sup = 0;
687 if (sp->cls1.classValid)
688 ndlp->nlp_class_sup |= FC_COS_CLASS1;
689 if (sp->cls2.classValid)
690 ndlp->nlp_class_sup |= FC_COS_CLASS2;
691 if (sp->cls3.classValid)
692 ndlp->nlp_class_sup |= FC_COS_CLASS3;
693 if (sp->cls4.classValid)
694 ndlp->nlp_class_sup |= FC_COS_CLASS4;
695 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
696 sp->cmn.bbRcvSizeLsb;
James Smart92494142011-02-16 12:39:44 -0500697
698 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
James Smart4258e982015-12-16 18:11:58 -0500699 if (fabric_param_changed) {
700 /* Reset FDMI attribute masks based on config parameter */
James Smart8663cbb2016-03-31 14:12:33 -0700701 if (phba->cfg_enable_SmartSAN ||
702 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
James Smart4258e982015-12-16 18:11:58 -0500703 /* Setup appropriate attribute masks */
704 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -0700705 if (phba->cfg_enable_SmartSAN)
James Smart4258e982015-12-16 18:11:58 -0500706 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
707 else
708 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -0700709 } else {
710 vport->fdmi_hba_mask = 0;
711 vport->fdmi_port_mask = 0;
James Smart4258e982015-12-16 18:11:58 -0500712 }
713
714 }
James Smart92494142011-02-16 12:39:44 -0500715 memcpy(&vport->fabric_portname, &sp->portName,
716 sizeof(struct lpfc_name));
717 memcpy(&vport->fabric_nodename, &sp->nodeName,
718 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500719 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
720
James Smart92d7f7b2007-06-17 19:56:38 -0500721 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
722 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400723 lpfc_printf_vlog(vport, KERN_WARNING,
724 LOG_ELS | LOG_VPORT,
725 "1816 FLOGI NPIV supported, "
726 "response data 0x%x\n",
727 sp->cmn.response_multiple_NPort);
James Smart1b511972011-12-13 13:23:09 -0500728 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500729 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500730 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500731 } else {
732 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400733 to call reg_vnpid atleast for the physcial host */
734 lpfc_printf_vlog(vport, KERN_WARNING,
735 LOG_ELS | LOG_VPORT,
736 "1817 Fabric does not support NPIV "
737 "- configuring single port mode.\n");
James Smart1b511972011-12-13 13:23:09 -0500738 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500739 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500740 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500741 }
742 }
743
James Smartae05ebe2013-03-01 16:35:38 -0500744 /*
745 * For FC we need to do some special processing because of the SLI
746 * Port's default settings of the Common Service Parameters.
747 */
James Smartd6de08c2015-12-16 18:11:53 -0500748 if ((phba->sli_rev == LPFC_SLI_REV4) &&
749 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
James Smartae05ebe2013-03-01 16:35:38 -0500750 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
James Smartd6de08c2015-12-16 18:11:53 -0500751 if (fabric_param_changed)
James Smartae05ebe2013-03-01 16:35:38 -0500752 lpfc_unregister_fcf_prep(phba);
753
754 /* This should just update the VFI CSPs*/
755 if (vport->fc_flag & FC_VFI_REGISTERED)
756 lpfc_issue_reg_vfi(vport);
757 }
758
James Smart92494142011-02-16 12:39:44 -0500759 if (fabric_param_changed &&
James Smart92d7f7b2007-06-17 19:56:38 -0500760 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
761
762 /* If our NportID changed, we need to ensure all
763 * remaining NPORTs get unreg_login'ed.
764 */
765 list_for_each_entry_safe(np, next_np,
766 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400767 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500768 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500769 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
770 !(np->nlp_flag & NLP_NPR_ADISC))
771 continue;
772 spin_lock_irq(shost->host_lock);
773 np->nlp_flag &= ~NLP_NPR_ADISC;
774 spin_unlock_irq(shost->host_lock);
775 lpfc_unreg_rpi(vport, np);
776 }
James Smart78730cf2010-04-06 15:06:30 -0400777 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -0400778
James Smart5248a742011-07-22 18:37:06 -0400779 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart5af5eee2010-10-22 11:06:38 -0400780 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500781 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500782 spin_lock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -0500783 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
784 spin_unlock_irq(shost->host_lock);
785 }
James Smart27aa1b72012-05-09 21:18:49 -0400786
787 /*
788 * For SLI3 and SLI4, the VPI needs to be reregistered in
789 * response to this fabric parameter change event.
790 */
791 spin_lock_irq(shost->host_lock);
792 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
793 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -0400794 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
795 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
796 /*
797 * Driver needs to re-reg VPI in order for f/w
798 * to update the MAC address.
799 */
James Smart9589b0622011-04-16 11:03:17 -0400800 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart38b92ef2010-08-04 16:11:39 -0400801 lpfc_register_new_vport(phba, vport, ndlp);
802 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500803 }
804
James Smart6fb120a2009-05-22 14:52:59 -0400805 if (phba->sli_rev < LPFC_SLI_REV4) {
806 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
807 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
808 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
809 lpfc_register_new_vport(phba, vport, ndlp);
810 else
811 lpfc_issue_fabric_reglogin(vport);
812 } else {
813 ndlp->nlp_type |= NLP_FABRIC;
814 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500815 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
816 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400817 lpfc_start_fdiscs(phba);
818 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500819 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500820 lpfc_issue_init_vpi(vport);
James Smart1b511972011-12-13 13:23:09 -0500821 else {
822 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
823 "3135 Need register VFI: (x%x/%x)\n",
824 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -0400825 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -0500826 }
James Smart92d7f7b2007-06-17 19:56:38 -0500827 }
dea31012005-04-17 16:05:31 -0500828 return 0;
dea31012005-04-17 16:05:31 -0500829}
James Smart1b511972011-12-13 13:23:09 -0500830
James Smarte59058c2008-08-24 21:49:00 -0400831/**
James Smart3621a712009-04-06 18:47:14 -0400832 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400833 * @vport: pointer to a host virtual N_Port data structure.
834 * @ndlp: pointer to a node-list data structure.
835 * @sp: pointer to service parameter data structure.
836 *
837 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
838 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
839 * in a point-to-point topology. First, the @vport's N_Port Name is compared
840 * with the received N_Port Name: if the @vport's N_Port Name is greater than
841 * the received N_Port Name lexicographically, this node shall assign local
842 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
843 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
844 * this node shall just wait for the remote node to issue PLOGI and assign
845 * N_Port IDs.
846 *
847 * Return code
848 * 0 - Success
849 * -ENXIO - Fail
850 **/
dea31012005-04-17 16:05:31 -0500851static int
James Smart2e0fef82007-06-17 19:56:36 -0500852lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
853 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500854{
James Smart2e0fef82007-06-17 19:56:36 -0500855 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
856 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500857 LPFC_MBOXQ_t *mbox;
858 int rc;
859
James Smart2e0fef82007-06-17 19:56:36 -0500860 spin_lock_irq(shost->host_lock);
861 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
James Smartd6de08c2015-12-16 18:11:53 -0500862 vport->fc_flag |= FC_PT2PT;
James Smart2e0fef82007-06-17 19:56:36 -0500863 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500864
James Smartd33d0eb2017-11-20 16:00:34 -0800865 /* If we are pt2pt with another NPort, force NPIV off! */
866 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
867
James Smartd6de08c2015-12-16 18:11:53 -0500868 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
869 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
870 lpfc_unregister_fcf_prep(phba);
871
872 spin_lock_irq(shost->host_lock);
873 vport->fc_flag &= ~FC_VFI_REGISTERED;
874 spin_unlock_irq(shost->host_lock);
875 phba->fc_topology_changed = 0;
876 }
877
James Smart2e0fef82007-06-17 19:56:36 -0500878 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500879 sizeof(vport->fc_portname));
James Smart2eb68622012-09-29 11:32:27 -0400880
dea31012005-04-17 16:05:31 -0500881 if (rc >= 0) {
882 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500883 spin_lock_irq(shost->host_lock);
884 vport->fc_flag |= FC_PT2PT_PLOGI;
885 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500886
887 /*
James Smartd6de08c2015-12-16 18:11:53 -0500888 * N_Port ID cannot be 0, set our Id to LocalID
889 * the other side will be RemoteID.
dea31012005-04-17 16:05:31 -0500890 */
891
892 /* not equal */
893 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500894 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500895
James Smarte47c9092008-02-08 18:49:26 -0500896 /* Decrement ndlp reference count indicating that ndlp can be
897 * safely released when other references to it are done.
898 */
James Smart329f9bc2007-04-25 09:53:01 -0400899 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500900
James Smart2e0fef82007-06-17 19:56:36 -0500901 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500902 if (!ndlp) {
903 /*
904 * Cannot find existing Fabric ndlp, so allocate a
905 * new one
906 */
James Smart9d3d3402017-04-21 16:05:00 -0700907 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500908 if (!ndlp)
909 goto fail;
James Smarte47c9092008-02-08 18:49:26 -0500910 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
911 ndlp = lpfc_enable_node(vport, ndlp,
912 NLP_STE_UNUSED_NODE);
913 if(!ndlp)
914 goto fail;
dea31012005-04-17 16:05:31 -0500915 }
916
917 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500918 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500919 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500920 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500921 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500922 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
923 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500924 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500925 spin_unlock_irq(shost->host_lock);
James Smartd33d0eb2017-11-20 16:00:34 -0800926
927 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
928 if (!mbox)
929 goto fail;
930
931 lpfc_config_link(phba, mbox);
932
933 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
934 mbox->vport = vport;
935 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
936 if (rc == MBX_NOT_FINISHED) {
937 mempool_free(mbox, phba->mbox_mem_pool);
938 goto fail;
939 }
940 } else {
James Smarte47c9092008-02-08 18:49:26 -0500941 /* This side will wait for the PLOGI, decrement ndlp reference
942 * count indicating that ndlp can be released when other
943 * references to it are done.
944 */
James Smart329f9bc2007-04-25 09:53:01 -0400945 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500946
James Smartd33d0eb2017-11-20 16:00:34 -0800947 /* Start discovery - this should just do CLEAR_LA */
948 lpfc_disc_start(vport);
James Smarte74c03c2013-04-17 20:15:19 -0400949 }
dea31012005-04-17 16:05:31 -0500950
dea31012005-04-17 16:05:31 -0500951 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500952fail:
dea31012005-04-17 16:05:31 -0500953 return -ENXIO;
954}
955
James Smarte59058c2008-08-24 21:49:00 -0400956/**
James Smart3621a712009-04-06 18:47:14 -0400957 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400958 * @phba: pointer to lpfc hba data structure.
959 * @cmdiocb: pointer to lpfc command iocb data structure.
960 * @rspiocb: pointer to lpfc response iocb data structure.
961 *
962 * This routine is the top-level completion callback function for issuing
963 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
964 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
965 * retry has been made (either immediately or delayed with lpfc_els_retry()
966 * returning 1), the command IOCB will be released and function returned.
967 * If the retry attempt has been given up (possibly reach the maximum
968 * number of retries), one additional decrement of ndlp reference shall be
969 * invoked before going out after releasing the command IOCB. This will
970 * actually release the remote node (Note, lpfc_els_free_iocb() will also
971 * invoke one decrement of ndlp reference count). If no error reported in
972 * the IOCB status, the command Port ID field is used to determine whether
973 * this is a point-to-point topology or a fabric topology: if the Port ID
974 * field is assigned, it is a fabric topology; otherwise, it is a
975 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
976 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
977 * specific topology completion conditions.
978 **/
dea31012005-04-17 16:05:31 -0500979static void
James Smart329f9bc2007-04-25 09:53:01 -0400980lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
981 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500982{
James Smart2e0fef82007-06-17 19:56:36 -0500983 struct lpfc_vport *vport = cmdiocb->vport;
984 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500985 IOCB_t *irsp = &rspiocb->iocb;
986 struct lpfc_nodelist *ndlp = cmdiocb->context1;
987 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
988 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500989 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500990 int rc;
991
992 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500993 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500994 /* One additional decrement on node reference count to
995 * trigger the release of the node
996 */
James Smart329f9bc2007-04-25 09:53:01 -0400997 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500998 goto out;
999 }
1000
James Smart858c9f62007-06-17 19:56:39 -05001001 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1002 "FLOGI cmpl: status:x%x/x%x state:x%x",
1003 irsp->ulpStatus, irsp->un.ulpWord[4],
1004 vport->port_state);
1005
dea31012005-04-17 16:05:31 -05001006 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -05001007 /*
James Smarta93ff372010-10-22 11:06:08 -04001008 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -05001009 * due to new FCF discovery
1010 */
1011 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart80c17842012-03-01 22:35:45 -05001012 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1013 if (phba->link_state < LPFC_LINK_UP)
1014 goto stop_rr_fcf_flogi;
1015 if ((phba->fcoe_cvl_eventtag_attn ==
1016 phba->fcoe_cvl_eventtag) &&
1017 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -04001018 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1019 IOERR_SLI_ABORTED))
James Smart80c17842012-03-01 22:35:45 -05001020 goto stop_rr_fcf_flogi;
1021 else
1022 phba->fcoe_cvl_eventtag_attn =
1023 phba->fcoe_cvl_eventtag;
James Smart0c9ab6f2010-02-26 14:15:57 -05001024 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001025 "2611 FLOGI failed on FCF (x%x), "
1026 "status:x%x/x%x, tmo:x%x, perform "
1027 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -04001028 phba->fcf.current_rec.fcf_indx,
1029 irsp->ulpStatus, irsp->un.ulpWord[4],
1030 irsp->ulpTimeout);
James Smart7d791df2011-07-22 18:37:52 -04001031 lpfc_sli4_set_fcf_flogi_fail(phba,
1032 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001033 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -04001034 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1035 if (rc)
1036 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001037 }
1038
James Smart80c17842012-03-01 22:35:45 -05001039stop_rr_fcf_flogi:
James Smart38b92ef2010-08-04 16:11:39 -04001040 /* FLOGI failure */
James Smartc73455e2017-11-20 16:00:28 -08001041 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1042 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1043 IOERR_LOOP_OPEN_FAILURE)))
1044 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1045 "2858 FLOGI failure Status:x%x/x%x "
1046 "TMO:x%x Data x%x x%x\n",
1047 irsp->ulpStatus, irsp->un.ulpWord[4],
1048 irsp->ulpTimeout, phba->hba_flag,
1049 phba->fcf.fcf_flag);
James Smart38b92ef2010-08-04 16:11:39 -04001050
dea31012005-04-17 16:05:31 -05001051 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001052 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001053 goto out;
James Smart2e0fef82007-06-17 19:56:36 -05001054
James Smarte62245d2019-08-14 16:57:08 -07001055 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
1056 "0150 FLOGI failure Status:x%x/x%x "
1057 "xri x%x TMO:x%x\n",
1058 irsp->ulpStatus, irsp->un.ulpWord[4],
1059 cmdiocb->sli4_xritag, irsp->ulpTimeout);
1060
James Smartae9e28f2017-05-15 15:20:51 -07001061 /* If this is not a loop open failure, bail out */
1062 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1063 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1064 IOERR_LOOP_OPEN_FAILURE)))
1065 goto flogifail;
1066
dea31012005-04-17 16:05:31 -05001067 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -05001068 spin_lock_irq(shost->host_lock);
1069 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1070 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001071
James Smart329f9bc2007-04-25 09:53:01 -04001072 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -05001073 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1074 * alpa map would take too long otherwise.
1075 */
James Smart1b511972011-12-13 13:23:09 -05001076 if (phba->alpa_map[0] == 0)
James Smart3de2a652007-08-02 11:09:59 -04001077 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smartff78d8f2011-12-13 13:21:35 -05001078 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1079 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
James Smarte74c03c2013-04-17 20:15:19 -04001080 (vport->fc_prevDID != vport->fc_myDID) ||
1081 phba->fc_topology_changed)) {
1082 if (vport->fc_flag & FC_VFI_REGISTERED) {
1083 if (phba->fc_topology_changed) {
1084 lpfc_unregister_fcf_prep(phba);
1085 spin_lock_irq(shost->host_lock);
1086 vport->fc_flag &= ~FC_VFI_REGISTERED;
1087 spin_unlock_irq(shost->host_lock);
1088 phba->fc_topology_changed = 0;
1089 } else {
1090 lpfc_sli4_unreg_all_rpis(vport);
1091 }
1092 }
James Smart342b59c2016-03-31 14:12:31 -07001093
1094 /* Do not register VFI if the driver aborted FLOGI */
1095 if (!lpfc_error_lost_link(irsp))
1096 lpfc_issue_reg_vfi(vport);
James Smartff78d8f2011-12-13 13:21:35 -05001097 lpfc_nlp_put(ndlp);
1098 goto out;
dea31012005-04-17 16:05:31 -05001099 }
dea31012005-04-17 16:05:31 -05001100 goto flogifail;
1101 }
James Smart695a8142010-01-26 23:08:03 -05001102 spin_lock_irq(shost->host_lock);
1103 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04001104 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -05001105 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001106
1107 /*
1108 * The FLogI succeeded. Sync the data for the CPU before
1109 * accessing it.
1110 */
1111 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04001112 if (!prsp)
1113 goto out;
dea31012005-04-17 16:05:31 -05001114 sp = prsp->virt + sizeof(uint32_t);
1115
1116 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -04001117 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smart88f43a02013-04-17 20:19:44 -04001118 "0101 FLOGI completes successfully, I/O tag:x%x, "
James Smartd496b9a2018-10-23 13:41:08 -07001119 "xri x%x Data: x%x x%x x%x x%x x%x %x\n",
1120 cmdiocb->iotag, cmdiocb->sli4_xritag,
James Smarte8b62012007-08-02 11:10:09 -04001121 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
James Smarte74c03c2013-04-17 20:15:19 -04001122 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1123 vport->port_state, vport->fc_flag);
dea31012005-04-17 16:05:31 -05001124
James Smart2e0fef82007-06-17 19:56:36 -05001125 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -05001126 /*
1127 * If Common Service Parameters indicate Nport
1128 * we are point to point, if Fport we are Fabric.
1129 */
1130 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -05001131 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -05001132 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001133 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -04001134 else {
1135 lpfc_printf_vlog(vport, KERN_ERR,
1136 LOG_FIP | LOG_ELS,
1137 "2831 FLOGI response with cleared Fabric "
1138 "bit fcf_index 0x%x "
1139 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1140 "Fabric Name "
1141 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1142 phba->fcf.current_rec.fcf_indx,
1143 phba->fcf.current_rec.switch_name[0],
1144 phba->fcf.current_rec.switch_name[1],
1145 phba->fcf.current_rec.switch_name[2],
1146 phba->fcf.current_rec.switch_name[3],
1147 phba->fcf.current_rec.switch_name[4],
1148 phba->fcf.current_rec.switch_name[5],
1149 phba->fcf.current_rec.switch_name[6],
1150 phba->fcf.current_rec.switch_name[7],
1151 phba->fcf.current_rec.fabric_name[0],
1152 phba->fcf.current_rec.fabric_name[1],
1153 phba->fcf.current_rec.fabric_name[2],
1154 phba->fcf.current_rec.fabric_name[3],
1155 phba->fcf.current_rec.fabric_name[4],
1156 phba->fcf.current_rec.fabric_name[5],
1157 phba->fcf.current_rec.fabric_name[6],
1158 phba->fcf.current_rec.fabric_name[7]);
1159 lpfc_nlp_put(ndlp);
1160 spin_lock_irq(&phba->hbalock);
1161 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001162 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -04001163 spin_unlock_irq(&phba->hbalock);
James Smart036cad12018-10-23 13:41:06 -07001164 phba->fcf.fcf_redisc_attempted = 0; /* reset */
James Smartdbb6b3a2010-06-08 18:31:37 -04001165 goto out;
1166 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001167 if (!rc) {
1168 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -04001169 if (phba->hba_flag & HBA_FIP_SUPPORT)
1170 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1171 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001172 "2769 FLOGI to FCF (x%x) "
1173 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -04001174 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001175 spin_lock_irq(&phba->hbalock);
1176 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001177 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -05001178 spin_unlock_irq(&phba->hbalock);
James Smart036cad12018-10-23 13:41:06 -07001179 phba->fcf.fcf_redisc_attempted = 0; /* reset */
dea31012005-04-17 16:05:31 -05001180 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001181 }
dea31012005-04-17 16:05:31 -05001182 }
1183
1184flogifail:
James Smart8fe5c162015-08-31 16:48:19 -04001185 spin_lock_irq(&phba->hbalock);
1186 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1187 spin_unlock_irq(&phba->hbalock);
James Smartd6de08c2015-12-16 18:11:53 -05001188
James Smart329f9bc2007-04-25 09:53:01 -04001189 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001190
James Smart858c9f62007-06-17 19:56:39 -05001191 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001192 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001193 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001194
1195 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001196 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001197 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04001198 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1199 IOERR_SLI_ABORTED) &&
1200 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1201 IOERR_SLI_DOWN))) &&
James Smart87af33f2007-10-27 13:37:43 -04001202 (phba->link_state != LPFC_CLEAR_LA)) {
1203 /* If FLOGI failed enable link interrupt. */
1204 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001205 }
dea31012005-04-17 16:05:31 -05001206out:
1207 lpfc_els_free_iocb(phba, cmdiocb);
1208}
1209
James Smarte59058c2008-08-24 21:49:00 -04001210/**
James Smart6ede2dd2019-08-14 16:56:44 -07001211 * lpfc_cmpl_els_link_down - Completion callback function for ELS command
1212 * aborted during a link down
1213 * @phba: pointer to lpfc hba data structure.
1214 * @cmdiocb: pointer to lpfc command iocb data structure.
1215 * @rspiocb: pointer to lpfc response iocb data structure.
1216 *
1217 */
1218static void
1219lpfc_cmpl_els_link_down(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1220 struct lpfc_iocbq *rspiocb)
1221{
1222 IOCB_t *irsp;
1223 uint32_t *pcmd;
1224 uint32_t cmd;
1225
1226 pcmd = (uint32_t *)(((struct lpfc_dmabuf *)cmdiocb->context2)->virt);
1227 cmd = *pcmd;
1228 irsp = &rspiocb->iocb;
1229
1230 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1231 "6445 ELS completes after LINK_DOWN: "
1232 " Status %x/%x cmd x%x flg x%x\n",
1233 irsp->ulpStatus, irsp->un.ulpWord[4], cmd,
1234 cmdiocb->iocb_flag);
1235
1236 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) {
1237 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
1238 atomic_dec(&phba->fabric_iocb_count);
1239 }
1240 lpfc_els_free_iocb(phba, cmdiocb);
1241}
1242
1243/**
James Smart3621a712009-04-06 18:47:14 -04001244 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001245 * @vport: pointer to a host virtual N_Port data structure.
1246 * @ndlp: pointer to a node-list data structure.
1247 * @retry: number of retries to the command IOCB.
1248 *
1249 * This routine issues a Fabric Login (FLOGI) Request ELS command
1250 * for a @vport. The initiator service parameters are put into the payload
1251 * of the FLOGI Request IOCB and the top-level callback function pointer
1252 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1253 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1254 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1255 *
1256 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1257 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1258 * will be stored into the context1 field of the IOCB for the completion
1259 * callback function to the FLOGI ELS command.
1260 *
1261 * Return code
1262 * 0 - successfully issued flogi iocb for @vport
1263 * 1 - failed to issue flogi iocb for @vport
1264 **/
dea31012005-04-17 16:05:31 -05001265static int
James Smart2e0fef82007-06-17 19:56:36 -05001266lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001267 uint8_t retry)
1268{
James Smart2e0fef82007-06-17 19:56:36 -05001269 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001270 struct serv_parm *sp;
1271 IOCB_t *icmd;
1272 struct lpfc_iocbq *elsiocb;
James Smart0a9e9682018-11-29 16:09:36 -08001273 struct lpfc_iocbq defer_flogi_acc;
dea31012005-04-17 16:05:31 -05001274 uint8_t *pcmd;
1275 uint16_t cmdsize;
James Smart0a9e9682018-11-29 16:09:36 -08001276 uint32_t tmo, did;
dea31012005-04-17 16:05:31 -05001277 int rc;
1278
James Smart92d7f7b2007-06-17 19:56:38 -05001279 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001280 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1281 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001282
James Smart488d1462006-03-07 15:02:37 -05001283 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001284 return 1;
dea31012005-04-17 16:05:31 -05001285
1286 icmd = &elsiocb->iocb;
1287 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1288
1289 /* For FLOGI request, remainder of payload is service parameters */
1290 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001291 pcmd += sizeof(uint32_t);
1292 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001293 sp = (struct serv_parm *) pcmd;
1294
1295 /* Setup CSPs accordingly for Fabric */
1296 sp->cmn.e_d_tov = 0;
1297 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05001298 sp->cmn.virtual_fabric_support = 0;
dea31012005-04-17 16:05:31 -05001299 sp->cls1.classValid = 0;
dea31012005-04-17 16:05:31 -05001300 if (sp->cmn.fcphLow < FC_PH3)
1301 sp->cmn.fcphLow = FC_PH3;
1302 if (sp->cmn.fcphHigh < FC_PH3)
1303 sp->cmn.fcphHigh = FC_PH3;
1304
James Smartc31098c2011-04-16 11:03:33 -04001305 if (phba->sli_rev == LPFC_SLI_REV4) {
1306 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1307 LPFC_SLI_INTF_IF_TYPE_0) {
1308 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1309 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1310 /* FLOGI needs to be 3 for WQE FCFI */
1311 /* Set the fcfi to the fcfi we registered with */
1312 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1313 }
James Smart0f378872012-10-31 14:45:01 -04001314 /* Can't do SLI4 class2 without support sequence coalescing */
1315 sp->cls2.classValid = 0;
1316 sp->cls2.seqDelivery = 0;
James Smart5248a742011-07-22 18:37:06 -04001317 } else {
James Smart0f378872012-10-31 14:45:01 -04001318 /* Historical, setting sequential-delivery bit for SLI3 */
1319 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1320 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
James Smart5248a742011-07-22 18:37:06 -04001321 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1322 sp->cmn.request_multiple_Nport = 1;
1323 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1324 icmd->ulpCt_h = 1;
1325 icmd->ulpCt_l = 0;
1326 } else
1327 sp->cmn.request_multiple_Nport = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001328 }
1329
James Smart76a95d72010-11-20 23:11:48 -05001330 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001331 icmd->un.elsreq64.myID = 0;
1332 icmd->un.elsreq64.fl = 1;
1333 }
1334
dea31012005-04-17 16:05:31 -05001335 tmo = phba->fc_ratov;
1336 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001337 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001338 phba->fc_ratov = tmo;
1339
1340 phba->fc_stat.elsXmitFLOGI++;
1341 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001342
1343 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1344 "Issue FLOGI: opt:x%x",
1345 phba->sli3_options, 0, 0);
1346
James Smart92d7f7b2007-06-17 19:56:38 -05001347 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
James Smart0a9e9682018-11-29 16:09:36 -08001348
1349 phba->hba_flag |= HBA_FLOGI_ISSUED;
1350
1351 /* Check for a deferred FLOGI ACC condition */
1352 if (phba->defer_flogi_acc_flag) {
1353 did = vport->fc_myDID;
1354 vport->fc_myDID = Fabric_DID;
1355
1356 memset(&defer_flogi_acc, 0, sizeof(struct lpfc_iocbq));
1357
1358 defer_flogi_acc.iocb.ulpContext = phba->defer_flogi_acc_rx_id;
1359 defer_flogi_acc.iocb.unsli3.rcvsli3.ox_id =
1360 phba->defer_flogi_acc_ox_id;
1361
1362 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1363 "3354 Xmit deferred FLOGI ACC: rx_id: x%x,"
1364 " ox_id: x%x, hba_flag x%x\n",
1365 phba->defer_flogi_acc_rx_id,
1366 phba->defer_flogi_acc_ox_id, phba->hba_flag);
1367
1368 /* Send deferred FLOGI ACC */
1369 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, &defer_flogi_acc,
1370 ndlp, NULL);
1371
1372 phba->defer_flogi_acc_flag = false;
1373
1374 vport->fc_myDID = did;
1375 }
1376
dea31012005-04-17 16:05:31 -05001377 if (rc == IOCB_ERROR) {
1378 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001379 return 1;
dea31012005-04-17 16:05:31 -05001380 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001381 return 0;
dea31012005-04-17 16:05:31 -05001382}
1383
James Smarte59058c2008-08-24 21:49:00 -04001384/**
James Smart3621a712009-04-06 18:47:14 -04001385 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001386 * @phba: pointer to lpfc hba data structure.
1387 *
1388 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1389 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1390 * list and issues an abort IOCB commond on each outstanding IOCB that
1391 * contains a active Fabric_DID ndlp. Note that this function is to issue
1392 * the abort IOCB command on all the outstanding IOCBs, thus when this
1393 * function returns, it does not guarantee all the IOCBs are actually aborted.
1394 *
1395 * Return code
Daniel Mack3ad2f3fb2010-02-03 08:01:28 +08001396 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001397 **/
dea31012005-04-17 16:05:31 -05001398int
James Smart2e0fef82007-06-17 19:56:36 -05001399lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001400{
1401 struct lpfc_sli_ring *pring;
1402 struct lpfc_iocbq *iocb, *next_iocb;
1403 struct lpfc_nodelist *ndlp;
1404 IOCB_t *icmd;
1405
1406 /* Abort outstanding I/O on NPort <nlp_DID> */
1407 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001408 "0201 Abort outstanding I/O on NPort x%x\n",
1409 Fabric_DID);
dea31012005-04-17 16:05:31 -05001410
James Smart895427b2017-02-12 13:52:30 -08001411 pring = lpfc_phba_elsring(phba);
James Smart5a9eeff2018-11-29 16:09:32 -08001412 if (unlikely(!pring))
1413 return -EIO;
dea31012005-04-17 16:05:31 -05001414
1415 /*
1416 * Check the txcmplq for an iocb that matches the nport the driver is
1417 * searching for.
1418 */
James Smart2e0fef82007-06-17 19:56:36 -05001419 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001420 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1421 icmd = &iocb->iocb;
James Smart1b511972011-12-13 13:23:09 -05001422 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
dea31012005-04-17 16:05:31 -05001423 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001424 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1425 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001426 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001427 }
1428 }
James Smart2e0fef82007-06-17 19:56:36 -05001429 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001430
1431 return 0;
1432}
1433
James Smarte59058c2008-08-24 21:49:00 -04001434/**
James Smart3621a712009-04-06 18:47:14 -04001435 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001436 * @vport: pointer to a host virtual N_Port data structure.
1437 *
1438 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1439 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1440 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1441 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1442 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1443 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1444 * @vport.
1445 *
1446 * Return code
1447 * 0 - failed to issue initial flogi for @vport
1448 * 1 - successfully issued initial flogi for @vport
1449 **/
dea31012005-04-17 16:05:31 -05001450int
James Smart2e0fef82007-06-17 19:56:36 -05001451lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001452{
1453 struct lpfc_nodelist *ndlp;
1454
James Smart98c9ea52007-10-27 13:37:33 -04001455 vport->port_state = LPFC_FLOGI;
1456 lpfc_set_disctmo(vport);
1457
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001458 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001459 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001460 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001461 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07001462 ndlp = lpfc_nlp_init(vport, Fabric_DID);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001463 if (!ndlp)
1464 return 0;
James Smart6fb120a2009-05-22 14:52:59 -04001465 /* Set the node type */
1466 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001467 /* Put ndlp onto node list */
1468 lpfc_enqueue_node(vport, ndlp);
1469 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1470 /* re-setup ndlp without removing from node list */
1471 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1472 if (!ndlp)
1473 return 0;
dea31012005-04-17 16:05:31 -05001474 }
James Smart87af33f2007-10-27 13:37:43 -04001475
James Smart5ac6b302010-10-22 11:05:36 -04001476 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001477 /* This decrement of reference count to node shall kick off
1478 * the release of the node.
1479 */
James Smart329f9bc2007-04-25 09:53:01 -04001480 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001481 return 0;
1482 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001483 return 1;
dea31012005-04-17 16:05:31 -05001484}
1485
James Smarte59058c2008-08-24 21:49:00 -04001486/**
James Smart3621a712009-04-06 18:47:14 -04001487 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001488 * @vport: pointer to a host virtual N_Port data structure.
1489 *
1490 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1491 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1492 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1493 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1494 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1495 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1496 * @vport.
1497 *
1498 * Return code
1499 * 0 - failed to issue initial fdisc for @vport
1500 * 1 - successfully issued initial fdisc for @vport
1501 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001502int
1503lpfc_initial_fdisc(struct lpfc_vport *vport)
1504{
James Smart92d7f7b2007-06-17 19:56:38 -05001505 struct lpfc_nodelist *ndlp;
1506
1507 /* First look for the Fabric ndlp */
1508 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1509 if (!ndlp) {
1510 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07001511 ndlp = lpfc_nlp_init(vport, Fabric_DID);
James Smart92d7f7b2007-06-17 19:56:38 -05001512 if (!ndlp)
1513 return 0;
James Smarte47c9092008-02-08 18:49:26 -05001514 /* Put ndlp onto node list */
1515 lpfc_enqueue_node(vport, ndlp);
1516 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1517 /* re-setup ndlp without removing from node list */
1518 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1519 if (!ndlp)
1520 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001521 }
James Smarte47c9092008-02-08 18:49:26 -05001522
James Smart92d7f7b2007-06-17 19:56:38 -05001523 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001524 /* decrement node reference count to trigger the release of
1525 * the node.
1526 */
James Smart92d7f7b2007-06-17 19:56:38 -05001527 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001528 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001529 }
1530 return 1;
1531}
James Smart87af33f2007-10-27 13:37:43 -04001532
James Smarte59058c2008-08-24 21:49:00 -04001533/**
James Smart3621a712009-04-06 18:47:14 -04001534 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001535 * @vport: pointer to a host virtual N_Port data structure.
1536 *
1537 * This routine checks whether there are more remaining Port Logins
1538 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1539 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1540 * to issue ELS PLOGIs up to the configured discover threads with the
1541 * @vport (@vport->cfg_discovery_threads). The function also decrement
1542 * the @vport's num_disc_node by 1 if it is not already 0.
1543 **/
James Smart87af33f2007-10-27 13:37:43 -04001544void
James Smart2e0fef82007-06-17 19:56:36 -05001545lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001546{
James Smart2e0fef82007-06-17 19:56:36 -05001547 if (vport->num_disc_nodes)
1548 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001549
1550 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001551 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1552 "0232 Continue discovery with %d PLOGIs to go "
1553 "Data: x%x x%x x%x\n",
1554 vport->num_disc_nodes, vport->fc_plogi_cnt,
1555 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001556 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001557 if (vport->fc_flag & FC_NLP_MORE)
1558 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -04001559 lpfc_els_disc_plogi(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001560
dea31012005-04-17 16:05:31 -05001561 return;
1562}
1563
James Smarte59058c2008-08-24 21:49:00 -04001564/**
James Smart3621a712009-04-06 18:47:14 -04001565 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001566 * @phba: pointer to lpfc hba data structure.
1567 * @prsp: pointer to response IOCB payload.
1568 * @ndlp: pointer to a node-list data structure.
1569 *
1570 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1571 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1572 * The following cases are considered N_Port confirmed:
1573 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1574 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1575 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1576 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1577 * 1) if there is a node on vport list other than the @ndlp with the same
1578 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1579 * on that node to release the RPI associated with the node; 2) if there is
1580 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1581 * into, a new node shall be allocated (or activated). In either case, the
1582 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1583 * be released and the new_ndlp shall be put on to the vport node list and
1584 * its pointer returned as the confirmed node.
1585 *
1586 * Note that before the @ndlp got "released", the keepDID from not-matching
1587 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1588 * of the @ndlp. This is because the release of @ndlp is actually to put it
1589 * into an inactive state on the vport node list and the vport node list
1590 * management algorithm does not allow two node with a same DID.
1591 *
1592 * Return code
1593 * pointer to the PLOGI N_Port @ndlp
1594 **/
James Smart488d1462006-03-07 15:02:37 -05001595static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001596lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001597 struct lpfc_nodelist *ndlp)
1598{
James Smarta0f2d3e2017-02-12 13:52:31 -08001599 struct lpfc_vport *vport = ndlp->vport;
James Smart953ceed2015-05-22 10:42:37 -04001600 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05001601 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001602 struct lpfc_rport_data *rdata;
1603 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001604 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001605 uint8_t name[sizeof(struct lpfc_name)];
James Smarte5abba42015-05-21 13:55:27 -04001606 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
James Smart92ea83a2018-11-29 16:09:34 -08001607 uint32_t keep_new_nlp_flag = 0;
James Smart953ceed2015-05-22 10:42:37 -04001608 uint16_t keep_nlp_state;
James Smart92ea83a2018-11-29 16:09:34 -08001609 u32 keep_nlp_fc4_type = 0;
Dick Kennedy4adc0412017-08-23 16:55:37 -07001610 struct lpfc_nvme_rport *keep_nrport = NULL;
James Smart38b92ef2010-08-04 16:11:39 -04001611 int put_node;
1612 int put_rport;
James Smartcff261f2013-12-17 20:29:47 -05001613 unsigned long *active_rrqs_xri_bitmap = NULL;
James Smart488d1462006-03-07 15:02:37 -05001614
James Smart2fb9bd82006-12-02 13:33:57 -05001615 /* Fabric nodes can have the same WWPN so we don't bother searching
1616 * by WWPN. Just return the ndlp that was given to us.
1617 */
1618 if (ndlp->nlp_type & NLP_FABRIC)
1619 return ndlp;
1620
James Smart92d7f7b2007-06-17 19:56:38 -05001621 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001622 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001623
James Smart685f0bf2007-04-25 09:53:08 -04001624 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001625 * we have for that ndlp. If not, we have some work to do.
1626 */
James Smart2e0fef82007-06-17 19:56:36 -05001627 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001628
James Smartd83ca3e2018-10-23 13:41:09 -07001629 /* return immediately if the WWPN matches ndlp */
James Smarte47c9092008-02-08 18:49:26 -05001630 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001631 return ndlp;
James Smartd83ca3e2018-10-23 13:41:09 -07001632
James Smartcff261f2013-12-17 20:29:47 -05001633 if (phba->sli_rev == LPFC_SLI_REV4) {
1634 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1635 GFP_KERNEL);
1636 if (active_rrqs_xri_bitmap)
1637 memset(active_rrqs_xri_bitmap, 0,
1638 phba->cfg_rrq_xri_bitmap_sz);
1639 }
James Smart488d1462006-03-07 15:02:37 -05001640
James Smartd83ca3e2018-10-23 13:41:09 -07001641 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1642 "3178 PLOGI confirm: ndlp x%x x%x x%x: "
1643 "new_ndlp x%x x%x x%x\n",
1644 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type,
1645 (new_ndlp ? new_ndlp->nlp_DID : 0),
1646 (new_ndlp ? new_ndlp->nlp_flag : 0),
1647 (new_ndlp ? new_ndlp->nlp_fc4_type : 0));
James Smart34f5ad82012-08-03 12:35:03 -04001648
James Smart488d1462006-03-07 15:02:37 -05001649 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001650 rc = memcmp(&ndlp->nlp_portname, name,
1651 sizeof(struct lpfc_name));
James Smartcff261f2013-12-17 20:29:47 -05001652 if (!rc) {
1653 if (active_rrqs_xri_bitmap)
1654 mempool_free(active_rrqs_xri_bitmap,
1655 phba->active_rrq_pool);
James Smart92795652006-07-06 15:50:02 -04001656 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001657 }
James Smart9d3d3402017-04-21 16:05:00 -07001658 new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
James Smartcff261f2013-12-17 20:29:47 -05001659 if (!new_ndlp) {
1660 if (active_rrqs_xri_bitmap)
1661 mempool_free(active_rrqs_xri_bitmap,
1662 phba->active_rrq_pool);
James Smart488d1462006-03-07 15:02:37 -05001663 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001664 }
James Smarte47c9092008-02-08 18:49:26 -05001665 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001666 rc = memcmp(&ndlp->nlp_portname, name,
1667 sizeof(struct lpfc_name));
James Smartcff261f2013-12-17 20:29:47 -05001668 if (!rc) {
1669 if (active_rrqs_xri_bitmap)
1670 mempool_free(active_rrqs_xri_bitmap,
1671 phba->active_rrq_pool);
James Smart58da1ff2008-04-07 10:15:56 -04001672 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001673 }
James Smarte47c9092008-02-08 18:49:26 -05001674 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1675 NLP_STE_UNUSED_NODE);
James Smartcff261f2013-12-17 20:29:47 -05001676 if (!new_ndlp) {
1677 if (active_rrqs_xri_bitmap)
1678 mempool_free(active_rrqs_xri_bitmap,
1679 phba->active_rrq_pool);
James Smarte47c9092008-02-08 18:49:26 -05001680 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001681 }
James Smart58da1ff2008-04-07 10:15:56 -04001682 keepDID = new_ndlp->nlp_DID;
James Smartcff261f2013-12-17 20:29:47 -05001683 if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap)
1684 memcpy(active_rrqs_xri_bitmap,
1685 new_ndlp->active_rrqs_xri_bitmap,
1686 phba->cfg_rrq_xri_bitmap_sz);
James Smart19ca7602010-11-20 23:11:55 -05001687 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001688 keepDID = new_ndlp->nlp_DID;
James Smartcff261f2013-12-17 20:29:47 -05001689 if (phba->sli_rev == LPFC_SLI_REV4 &&
1690 active_rrqs_xri_bitmap)
1691 memcpy(active_rrqs_xri_bitmap,
1692 new_ndlp->active_rrqs_xri_bitmap,
1693 phba->cfg_rrq_xri_bitmap_sz);
James Smart19ca7602010-11-20 23:11:55 -05001694 }
James Smart488d1462006-03-07 15:02:37 -05001695
James Smartd83ca3e2018-10-23 13:41:09 -07001696 /* At this point in this routine, we know new_ndlp will be
1697 * returned. however, any previous GID_FTs that were done
1698 * would have updated nlp_fc4_type in ndlp, so we must ensure
1699 * new_ndlp has the right value.
1700 */
James Smart92ea83a2018-11-29 16:09:34 -08001701 if (vport->fc_flag & FC_FABRIC) {
1702 keep_nlp_fc4_type = new_ndlp->nlp_fc4_type;
James Smartd83ca3e2018-10-23 13:41:09 -07001703 new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
James Smart92ea83a2018-11-29 16:09:34 -08001704 }
James Smartd83ca3e2018-10-23 13:41:09 -07001705
James Smart2e0fef82007-06-17 19:56:36 -05001706 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001707 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001708 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001709 if (phba->sli_rev == LPFC_SLI_REV4)
James Smartcff261f2013-12-17 20:29:47 -05001710 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1711 ndlp->active_rrqs_xri_bitmap,
1712 phba->cfg_rrq_xri_bitmap_sz);
James Smart0ff10d42008-01-11 01:52:36 -05001713
James Smart953ceed2015-05-22 10:42:37 -04001714 spin_lock_irq(shost->host_lock);
James Smart92ea83a2018-11-29 16:09:34 -08001715 keep_new_nlp_flag = new_ndlp->nlp_flag;
1716 keep_nlp_flag = ndlp->nlp_flag;
James Smarte5abba42015-05-21 13:55:27 -04001717 new_ndlp->nlp_flag = ndlp->nlp_flag;
James Smartdea16bd2018-11-29 16:09:30 -08001718
1719 /* if new_ndlp had NLP_UNREG_INP set, keep it */
James Smart92ea83a2018-11-29 16:09:34 -08001720 if (keep_new_nlp_flag & NLP_UNREG_INP)
James Smartdea16bd2018-11-29 16:09:30 -08001721 new_ndlp->nlp_flag |= NLP_UNREG_INP;
1722 else
1723 new_ndlp->nlp_flag &= ~NLP_UNREG_INP;
1724
James Smart92ea83a2018-11-29 16:09:34 -08001725 /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */
1726 if (keep_new_nlp_flag & NLP_RPI_REGISTERED)
1727 new_ndlp->nlp_flag |= NLP_RPI_REGISTERED;
James Smartdea16bd2018-11-29 16:09:30 -08001728 else
James Smart92ea83a2018-11-29 16:09:34 -08001729 new_ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1730
1731 ndlp->nlp_flag = keep_new_nlp_flag;
1732
1733 /* if ndlp had NLP_UNREG_INP set, keep it */
1734 if (keep_nlp_flag & NLP_UNREG_INP)
1735 ndlp->nlp_flag |= NLP_UNREG_INP;
1736 else
1737 ndlp->nlp_flag &= ~NLP_UNREG_INP;
1738
1739 /* if ndlp had NLP_RPI_REGISTERED set, keep it */
1740 if (keep_nlp_flag & NLP_RPI_REGISTERED)
1741 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1742 else
1743 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
James Smartdea16bd2018-11-29 16:09:30 -08001744
James Smart953ceed2015-05-22 10:42:37 -04001745 spin_unlock_irq(shost->host_lock);
James Smart0ff10d42008-01-11 01:52:36 -05001746
James Smart953ceed2015-05-22 10:42:37 -04001747 /* Set nlp_states accordingly */
1748 keep_nlp_state = new_ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001749 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001750
Dick Kennedy4adc0412017-08-23 16:55:37 -07001751 /* interchange the nvme remoteport structs */
1752 keep_nrport = new_ndlp->nrport;
1753 new_ndlp->nrport = ndlp->nrport;
1754
James Smart2e0fef82007-06-17 19:56:36 -05001755 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001756 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1757 /* The new_ndlp is replacing ndlp totally, so we need
1758 * to put ndlp on UNUSED list and try to free it.
1759 */
James Smart34f5ad82012-08-03 12:35:03 -04001760 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1761 "3179 PLOGI confirm NEW: %x %x\n",
1762 new_ndlp->nlp_DID, keepDID);
James Smart0ff10d42008-01-11 01:52:36 -05001763
1764 /* Fix up the rport accordingly */
1765 rport = ndlp->rport;
1766 if (rport) {
1767 rdata = rport->dd_data;
1768 if (rdata->pnode == ndlp) {
James Smart466e8402015-05-21 13:55:28 -04001769 /* break the link before dropping the ref */
James Smart0ff10d42008-01-11 01:52:36 -05001770 ndlp->rport = NULL;
James Smart466e8402015-05-21 13:55:28 -04001771 lpfc_nlp_put(ndlp);
James Smart0ff10d42008-01-11 01:52:36 -05001772 rdata->pnode = lpfc_nlp_get(new_ndlp);
1773 new_ndlp->rport = rport;
1774 }
1775 new_ndlp->nlp_type = ndlp->nlp_type;
1776 }
Dick Kennedy4adc0412017-08-23 16:55:37 -07001777
1778 /* Fix up the nvme rport */
1779 if (ndlp->nrport) {
1780 ndlp->nrport = NULL;
1781 lpfc_nlp_put(ndlp);
1782 }
1783
James Smart58da1ff2008-04-07 10:15:56 -04001784 /* We shall actually free the ndlp with both nlp_DID and
1785 * nlp_portname fields equals 0 to avoid any ndlp on the
1786 * nodelist never to be used.
1787 */
1788 if (ndlp->nlp_DID == 0) {
1789 spin_lock_irq(&phba->ndlp_lock);
1790 NLP_SET_FREE_REQ(ndlp);
1791 spin_unlock_irq(&phba->ndlp_lock);
1792 }
James Smart0ff10d42008-01-11 01:52:36 -05001793
James Smart92ea83a2018-11-29 16:09:34 -08001794 /* Two ndlps cannot have the same did on the nodelist.
1795 * Note: for this case, ndlp has a NULL WWPN so setting
1796 * the nlp_fc4_type isn't required.
1797 */
James Smart58da1ff2008-04-07 10:15:56 -04001798 ndlp->nlp_DID = keepDID;
James Smart49382502017-11-20 16:00:38 -08001799 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
James Smartcff261f2013-12-17 20:29:47 -05001800 if (phba->sli_rev == LPFC_SLI_REV4 &&
1801 active_rrqs_xri_bitmap)
1802 memcpy(ndlp->active_rrqs_xri_bitmap,
1803 active_rrqs_xri_bitmap,
1804 phba->cfg_rrq_xri_bitmap_sz);
James Smarte5abba42015-05-21 13:55:27 -04001805
1806 if (!NLP_CHK_NODE_ACT(ndlp))
1807 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001808 }
James Smart92795652006-07-06 15:50:02 -04001809 else {
James Smart34f5ad82012-08-03 12:35:03 -04001810 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1811 "3180 PLOGI confirm SWAP: %x %x\n",
1812 new_ndlp->nlp_DID, keepDID);
1813
James Smart2e0fef82007-06-17 19:56:36 -05001814 lpfc_unreg_rpi(vport, ndlp);
James Smart34f5ad82012-08-03 12:35:03 -04001815
James Smart92ea83a2018-11-29 16:09:34 -08001816 /* Two ndlps cannot have the same did and the fc4
1817 * type must be transferred because the ndlp is in
1818 * flight.
1819 */
James Smart58da1ff2008-04-07 10:15:56 -04001820 ndlp->nlp_DID = keepDID;
James Smart92ea83a2018-11-29 16:09:34 -08001821 ndlp->nlp_fc4_type = keep_nlp_fc4_type;
1822
James Smartcff261f2013-12-17 20:29:47 -05001823 if (phba->sli_rev == LPFC_SLI_REV4 &&
1824 active_rrqs_xri_bitmap)
1825 memcpy(ndlp->active_rrqs_xri_bitmap,
1826 active_rrqs_xri_bitmap,
1827 phba->cfg_rrq_xri_bitmap_sz);
James Smart34f5ad82012-08-03 12:35:03 -04001828
James Smart953ceed2015-05-22 10:42:37 -04001829 /* Since we are switching over to the new_ndlp,
1830 * reset the old ndlp state
James Smart34f5ad82012-08-03 12:35:03 -04001831 */
1832 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1833 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
James Smart953ceed2015-05-22 10:42:37 -04001834 keep_nlp_state = NLP_STE_NPR_NODE;
1835 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
James Smart34f5ad82012-08-03 12:35:03 -04001836
Dick Kennedy4adc0412017-08-23 16:55:37 -07001837 /* Previous ndlp no longer active with nvme host transport.
1838 * Remove reference from earlier registration unless the
1839 * nvme host took care of it.
1840 */
1841 if (ndlp->nrport)
1842 lpfc_nlp_put(ndlp);
1843 ndlp->nrport = keep_nrport;
1844
James Smart38b92ef2010-08-04 16:11:39 -04001845 /* Fix up the rport accordingly */
1846 rport = ndlp->rport;
1847 if (rport) {
1848 rdata = rport->dd_data;
1849 put_node = rdata->pnode != NULL;
1850 put_rport = ndlp->rport != NULL;
1851 rdata->pnode = NULL;
1852 ndlp->rport = NULL;
1853 if (put_node)
1854 lpfc_nlp_put(ndlp);
1855 if (put_rport)
1856 put_device(&rport->dev);
1857 }
James Smart92795652006-07-06 15:50:02 -04001858 }
James Smartcff261f2013-12-17 20:29:47 -05001859 if (phba->sli_rev == LPFC_SLI_REV4 &&
1860 active_rrqs_xri_bitmap)
1861 mempool_free(active_rrqs_xri_bitmap,
1862 phba->active_rrq_pool);
James Smartd83ca3e2018-10-23 13:41:09 -07001863
1864 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1865 "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
1866 new_ndlp->nlp_DID, new_ndlp->nlp_flag,
1867 new_ndlp->nlp_fc4_type);
1868
James Smart488d1462006-03-07 15:02:37 -05001869 return new_ndlp;
1870}
1871
James Smarte59058c2008-08-24 21:49:00 -04001872/**
James Smart3621a712009-04-06 18:47:14 -04001873 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001874 * @vport: pointer to a host virtual N_Port data structure.
1875 *
1876 * This routine checks whether more Registration State Change
1877 * Notifications (RSCNs) came in while the discovery state machine was in
1878 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1879 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1880 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1881 * handling the RSCNs.
1882 **/
James Smart87af33f2007-10-27 13:37:43 -04001883void
1884lpfc_end_rscn(struct lpfc_vport *vport)
1885{
1886 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1887
1888 if (vport->fc_flag & FC_RSCN_MODE) {
1889 /*
1890 * Check to see if more RSCNs came in while we were
1891 * processing this one.
1892 */
1893 if (vport->fc_rscn_id_cnt ||
1894 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1895 lpfc_els_handle_rscn(vport);
1896 else {
1897 spin_lock_irq(shost->host_lock);
1898 vport->fc_flag &= ~FC_RSCN_MODE;
1899 spin_unlock_irq(shost->host_lock);
1900 }
1901 }
1902}
1903
James Smarte59058c2008-08-24 21:49:00 -04001904/**
James Smart19ca7602010-11-20 23:11:55 -05001905 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1906 * @phba: pointer to lpfc hba data structure.
1907 * @cmdiocb: pointer to lpfc command iocb data structure.
1908 * @rspiocb: pointer to lpfc response iocb data structure.
1909 *
1910 * This routine will call the clear rrq function to free the rrq and
1911 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1912 * exist then the clear_rrq is still called because the rrq needs to
1913 * be freed.
1914 **/
1915
1916static void
1917lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1918 struct lpfc_iocbq *rspiocb)
1919{
1920 struct lpfc_vport *vport = cmdiocb->vport;
1921 IOCB_t *irsp;
1922 struct lpfc_nodelist *ndlp;
1923 struct lpfc_node_rrq *rrq;
1924
1925 /* we pass cmdiocb to state machine which needs rspiocb as well */
1926 rrq = cmdiocb->context_un.rrq;
1927 cmdiocb->context_un.rsp_iocb = rspiocb;
1928
1929 irsp = &rspiocb->iocb;
1930 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1931 "RRQ cmpl: status:x%x/x%x did:x%x",
1932 irsp->ulpStatus, irsp->un.ulpWord[4],
1933 irsp->un.elsreq64.remoteID);
1934
1935 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1936 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1937 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1938 "2882 RRQ completes to NPort x%x "
1939 "with no ndlp. Data: x%x x%x x%x\n",
1940 irsp->un.elsreq64.remoteID,
1941 irsp->ulpStatus, irsp->un.ulpWord[4],
1942 irsp->ulpIoTag);
1943 goto out;
1944 }
1945
1946 /* rrq completes to NPort <nlp_DID> */
1947 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1948 "2880 RRQ completes to NPort x%x "
1949 "Data: x%x x%x x%x x%x x%x\n",
1950 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1951 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1952
1953 if (irsp->ulpStatus) {
1954 /* Check for retry */
1955 /* RRQ failed Don't print the vport to vport rjts */
1956 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1957 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1958 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1959 (phba)->pport->cfg_log_verbose & LOG_ELS)
1960 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1961 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1962 ndlp->nlp_DID, irsp->ulpStatus,
1963 irsp->un.ulpWord[4]);
1964 }
1965out:
1966 if (rrq)
1967 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1968 lpfc_els_free_iocb(phba, cmdiocb);
1969 return;
1970}
1971/**
James Smart3621a712009-04-06 18:47:14 -04001972 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001973 * @phba: pointer to lpfc hba data structure.
1974 * @cmdiocb: pointer to lpfc command iocb data structure.
1975 * @rspiocb: pointer to lpfc response iocb data structure.
1976 *
1977 * This routine is the completion callback function for issuing the Port
1978 * Login (PLOGI) command. For PLOGI completion, there must be an active
1979 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001980 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001981 * ignored and command IOCB released. The PLOGI response IOCB status is
1982 * checked for error conditons. If there is error status reported, PLOGI
1983 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1984 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1985 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1986 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1987 * there are additional N_Port nodes with the vport that need to perform
1988 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1989 * PLOGIs.
1990 **/
dea31012005-04-17 16:05:31 -05001991static void
James Smart2e0fef82007-06-17 19:56:36 -05001992lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1993 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001994{
James Smart2e0fef82007-06-17 19:56:36 -05001995 struct lpfc_vport *vport = cmdiocb->vport;
1996 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001997 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001998 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001999 struct lpfc_dmabuf *prsp;
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07002000 int disc;
dea31012005-04-17 16:05:31 -05002001
dea31012005-04-17 16:05:31 -05002002 /* we pass cmdiocb to state machine which needs rspiocb as well */
2003 cmdiocb->context_un.rsp_iocb = rspiocb;
2004
2005 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05002006 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2007 "PLOGI cmpl: status:x%x/x%x did:x%x",
2008 irsp->ulpStatus, irsp->un.ulpWord[4],
2009 irsp->un.elsreq64.remoteID);
2010
James Smart2e0fef82007-06-17 19:56:36 -05002011 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05002012 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04002013 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2014 "0136 PLOGI completes to NPort x%x "
2015 "with no ndlp. Data: x%x x%x x%x\n",
2016 irsp->un.elsreq64.remoteID,
2017 irsp->ulpStatus, irsp->un.ulpWord[4],
2018 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05002019 goto out;
James Smarted957682007-06-17 19:56:37 -05002020 }
dea31012005-04-17 16:05:31 -05002021
2022 /* Since ndlp can be freed in the disc state machine, note if this node
2023 * is being used during discovery.
2024 */
James Smart2e0fef82007-06-17 19:56:36 -05002025 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002026 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05002027 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002028 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002029
2030 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002031 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta0f2d3e2017-02-12 13:52:31 -08002032 "0102 PLOGI completes to NPort x%06x "
James Smarte8b62012007-08-02 11:10:09 -04002033 "Data: x%x x%x x%x x%x x%x\n",
James Smarta0f2d3e2017-02-12 13:52:31 -08002034 ndlp->nlp_DID, ndlp->nlp_fc4_type,
2035 irsp->ulpStatus, irsp->un.ulpWord[4],
2036 disc, vport->num_disc_nodes);
2037
dea31012005-04-17 16:05:31 -05002038 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002039 if (lpfc_els_chk_latt(vport)) {
2040 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002041 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002042 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002043 goto out;
2044 }
2045
dea31012005-04-17 16:05:31 -05002046 if (irsp->ulpStatus) {
2047 /* Check for retry */
2048 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2049 /* ELS command is being retried */
2050 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002051 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002052 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002053 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002054 }
2055 goto out;
2056 }
James Smart2a9bf3d2010-06-07 15:24:45 -04002057 /* PLOGI failed Don't print the vport to vport rjts */
2058 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
2059 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
2060 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
2061 (phba)->pport->cfg_log_verbose & LOG_ELS)
2062 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05002063 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
2064 ndlp->nlp_DID, irsp->ulpStatus,
2065 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002066 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07002067 if (!lpfc_error_lost_link(irsp))
2068 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2069 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05002070 } else {
2071 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04002072 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05002073 cmdiocb->context2)->list.next,
2074 struct lpfc_dmabuf, list);
2075 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07002076 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002077 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05002078 }
2079
James Smart2e0fef82007-06-17 19:56:36 -05002080 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05002081 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002082 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05002083
James Smart2e0fef82007-06-17 19:56:36 -05002084 if (vport->num_disc_nodes == 0) {
2085 spin_lock_irq(shost->host_lock);
2086 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2087 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002088
James Smart2e0fef82007-06-17 19:56:36 -05002089 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04002090 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05002091 }
2092 }
2093
2094out:
2095 lpfc_els_free_iocb(phba, cmdiocb);
2096 return;
2097}
2098
James Smarte59058c2008-08-24 21:49:00 -04002099/**
James Smart3621a712009-04-06 18:47:14 -04002100 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04002101 * @vport: pointer to a host virtual N_Port data structure.
2102 * @did: destination port identifier.
2103 * @retry: number of retries to the command IOCB.
2104 *
2105 * This routine issues a Port Login (PLOGI) command to a remote N_Port
2106 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
2107 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
2108 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
2109 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
2110 *
2111 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2112 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2113 * will be stored into the context1 field of the IOCB for the completion
2114 * callback function to the PLOGI ELS command.
2115 *
2116 * Return code
2117 * 0 - Successfully issued a plogi for @vport
2118 * 1 - failed to issue a plogi for @vport
2119 **/
dea31012005-04-17 16:05:31 -05002120int
James Smart2e0fef82007-06-17 19:56:36 -05002121lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05002122{
James Smart2e0fef82007-06-17 19:56:36 -05002123 struct lpfc_hba *phba = vport->phba;
Dick Kennedy8db1c2b2017-08-23 16:55:36 -07002124 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05002125 struct serv_parm *sp;
James Smart98c9ea52007-10-27 13:37:33 -04002126 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002127 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002128 uint8_t *pcmd;
2129 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002130 int ret;
dea31012005-04-17 16:05:31 -05002131
James Smart98c9ea52007-10-27 13:37:33 -04002132 ndlp = lpfc_findnode_did(vport, did);
James Smartdea16bd2018-11-29 16:09:30 -08002133
2134 if (ndlp) {
2135 /* Defer the processing of the issue PLOGI until after the
2136 * outstanding UNREG_RPI mbox command completes, unless we
2137 * are going offline. This logic does not apply for Fabric DIDs
2138 */
2139 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2140 ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
2141 !(vport->fc_flag & FC_OFFLINE_MODE)) {
2142 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2143 "4110 Issue PLOGI x%x deferred "
James Smart32350662019-08-14 16:57:06 -07002144 "on NPort x%x rpi x%x Data: x%px\n",
James Smartdea16bd2018-11-29 16:09:30 -08002145 ndlp->nlp_defer_did, ndlp->nlp_DID,
2146 ndlp->nlp_rpi, ndlp);
2147
2148 /* We can only defer 1st PLOGI */
2149 if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING)
2150 ndlp->nlp_defer_did = did;
2151 return 0;
2152 }
2153 if (!NLP_CHK_NODE_ACT(ndlp))
2154 ndlp = NULL;
2155 }
James Smart98c9ea52007-10-27 13:37:33 -04002156
James Smarte47c9092008-02-08 18:49:26 -05002157 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05002158 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04002159 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05002160 ELS_CMD_PLOGI);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002161 if (!elsiocb)
2162 return 1;
dea31012005-04-17 16:05:31 -05002163
Dick Kennedy8db1c2b2017-08-23 16:55:36 -07002164 shost = lpfc_shost_from_vport(vport);
2165 spin_lock_irq(shost->host_lock);
2166 ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
2167 spin_unlock_irq(shost->host_lock);
2168
dea31012005-04-17 16:05:31 -05002169 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2170
2171 /* For PLOGI request, remainder of payload is service parameters */
2172 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05002173 pcmd += sizeof(uint32_t);
2174 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05002175 sp = (struct serv_parm *) pcmd;
2176
James Smart5ac6b302010-10-22 11:05:36 -04002177 /*
2178 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2179 * to device on remote loops work.
2180 */
2181 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
2182 sp->cmn.altBbCredit = 1;
2183
dea31012005-04-17 16:05:31 -05002184 if (sp->cmn.fcphLow < FC_PH_4_3)
2185 sp->cmn.fcphLow = FC_PH_4_3;
2186
2187 if (sp->cmn.fcphHigh < FC_PH3)
2188 sp->cmn.fcphHigh = FC_PH3;
2189
James Smarte0165f22016-12-19 15:07:20 -08002190 sp->cmn.valid_vendor_ver_level = 0;
James Smart8c258642017-02-12 13:52:36 -08002191 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
James Smart44fd7fe2017-08-23 16:55:47 -07002192 sp->cmn.bbRcvSizeMsb &= 0xF;
James Smarte0165f22016-12-19 15:07:20 -08002193
James Smart858c9f62007-06-17 19:56:39 -05002194 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2195 "Issue PLOGI: did:x%x",
2196 did, 0, 0);
2197
James Smart8c258642017-02-12 13:52:36 -08002198 /* If our firmware supports this feature, convey that
2199 * information to the target using the vendor specific field.
2200 */
2201 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2202 sp->cmn.valid_vendor_ver_level = 1;
2203 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2204 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2205 }
2206
dea31012005-04-17 16:05:31 -05002207 phba->fc_stat.elsXmitPLOGI++;
2208 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04002209 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002210
2211 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002212 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002213 return 1;
dea31012005-04-17 16:05:31 -05002214 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002215 return 0;
dea31012005-04-17 16:05:31 -05002216}
2217
James Smarte59058c2008-08-24 21:49:00 -04002218/**
James Smart3621a712009-04-06 18:47:14 -04002219 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04002220 * @phba: pointer to lpfc hba data structure.
2221 * @cmdiocb: pointer to lpfc command iocb data structure.
2222 * @rspiocb: pointer to lpfc response iocb data structure.
2223 *
2224 * This routine is the completion callback function for a Process Login
2225 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2226 * status. If there is error status reported, PRLI retry shall be attempted
2227 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2228 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2229 * ndlp to mark the PRLI completion.
2230 **/
dea31012005-04-17 16:05:31 -05002231static void
James Smart2e0fef82007-06-17 19:56:36 -05002232lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2233 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002234{
James Smart2e0fef82007-06-17 19:56:36 -05002235 struct lpfc_vport *vport = cmdiocb->vport;
2236 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002237 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002238 struct lpfc_nodelist *ndlp;
James Smart2332e6e2019-11-04 16:57:01 -08002239 char *mode;
dea31012005-04-17 16:05:31 -05002240
dea31012005-04-17 16:05:31 -05002241 /* we pass cmdiocb to state machine which needs rspiocb as well */
2242 cmdiocb->context_un.rsp_iocb = rspiocb;
2243
2244 irsp = &(rspiocb->iocb);
2245 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05002246 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002247 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart9de416a2017-12-08 17:18:07 -08002248
2249 /* Driver supports multiple FC4 types. Counters matter. */
2250 vport->fc_prli_sent--;
2251 ndlp->fc4_prli_sent--;
James Smart2e0fef82007-06-17 19:56:36 -05002252 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002253
James Smart858c9f62007-06-17 19:56:39 -05002254 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2255 "PRLI cmpl: status:x%x/x%x did:x%x",
2256 irsp->ulpStatus, irsp->un.ulpWord[4],
2257 ndlp->nlp_DID);
James Smarta0f2d3e2017-02-12 13:52:31 -08002258
dea31012005-04-17 16:05:31 -05002259 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002260 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta0f2d3e2017-02-12 13:52:31 -08002261 "0103 PRLI completes to NPort x%06x "
James Smarte8b62012007-08-02 11:10:09 -04002262 "Data: x%x x%x x%x x%x\n",
2263 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
James Smarta0f2d3e2017-02-12 13:52:31 -08002264 vport->num_disc_nodes, ndlp->fc4_prli_sent);
dea31012005-04-17 16:05:31 -05002265
dea31012005-04-17 16:05:31 -05002266 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002267 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002268 goto out;
2269
2270 if (irsp->ulpStatus) {
2271 /* Check for retry */
2272 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2273 /* ELS command is being retried */
2274 goto out;
2275 }
James Smart31200462017-05-15 15:20:42 -07002276
James Smart2332e6e2019-11-04 16:57:01 -08002277 /* If we don't send GFT_ID to Fabric, a PRLI error
2278 * could be expected.
2279 */
2280 if ((vport->fc_flag & FC_FABRIC) ||
2281 (vport->cfg_enable_fc4_type != LPFC_ENABLE_BOTH))
2282 mode = KERN_ERR;
2283 else
2284 mode = KERN_INFO;
2285
dea31012005-04-17 16:05:31 -05002286 /* PRLI failed */
James Smart2332e6e2019-11-04 16:57:01 -08002287 lpfc_printf_vlog(vport, mode, LOG_ELS,
James Smart31200462017-05-15 15:20:42 -07002288 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2289 "data: x%x\n",
James Smarte40a02c2010-02-26 14:13:54 -05002290 ndlp->nlp_DID, irsp->ulpStatus,
James Smart31200462017-05-15 15:20:42 -07002291 irsp->un.ulpWord[4], ndlp->fc4_prli_sent);
2292
dea31012005-04-17 16:05:31 -05002293 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002294 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002295 goto out;
James Smarte47c9092008-02-08 18:49:26 -05002296 else
James Smart2e0fef82007-06-17 19:56:36 -05002297 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002298 NLP_EVT_CMPL_PRLI);
James Smartdea16bd2018-11-29 16:09:30 -08002299 } else {
James Smarta0f2d3e2017-02-12 13:52:31 -08002300 /* Good status, call state machine. However, if another
2301 * PRLI is outstanding, don't call the state machine
2302 * because final disposition to Mapped or Unmapped is
2303 * completed there.
2304 */
James Smart2e0fef82007-06-17 19:56:36 -05002305 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002306 NLP_EVT_CMPL_PRLI);
James Smartdea16bd2018-11-29 16:09:30 -08002307 }
James Smarta0f2d3e2017-02-12 13:52:31 -08002308
dea31012005-04-17 16:05:31 -05002309out:
2310 lpfc_els_free_iocb(phba, cmdiocb);
2311 return;
2312}
2313
James Smarte59058c2008-08-24 21:49:00 -04002314/**
James Smart3621a712009-04-06 18:47:14 -04002315 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04002316 * @vport: pointer to a host virtual N_Port data structure.
2317 * @ndlp: pointer to a node-list data structure.
2318 * @retry: number of retries to the command IOCB.
2319 *
2320 * This routine issues a Process Login (PRLI) ELS command for the
2321 * @vport. The PRLI service parameters are set up in the payload of the
2322 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2323 * is put to the IOCB completion callback func field before invoking the
2324 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2325 *
2326 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2327 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2328 * will be stored into the context1 field of the IOCB for the completion
2329 * callback function to the PRLI ELS command.
2330 *
2331 * Return code
2332 * 0 - successfully issued prli iocb command for @vport
2333 * 1 - failed to issue prli iocb command for @vport
2334 **/
dea31012005-04-17 16:05:31 -05002335int
James Smart2e0fef82007-06-17 19:56:36 -05002336lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002337 uint8_t retry)
2338{
James Smart2e0fef82007-06-17 19:56:36 -05002339 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2340 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002341 PRLI *npr;
James Smarta0f2d3e2017-02-12 13:52:31 -08002342 struct lpfc_nvme_prli *npr_nvme;
dea31012005-04-17 16:05:31 -05002343 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002344 uint8_t *pcmd;
2345 uint16_t cmdsize;
James Smarta0f2d3e2017-02-12 13:52:31 -08002346 u32 local_nlp_type, elscmd;
dea31012005-04-17 16:05:31 -05002347
Dick Kennedy991f0c02017-08-23 16:55:39 -07002348 /*
2349 * If we are in RSCN mode, the FC4 types supported from a
2350 * previous GFT_ID command may not be accurate. So, if we
2351 * are a NVME Initiator, always look for the possibility of
2352 * the remote NPort beng a NVME Target.
2353 */
2354 if (phba->sli_rev == LPFC_SLI_REV4 &&
2355 vport->fc_flag & FC_RSCN_MODE &&
2356 vport->nvmei_support)
2357 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
James Smarta0f2d3e2017-02-12 13:52:31 -08002358 local_nlp_type = ndlp->nlp_fc4_type;
2359
James Smart9de416a2017-12-08 17:18:07 -08002360 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2361 * fields here before any of them can complete.
2362 */
2363 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2364 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
2365 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
James Smartdea16bd2018-11-29 16:09:30 -08002366 ndlp->nlp_flag &= ~(NLP_FIRSTBURST | NLP_NPR_2B_DISC);
James Smart9de416a2017-12-08 17:18:07 -08002367 ndlp->nvme_fb_size = 0;
2368
James Smarta0f2d3e2017-02-12 13:52:31 -08002369 send_next_prli:
2370 if (local_nlp_type & NLP_FC4_FCP) {
2371 /* Payload is 4 + 16 = 20 x14 bytes. */
2372 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2373 elscmd = ELS_CMD_PRLI;
2374 } else if (local_nlp_type & NLP_FC4_NVME) {
2375 /* Payload is 4 + 20 = 24 x18 bytes. */
2376 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2377 elscmd = ELS_CMD_NVMEPRLI;
2378 } else {
2379 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2380 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2381 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2382 return 1;
2383 }
James Smart09559e82017-06-15 22:56:46 -07002384
2385 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2386 * FC4 type, implicitly LOGO.
2387 */
2388 if (phba->sli_rev == LPFC_SLI_REV3 &&
2389 ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2390 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2391 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2392 ndlp->nlp_type);
2393 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2394 return 1;
2395 }
2396
James Smart2e0fef82007-06-17 19:56:36 -05002397 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
James Smarta0f2d3e2017-02-12 13:52:31 -08002398 ndlp->nlp_DID, elscmd);
James Smart488d1462006-03-07 15:02:37 -05002399 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002400 return 1;
dea31012005-04-17 16:05:31 -05002401
dea31012005-04-17 16:05:31 -05002402 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2403
2404 /* For PRLI request, remainder of payload is service parameters */
James Smarta0f2d3e2017-02-12 13:52:31 -08002405 memset(pcmd, 0, cmdsize);
dea31012005-04-17 16:05:31 -05002406
James Smarta0f2d3e2017-02-12 13:52:31 -08002407 if (local_nlp_type & NLP_FC4_FCP) {
2408 /* Remainder of payload is FCP PRLI parameter page.
2409 * Note: this data structure is defined as
2410 * BE/LE in the structure definition so no
2411 * byte swap call is made.
2412 */
2413 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2414 pcmd += sizeof(uint32_t);
2415 npr = (PRLI *)pcmd;
2416
2417 /*
2418 * If our firmware version is 3.20 or later,
2419 * set the following bits for FC-TAPE support.
2420 */
2421 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2422 npr->ConfmComplAllowed = 1;
2423 npr->Retry = 1;
2424 npr->TaskRetryIdReq = 1;
2425 }
2426 npr->estabImagePair = 1;
2427 npr->readXferRdyDis = 1;
2428 if (vport->cfg_first_burst_size)
2429 npr->writeXferRdyDis = 1;
2430
2431 /* For FCP support */
2432 npr->prliType = PRLI_FCP_TYPE;
2433 npr->initiatorFunc = 1;
2434 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2435
2436 /* Remove FCP type - processed. */
2437 local_nlp_type &= ~NLP_FC4_FCP;
2438 } else if (local_nlp_type & NLP_FC4_NVME) {
2439 /* Remainder of payload is NVME PRLI parameter page.
2440 * This data structure is the newer definition that
2441 * uses bf macros so a byte swap is required.
2442 */
2443 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2444 pcmd += sizeof(uint32_t);
2445 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2446 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2447 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
James Smart0d8af092019-08-14 16:57:10 -07002448 if (phba->nsler) {
2449 bf_set(prli_nsler, npr_nvme, 1);
2450 bf_set(prli_conf, npr_nvme, 1);
2451 }
James Smarta0f2d3e2017-02-12 13:52:31 -08002452
2453 /* Only initiators request first burst. */
2454 if ((phba->cfg_nvme_enable_fb) &&
2455 !phba->nvmet_support)
2456 bf_set(prli_fba, npr_nvme, 1);
2457
James Smart8c258642017-02-12 13:52:36 -08002458 if (phba->nvmet_support) {
2459 bf_set(prli_tgt, npr_nvme, 1);
2460 bf_set(prli_disc, npr_nvme, 1);
James Smart8c258642017-02-12 13:52:36 -08002461 } else {
2462 bf_set(prli_init, npr_nvme, 1);
James Smarta5ff0682018-01-30 15:58:56 -08002463 bf_set(prli_conf, npr_nvme, 1);
James Smart8c258642017-02-12 13:52:36 -08002464 }
James Smarta5ff0682018-01-30 15:58:56 -08002465
James Smarta0f2d3e2017-02-12 13:52:31 -08002466 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2467 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2468 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2469
2470 /* Remove NVME type - processed. */
2471 local_nlp_type &= ~NLP_FC4_NVME;
dea31012005-04-17 16:05:31 -05002472 }
dea31012005-04-17 16:05:31 -05002473
James Smart858c9f62007-06-17 19:56:39 -05002474 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2475 "Issue PRLI: did:x%x",
2476 ndlp->nlp_DID, 0, 0);
2477
dea31012005-04-17 16:05:31 -05002478 phba->fc_stat.elsXmitPRLI++;
2479 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05002480 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002481 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart9de416a2017-12-08 17:18:07 -08002482
2483 /* The vport counters are used for lpfc_scan_finished, but
2484 * the ndlp is used to track outstanding PRLIs for different
2485 * FC4 types.
2486 */
2487 vport->fc_prli_sent++;
2488 ndlp->fc4_prli_sent++;
James Smart2e0fef82007-06-17 19:56:36 -05002489 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002490 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2491 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002492 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002493 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002494 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002495 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002496 return 1;
dea31012005-04-17 16:05:31 -05002497 }
James Smarta0f2d3e2017-02-12 13:52:31 -08002498
James Smarta0f2d3e2017-02-12 13:52:31 -08002499
2500 /* The driver supports 2 FC4 types. Make sure
2501 * a PRLI is issued for all types before exiting.
2502 */
James Smart09559e82017-06-15 22:56:46 -07002503 if (phba->sli_rev == LPFC_SLI_REV4 &&
2504 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
James Smarta0f2d3e2017-02-12 13:52:31 -08002505 goto send_next_prli;
2506
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002507 return 0;
dea31012005-04-17 16:05:31 -05002508}
2509
James Smarte59058c2008-08-24 21:49:00 -04002510/**
James Smart3621a712009-04-06 18:47:14 -04002511 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04002512 * @vport: pointer to a host virtual N_Port data structure.
2513 *
2514 * This routine performs Registration State Change Notification (RSCN)
2515 * discovery for a @vport. If the @vport's node port recovery count is not
2516 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2517 * the nodes that need recovery. If none of the PLOGI were needed through
2518 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2519 * invoked to check and handle possible more RSCN came in during the period
2520 * of processing the current ones.
2521 **/
2522static void
2523lpfc_rscn_disc(struct lpfc_vport *vport)
2524{
2525 lpfc_can_disctmo(vport);
2526
2527 /* RSCN discovery */
2528 /* go thru NPR nodes and issue ELS PLOGIs */
2529 if (vport->fc_npr_cnt)
2530 if (lpfc_els_disc_plogi(vport))
2531 return;
2532
2533 lpfc_end_rscn(vport);
2534}
2535
2536/**
James Smart3621a712009-04-06 18:47:14 -04002537 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002538 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2539 *
2540 * This function is called when the final ADISC is completed during discovery.
2541 * This function handles clearing link attention or issuing reg_vpi depending
2542 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2543 * discovery.
2544 * This function is called with no locks held.
2545 **/
2546static void
2547lpfc_adisc_done(struct lpfc_vport *vport)
2548{
2549 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2550 struct lpfc_hba *phba = vport->phba;
2551
2552 /*
2553 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2554 * and continue discovery.
2555 */
2556 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002557 !(vport->fc_flag & FC_RSCN_MODE) &&
2558 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smartd454c912014-12-30 12:08:58 -05002559 /* The ADISCs are complete. Doesn't matter if they
2560 * succeeded or failed because the ADISC completion
2561 * routine guarantees to call the state machine and
2562 * the RPI is either unregistered (failed ADISC response)
2563 * or the RPI is still valid and the node is marked
2564 * mapped for a target. The exchanges should be in the
2565 * correct state. This code is specific to SLI3.
2566 */
2567 lpfc_issue_clear_la(phba, vport);
James Smart90160e02008-08-24 21:49:45 -04002568 lpfc_issue_reg_vpi(phba, vport);
2569 return;
2570 }
2571 /*
2572 * For SLI2, we need to set port_state to READY
2573 * and continue discovery.
2574 */
2575 if (vport->port_state < LPFC_VPORT_READY) {
2576 /* If we get here, there is nothing to ADISC */
James Smart85c0f172015-04-07 15:07:12 -04002577 lpfc_issue_clear_la(phba, vport);
James Smart90160e02008-08-24 21:49:45 -04002578 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2579 vport->num_disc_nodes = 0;
2580 /* go thru NPR list, issue ELS PLOGIs */
2581 if (vport->fc_npr_cnt)
2582 lpfc_els_disc_plogi(vport);
2583 if (!vport->num_disc_nodes) {
2584 spin_lock_irq(shost->host_lock);
2585 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2586 spin_unlock_irq(shost->host_lock);
2587 lpfc_can_disctmo(vport);
2588 lpfc_end_rscn(vport);
2589 }
2590 }
2591 vport->port_state = LPFC_VPORT_READY;
2592 } else
2593 lpfc_rscn_disc(vport);
2594}
2595
2596/**
James Smart3621a712009-04-06 18:47:14 -04002597 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002598 * @vport: pointer to a host virtual N_Port data structure.
2599 *
2600 * This routine determines whether there are more ndlps on a @vport
2601 * node list need to have Address Discover (ADISC) issued. If so, it will
2602 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2603 * remaining nodes which need to have ADISC sent.
2604 **/
James Smart0ff10d42008-01-11 01:52:36 -05002605void
James Smart2e0fef82007-06-17 19:56:36 -05002606lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002607{
James Smart2e0fef82007-06-17 19:56:36 -05002608 if (vport->num_disc_nodes)
2609 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002610 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002611 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2612 "0210 Continue discovery with %d ADISCs to go "
2613 "Data: x%x x%x x%x\n",
2614 vport->num_disc_nodes, vport->fc_adisc_cnt,
2615 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002616 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002617 if (vport->fc_flag & FC_NLP_MORE) {
2618 lpfc_set_disctmo(vport);
2619 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smarteb016562014-09-03 12:58:06 -04002620 lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002621 }
James Smart90160e02008-08-24 21:49:45 -04002622 if (!vport->num_disc_nodes)
2623 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002624 return;
2625}
2626
James Smarte59058c2008-08-24 21:49:00 -04002627/**
James Smart3621a712009-04-06 18:47:14 -04002628 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002629 * @phba: pointer to lpfc hba data structure.
2630 * @cmdiocb: pointer to lpfc command iocb data structure.
2631 * @rspiocb: pointer to lpfc response iocb data structure.
2632 *
2633 * This routine is the completion function for issuing the Address Discover
2634 * (ADISC) command. It first checks to see whether link went down during
2635 * the discovery process. If so, the node will be marked as node port
2636 * recovery for issuing discover IOCB by the link attention handler and
2637 * exit. Otherwise, the response status is checked. If error was reported
2638 * in the response status, the ADISC command shall be retried by invoking
2639 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2640 * the response status, the state machine is invoked to set transition
2641 * with respect to NLP_EVT_CMPL_ADISC event.
2642 **/
dea31012005-04-17 16:05:31 -05002643static void
James Smart2e0fef82007-06-17 19:56:36 -05002644lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2645 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002646{
James Smart2e0fef82007-06-17 19:56:36 -05002647 struct lpfc_vport *vport = cmdiocb->vport;
2648 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002649 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002650 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002651 int disc;
dea31012005-04-17 16:05:31 -05002652
2653 /* we pass cmdiocb to state machine which needs rspiocb as well */
2654 cmdiocb->context_un.rsp_iocb = rspiocb;
2655
2656 irsp = &(rspiocb->iocb);
2657 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002658
James Smart858c9f62007-06-17 19:56:39 -05002659 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2660 "ADISC cmpl: status:x%x/x%x did:x%x",
2661 irsp->ulpStatus, irsp->un.ulpWord[4],
2662 ndlp->nlp_DID);
2663
dea31012005-04-17 16:05:31 -05002664 /* Since ndlp can be freed in the disc state machine, note if this node
2665 * is being used during discovery.
2666 */
James Smart2e0fef82007-06-17 19:56:36 -05002667 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002668 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002669 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002670 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002671 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002672 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2673 "0104 ADISC completes to NPort x%x "
2674 "Data: x%x x%x x%x x%x x%x\n",
2675 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2676 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002677 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002678 if (lpfc_els_chk_latt(vport)) {
2679 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002680 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002681 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002682 goto out;
2683 }
2684
2685 if (irsp->ulpStatus) {
2686 /* Check for retry */
2687 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2688 /* ELS command is being retried */
2689 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002690 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002691 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002692 spin_unlock_irq(shost->host_lock);
2693 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002694 }
2695 goto out;
2696 }
2697 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002698 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2699 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2700 ndlp->nlp_DID, irsp->ulpStatus,
2701 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002702 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002703 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002704 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002705 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002706 } else
dea31012005-04-17 16:05:31 -05002707 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002708 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002709 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002710
James Smart90160e02008-08-24 21:49:45 -04002711 /* Check to see if there are more ADISCs to be sent */
2712 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002713 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002714out:
2715 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_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002721 * @vport: pointer to a virtual N_Port data structure.
2722 * @ndlp: pointer to a node-list data structure.
2723 * @retry: number of retries to the command IOCB.
2724 *
2725 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2726 * @vport. It prepares the payload of the ADISC ELS command, updates the
2727 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2728 * to issue the ADISC ELS command.
2729 *
2730 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2731 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2732 * will be stored into the context1 field of the IOCB for the completion
2733 * callback function to the ADISC ELS command.
2734 *
2735 * Return code
2736 * 0 - successfully issued adisc
2737 * 1 - failed to issue adisc
2738 **/
dea31012005-04-17 16:05:31 -05002739int
James Smart2e0fef82007-06-17 19:56:36 -05002740lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002741 uint8_t retry)
2742{
James Smart2e0fef82007-06-17 19:56:36 -05002743 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2744 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002745 ADISC *ap;
dea31012005-04-17 16:05:31 -05002746 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002747 uint8_t *pcmd;
2748 uint16_t cmdsize;
2749
James Smart92d7f7b2007-06-17 19:56:38 -05002750 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002751 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2752 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002753 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002754 return 1;
dea31012005-04-17 16:05:31 -05002755
dea31012005-04-17 16:05:31 -05002756 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2757
2758 /* For ADISC request, remainder of payload is service parameters */
2759 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002760 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002761
2762 /* Fill in ADISC payload */
2763 ap = (ADISC *) pcmd;
2764 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002765 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2766 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002767 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002768
James Smart858c9f62007-06-17 19:56:39 -05002769 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2770 "Issue ADISC: did:x%x",
2771 ndlp->nlp_DID, 0, 0);
2772
dea31012005-04-17 16:05:31 -05002773 phba->fc_stat.elsXmitADISC++;
2774 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002775 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002776 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002777 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002778 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2779 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002780 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002781 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002782 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002783 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002784 return 1;
dea31012005-04-17 16:05:31 -05002785 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002786 return 0;
dea31012005-04-17 16:05:31 -05002787}
2788
James Smarte59058c2008-08-24 21:49:00 -04002789/**
James Smart3621a712009-04-06 18:47:14 -04002790 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002791 * @phba: pointer to lpfc hba data structure.
2792 * @cmdiocb: pointer to lpfc command iocb data structure.
2793 * @rspiocb: pointer to lpfc response iocb data structure.
2794 *
2795 * This routine is the completion function for issuing the ELS Logout (LOGO)
2796 * command. If no error status was reported from the LOGO response, the
2797 * state machine of the associated ndlp shall be invoked for transition with
2798 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2799 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2800 **/
dea31012005-04-17 16:05:31 -05002801static void
James Smart2e0fef82007-06-17 19:56:36 -05002802lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2803 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002804{
James Smart2e0fef82007-06-17 19:56:36 -05002805 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2806 struct lpfc_vport *vport = ndlp->vport;
2807 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002808 IOCB_t *irsp;
James Smart92494142011-02-16 12:39:44 -05002809 struct lpfcMboxq *mbox;
James Smart086a3452012-08-14 14:25:21 -04002810 unsigned long flags;
2811 uint32_t skip_recovery = 0;
dea31012005-04-17 16:05:31 -05002812
dea31012005-04-17 16:05:31 -05002813 /* we pass cmdiocb to state machine which needs rspiocb as well */
2814 cmdiocb->context_un.rsp_iocb = rspiocb;
2815
2816 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002817 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002818 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002819 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002820
James Smart858c9f62007-06-17 19:56:39 -05002821 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2822 "LOGO cmpl: status:x%x/x%x did:x%x",
2823 irsp->ulpStatus, irsp->un.ulpWord[4],
2824 ndlp->nlp_DID);
James Smart086a3452012-08-14 14:25:21 -04002825
dea31012005-04-17 16:05:31 -05002826 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002827 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2828 "0105 LOGO completes to NPort x%x "
2829 "Data: x%x x%x x%x x%x\n",
2830 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2831 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002832
James Smart086a3452012-08-14 14:25:21 -04002833 if (lpfc_els_chk_latt(vport)) {
2834 skip_recovery = 1;
2835 goto out;
2836 }
2837
2838 /* Check to see if link went down during discovery */
James Smart92d7f7b2007-06-17 19:56:38 -05002839 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2840 /* NLP_EVT_DEVICE_RM should unregister the RPI
2841 * which should abort all outstanding IOs.
2842 */
2843 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2844 NLP_EVT_DEVICE_RM);
James Smart086a3452012-08-14 14:25:21 -04002845 skip_recovery = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002846 goto out;
2847 }
2848
James Smart30e196c2018-10-23 13:41:03 -07002849 /* The LOGO will not be retried on failure. A LOGO was
2850 * issued to the remote rport and a ACC or RJT or no Answer are
2851 * all acceptable. Note the failure and move forward with
2852 * discovery. The PLOGI will retry.
2853 */
dea31012005-04-17 16:05:31 -05002854 if (irsp->ulpStatus) {
dea31012005-04-17 16:05:31 -05002855 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002856 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart30e196c2018-10-23 13:41:03 -07002857 "2756 LOGO failure, No Retry DID:%06X Status:x%x/x%x\n",
James Smarte40a02c2010-02-26 14:13:54 -05002858 ndlp->nlp_DID, irsp->ulpStatus,
2859 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002860 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart086a3452012-08-14 14:25:21 -04002861 if (lpfc_error_lost_link(irsp)) {
2862 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002863 goto out;
James Smart086a3452012-08-14 14:25:21 -04002864 }
2865 }
2866
2867 /* Call state machine. This will unregister the rpi if needed. */
2868 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2869
dea31012005-04-17 16:05:31 -05002870out:
2871 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92494142011-02-16 12:39:44 -05002872 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2873 if ((vport->fc_flag & FC_PT2PT) &&
2874 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2875 phba->pport->fc_myDID = 0;
James Smarta0f2d3e2017-02-12 13:52:31 -08002876
James Smartf6e84792019-01-28 11:14:38 -08002877 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
2878 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smartd613b6a2017-02-12 13:52:37 -08002879 if (phba->nvmet_support)
2880 lpfc_nvmet_update_targetport(phba);
2881 else
James Smart8c258642017-02-12 13:52:36 -08002882 lpfc_nvme_update_localport(phba->pport);
James Smart8c258642017-02-12 13:52:36 -08002883 }
James Smarta0f2d3e2017-02-12 13:52:31 -08002884
James Smart92494142011-02-16 12:39:44 -05002885 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2886 if (mbox) {
2887 lpfc_config_link(phba, mbox);
2888 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2889 mbox->vport = vport;
2890 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2891 MBX_NOT_FINISHED) {
2892 mempool_free(mbox, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04002893 skip_recovery = 1;
James Smart92494142011-02-16 12:39:44 -05002894 }
2895 }
2896 }
James Smart086a3452012-08-14 14:25:21 -04002897
2898 /*
2899 * If the node is a target, the handling attempts to recover the port.
2900 * For any other port type, the rpi is unregistered as an implicit
2901 * LOGO.
2902 */
James Smart30e196c2018-10-23 13:41:03 -07002903 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
2904 skip_recovery == 0) {
James Smart086a3452012-08-14 14:25:21 -04002905 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2906 spin_lock_irqsave(shost->host_lock, flags);
2907 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2908 spin_unlock_irqrestore(shost->host_lock, flags);
2909
2910 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2911 "3187 LOGO completes to NPort x%x: Start "
2912 "Recovery Data: x%x x%x x%x x%x\n",
2913 ndlp->nlp_DID, irsp->ulpStatus,
2914 irsp->un.ulpWord[4], irsp->ulpTimeout,
2915 vport->num_disc_nodes);
2916 lpfc_disc_start(vport);
2917 }
dea31012005-04-17 16:05:31 -05002918 return;
2919}
2920
James Smarte59058c2008-08-24 21:49:00 -04002921/**
James Smart3621a712009-04-06 18:47:14 -04002922 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002923 * @vport: pointer to a virtual N_Port data structure.
2924 * @ndlp: pointer to a node-list data structure.
2925 * @retry: number of retries to the command IOCB.
2926 *
2927 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2928 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2929 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2930 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2931 *
2932 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2933 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2934 * will be stored into the context1 field of the IOCB for the completion
2935 * callback function to the LOGO ELS command.
2936 *
James Smart30e196c2018-10-23 13:41:03 -07002937 * Callers of this routine are expected to unregister the RPI first
2938 *
James Smarte59058c2008-08-24 21:49:00 -04002939 * Return code
2940 * 0 - successfully issued logo
2941 * 1 - failed to issue logo
2942 **/
dea31012005-04-17 16:05:31 -05002943int
James Smart2e0fef82007-06-17 19:56:36 -05002944lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002945 uint8_t retry)
2946{
James Smart2e0fef82007-06-17 19:56:36 -05002947 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2948 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002949 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002950 uint8_t *pcmd;
2951 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002952 int rc;
dea31012005-04-17 16:05:31 -05002953
James Smart98c9ea52007-10-27 13:37:33 -04002954 spin_lock_irq(shost->host_lock);
2955 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2956 spin_unlock_irq(shost->host_lock);
2957 return 0;
2958 }
2959 spin_unlock_irq(shost->host_lock);
2960
James Smart92d7f7b2007-06-17 19:56:38 -05002961 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002962 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2963 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002964 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002965 return 1;
dea31012005-04-17 16:05:31 -05002966
dea31012005-04-17 16:05:31 -05002967 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2968 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002969 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002970
2971 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002972 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002973 pcmd += sizeof(uint32_t);
2974 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002975
James Smart858c9f62007-06-17 19:56:39 -05002976 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2977 "Issue LOGO: did:x%x",
2978 ndlp->nlp_DID, 0, 0);
2979
dea31012005-04-17 16:05:31 -05002980 phba->fc_stat.elsXmitLOGO++;
2981 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002982 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002983 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart086a3452012-08-14 14:25:21 -04002984 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
James Smart2e0fef82007-06-17 19:56:36 -05002985 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002986 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002987 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002988 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002989 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002990 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002991 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002992 return 1;
dea31012005-04-17 16:05:31 -05002993 }
James Smart30e196c2018-10-23 13:41:03 -07002994
2995 spin_lock_irq(shost->host_lock);
2996 ndlp->nlp_prev_state = ndlp->nlp_state;
2997 spin_unlock_irq(shost->host_lock);
2998 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002999 return 0;
dea31012005-04-17 16:05:31 -05003000}
3001
James Smarte59058c2008-08-24 21:49:00 -04003002/**
James Smart3621a712009-04-06 18:47:14 -04003003 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04003004 * @phba: pointer to lpfc hba data structure.
3005 * @cmdiocb: pointer to lpfc command iocb data structure.
3006 * @rspiocb: pointer to lpfc response iocb data structure.
3007 *
3008 * This routine is a generic completion callback function for ELS commands.
3009 * Specifically, it is the callback function which does not need to perform
3010 * any command specific operations. It is currently used by the ELS command
James Smartdf3fe762020-02-10 09:31:55 -08003011 * issuing routines for RSCN, lpfc_issue_els_rscn, and the ELS Fibre Channel
3012 * Address Resolution Protocol Response (FARPR) routine, lpfc_issue_els_farpr().
3013 * Other than certain debug loggings, this callback function simply invokes the
James Smarte59058c2008-08-24 21:49:00 -04003014 * lpfc_els_chk_latt() routine to check whether link went down during the
3015 * discovery process.
3016 **/
dea31012005-04-17 16:05:31 -05003017static void
James Smart2e0fef82007-06-17 19:56:36 -05003018lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3019 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003020{
James Smart2e0fef82007-06-17 19:56:36 -05003021 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05003022 IOCB_t *irsp;
3023
3024 irsp = &rspiocb->iocb;
3025
James Smart858c9f62007-06-17 19:56:39 -05003026 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
James Smartdf3fe762020-02-10 09:31:55 -08003027 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3028 irsp->ulpStatus, irsp->un.ulpWord[4],
3029 irsp->un.elsreq64.remoteID);
3030
dea31012005-04-17 16:05:31 -05003031 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003032 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3033 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
3034 irsp->ulpIoTag, irsp->ulpStatus,
3035 irsp->un.ulpWord[4], irsp->ulpTimeout);
James Smartdf3fe762020-02-10 09:31:55 -08003036
3037 /* Check to see if link went down during discovery */
3038 lpfc_els_chk_latt(vport);
3039 lpfc_els_free_iocb(phba, cmdiocb);
3040}
3041
3042/**
3043 * lpfc_cmpl_els_disc_cmd - Completion callback function for Discovery ELS cmd
3044 * @phba: pointer to lpfc hba data structure.
3045 * @cmdiocb: pointer to lpfc command iocb data structure.
3046 * @rspiocb: pointer to lpfc response iocb data structure.
3047 *
3048 * This routine is a generic completion callback function for Discovery ELS cmd.
3049 * Currently used by the ELS command issuing routines for the ELS State Change
3050 * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf().
3051 * These commands will be retried once only for ELS timeout errors.
3052 **/
3053static void
3054lpfc_cmpl_els_disc_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3055 struct lpfc_iocbq *rspiocb)
3056{
3057 struct lpfc_vport *vport = cmdiocb->vport;
3058 IOCB_t *irsp;
3059 struct lpfc_els_rdf_rsp *prdf;
3060 struct lpfc_dmabuf *pcmd, *prsp;
3061 u32 *pdata;
3062 u32 cmd;
3063
3064 irsp = &rspiocb->iocb;
3065
3066 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3067 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3068 irsp->ulpStatus, irsp->un.ulpWord[4],
3069 irsp->un.elsreq64.remoteID);
3070 /* ELS cmd tag <ulpIoTag> completes */
3071 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3072 "0217 ELS cmd tag x%x completes Data: x%x x%x x%x "
3073 "x%x\n",
3074 irsp->ulpIoTag, irsp->ulpStatus,
3075 irsp->un.ulpWord[4], irsp->ulpTimeout,
3076 cmdiocb->retry);
3077
3078 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3079 if (!pcmd)
3080 goto out;
3081
3082 pdata = (u32 *)pcmd->virt;
3083 if (!pdata)
3084 goto out;
3085 cmd = *pdata;
3086
3087 /* Only 1 retry for ELS Timeout only */
3088 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
3089 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
3090 IOERR_SEQUENCE_TIMEOUT)) {
3091 cmdiocb->retry++;
3092 if (cmdiocb->retry <= 1) {
3093 switch (cmd) {
3094 case ELS_CMD_SCR:
3095 lpfc_issue_els_scr(vport, cmdiocb->retry);
3096 break;
3097 case ELS_CMD_RDF:
3098 cmdiocb->context1 = NULL; /* save ndlp refcnt */
3099 lpfc_issue_els_rdf(vport, cmdiocb->retry);
3100 break;
3101 }
3102 goto out;
3103 }
3104 phba->fc_stat.elsRetryExceeded++;
3105 }
3106 if (irsp->ulpStatus) {
3107 /* ELS discovery cmd completes with error */
3108 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
3109 "4203 ELS cmd x%x error: x%x x%X\n", cmd,
3110 irsp->ulpStatus, irsp->un.ulpWord[4]);
3111 goto out;
3112 }
3113
3114 /* The RDF response doesn't have any impact on the running driver
3115 * but the notification descriptors are dumped here for support.
3116 */
3117 if (cmd == ELS_CMD_RDF) {
3118 int i;
3119
3120 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
3121 if (!prsp)
3122 goto out;
3123
3124 prdf = (struct lpfc_els_rdf_rsp *)prsp->virt;
3125 if (!prdf)
3126 goto out;
3127
3128 for (i = 0; i < ELS_RDF_REG_TAG_CNT &&
3129 i < be32_to_cpu(prdf->reg_d1.reg_desc.count); i++)
3130 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3131 "4677 Fabric RDF Notication Grant Data: "
3132 "0x%08x\n",
3133 be32_to_cpu(
3134 prdf->reg_d1.desc_tags[i]));
3135 }
3136
3137out:
dea31012005-04-17 16:05:31 -05003138 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05003139 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05003140 lpfc_els_free_iocb(phba, cmdiocb);
3141 return;
3142}
3143
James Smarte59058c2008-08-24 21:49:00 -04003144/**
James Smart3621a712009-04-06 18:47:14 -04003145 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04003146 * @vport: pointer to a host virtual N_Port data structure.
James Smartdf3fe762020-02-10 09:31:55 -08003147 * @retry: retry counter for the command IOCB.
James Smarte59058c2008-08-24 21:49:00 -04003148 *
3149 * This routine issues a State Change Request (SCR) to a fabric node
James Smartdf3fe762020-02-10 09:31:55 -08003150 * on a @vport. The remote node is Fabric Controller (0xfffffd). It
James Smarte59058c2008-08-24 21:49:00 -04003151 * first search the @vport node list to find the matching ndlp. If no such
3152 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
3153 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
3154 * routine is invoked to send the SCR IOCB.
3155 *
3156 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3157 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3158 * will be stored into the context1 field of the IOCB for the completion
3159 * callback function to the SCR ELS command.
3160 *
3161 * Return code
3162 * 0 - Successfully issued scr command
3163 * 1 - Failed to issue scr command
3164 **/
dea31012005-04-17 16:05:31 -05003165int
James Smartdf3fe762020-02-10 09:31:55 -08003166lpfc_issue_els_scr(struct lpfc_vport *vport, uint8_t retry)
dea31012005-04-17 16:05:31 -05003167{
James Smart2e0fef82007-06-17 19:56:36 -05003168 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003169 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003170 uint8_t *pcmd;
3171 uint16_t cmdsize;
3172 struct lpfc_nodelist *ndlp;
3173
James Smart92d7f7b2007-06-17 19:56:38 -05003174 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05003175
James Smartdf3fe762020-02-10 09:31:55 -08003176 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
James Smarte47c9092008-02-08 18:49:26 -05003177 if (!ndlp) {
James Smartdf3fe762020-02-10 09:31:55 -08003178 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
James Smarte47c9092008-02-08 18:49:26 -05003179 if (!ndlp)
3180 return 1;
James Smarte47c9092008-02-08 18:49:26 -05003181 lpfc_enqueue_node(vport, ndlp);
3182 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3183 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3184 if (!ndlp)
3185 return 1;
3186 }
dea31012005-04-17 16:05:31 -05003187
James Smart2e0fef82007-06-17 19:56:36 -05003188 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3189 ndlp->nlp_DID, ELS_CMD_SCR);
3190
James Smart488d1462006-03-07 15:02:37 -05003191 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05003192 /* This will trigger the release of the node just
3193 * allocated
3194 */
James Smart329f9bc2007-04-25 09:53:01 -04003195 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003196 return 1;
dea31012005-04-17 16:05:31 -05003197 }
3198
dea31012005-04-17 16:05:31 -05003199 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3200
3201 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05003202 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003203
3204 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003205 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05003206 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
3207
James Smart858c9f62007-06-17 19:56:39 -05003208 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3209 "Issue SCR: did:x%x",
3210 ndlp->nlp_DID, 0, 0);
3211
dea31012005-04-17 16:05:31 -05003212 phba->fc_stat.elsXmitSCR++;
James Smartdf3fe762020-02-10 09:31:55 -08003213 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
James Smart3772a992009-05-22 14:50:54 -04003214 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3215 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05003216 /* The additional lpfc_nlp_put will cause the following
3217 * lpfc_els_free_iocb routine to trigger the rlease of
3218 * the node.
3219 */
James Smart329f9bc2007-04-25 09:53:01 -04003220 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003221 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003222 return 1;
dea31012005-04-17 16:05:31 -05003223 }
James Smartfa4066b2008-01-11 01:53:27 -05003224 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3225 * trigger the release of node.
3226 */
James Smartb7e50c52017-11-20 16:00:37 -08003227 if (!(vport->fc_flag & FC_PT2PT))
3228 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003229 return 0;
dea31012005-04-17 16:05:31 -05003230}
3231
James Smarte59058c2008-08-24 21:49:00 -04003232/**
James Smartf60cb932019-05-14 14:58:05 -07003233 * lpfc_issue_els_rscn - Issue an RSCN to the Fabric Controller (Fabric)
3234 * or the other nport (pt2pt).
3235 * @vport: pointer to a host virtual N_Port data structure.
3236 * @retry: number of retries to the command IOCB.
3237 *
3238 * This routine issues a RSCN to the Fabric Controller (DID 0xFFFFFD)
3239 * when connected to a fabric, or to the remote port when connected
3240 * in point-to-point mode. When sent to the Fabric Controller, it will
3241 * replay the RSCN to registered recipients.
3242 *
3243 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3244 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3245 * will be stored into the context1 field of the IOCB for the completion
3246 * callback function to the RSCN ELS command.
3247 *
3248 * Return code
3249 * 0 - Successfully issued RSCN command
3250 * 1 - Failed to issue RSCN command
3251 **/
3252int
3253lpfc_issue_els_rscn(struct lpfc_vport *vport, uint8_t retry)
3254{
3255 struct lpfc_hba *phba = vport->phba;
3256 struct lpfc_iocbq *elsiocb;
3257 struct lpfc_nodelist *ndlp;
3258 struct {
3259 struct fc_els_rscn rscn;
3260 struct fc_els_rscn_page portid;
3261 } *event;
3262 uint32_t nportid;
3263 uint16_t cmdsize = sizeof(*event);
3264
3265 /* Not supported for private loop */
3266 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
3267 !(vport->fc_flag & FC_PUBLIC_LOOP))
3268 return 1;
3269
3270 if (vport->fc_flag & FC_PT2PT) {
3271 /* find any mapped nport - that would be the other nport */
3272 ndlp = lpfc_findnode_mapped(vport);
3273 if (!ndlp)
3274 return 1;
3275 } else {
3276 nportid = FC_FID_FCTRL;
3277 /* find the fabric controller node */
3278 ndlp = lpfc_findnode_did(vport, nportid);
3279 if (!ndlp) {
3280 /* if one didn't exist, make one */
3281 ndlp = lpfc_nlp_init(vport, nportid);
3282 if (!ndlp)
3283 return 1;
3284 lpfc_enqueue_node(vport, ndlp);
3285 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3286 ndlp = lpfc_enable_node(vport, ndlp,
3287 NLP_STE_UNUSED_NODE);
3288 if (!ndlp)
3289 return 1;
3290 }
3291 }
3292
3293 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3294 ndlp->nlp_DID, ELS_CMD_RSCN_XMT);
3295
3296 if (!elsiocb) {
3297 /* This will trigger the release of the node just
3298 * allocated
3299 */
3300 lpfc_nlp_put(ndlp);
3301 return 1;
3302 }
3303
3304 event = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3305
3306 event->rscn.rscn_cmd = ELS_RSCN;
3307 event->rscn.rscn_page_len = sizeof(struct fc_els_rscn_page);
3308 event->rscn.rscn_plen = cpu_to_be16(cmdsize);
3309
3310 nportid = vport->fc_myDID;
3311 /* appears that page flags must be 0 for fabric to broadcast RSCN */
3312 event->portid.rscn_page_flags = 0;
3313 event->portid.rscn_fid[0] = (nportid & 0x00FF0000) >> 16;
3314 event->portid.rscn_fid[1] = (nportid & 0x0000FF00) >> 8;
3315 event->portid.rscn_fid[2] = nportid & 0x000000FF;
3316
3317 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3318 "Issue RSCN: did:x%x",
3319 ndlp->nlp_DID, 0, 0);
3320
3321 phba->fc_stat.elsXmitRSCN++;
3322 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3323 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3324 IOCB_ERROR) {
3325 /* The additional lpfc_nlp_put will cause the following
3326 * lpfc_els_free_iocb routine to trigger the rlease of
3327 * the node.
3328 */
3329 lpfc_nlp_put(ndlp);
3330 lpfc_els_free_iocb(phba, elsiocb);
3331 return 1;
3332 }
3333 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3334 * trigger the release of node.
3335 */
3336 if (!(vport->fc_flag & FC_PT2PT))
3337 lpfc_nlp_put(ndlp);
3338
3339 return 0;
3340}
3341
3342/**
James Smart3621a712009-04-06 18:47:14 -04003343 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04003344 * @vport: pointer to a host virtual N_Port data structure.
3345 * @nportid: N_Port identifier to the remote node.
3346 * @retry: number of retries to the command IOCB.
3347 *
3348 * This routine issues a Fibre Channel Address Resolution Response
3349 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
3350 * is passed into the function. It first search the @vport node list to find
3351 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
3352 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
3353 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
3354 *
3355 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3356 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3357 * will be stored into the context1 field of the IOCB for the completion
3358 * callback function to the PARPR ELS command.
3359 *
3360 * Return code
3361 * 0 - Successfully issued farpr command
3362 * 1 - Failed to issue farpr command
3363 **/
dea31012005-04-17 16:05:31 -05003364static int
James Smart2e0fef82007-06-17 19:56:36 -05003365lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05003366{
James Smart2e0fef82007-06-17 19:56:36 -05003367 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003368 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003369 FARP *fp;
3370 uint8_t *pcmd;
3371 uint32_t *lp;
3372 uint16_t cmdsize;
3373 struct lpfc_nodelist *ondlp;
3374 struct lpfc_nodelist *ndlp;
3375
James Smart92d7f7b2007-06-17 19:56:38 -05003376 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05003377
James Smarte47c9092008-02-08 18:49:26 -05003378 ndlp = lpfc_findnode_did(vport, nportid);
3379 if (!ndlp) {
James Smart9d3d3402017-04-21 16:05:00 -07003380 ndlp = lpfc_nlp_init(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05003381 if (!ndlp)
3382 return 1;
James Smarte47c9092008-02-08 18:49:26 -05003383 lpfc_enqueue_node(vport, ndlp);
3384 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3385 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3386 if (!ndlp)
3387 return 1;
3388 }
James Smart2e0fef82007-06-17 19:56:36 -05003389
3390 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3391 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05003392 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05003393 /* This will trigger the release of the node just
3394 * allocated
3395 */
James Smart329f9bc2007-04-25 09:53:01 -04003396 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003397 return 1;
dea31012005-04-17 16:05:31 -05003398 }
3399
dea31012005-04-17 16:05:31 -05003400 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3401
3402 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05003403 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003404
3405 /* Fill in FARPR payload */
3406 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05003407 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05003408 lp = (uint32_t *) pcmd;
3409 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05003410 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003411 fp->Rflags = 0;
3412 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
3413
James Smart92d7f7b2007-06-17 19:56:38 -05003414 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
3415 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003416 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05003417 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05003418 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003419 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003420 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05003421 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003422 }
3423
James Smart858c9f62007-06-17 19:56:39 -05003424 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3425 "Issue FARPR: did:x%x",
3426 ndlp->nlp_DID, 0, 0);
3427
dea31012005-04-17 16:05:31 -05003428 phba->fc_stat.elsXmitFARPR++;
3429 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04003430 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3431 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05003432 /* The additional lpfc_nlp_put will cause the following
3433 * lpfc_els_free_iocb routine to trigger the release of
3434 * the node.
3435 */
James Smart329f9bc2007-04-25 09:53:01 -04003436 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003437 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003438 return 1;
dea31012005-04-17 16:05:31 -05003439 }
James Smartfa4066b2008-01-11 01:53:27 -05003440 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3441 * trigger the release of the node.
3442 */
James Smartdf3fe762020-02-10 09:31:55 -08003443 /* Don't release reference count as RDF is likely outstanding */
3444 return 0;
3445}
3446
3447/**
3448 * lpfc_issue_els_rdf - Register for diagnostic functions from the fabric.
3449 * @vport: pointer to a host virtual N_Port data structure.
3450 * @retry: retry counter for the command IOCB.
3451 *
3452 * This routine issues an ELS RDF to the Fabric Controller to register
3453 * for diagnostic functions.
3454 *
3455 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3456 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3457 * will be stored into the context1 field of the IOCB for the completion
3458 * callback function to the RDF ELS command.
3459 *
3460 * Return code
3461 * 0 - Successfully issued rdf command
3462 * 1 - Failed to issue rdf command
3463 **/
3464int
3465lpfc_issue_els_rdf(struct lpfc_vport *vport, uint8_t retry)
3466{
3467 struct lpfc_hba *phba = vport->phba;
3468 struct lpfc_iocbq *elsiocb;
3469 struct lpfc_els_rdf_req *prdf;
3470 struct lpfc_nodelist *ndlp;
3471 uint16_t cmdsize;
3472
3473 cmdsize = sizeof(*prdf);
3474
3475 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3476 if (!ndlp) {
3477 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3478 if (!ndlp)
3479 return -ENODEV;
3480 lpfc_enqueue_node(vport, ndlp);
3481 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3482 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3483 if (!ndlp)
3484 return -ENODEV;
3485 }
3486
3487 /* RDF ELS is not required on an NPIV VN_Port. */
3488 if (vport->port_type == LPFC_NPIV_PORT) {
3489 lpfc_nlp_put(ndlp);
3490 return -EACCES;
3491 }
3492
3493 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3494 ndlp->nlp_DID, ELS_CMD_RDF);
3495 if (!elsiocb) {
3496 /* This will trigger the release of the node just
3497 * allocated
3498 */
3499 lpfc_nlp_put(ndlp);
3500 return -ENOMEM;
3501 }
3502
3503 /* Configure the payload for the supported FPIN events. */
3504 prdf = (struct lpfc_els_rdf_req *)
3505 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
3506 memset(prdf, 0, cmdsize);
3507 prdf->rdf.fpin_cmd = ELS_RDF;
3508 prdf->rdf.desc_len = cpu_to_be32(sizeof(struct lpfc_els_rdf_req) -
3509 sizeof(struct fc_els_rdf));
3510 prdf->reg_d1.reg_desc.desc_tag = cpu_to_be32(ELS_DTAG_FPIN_REGISTER);
3511 prdf->reg_d1.reg_desc.desc_len = cpu_to_be32(
3512 FC_TLV_DESC_LENGTH_FROM_SZ(prdf->reg_d1));
3513 prdf->reg_d1.reg_desc.count = cpu_to_be32(ELS_RDF_REG_TAG_CNT);
3514 prdf->reg_d1.desc_tags[0] = cpu_to_be32(ELS_DTAG_LNK_INTEGRITY);
3515
3516 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3517 "Issue RDF: did:x%x",
3518 ndlp->nlp_DID, 0, 0);
3519
3520 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3521 "6444 Xmit RDF to remote NPORT x%x\n",
3522 ndlp->nlp_DID);
3523
3524 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
3525 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3526 IOCB_ERROR) {
3527 /* The additional lpfc_nlp_put will cause the following
3528 * lpfc_els_free_iocb routine to trigger the rlease of
3529 * the node.
3530 */
3531 lpfc_nlp_put(ndlp);
3532 lpfc_els_free_iocb(phba, elsiocb);
3533 return -EIO;
3534 }
3535
3536 /* An RDF was issued - this put ensures the ndlp is cleaned up
3537 * when the RDF completes.
3538 */
James Smart329f9bc2007-04-25 09:53:01 -04003539 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003540 return 0;
dea31012005-04-17 16:05:31 -05003541}
3542
James Smarte59058c2008-08-24 21:49:00 -04003543/**
James Smart3621a712009-04-06 18:47:14 -04003544 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04003545 * @vport: pointer to a host virtual N_Port data structure.
3546 * @nlp: pointer to a node-list data structure.
3547 *
3548 * This routine cancels the timer with a delayed IOCB-command retry for
3549 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3550 * removes the ELS retry event if it presents. In addition, if the
3551 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3552 * commands are sent for the @vport's nodes that require issuing discovery
3553 * ADISC.
3554 **/
dea31012005-04-17 16:05:31 -05003555void
James Smart2e0fef82007-06-17 19:56:36 -05003556lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05003557{
James Smart2e0fef82007-06-17 19:56:36 -05003558 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05003559 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05003560
James Smart0d2b6b82008-06-14 22:52:47 -04003561 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3562 return;
James Smart2e0fef82007-06-17 19:56:36 -05003563 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05003564 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003565 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05003566 del_timer_sync(&nlp->nlp_delayfunc);
3567 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05003568 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05003569 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05003570 /* Decrement nlp reference count held for the delayed retry */
3571 evtp = &nlp->els_retry_evt;
3572 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3573 }
James Smartfdcebe22006-03-07 15:04:01 -05003574 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05003575 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05003576 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05003577 spin_unlock_irq(shost->host_lock);
3578 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04003579 if (vport->port_state < LPFC_VPORT_READY) {
3580 /* Check if there are more ADISCs to be sent */
3581 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04003582 } else {
3583 /* Check if there are more PLOGIs to be sent */
3584 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04003585 if (vport->num_disc_nodes == 0) {
3586 spin_lock_irq(shost->host_lock);
3587 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3588 spin_unlock_irq(shost->host_lock);
3589 lpfc_can_disctmo(vport);
3590 lpfc_end_rscn(vport);
3591 }
James Smartfdcebe22006-03-07 15:04:01 -05003592 }
3593 }
3594 }
3595 return;
3596}
3597
James Smarte59058c2008-08-24 21:49:00 -04003598/**
James Smart3621a712009-04-06 18:47:14 -04003599 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04003600 * @ptr: holder for the pointer to the timer function associated data (ndlp).
3601 *
3602 * This routine is invoked by the ndlp delayed-function timer to check
3603 * whether there is any pending ELS retry event(s) with the node. If not, it
3604 * simply returns. Otherwise, if there is at least one ELS delayed event, it
3605 * adds the delayed events to the HBA work list and invokes the
3606 * lpfc_worker_wake_up() routine to wake up worker thread to process the
3607 * event. Note that lpfc_nlp_get() is called before posting the event to
3608 * the work list to hold reference count of ndlp so that it guarantees the
3609 * reference to ndlp will still be available when the worker thread gets
3610 * to the event associated with the ndlp.
3611 **/
James Smartfdcebe22006-03-07 15:04:01 -05003612void
Kees Cookf22eb4d2017-09-06 20:24:26 -07003613lpfc_els_retry_delay(struct timer_list *t)
dea31012005-04-17 16:05:31 -05003614{
Kees Cookf22eb4d2017-09-06 20:24:26 -07003615 struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
James Smart2e0fef82007-06-17 19:56:36 -05003616 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05003617 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05003618 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05003619 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05003620
James Smart92d7f7b2007-06-17 19:56:38 -05003621 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003622 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003623 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003624 return;
3625 }
3626
James Smartfa4066b2008-01-11 01:53:27 -05003627 /* We need to hold the node by incrementing the reference
3628 * count until the queued work is done
3629 */
3630 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04003631 if (evtp->evt_arg1) {
3632 evtp->evt = LPFC_EVT_ELS_RETRY;
3633 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05003634 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04003635 }
James Smart92d7f7b2007-06-17 19:56:38 -05003636 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003637 return;
3638}
3639
James Smarte59058c2008-08-24 21:49:00 -04003640/**
James Smart3621a712009-04-06 18:47:14 -04003641 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04003642 * @ndlp: pointer to a node-list data structure.
3643 *
3644 * This routine is the worker-thread handler for processing the @ndlp delayed
3645 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3646 * the last ELS command from the associated ndlp and invokes the proper ELS
3647 * function according to the delayed ELS command to retry the command.
3648 **/
dea31012005-04-17 16:05:31 -05003649void
3650lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3651{
James Smart2e0fef82007-06-17 19:56:36 -05003652 struct lpfc_vport *vport = ndlp->vport;
3653 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarteb016562014-09-03 12:58:06 -04003654 uint32_t cmd, retry;
dea31012005-04-17 16:05:31 -05003655
James Smart2e0fef82007-06-17 19:56:36 -05003656 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003657 cmd = ndlp->nlp_last_elscmd;
3658 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05003659
3660 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05003661 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003662 return;
3663 }
3664
3665 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003666 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05003667 /*
3668 * If a discovery event readded nlp_delayfunc after timer
3669 * firing and before processing the timer, cancel the
3670 * nlp_delayfunc.
3671 */
3672 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05003673 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04003674 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05003675
3676 switch (cmd) {
3677 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003678 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05003679 break;
3680 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003681 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003682 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003683 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003684 }
dea31012005-04-17 16:05:31 -05003685 break;
3686 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05003687 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003688 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003689 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003690 }
dea31012005-04-17 16:05:31 -05003691 break;
3692 case ELS_CMD_PRLI:
James Smarta0f2d3e2017-02-12 13:52:31 -08003693 case ELS_CMD_NVMEPRLI:
James Smart2e0fef82007-06-17 19:56:36 -05003694 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003695 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003696 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003697 }
dea31012005-04-17 16:05:31 -05003698 break;
3699 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05003700 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003701 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04003702 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003703 }
dea31012005-04-17 16:05:31 -05003704 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003705 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05003706 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3707 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05003708 break;
dea31012005-04-17 16:05:31 -05003709 }
3710 return;
3711}
3712
James Smarte59058c2008-08-24 21:49:00 -04003713/**
James Smart5cca2ab2018-10-23 13:41:04 -07003714 * lpfc_link_reset - Issue link reset
3715 * @vport: pointer to a virtual N_Port data structure.
3716 *
3717 * This routine performs link reset by sending INIT_LINK mailbox command.
3718 * For SLI-3 adapter, link attention interrupt is enabled before issuing
3719 * INIT_LINK mailbox command.
3720 *
3721 * Return code
3722 * 0 - Link reset initiated successfully
3723 * 1 - Failed to initiate link reset
3724 **/
3725int
3726lpfc_link_reset(struct lpfc_vport *vport)
3727{
3728 struct lpfc_hba *phba = vport->phba;
3729 LPFC_MBOXQ_t *mbox;
3730 uint32_t control;
3731 int rc;
3732
3733 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3734 "2851 Attempt link reset\n");
3735 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3736 if (!mbox) {
3737 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
3738 "2852 Failed to allocate mbox memory");
3739 return 1;
3740 }
3741
3742 /* Enable Link attention interrupts */
3743 if (phba->sli_rev <= LPFC_SLI_REV3) {
3744 spin_lock_irq(&phba->hbalock);
3745 phba->sli.sli_flag |= LPFC_PROCESS_LA;
3746 control = readl(phba->HCregaddr);
3747 control |= HC_LAINT_ENA;
3748 writel(control, phba->HCregaddr);
3749 readl(phba->HCregaddr); /* flush */
3750 spin_unlock_irq(&phba->hbalock);
3751 }
3752
3753 lpfc_init_link(phba, mbox, phba->cfg_topology,
3754 phba->cfg_link_speed);
3755 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3756 mbox->vport = vport;
3757 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3758 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
3759 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
3760 "2853 Failed to issue INIT_LINK "
3761 "mbox command, rc:x%x\n", rc);
3762 mempool_free(mbox, phba->mbox_mem_pool);
3763 return 1;
3764 }
3765
3766 return 0;
3767}
3768
3769/**
James Smart3621a712009-04-06 18:47:14 -04003770 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04003771 * @phba: pointer to lpfc hba data structure.
3772 * @cmdiocb: pointer to lpfc command iocb data structure.
3773 * @rspiocb: pointer to lpfc response iocb data structure.
3774 *
3775 * This routine makes a retry decision on an ELS command IOCB, which has
3776 * failed. The following ELS IOCBs use this function for retrying the command
3777 * when previously issued command responsed with error status: FLOGI, PLOGI,
3778 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3779 * returned error status, it makes the decision whether a retry shall be
3780 * issued for the command, and whether a retry shall be made immediately or
3781 * delayed. In the former case, the corresponding ELS command issuing-function
3782 * is called to retry the command. In the later case, the ELS command shall
3783 * be posted to the ndlp delayed event and delayed function timer set to the
3784 * ndlp for the delayed command issusing.
3785 *
3786 * Return code
3787 * 0 - No retry of els command is made
3788 * 1 - Immediate or delayed retry of els command is made
3789 **/
dea31012005-04-17 16:05:31 -05003790static int
James Smart2e0fef82007-06-17 19:56:36 -05003791lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3792 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003793{
James Smart2e0fef82007-06-17 19:56:36 -05003794 struct lpfc_vport *vport = cmdiocb->vport;
3795 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3796 IOCB_t *irsp = &rspiocb->iocb;
3797 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3798 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05003799 uint32_t *elscmd;
3800 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05003801 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04003802 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003803 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05003804 uint32_t did;
James Smart5cca2ab2018-10-23 13:41:04 -07003805 int link_reset = 0, rc;
dea31012005-04-17 16:05:31 -05003806
James Smart488d1462006-03-07 15:02:37 -05003807
dea31012005-04-17 16:05:31 -05003808 /* Note: context2 may be 0 for internal driver abort
3809 * of delays ELS command.
3810 */
3811
3812 if (pcmd && pcmd->virt) {
3813 elscmd = (uint32_t *) (pcmd->virt);
3814 cmd = *elscmd++;
3815 }
3816
James Smarte47c9092008-02-08 18:49:26 -05003817 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05003818 did = ndlp->nlp_DID;
3819 else {
3820 /* We should only hit this case for retrying PLOGI */
3821 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003822 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05003823 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3824 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05003825 return 1;
3826 }
3827
James Smart858c9f62007-06-17 19:56:39 -05003828 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3829 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3830 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3831
dea31012005-04-17 16:05:31 -05003832 switch (irsp->ulpStatus) {
3833 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05003834 break;
James Smart1151e3e2011-02-16 12:39:35 -05003835 case IOSTAT_REMOTE_STOP:
3836 if (phba->sli_rev == LPFC_SLI_REV4) {
3837 /* This IO was aborted by the target, we don't
3838 * know the rxid and because we did not send the
3839 * ABTS we cannot generate and RRQ.
3840 */
3841 lpfc_set_rrq_active(phba, ndlp,
James Smartee0f4fe2012-05-09 21:19:14 -04003842 cmdiocb->sli4_lxritag, 0, 0);
James Smart1151e3e2011-02-16 12:39:35 -05003843 }
3844 break;
dea31012005-04-17 16:05:31 -05003845 case IOSTAT_LOCAL_REJECT:
James Smarte3d2b802012-08-14 14:25:43 -04003846 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
dea31012005-04-17 16:05:31 -05003847 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05003848 if (cmd == ELS_CMD_FLOGI) {
3849 if (PCI_DEVICE_ID_HORNET ==
3850 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05003851 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05003852 phba->pport->fc_myDID = 0;
3853 phba->alpa_map[0] = 0;
3854 phba->alpa_map[1] = 0;
3855 }
3856 }
James Smart2e0fef82007-06-17 19:56:36 -05003857 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003858 delay = 1000;
dea31012005-04-17 16:05:31 -05003859 retry = 1;
3860 break;
3861
James Smart92d7f7b2007-06-17 19:56:38 -05003862 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05003863 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3864 "0124 Retry illegal cmd x%x "
3865 "retry:x%x delay:x%x\n",
3866 cmd, cmdiocb->retry, delay);
3867 retry = 1;
3868 /* All command's retry policy */
3869 maxretry = 8;
3870 if (cmdiocb->retry > 2)
3871 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05003872 break;
3873
dea31012005-04-17 16:05:31 -05003874 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04003875 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05003876 retry = 1;
3877 if (cmdiocb->retry > 100)
3878 delay = 100;
3879 maxretry = 250;
3880 break;
3881
3882 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05003883 delay = 100;
dea31012005-04-17 16:05:31 -05003884 retry = 1;
3885 break;
3886
3887 case IOERR_INVALID_RPI:
James Smart5b5b36a2013-01-03 15:43:19 -05003888 if (cmd == ELS_CMD_PLOGI &&
3889 did == NameServer_DID) {
3890 /* Continue forever if plogi to */
3891 /* the nameserver fails */
3892 maxretry = 0;
3893 delay = 100;
3894 }
dea31012005-04-17 16:05:31 -05003895 retry = 1;
3896 break;
James Smart5cca2ab2018-10-23 13:41:04 -07003897
3898 case IOERR_SEQUENCE_TIMEOUT:
3899 if (cmd == ELS_CMD_PLOGI &&
3900 did == NameServer_DID &&
3901 (cmdiocb->retry + 1) == maxretry) {
3902 /* Reset the Link */
3903 link_reset = 1;
3904 break;
3905 }
3906 retry = 1;
3907 delay = 100;
3908 break;
dea31012005-04-17 16:05:31 -05003909 }
3910 break;
3911
3912 case IOSTAT_NPORT_RJT:
3913 case IOSTAT_FABRIC_RJT:
3914 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3915 retry = 1;
3916 break;
3917 }
3918 break;
3919
3920 case IOSTAT_NPORT_BSY:
3921 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04003922 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05003923 retry = 1;
3924 break;
3925
3926 case IOSTAT_LS_RJT:
3927 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3928 /* Added for Vendor specifc support
3929 * Just keep retrying for these Rsn / Exp codes
3930 */
3931 switch (stat.un.b.lsRjtRsnCode) {
3932 case LSRJT_UNABLE_TPC:
James Smartdea37e82017-06-01 21:07:07 -07003933 /* The driver has a VALID PLOGI but the rport has
3934 * rejected the PRLI - can't do it now. Delay
3935 * for 1 second and try again - don't care about
3936 * the explanation.
3937 */
3938 if (cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) {
3939 delay = 1000;
3940 maxretry = lpfc_max_els_tries + 1;
3941 retry = 1;
3942 break;
3943 }
3944
3945 /* Legacy bug fix code for targets with PLOGI delays. */
dea31012005-04-17 16:05:31 -05003946 if (stat.un.b.lsRjtRsnCodeExp ==
3947 LSEXP_CMD_IN_PROGRESS) {
3948 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003949 delay = 1000;
dea31012005-04-17 16:05:31 -05003950 maxretry = 48;
3951 }
3952 retry = 1;
3953 break;
3954 }
James Smartffc95492010-06-07 15:23:17 -04003955 if (stat.un.b.lsRjtRsnCodeExp ==
3956 LSEXP_CANT_GIVE_DATA) {
3957 if (cmd == ELS_CMD_PLOGI) {
3958 delay = 1000;
3959 maxretry = 48;
3960 }
3961 retry = 1;
3962 break;
3963 }
James Smartdea37e82017-06-01 21:07:07 -07003964 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003965 delay = 1000;
dea31012005-04-17 16:05:31 -05003966 maxretry = lpfc_max_els_tries + 1;
3967 retry = 1;
3968 break;
3969 }
James Smart92d7f7b2007-06-17 19:56:38 -05003970 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3971 (cmd == ELS_CMD_FDISC) &&
3972 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04003973 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3974 "0125 FDISC Failed (x%x). "
3975 "Fabric out of resources\n",
3976 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003977 lpfc_vport_set_state(vport,
3978 FC_VPORT_NO_FABRIC_RSCS);
3979 }
dea31012005-04-17 16:05:31 -05003980 break;
3981
3982 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003983 if ((cmd == ELS_CMD_PLOGI) ||
James Smarta0f2d3e2017-02-12 13:52:31 -08003984 (cmd == ELS_CMD_PRLI) ||
3985 (cmd == ELS_CMD_NVMEPRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003986 delay = 1000;
dea31012005-04-17 16:05:31 -05003987 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003988 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003989 /* FDISC retry policy */
3990 maxretry = 48;
3991 if (cmdiocb->retry >= 32)
3992 delay = 1000;
dea31012005-04-17 16:05:31 -05003993 }
3994 retry = 1;
3995 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003996
3997 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05003998 /* There are some cases where switches return this
3999 * error when they are not ready and should be returning
4000 * Logical Busy. We should delay every time.
4001 */
4002 if (cmd == ELS_CMD_FDISC &&
4003 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
4004 maxretry = 3;
4005 delay = 1000;
4006 retry = 1;
James Smart44fd7fe2017-08-23 16:55:47 -07004007 } else if (cmd == ELS_CMD_FLOGI &&
4008 stat.un.b.lsRjtRsnCodeExp ==
4009 LSEXP_NOTHING_MORE) {
4010 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
4011 retry = 1;
4012 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4013 "0820 FLOGI Failed (x%x). "
4014 "BBCredit Not Supported\n",
4015 stat.un.lsRjtError);
James Smart7f5f3d02008-02-08 18:50:14 -05004016 }
James Smart44fd7fe2017-08-23 16:55:47 -07004017 break;
4018
James Smart92d7f7b2007-06-17 19:56:38 -05004019 case LSRJT_PROTOCOL_ERR:
4020 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4021 (cmd == ELS_CMD_FDISC) &&
4022 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
4023 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
4024 ) {
James Smarte8b62012007-08-02 11:10:09 -04004025 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04004026 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04004027 "Fabric Detected Bad WWN\n",
4028 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05004029 lpfc_vport_set_state(vport,
4030 FC_VPORT_FABRIC_REJ_WWN);
4031 }
4032 break;
James Smart7bdedb32016-07-06 12:36:00 -07004033 case LSRJT_VENDOR_UNIQUE:
4034 if ((stat.un.b.vendorUnique == 0x45) &&
4035 (cmd == ELS_CMD_FLOGI)) {
4036 goto out_retry;
4037 }
4038 break;
Dick Kennedy8db1c2b2017-08-23 16:55:36 -07004039 case LSRJT_CMD_UNSUPPORTED:
4040 /* lpfc nvmet returns this type of LS_RJT when it
4041 * receives an FCP PRLI because lpfc nvmet only
4042 * support NVME. ELS request is terminated for FCP4
4043 * on this rport.
4044 */
4045 if (stat.un.b.lsRjtRsnCodeExp ==
4046 LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) {
4047 spin_lock_irq(shost->host_lock);
4048 ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
4049 spin_unlock_irq(shost->host_lock);
4050 retry = 0;
4051 goto out_retry;
4052 }
4053 break;
dea31012005-04-17 16:05:31 -05004054 }
4055 break;
4056
4057 case IOSTAT_INTERMED_RSP:
4058 case IOSTAT_BA_RJT:
4059 break;
4060
4061 default:
4062 break;
4063 }
4064
James Smart5cca2ab2018-10-23 13:41:04 -07004065 if (link_reset) {
4066 rc = lpfc_link_reset(vport);
4067 if (rc) {
4068 /* Do not give up. Retry PLOGI one more time and attempt
4069 * link reset if PLOGI fails again.
4070 */
4071 retry = 1;
4072 delay = 100;
4073 goto out_retry;
4074 }
4075 return 1;
4076 }
4077
James Smart488d1462006-03-07 15:02:37 -05004078 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05004079 retry = 1;
dea31012005-04-17 16:05:31 -05004080
James Smartdf9e1b52011-12-13 13:22:17 -05004081 if ((cmd == ELS_CMD_FLOGI) &&
James Smart76a95d72010-11-20 23:11:48 -05004082 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05004083 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04004084 /* FLOGI retry policy */
4085 retry = 1;
James Smartdf9e1b52011-12-13 13:22:17 -05004086 /* retry FLOGI forever */
James Smart6eae4302015-04-07 15:07:23 -04004087 if (phba->link_flag != LS_LOOPBACK_MODE)
4088 maxretry = 0;
4089 else
4090 maxretry = 2;
4091
James Smart6669f9b2009-10-02 15:16:45 -04004092 if (cmdiocb->retry >= 100)
4093 delay = 5000;
4094 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04004095 delay = 1000;
James Smartdf9e1b52011-12-13 13:22:17 -05004096 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
4097 /* retry FDISCs every second up to devloss */
4098 retry = 1;
4099 maxretry = vport->cfg_devloss_tmo;
4100 delay = 1000;
James Smart98c9ea52007-10-27 13:37:33 -04004101 }
4102
James Smart6669f9b2009-10-02 15:16:45 -04004103 cmdiocb->retry++;
4104 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05004105 phba->fc_stat.elsRetryExceeded++;
4106 retry = 0;
4107 }
4108
James Smarted957682007-06-17 19:56:37 -05004109 if ((vport->load_flag & FC_UNLOADING) != 0)
4110 retry = 0;
4111
James Smart7bdedb32016-07-06 12:36:00 -07004112out_retry:
dea31012005-04-17 16:05:31 -05004113 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04004114 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
4115 /* Stop retrying PLOGI and FDISC if in FCF discovery */
4116 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
4117 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4118 "2849 Stop retry ELS command "
4119 "x%x to remote NPORT x%x, "
4120 "Data: x%x x%x\n", cmd, did,
4121 cmdiocb->retry, delay);
4122 return 0;
4123 }
4124 }
dea31012005-04-17 16:05:31 -05004125
4126 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04004127 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4128 "0107 Retry ELS command x%x to remote "
4129 "NPORT x%x Data: x%x x%x\n",
4130 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05004131
James Smart858c9f62007-06-17 19:56:39 -05004132 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
4133 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04004134 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
4135 IOERR_NO_RESOURCES))) {
James Smart858c9f62007-06-17 19:56:39 -05004136 /* Don't reset timer for no resources */
4137
dea31012005-04-17 16:05:31 -05004138 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05004139 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05004140 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05004141 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004142 }
4143
4144 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04004145 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05004146 phba->fc_stat.elsDelayRetry++;
4147 ndlp->nlp_retry = cmdiocb->retry;
4148
James Smart92d7f7b2007-06-17 19:56:38 -05004149 /* delay is specified in milliseconds */
4150 mod_timer(&ndlp->nlp_delayfunc,
4151 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05004152 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004153 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05004154 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004155
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004156 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smarta0f2d3e2017-02-12 13:52:31 -08004157 if ((cmd == ELS_CMD_PRLI) ||
4158 (cmd == ELS_CMD_NVMEPRLI))
James Smart858c9f62007-06-17 19:56:39 -05004159 lpfc_nlp_set_state(vport, ndlp,
James Smart4c1b64b2012-09-29 11:31:11 -04004160 NLP_STE_PRLI_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05004161 else
4162 lpfc_nlp_set_state(vport, ndlp,
4163 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05004164 ndlp->nlp_last_elscmd = cmd;
4165
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004166 return 1;
dea31012005-04-17 16:05:31 -05004167 }
4168 switch (cmd) {
4169 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05004170 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004171 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05004172 case ELS_CMD_FDISC:
4173 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
4174 return 1;
dea31012005-04-17 16:05:31 -05004175 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04004176 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05004177 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004178 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04004179 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05004180 }
James Smart2e0fef82007-06-17 19:56:36 -05004181 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004182 return 1;
dea31012005-04-17 16:05:31 -05004183 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004184 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004185 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4186 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004187 return 1;
dea31012005-04-17 16:05:31 -05004188 case ELS_CMD_PRLI:
James Smarta0f2d3e2017-02-12 13:52:31 -08004189 case ELS_CMD_NVMEPRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004190 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004191 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
4192 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004193 return 1;
dea31012005-04-17 16:05:31 -05004194 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004195 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04004196 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05004197 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004198 return 1;
dea31012005-04-17 16:05:31 -05004199 }
4200 }
dea31012005-04-17 16:05:31 -05004201 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04004202 if (logerr) {
4203 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4204 "0137 No retry ELS command x%x to remote "
4205 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
4206 cmd, did, irsp->ulpStatus,
4207 irsp->un.ulpWord[4]);
4208 }
4209 else {
4210 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04004211 "0108 No retry ELS command x%x to remote "
4212 "NPORT x%x Retried:%d Error:x%x/%x\n",
4213 cmd, did, cmdiocb->retry, irsp->ulpStatus,
4214 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04004215 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004216 return 0;
dea31012005-04-17 16:05:31 -05004217}
4218
James Smarte59058c2008-08-24 21:49:00 -04004219/**
James Smart3621a712009-04-06 18:47:14 -04004220 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04004221 * @phba: pointer to lpfc hba data structure.
4222 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
4223 *
4224 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
4225 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
4226 * checks to see whether there is a lpfc DMA buffer associated with the
4227 * response of the command IOCB. If so, it will be released before releasing
4228 * the lpfc DMA buffer associated with the IOCB itself.
4229 *
4230 * Return code
4231 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
4232 **/
James Smart09372822008-01-11 01:52:54 -05004233static int
James Smart87af33f2007-10-27 13:37:43 -04004234lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
4235{
4236 struct lpfc_dmabuf *buf_ptr;
4237
James Smarte59058c2008-08-24 21:49:00 -04004238 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04004239 if (!list_empty(&buf_ptr1->list)) {
4240 list_remove_head(&buf_ptr1->list, buf_ptr,
4241 struct lpfc_dmabuf,
4242 list);
4243 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4244 kfree(buf_ptr);
4245 }
4246 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
4247 kfree(buf_ptr1);
4248 return 0;
4249}
4250
James Smarte59058c2008-08-24 21:49:00 -04004251/**
James Smart3621a712009-04-06 18:47:14 -04004252 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04004253 * @phba: pointer to lpfc hba data structure.
4254 * @buf_ptr: pointer to the lpfc dma buffer data structure.
4255 *
4256 * This routine releases the lpfc Direct Memory Access (DMA) buffer
4257 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
4258 * pool.
4259 *
4260 * Return code
4261 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
4262 **/
James Smart09372822008-01-11 01:52:54 -05004263static int
James Smart87af33f2007-10-27 13:37:43 -04004264lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
4265{
4266 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4267 kfree(buf_ptr);
4268 return 0;
4269}
4270
James Smarte59058c2008-08-24 21:49:00 -04004271/**
James Smart3621a712009-04-06 18:47:14 -04004272 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04004273 * @phba: pointer to lpfc hba data structure.
4274 * @elsiocb: pointer to lpfc els command iocb data structure.
4275 *
4276 * This routine frees a command IOCB and its associated resources. The
4277 * command IOCB data structure contains the reference to various associated
4278 * resources, these fields must be set to NULL if the associated reference
4279 * not present:
4280 * context1 - reference to ndlp
4281 * context2 - reference to cmd
4282 * context2->next - reference to rsp
4283 * context3 - reference to bpl
4284 *
4285 * It first properly decrements the reference count held on ndlp for the
4286 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
4287 * set, it invokes the lpfc_els_free_data() routine to release the Direct
4288 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
4289 * adds the DMA buffer the @phba data structure for the delayed release.
4290 * If reference to the Buffer Pointer List (BPL) is present, the
4291 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
4292 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
4293 * invoked to release the IOCB data structure back to @phba IOCBQ list.
4294 *
4295 * Return code
4296 * 0 - Success (currently, always return 0)
4297 **/
James Smart87af33f2007-10-27 13:37:43 -04004298int
James Smart329f9bc2007-04-25 09:53:01 -04004299lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05004300{
4301 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04004302 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004303
James Smarta8adb832007-10-27 13:37:53 -04004304 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
4305 if (ndlp) {
4306 if (ndlp->nlp_flag & NLP_DEFER_RM) {
4307 lpfc_nlp_put(ndlp);
4308
4309 /* If the ndlp is not being used by another discovery
4310 * thread, free it.
4311 */
4312 if (!lpfc_nlp_not_used(ndlp)) {
4313 /* If ndlp is being used by another discovery
4314 * thread, just clear NLP_DEFER_RM
4315 */
4316 ndlp->nlp_flag &= ~NLP_DEFER_RM;
4317 }
4318 }
4319 else
4320 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04004321 elsiocb->context1 = NULL;
4322 }
dea31012005-04-17 16:05:31 -05004323 /* context2 = cmd, context2->next = rsp, context3 = bpl */
4324 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05004325 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
4326 /* Firmware could still be in progress of DMAing
4327 * payload, so don't free data buffer till after
4328 * a hbeat.
4329 */
4330 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
4331 buf_ptr = elsiocb->context2;
4332 elsiocb->context2 = NULL;
4333 if (buf_ptr) {
4334 buf_ptr1 = NULL;
4335 spin_lock_irq(&phba->hbalock);
4336 if (!list_empty(&buf_ptr->list)) {
4337 list_remove_head(&buf_ptr->list,
4338 buf_ptr1, struct lpfc_dmabuf,
4339 list);
4340 INIT_LIST_HEAD(&buf_ptr1->list);
4341 list_add_tail(&buf_ptr1->list,
4342 &phba->elsbuf);
4343 phba->elsbuf_cnt++;
4344 }
4345 INIT_LIST_HEAD(&buf_ptr->list);
4346 list_add_tail(&buf_ptr->list, &phba->elsbuf);
4347 phba->elsbuf_cnt++;
4348 spin_unlock_irq(&phba->hbalock);
4349 }
4350 } else {
4351 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
4352 lpfc_els_free_data(phba, buf_ptr1);
Johannes Thumshirn8667f512017-01-10 12:05:54 +01004353 elsiocb->context2 = NULL;
James Smart0ff10d42008-01-11 01:52:36 -05004354 }
dea31012005-04-17 16:05:31 -05004355 }
4356
4357 if (elsiocb->context3) {
4358 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04004359 lpfc_els_free_bpl(phba, buf_ptr);
Johannes Thumshirn8667f512017-01-10 12:05:54 +01004360 elsiocb->context3 = NULL;
dea31012005-04-17 16:05:31 -05004361 }
James Bottomley604a3e32005-10-29 10:28:33 -05004362 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05004363 return 0;
4364}
4365
James Smarte59058c2008-08-24 21:49:00 -04004366/**
James Smart3621a712009-04-06 18:47:14 -04004367 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04004368 * @phba: pointer to lpfc hba data structure.
4369 * @cmdiocb: pointer to lpfc command iocb data structure.
4370 * @rspiocb: pointer to lpfc response iocb data structure.
4371 *
4372 * This routine is the completion callback function to the Logout (LOGO)
4373 * Accept (ACC) Response ELS command. This routine is invoked to indicate
4374 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
4375 * release the ndlp if it has the last reference remaining (reference count
4376 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
4377 * field to NULL to inform the following lpfc_els_free_iocb() routine no
4378 * ndlp reference count needs to be decremented. Otherwise, the ndlp
4379 * reference use-count shall be decremented by the lpfc_els_free_iocb()
4380 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
4381 * IOCB data structure.
4382 **/
dea31012005-04-17 16:05:31 -05004383static void
James Smart2e0fef82007-06-17 19:56:36 -05004384lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4385 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05004386{
James Smart2e0fef82007-06-17 19:56:36 -05004387 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4388 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05004389 IOCB_t *irsp;
4390
4391 irsp = &rspiocb->iocb;
4392 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4393 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
4394 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05004395 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04004396 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4397 "0109 ACC to LOGO completes to NPort x%x "
4398 "Data: x%x x%x x%x\n",
4399 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4400 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04004401
4402 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
4403 /* NPort Recovery mode or node is just allocated */
4404 if (!lpfc_nlp_not_used(ndlp)) {
4405 /* If the ndlp is being used by another discovery
4406 * thread, just unregister the RPI.
4407 */
4408 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05004409 } else {
4410 /* Indicate the node has already released, should
4411 * not reference to it from within lpfc_els_free_iocb.
4412 */
4413 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04004414 }
dea31012005-04-17 16:05:31 -05004415 }
James Smart73d91e52011-10-10 21:32:10 -04004416
4417 /*
4418 * The driver received a LOGO from the rport and has ACK'd it.
James Smartdf9e1b52011-12-13 13:22:17 -05004419 * At this point, the driver is done so release the IOCB
James Smart73d91e52011-10-10 21:32:10 -04004420 */
dea31012005-04-17 16:05:31 -05004421 lpfc_els_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05004422}
4423
James Smarte59058c2008-08-24 21:49:00 -04004424/**
James Smart3621a712009-04-06 18:47:14 -04004425 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04004426 * @phba: pointer to lpfc hba data structure.
4427 * @pmb: pointer to the driver internal queue element for mailbox command.
4428 *
4429 * This routine is the completion callback function for unregister default
4430 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
4431 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
4432 * decrements the ndlp reference count held for this completion callback
4433 * function. After that, it invokes the lpfc_nlp_not_used() to check
4434 * whether there is only one reference left on the ndlp. If so, it will
4435 * perform one more decrement and trigger the release of the ndlp.
4436 **/
James Smart858c9f62007-06-17 19:56:39 -05004437void
4438lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4439{
James Smart3e1f0712018-11-29 16:09:29 -08004440 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4441 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smart858c9f62007-06-17 19:56:39 -05004442
James Smart3e1f0712018-11-29 16:09:29 -08004443 pmb->ctx_buf = NULL;
4444 pmb->ctx_ndlp = NULL;
James Smartd439d282010-09-29 11:18:45 -04004445
James Smart858c9f62007-06-17 19:56:39 -05004446 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4447 kfree(mp);
4448 mempool_free(pmb, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04004449 if (ndlp) {
James Smartbe6bb942015-04-07 15:07:22 -04004450 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
James Smart32350662019-08-14 16:57:06 -07004451 "0006 rpi%x DID:%x flg:%x %d map:%x x%px\n",
James Smartbe6bb942015-04-07 15:07:22 -04004452 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004453 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04004454 ndlp->nlp_usg_map, ndlp);
James Smart086a3452012-08-14 14:25:21 -04004455 if (NLP_CHK_NODE_ACT(ndlp)) {
4456 lpfc_nlp_put(ndlp);
4457 /* This is the end of the default RPI cleanup logic for
4458 * this ndlp. If no other discovery threads are using
4459 * this ndlp, free all resources associated with it.
4460 */
4461 lpfc_nlp_not_used(ndlp);
4462 } else {
4463 lpfc_drop_node(ndlp->vport, ndlp);
4464 }
James Smarta8adb832007-10-27 13:37:53 -04004465 }
James Smart3772a992009-05-22 14:50:54 -04004466
James Smart858c9f62007-06-17 19:56:39 -05004467 return;
4468}
4469
James Smarte59058c2008-08-24 21:49:00 -04004470/**
James Smart3621a712009-04-06 18:47:14 -04004471 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004472 * @phba: pointer to lpfc hba data structure.
4473 * @cmdiocb: pointer to lpfc command iocb data structure.
4474 * @rspiocb: pointer to lpfc response iocb data structure.
4475 *
4476 * This routine is the completion callback function for ELS Response IOCB
4477 * command. In normal case, this callback function just properly sets the
4478 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
4479 * field in the command IOCB is not NULL, the referred mailbox command will
4480 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
4481 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
4482 * link down event occurred during the discovery, the lpfc_nlp_not_used()
4483 * routine shall be invoked trying to release the ndlp if no other threads
4484 * are currently referring it.
4485 **/
dea31012005-04-17 16:05:31 -05004486static void
James Smart858c9f62007-06-17 19:56:39 -05004487lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04004488 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05004489{
James Smart2e0fef82007-06-17 19:56:36 -05004490 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4491 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
4492 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04004493 IOCB_t *irsp;
4494 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05004495 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004496 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04004497 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05004498
James Smart33ccf8d2006-08-17 11:57:58 -04004499 irsp = &rspiocb->iocb;
4500
James Smart43bfea12019-09-21 20:58:57 -07004501 if (!vport) {
James Smartf84f8f92019-10-18 14:18:23 -07004502 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
4503 "3177 ELS response failed\n");
James Smart43bfea12019-09-21 20:58:57 -07004504 goto out;
4505 }
dea31012005-04-17 16:05:31 -05004506 if (cmdiocb->context_un.mbox)
4507 mbox = cmdiocb->context_un.mbox;
4508
James Smartfa4066b2008-01-11 01:53:27 -05004509 /* First determine if this is a LS_RJT cmpl. Note, this callback
4510 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
4511 */
James Smart87af33f2007-10-27 13:37:43 -04004512 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04004513 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
4514 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05004515 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3fb2010-02-03 08:01:28 +08004516 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04004517 */
4518 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4519 ls_rjt = 1;
4520 }
4521
dea31012005-04-17 16:05:31 -05004522 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04004523 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05004524 if (mbox) {
James Smart3e1f0712018-11-29 16:09:29 -08004525 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
James Smart14691152006-12-02 13:34:28 -05004526 if (mp) {
4527 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4528 kfree(mp);
4529 }
James Smart329f9bc2007-04-25 09:53:01 -04004530 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004531 }
James Smart58da1ff2008-04-07 10:15:56 -04004532 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
4533 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05004534 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04004535 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05004536 /* Indicate the node has already released,
4537 * should not reference to it from within
4538 * the routine lpfc_els_free_iocb.
4539 */
4540 cmdiocb->context1 = NULL;
4541 }
dea31012005-04-17 16:05:31 -05004542 goto out;
4543 }
4544
James Smart858c9f62007-06-17 19:56:39 -05004545 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04004546 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05004547 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04004548 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05004549 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04004550 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4551 "0110 ELS response tag x%x completes "
4552 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
4553 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
4554 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
4555 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4556 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004557 if (mbox) {
4558 if ((rspiocb->iocb.ulpStatus == 0)
4559 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
Dick Kennedy1fe68472017-08-23 16:55:30 -07004560 if (!lpfc_unreg_rpi(vport, ndlp) &&
James Smartf22bfe82019-05-21 17:48:58 -07004561 (!(vport->fc_flag & FC_PT2PT)) &&
Dick Kennedy1fe68472017-08-23 16:55:30 -07004562 (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4563 ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE)) {
4564 lpfc_printf_vlog(vport, KERN_INFO,
4565 LOG_DISCOVERY,
4566 "0314 PLOGI recov DID x%x "
4567 "Data: x%x x%x x%x\n",
4568 ndlp->nlp_DID, ndlp->nlp_state,
4569 ndlp->nlp_rpi, ndlp->nlp_flag);
James Smart3e1f0712018-11-29 16:09:29 -08004570 mp = mbox->ctx_buf;
Dick Kennedy1fe68472017-08-23 16:55:30 -07004571 if (mp) {
4572 lpfc_mbuf_free(phba, mp->virt,
4573 mp->phys);
4574 kfree(mp);
4575 }
4576 mempool_free(mbox, phba->mbox_mem_pool);
4577 goto out;
4578 }
4579
James Smarte47c9092008-02-08 18:49:26 -05004580 /* Increment reference count to ndlp to hold the
4581 * reference to ndlp for the callback function.
4582 */
James Smart3e1f0712018-11-29 16:09:29 -08004583 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05004584 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05004585 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
4586 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4587 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4588 }
4589 else {
4590 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
4591 ndlp->nlp_prev_state = ndlp->nlp_state;
4592 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05004593 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05004594 }
James Smart4b7789b72015-12-16 18:11:55 -05004595
4596 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
James Smart0b727fe2007-10-27 13:37:25 -04004597 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05004598 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05004599 goto out;
James Smart4b7789b72015-12-16 18:11:55 -05004600
4601 /* Decrement the ndlp reference count we
4602 * set for this failed mailbox command.
4603 */
4604 lpfc_nlp_put(ndlp);
4605 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
James Smart98c9ea52007-10-27 13:37:33 -04004606
4607 /* ELS rsp: Cannot issue reg_login for <NPortid> */
4608 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4609 "0138 ELS rsp: Cannot issue reg_login for x%x "
4610 "Data: x%x x%x x%x\n",
4611 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4612 ndlp->nlp_rpi);
4613
James Smartfa4066b2008-01-11 01:53:27 -05004614 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04004615 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05004616 /* Indicate node has already been released,
4617 * should not reference to it from within
4618 * the routine lpfc_els_free_iocb.
4619 */
4620 cmdiocb->context1 = NULL;
4621 }
dea31012005-04-17 16:05:31 -05004622 } else {
James Smart858c9f62007-06-17 19:56:39 -05004623 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
4624 if (!lpfc_error_lost_link(irsp) &&
4625 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05004626 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04004627 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05004628 /* Indicate node has already been
4629 * released, should not reference
4630 * to it from within the routine
4631 * lpfc_els_free_iocb.
4632 */
4633 cmdiocb->context1 = NULL;
4634 }
dea31012005-04-17 16:05:31 -05004635 }
4636 }
James Smart3e1f0712018-11-29 16:09:29 -08004637 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
James Smart14691152006-12-02 13:34:28 -05004638 if (mp) {
4639 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4640 kfree(mp);
4641 }
4642 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004643 }
4644out:
James Smart6c6d59e2019-11-11 15:03:57 -08004645 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && shost) {
James Smart2e0fef82007-06-17 19:56:36 -05004646 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05004647 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05004648 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04004649
4650 /* If the node is not being used by another discovery thread,
4651 * and we are sending a reject, we are done with it.
4652 * Release driver reference count here and free associated
4653 * resources.
4654 */
4655 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05004656 if (lpfc_nlp_not_used(ndlp))
4657 /* Indicate node has already been released,
4658 * should not reference to it from within
4659 * the routine lpfc_els_free_iocb.
4660 */
4661 cmdiocb->context1 = NULL;
James Smart4b7789b72015-12-16 18:11:55 -05004662
dea31012005-04-17 16:05:31 -05004663 }
James Smart87af33f2007-10-27 13:37:43 -04004664
dea31012005-04-17 16:05:31 -05004665 lpfc_els_free_iocb(phba, cmdiocb);
4666 return;
4667}
4668
James Smarte59058c2008-08-24 21:49:00 -04004669/**
James Smart3621a712009-04-06 18:47:14 -04004670 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004671 * @vport: pointer to a host virtual N_Port data structure.
4672 * @flag: the els command code to be accepted.
4673 * @oldiocb: pointer to the original lpfc command iocb data structure.
4674 * @ndlp: pointer to a node-list data structure.
4675 * @mbox: pointer to the driver internal queue element for mailbox command.
4676 *
4677 * This routine prepares and issues an Accept (ACC) response IOCB
4678 * command. It uses the @flag to properly set up the IOCB field for the
4679 * specific ACC response command to be issued and invokes the
4680 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
4681 * @mbox pointer is passed in, it will be put into the context_un.mbox
4682 * field of the IOCB for the completion callback function to issue the
4683 * mailbox command to the HBA later when callback is invoked.
4684 *
4685 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4686 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4687 * will be stored into the context1 field of the IOCB for the completion
4688 * callback function to the corresponding response ELS IOCB command.
4689 *
4690 * Return code
4691 * 0 - Successfully issued acc response
4692 * 1 - Failed to issue acc response
4693 **/
dea31012005-04-17 16:05:31 -05004694int
James Smart2e0fef82007-06-17 19:56:36 -05004695lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
4696 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04004697 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05004698{
James Smart2e0fef82007-06-17 19:56:36 -05004699 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4700 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004701 IOCB_t *icmd;
4702 IOCB_t *oldcmd;
4703 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004704 uint8_t *pcmd;
James Smartd6de08c2015-12-16 18:11:53 -05004705 struct serv_parm *sp;
dea31012005-04-17 16:05:31 -05004706 uint16_t cmdsize;
4707 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04004708 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05004709
dea31012005-04-17 16:05:31 -05004710 oldcmd = &oldiocb->iocb;
4711
4712 switch (flag) {
4713 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05004714 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05004715 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4716 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004717 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05004718 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004719 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05004720 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004721 return 1;
dea31012005-04-17 16:05:31 -05004722 }
James Smart2e0fef82007-06-17 19:56:36 -05004723
dea31012005-04-17 16:05:31 -05004724 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004725 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4726 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05004727 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4728 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004729 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05004730
4731 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4732 "Issue ACC: did:x%x flg:x%x",
4733 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05004734 break;
James Smartd6de08c2015-12-16 18:11:53 -05004735 case ELS_CMD_FLOGI:
dea31012005-04-17 16:05:31 -05004736 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05004737 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05004738 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4739 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004740 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004741 return 1;
James Smart488d1462006-03-07 15:02:37 -05004742
dea31012005-04-17 16:05:31 -05004743 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004744 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4745 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05004746 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4747
4748 if (mbox)
4749 elsiocb->context_un.mbox = mbox;
4750
4751 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004752 pcmd += sizeof(uint32_t);
James Smartd6de08c2015-12-16 18:11:53 -05004753 sp = (struct serv_parm *)pcmd;
4754
4755 if (flag == ELS_CMD_FLOGI) {
4756 /* Copy the received service parameters back */
4757 memcpy(sp, &phba->fc_fabparam,
4758 sizeof(struct serv_parm));
4759
4760 /* Clear the F_Port bit */
4761 sp->cmn.fPort = 0;
4762
4763 /* Mark all class service parameters as invalid */
4764 sp->cls1.classValid = 0;
4765 sp->cls2.classValid = 0;
4766 sp->cls3.classValid = 0;
4767 sp->cls4.classValid = 0;
4768
4769 /* Copy our worldwide names */
4770 memcpy(&sp->portName, &vport->fc_sparam.portName,
4771 sizeof(struct lpfc_name));
4772 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4773 sizeof(struct lpfc_name));
James Smart8c258642017-02-12 13:52:36 -08004774 } else {
James Smartd6de08c2015-12-16 18:11:53 -05004775 memcpy(pcmd, &vport->fc_sparam,
4776 sizeof(struct serv_parm));
James Smarte0165f22016-12-19 15:07:20 -08004777
James Smart8c258642017-02-12 13:52:36 -08004778 sp->cmn.valid_vendor_ver_level = 0;
4779 memset(sp->un.vendorVersion, 0,
4780 sizeof(sp->un.vendorVersion));
James Smart44fd7fe2017-08-23 16:55:47 -07004781 sp->cmn.bbRcvSizeMsb &= 0xF;
James Smart8c258642017-02-12 13:52:36 -08004782
4783 /* If our firmware supports this feature, convey that
4784 * info to the target using the vendor specific field.
4785 */
4786 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4787 sp->cmn.valid_vendor_ver_level = 1;
4788 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4789 sp->un.vv.flags =
4790 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4791 }
4792 }
4793
James Smart858c9f62007-06-17 19:56:39 -05004794 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smartd6de08c2015-12-16 18:11:53 -05004795 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
James Smart858c9f62007-06-17 19:56:39 -05004796 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05004797 break;
James Smart82d9a2a2006-04-15 11:53:05 -04004798 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05004799 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05004800 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04004801 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4802 if (!elsiocb)
4803 return 1;
4804
4805 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004806 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4807 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04004808 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4809
4810 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05004811 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04004812 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4813 els_pkt_ptr = (ELS_PKT *) pcmd;
4814 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05004815
4816 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4817 "Issue ACC PRLO: did:x%x flg:x%x",
4818 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04004819 break;
dea31012005-04-17 16:05:31 -05004820 default:
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004821 return 1;
dea31012005-04-17 16:05:31 -05004822 }
dea31012005-04-17 16:05:31 -05004823 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05004824 spin_lock_irq(shost->host_lock);
James Smart7c5e5182015-05-22 10:42:43 -04004825 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4826 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4827 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05004828 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004829 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4830 } else {
James Smart858c9f62007-06-17 19:56:39 -05004831 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004832 }
4833
4834 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004835 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004836 if (rc == IOCB_ERROR) {
4837 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004838 return 1;
dea31012005-04-17 16:05:31 -05004839 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004840 return 0;
dea31012005-04-17 16:05:31 -05004841}
4842
James Smarte59058c2008-08-24 21:49:00 -04004843/**
James Smart3621a712009-04-06 18:47:14 -04004844 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004845 * @vport: pointer to a virtual N_Port data structure.
4846 * @rejectError:
4847 * @oldiocb: pointer to the original lpfc command iocb data structure.
4848 * @ndlp: pointer to a node-list data structure.
4849 * @mbox: pointer to the driver internal queue element for mailbox command.
4850 *
4851 * This routine prepares and issue an Reject (RJT) response IOCB
4852 * command. If a @mbox pointer is passed in, it will be put into the
4853 * context_un.mbox field of the IOCB for the completion callback function
4854 * to issue to the HBA later.
4855 *
4856 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4857 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4858 * will be stored into the context1 field of the IOCB for the completion
4859 * callback function to the reject response ELS IOCB command.
4860 *
4861 * Return code
4862 * 0 - Successfully issued reject response
4863 * 1 - Failed to issue reject response
4864 **/
dea31012005-04-17 16:05:31 -05004865int
James Smart2e0fef82007-06-17 19:56:36 -05004866lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05004867 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4868 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05004869{
James Smart2e0fef82007-06-17 19:56:36 -05004870 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004871 IOCB_t *icmd;
4872 IOCB_t *oldcmd;
4873 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004874 uint8_t *pcmd;
4875 uint16_t cmdsize;
4876 int rc;
4877
James Smart92d7f7b2007-06-17 19:56:38 -05004878 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05004879 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4880 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05004881 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004882 return 1;
dea31012005-04-17 16:05:31 -05004883
4884 icmd = &elsiocb->iocb;
4885 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004886 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4887 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05004888 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4889
4890 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05004891 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004892 *((uint32_t *) (pcmd)) = rejectError;
4893
James Smart51ef4c22007-08-02 11:10:31 -04004894 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05004895 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05004896
dea31012005-04-17 16:05:31 -05004897 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004898 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4899 "0129 Xmit ELS RJT x%x response tag x%x "
4900 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4901 "rpi x%x\n",
4902 rejectError, elsiocb->iotag,
4903 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4904 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004905 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4906 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4907 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4908
dea31012005-04-17 16:05:31 -05004909 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05004910 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004911 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04004912
dea31012005-04-17 16:05:31 -05004913 if (rc == IOCB_ERROR) {
4914 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004915 return 1;
dea31012005-04-17 16:05:31 -05004916 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004917 return 0;
dea31012005-04-17 16:05:31 -05004918}
4919
James Smarte59058c2008-08-24 21:49:00 -04004920/**
James Smart3621a712009-04-06 18:47:14 -04004921 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004922 * @vport: pointer to a virtual N_Port data structure.
4923 * @oldiocb: pointer to the original lpfc command iocb data structure.
4924 * @ndlp: pointer to a node-list data structure.
4925 *
4926 * This routine prepares and issues an Accept (ACC) response to Address
4927 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4928 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4929 *
4930 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4931 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4932 * will be stored into the context1 field of the IOCB for the completion
4933 * callback function to the ADISC Accept response ELS IOCB command.
4934 *
4935 * Return code
4936 * 0 - Successfully issued acc adisc response
4937 * 1 - Failed to issue adisc acc response
4938 **/
dea31012005-04-17 16:05:31 -05004939int
James Smart2e0fef82007-06-17 19:56:36 -05004940lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4941 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004942{
James Smart2e0fef82007-06-17 19:56:36 -05004943 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004944 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05004945 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004946 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004947 uint8_t *pcmd;
4948 uint16_t cmdsize;
4949 int rc;
4950
James Smart92d7f7b2007-06-17 19:56:38 -05004951 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05004952 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4953 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004954 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004955 return 1;
dea31012005-04-17 16:05:31 -05004956
dea31012005-04-17 16:05:31 -05004957 icmd = &elsiocb->iocb;
4958 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004959 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4960 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04004961
4962 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004963 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4964 "0130 Xmit ADISC ACC response iotag x%x xri: "
4965 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4966 elsiocb->iotag, elsiocb->iocb.ulpContext,
4967 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4968 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004969 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4970
4971 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004972 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004973
4974 ap = (ADISC *) (pcmd);
4975 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05004976 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4977 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05004978 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05004979
James Smart858c9f62007-06-17 19:56:39 -05004980 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4981 "Issue ACC ADISC: did:x%x flg:x%x",
4982 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4983
dea31012005-04-17 16:05:31 -05004984 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004985 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004986 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004987 if (rc == IOCB_ERROR) {
4988 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004989 return 1;
dea31012005-04-17 16:05:31 -05004990 }
James Smartd496b9a2018-10-23 13:41:08 -07004991
4992 /* Xmit ELS ACC response tag <ulpIoTag> */
4993 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4994 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
4995 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
4996 "RPI: x%x, fc_flag x%x\n",
4997 rc, elsiocb->iotag, elsiocb->sli4_xritag,
4998 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4999 ndlp->nlp_rpi, vport->fc_flag);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005000 return 0;
dea31012005-04-17 16:05:31 -05005001}
5002
James Smarte59058c2008-08-24 21:49:00 -04005003/**
James Smart3621a712009-04-06 18:47:14 -04005004 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04005005 * @vport: pointer to a virtual N_Port data structure.
5006 * @oldiocb: pointer to the original lpfc command iocb data structure.
5007 * @ndlp: pointer to a node-list data structure.
5008 *
5009 * This routine prepares and issues an Accept (ACC) response to Process
5010 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
5011 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
5012 *
5013 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5014 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5015 * will be stored into the context1 field of the IOCB for the completion
5016 * callback function to the PRLI Accept response ELS IOCB command.
5017 *
5018 * Return code
5019 * 0 - Successfully issued acc prli response
5020 * 1 - Failed to issue acc prli response
5021 **/
dea31012005-04-17 16:05:31 -05005022int
James Smart2e0fef82007-06-17 19:56:36 -05005023lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04005024 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005025{
James Smart2e0fef82007-06-17 19:56:36 -05005026 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005027 PRLI *npr;
James Smarta0f2d3e2017-02-12 13:52:31 -08005028 struct lpfc_nvme_prli *npr_nvme;
dea31012005-04-17 16:05:31 -05005029 lpfc_vpd_t *vpd;
5030 IOCB_t *icmd;
5031 IOCB_t *oldcmd;
5032 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05005033 uint8_t *pcmd;
5034 uint16_t cmdsize;
James Smarta0f2d3e2017-02-12 13:52:31 -08005035 uint32_t prli_fc4_req, *req_payload;
5036 struct lpfc_dmabuf *req_buf;
dea31012005-04-17 16:05:31 -05005037 int rc;
James Smarta0f2d3e2017-02-12 13:52:31 -08005038 u32 elsrspcmd;
dea31012005-04-17 16:05:31 -05005039
James Smarta0f2d3e2017-02-12 13:52:31 -08005040 /* Need the incoming PRLI payload to determine if the ACC is for an
5041 * FC4 or NVME PRLI type. The PRLI type is at word 1.
5042 */
5043 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
5044 req_payload = (((uint32_t *)req_buf->virt) + 1);
5045
5046 /* PRLI type payload is at byte 3 for FCP or NVME. */
5047 prli_fc4_req = be32_to_cpu(*req_payload);
5048 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
5049 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5050 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
5051 prli_fc4_req, *((uint32_t *)req_payload));
5052
5053 if (prli_fc4_req == PRLI_FCP_TYPE) {
5054 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
5055 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
5056 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5057 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
5058 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
5059 } else {
5060 return 1;
5061 }
5062
James Smart2e0fef82007-06-17 19:56:36 -05005063 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smarta0f2d3e2017-02-12 13:52:31 -08005064 ndlp->nlp_DID, elsrspcmd);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005065 if (!elsiocb)
5066 return 1;
dea31012005-04-17 16:05:31 -05005067
dea31012005-04-17 16:05:31 -05005068 icmd = &elsiocb->iocb;
5069 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005070 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5071 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5072
James Smart5b8bd0c2007-04-25 09:52:49 -04005073 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005074 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5075 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
5076 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5077 elsiocb->iotag, elsiocb->iocb.ulpContext,
5078 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5079 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05005080 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
James Smarta0f2d3e2017-02-12 13:52:31 -08005081 memset(pcmd, 0, cmdsize);
dea31012005-04-17 16:05:31 -05005082
James Smartc07f10c2017-04-21 16:04:54 -07005083 *((uint32_t *)(pcmd)) = elsrspcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05005084 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05005085
5086 /* For PRLI, remainder of payload is PRLI parameter page */
dea31012005-04-17 16:05:31 -05005087 vpd = &phba->vpd;
James Smarta0f2d3e2017-02-12 13:52:31 -08005088
5089 if (prli_fc4_req == PRLI_FCP_TYPE) {
5090 /*
5091 * If the remote port is a target and our firmware version
5092 * is 3.20 or later, set the following bits for FC-TAPE
5093 * support.
5094 */
5095 npr = (PRLI *) pcmd;
5096 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
5097 (vpd->rev.feaLevelHigh >= 0x02)) {
5098 npr->ConfmComplAllowed = 1;
5099 npr->Retry = 1;
5100 npr->TaskRetryIdReq = 1;
5101 }
5102 npr->acceptRspCode = PRLI_REQ_EXECUTED;
5103 npr->estabImagePair = 1;
5104 npr->readXferRdyDis = 1;
dea31012005-04-17 16:05:31 -05005105 npr->ConfmComplAllowed = 1;
James Smarta0f2d3e2017-02-12 13:52:31 -08005106 npr->prliType = PRLI_FCP_TYPE;
5107 npr->initiatorFunc = 1;
5108 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5109 /* Respond with an NVME PRLI Type */
5110 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
5111 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
5112 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
5113 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
James Smart8c258642017-02-12 13:52:36 -08005114 if (phba->nvmet_support) {
5115 bf_set(prli_tgt, npr_nvme, 1);
5116 bf_set(prli_disc, npr_nvme, 1);
5117 if (phba->cfg_nvme_enable_fb) {
5118 bf_set(prli_fba, npr_nvme, 1);
5119
5120 /* TBD. Target mode needs to post buffers
5121 * that support the configured first burst
5122 * byte size.
5123 */
5124 bf_set(prli_fb_sz, npr_nvme,
5125 phba->cfg_nvmet_fb_size);
5126 }
5127 } else {
5128 bf_set(prli_init, npr_nvme, 1);
5129 }
dea31012005-04-17 16:05:31 -05005130
James Smarta0f2d3e2017-02-12 13:52:31 -08005131 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
5132 "6015 NVME issue PRLI ACC word1 x%08x "
5133 "word4 x%08x word5 x%08x flag x%x, "
5134 "fcp_info x%x nlp_type x%x\n",
5135 npr_nvme->word1, npr_nvme->word4,
5136 npr_nvme->word5, ndlp->nlp_flag,
5137 ndlp->nlp_fcp_info, ndlp->nlp_type);
5138 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
5139 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
5140 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
5141 } else
5142 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5143 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
5144 prli_fc4_req, ndlp->nlp_fc4_type,
5145 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05005146
James Smart858c9f62007-06-17 19:56:39 -05005147 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5148 "Issue ACC PRLI: did:x%x flg:x%x",
5149 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5150
dea31012005-04-17 16:05:31 -05005151 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05005152 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05005153
James Smart3772a992009-05-22 14:50:54 -04005154 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05005155 if (rc == IOCB_ERROR) {
5156 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005157 return 1;
dea31012005-04-17 16:05:31 -05005158 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005159 return 0;
dea31012005-04-17 16:05:31 -05005160}
5161
James Smarte59058c2008-08-24 21:49:00 -04005162/**
James Smart3621a712009-04-06 18:47:14 -04005163 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04005164 * @vport: pointer to a virtual N_Port data structure.
5165 * @format: rnid command format.
5166 * @oldiocb: pointer to the original lpfc command iocb data structure.
5167 * @ndlp: pointer to a node-list data structure.
5168 *
5169 * This routine issues a Request Node Identification Data (RNID) Accept
5170 * (ACC) response. It constructs the RNID ACC response command according to
5171 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
5172 * issue the response. Note that this command does not need to hold the ndlp
5173 * reference count for the callback. So, the ndlp reference count taken by
5174 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
5175 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
5176 * there is no ndlp reference available.
5177 *
5178 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5179 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5180 * will be stored into the context1 field of the IOCB for the completion
5181 * callback function. However, for the RNID Accept Response ELS command,
5182 * this is undone later by this routine after the IOCB is allocated.
5183 *
5184 * Return code
5185 * 0 - Successfully issued acc rnid response
5186 * 1 - Failed to issue acc rnid response
5187 **/
dea31012005-04-17 16:05:31 -05005188static int
James Smart2e0fef82007-06-17 19:56:36 -05005189lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04005190 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005191{
James Smart2e0fef82007-06-17 19:56:36 -05005192 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005193 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05005194 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05005195 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05005196 uint8_t *pcmd;
5197 uint16_t cmdsize;
5198 int rc;
5199
James Smart92d7f7b2007-06-17 19:56:38 -05005200 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
5201 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05005202 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05005203 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05005204
James Smart2e0fef82007-06-17 19:56:36 -05005205 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5206 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05005207 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005208 return 1;
dea31012005-04-17 16:05:31 -05005209
dea31012005-04-17 16:05:31 -05005210 icmd = &elsiocb->iocb;
5211 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005212 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5213 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5214
James Smart5b8bd0c2007-04-25 09:52:49 -04005215 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005216 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5217 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
5218 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05005219 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05005220 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005221 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05005222
James Smart92d7f7b2007-06-17 19:56:38 -05005223 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05005224 rn = (RNID *) (pcmd);
5225 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05005226 rn->CommonLen = (2 * sizeof(struct lpfc_name));
5227 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5228 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05005229 switch (format) {
5230 case 0:
5231 rn->SpecificLen = 0;
5232 break;
5233 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05005234 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05005235 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05005236 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05005237 rn->un.topologyDisc.unitType = RNID_HBA;
5238 rn->un.topologyDisc.physPort = 0;
5239 rn->un.topologyDisc.attachedNodes = 0;
5240 break;
5241 default:
5242 rn->CommonLen = 0;
5243 rn->SpecificLen = 0;
5244 break;
5245 }
5246
James Smart858c9f62007-06-17 19:56:39 -05005247 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5248 "Issue ACC RNID: did:x%x flg:x%x",
5249 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5250
dea31012005-04-17 16:05:31 -05005251 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05005252 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05005253
James Smart3772a992009-05-22 14:50:54 -04005254 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05005255 if (rc == IOCB_ERROR) {
5256 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005257 return 1;
dea31012005-04-17 16:05:31 -05005258 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005259 return 0;
dea31012005-04-17 16:05:31 -05005260}
5261
James Smarte59058c2008-08-24 21:49:00 -04005262/**
James Smart19ca7602010-11-20 23:11:55 -05005263 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
5264 * @vport: pointer to a virtual N_Port data structure.
5265 * @iocb: pointer to the lpfc command iocb data structure.
5266 * @ndlp: pointer to a node-list data structure.
5267 *
5268 * Return
5269 **/
5270static void
5271lpfc_els_clear_rrq(struct lpfc_vport *vport,
James Smarta0f2d3e2017-02-12 13:52:31 -08005272 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
James Smart19ca7602010-11-20 23:11:55 -05005273{
5274 struct lpfc_hba *phba = vport->phba;
5275 uint8_t *pcmd;
5276 struct RRQ *rrq;
5277 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05005278 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05005279 struct lpfc_node_rrq *prrq;
5280
5281
5282 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
5283 pcmd += sizeof(uint32_t);
5284 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05005285 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b0622011-04-16 11:03:17 -04005286 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05005287
5288 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5289 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
5290 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05005291 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b0622011-04-16 11:03:17 -04005292 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05005293 rxid,
5294 iocb->iotag, iocb->iocb.ulpContext);
5295
5296 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5297 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
5298 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05005299 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b0622011-04-16 11:03:17 -04005300 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05005301 else
5302 xri = rxid;
5303 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05005304 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05005305 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05005306 return;
5307}
5308
5309/**
James Smart12265f62010-10-22 11:05:53 -04005310 * lpfc_els_rsp_echo_acc - Issue echo acc response
5311 * @vport: pointer to a virtual N_Port data structure.
5312 * @data: pointer to echo data to return in the accept.
5313 * @oldiocb: pointer to the original lpfc command iocb data structure.
5314 * @ndlp: pointer to a node-list data structure.
5315 *
5316 * Return code
5317 * 0 - Successfully issued acc echo response
5318 * 1 - Failed to issue acc echo response
5319 **/
5320static int
5321lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
5322 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5323{
5324 struct lpfc_hba *phba = vport->phba;
5325 struct lpfc_iocbq *elsiocb;
James Smart12265f62010-10-22 11:05:53 -04005326 uint8_t *pcmd;
5327 uint16_t cmdsize;
5328 int rc;
5329
James Smart12265f62010-10-22 11:05:53 -04005330 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
5331
James Smartbf086112011-08-21 21:48:13 -04005332 /* The accumulated length can exceed the BPL_SIZE. For
5333 * now, use this as the limit
5334 */
5335 if (cmdsize > LPFC_BPL_SIZE)
5336 cmdsize = LPFC_BPL_SIZE;
James Smart12265f62010-10-22 11:05:53 -04005337 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5338 ndlp->nlp_DID, ELS_CMD_ACC);
5339 if (!elsiocb)
5340 return 1;
5341
James Smart7851fe22011-07-22 18:36:52 -04005342 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
5343 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
5344
James Smart12265f62010-10-22 11:05:53 -04005345 /* Xmit ECHO ACC response tag <ulpIoTag> */
5346 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5347 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
5348 elsiocb->iotag, elsiocb->iocb.ulpContext);
5349 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5350 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5351 pcmd += sizeof(uint32_t);
5352 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
5353
5354 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5355 "Issue ACC ECHO: did:x%x flg:x%x",
5356 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5357
5358 phba->fc_stat.elsXmitACC++;
5359 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart12265f62010-10-22 11:05:53 -04005360
5361 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5362 if (rc == IOCB_ERROR) {
5363 lpfc_els_free_iocb(phba, elsiocb);
5364 return 1;
5365 }
5366 return 0;
5367}
5368
5369/**
James Smart3621a712009-04-06 18:47:14 -04005370 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04005371 * @vport: pointer to a host virtual N_Port data structure.
5372 *
5373 * This routine issues Address Discover (ADISC) ELS commands to those
5374 * N_Ports which are in node port recovery state and ADISC has not been issued
5375 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
5376 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
5377 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
5378 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
5379 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
5380 * IOCBs quit for later pick up. On the other hand, after walking through
5381 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
5382 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
5383 * no more ADISC need to be sent.
5384 *
5385 * Return code
5386 * The number of N_Ports with adisc issued.
5387 **/
dea31012005-04-17 16:05:31 -05005388int
James Smart2e0fef82007-06-17 19:56:36 -05005389lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005390{
James Smart2e0fef82007-06-17 19:56:36 -05005391 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005392 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05005393 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05005394
James Smart685f0bf2007-04-25 09:53:08 -04005395 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05005396 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005397 if (!NLP_CHK_NODE_ACT(ndlp))
5398 continue;
James Smart685f0bf2007-04-25 09:53:08 -04005399 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5400 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5401 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05005402 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005403 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05005404 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005405 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005406 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
5407 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04005408 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05005409 vport->num_disc_nodes++;
5410 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04005411 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05005412 spin_lock_irq(shost->host_lock);
5413 vport->fc_flag |= FC_NLP_MORE;
5414 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005415 break;
dea31012005-04-17 16:05:31 -05005416 }
5417 }
5418 }
5419 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05005420 spin_lock_irq(shost->host_lock);
5421 vport->fc_flag &= ~FC_NLP_MORE;
5422 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005423 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005424 return sentadisc;
dea31012005-04-17 16:05:31 -05005425}
5426
James Smarte59058c2008-08-24 21:49:00 -04005427/**
James Smart3621a712009-04-06 18:47:14 -04005428 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04005429 * @vport: pointer to a host virtual N_Port data structure.
5430 *
5431 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
5432 * which are in node port recovery state, with a @vport. Each time an ELS
5433 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
5434 * the per @vport number of discover count (num_disc_nodes) shall be
5435 * incremented. If the num_disc_nodes reaches a pre-configured threshold
5436 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
5437 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
5438 * later pick up. On the other hand, after walking through all the ndlps with
5439 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
5440 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
5441 * PLOGI need to be sent.
5442 *
5443 * Return code
5444 * The number of N_Ports with plogi issued.
5445 **/
dea31012005-04-17 16:05:31 -05005446int
James Smart2e0fef82007-06-17 19:56:36 -05005447lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005448{
James Smart2e0fef82007-06-17 19:56:36 -05005449 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005450 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05005451 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05005452
James Smart2e0fef82007-06-17 19:56:36 -05005453 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
5454 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005455 if (!NLP_CHK_NODE_ACT(ndlp))
5456 continue;
James Smart685f0bf2007-04-25 09:53:08 -04005457 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
James Smart8b017a32015-05-21 13:55:18 -04005458 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5459 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
5460 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
James Smart685f0bf2007-04-25 09:53:08 -04005461 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005462 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5463 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04005464 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05005465 vport->num_disc_nodes++;
5466 if (vport->num_disc_nodes >=
James Smart8b017a32015-05-21 13:55:18 -04005467 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05005468 spin_lock_irq(shost->host_lock);
5469 vport->fc_flag |= FC_NLP_MORE;
5470 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005471 break;
dea31012005-04-17 16:05:31 -05005472 }
5473 }
5474 }
James Smartb4b34172019-10-18 14:18:31 -07005475
5476 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5477 "6452 Discover PLOGI %d flag x%x\n",
5478 sentplogi, vport->fc_flag);
5479
James Smart87af33f2007-10-27 13:37:43 -04005480 if (sentplogi) {
5481 lpfc_set_disctmo(vport);
5482 }
5483 else {
James Smart2e0fef82007-06-17 19:56:36 -05005484 spin_lock_irq(shost->host_lock);
5485 vport->fc_flag &= ~FC_NLP_MORE;
5486 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005487 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005488 return sentplogi;
dea31012005-04-17 16:05:31 -05005489}
5490
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005491static uint32_t
James Smart86478872015-05-21 13:55:21 -04005492lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
5493 uint32_t word0)
5494{
5495
5496 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
5497 desc->payload.els_req = word0;
5498 desc->length = cpu_to_be32(sizeof(desc->payload));
James Smart6c92d1d2016-07-06 12:35:55 -07005499
5500 return sizeof(struct fc_rdp_link_service_desc);
James Smart86478872015-05-21 13:55:21 -04005501}
5502
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005503static uint32_t
James Smart86478872015-05-21 13:55:21 -04005504lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
5505 uint8_t *page_a0, uint8_t *page_a2)
5506{
5507 uint16_t wavelength;
5508 uint16_t temperature;
5509 uint16_t rx_power;
5510 uint16_t tx_bias;
5511 uint16_t tx_power;
5512 uint16_t vcc;
5513 uint16_t flag = 0;
5514 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
5515 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
5516
5517 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
5518
5519 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
5520 &page_a0[SSF_TRANSCEIVER_CODE_B4];
5521 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
5522 &page_a0[SSF_TRANSCEIVER_CODE_B5];
5523
5524 if ((trasn_code_byte4->fc_sw_laser) ||
5525 (trasn_code_byte5->fc_sw_laser_sl) ||
5526 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
5527 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
5528 } else if (trasn_code_byte4->fc_lw_laser) {
5529 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
5530 page_a0[SSF_WAVELENGTH_B0];
5531 if (wavelength == SFP_WAVELENGTH_LC1310)
5532 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
5533 if (wavelength == SFP_WAVELENGTH_LL1550)
5534 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
5535 }
5536 /* check if its SFP+ */
5537 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
5538 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
5539 << SFP_FLAG_CT_SHIFT;
5540
5541 /* check if its OPTICAL */
5542 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
5543 SFP_FLAG_IS_OPTICAL_PORT : 0)
5544 << SFP_FLAG_IS_OPTICAL_SHIFT;
5545
5546 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
5547 page_a2[SFF_TEMPERATURE_B0]);
5548 vcc = (page_a2[SFF_VCC_B1] << 8 |
5549 page_a2[SFF_VCC_B0]);
5550 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
5551 page_a2[SFF_TXPOWER_B0]);
5552 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
5553 page_a2[SFF_TX_BIAS_CURRENT_B0]);
5554 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
5555 page_a2[SFF_RXPOWER_B0]);
5556 desc->sfp_info.temperature = cpu_to_be16(temperature);
5557 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
5558 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
5559 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
5560 desc->sfp_info.vcc = cpu_to_be16(vcc);
5561
5562 desc->sfp_info.flags = cpu_to_be16(flag);
5563 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005564
5565 return sizeof(struct fc_rdp_sfp_desc);
James Smart86478872015-05-21 13:55:21 -04005566}
5567
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005568static uint32_t
James Smart86478872015-05-21 13:55:21 -04005569lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
5570 READ_LNK_VAR *stat)
5571{
5572 uint32_t type;
5573
5574 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
5575
5576 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
5577
5578 desc->info.port_type = cpu_to_be32(type);
5579
5580 desc->info.link_status.link_failure_cnt =
5581 cpu_to_be32(stat->linkFailureCnt);
5582 desc->info.link_status.loss_of_synch_cnt =
5583 cpu_to_be32(stat->lossSyncCnt);
5584 desc->info.link_status.loss_of_signal_cnt =
5585 cpu_to_be32(stat->lossSignalCnt);
5586 desc->info.link_status.primitive_seq_proto_err =
5587 cpu_to_be32(stat->primSeqErrCnt);
5588 desc->info.link_status.invalid_trans_word =
5589 cpu_to_be32(stat->invalidXmitWord);
5590 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
5591
5592 desc->length = cpu_to_be32(sizeof(desc->info));
James Smart6c92d1d2016-07-06 12:35:55 -07005593
5594 return sizeof(struct fc_rdp_link_error_status_desc);
James Smart86478872015-05-21 13:55:21 -04005595}
5596
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005597static uint32_t
James Smart56204982016-03-31 14:12:32 -07005598lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
5599 struct lpfc_vport *vport)
5600{
James Smart3aaaa312016-07-06 12:35:57 -07005601 uint32_t bbCredit;
5602
James Smart56204982016-03-31 14:12:32 -07005603 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
5604
James Smart3aaaa312016-07-06 12:35:57 -07005605 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
5606 (vport->fc_sparam.cmn.bbCreditMsb << 8);
5607 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
5608 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
5609 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
5610 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
5611 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
5612 } else {
James Smart56204982016-03-31 14:12:32 -07005613 desc->bbc_info.attached_port_bbc = 0;
James Smart3aaaa312016-07-06 12:35:57 -07005614 }
James Smart56204982016-03-31 14:12:32 -07005615
5616 desc->bbc_info.rtt = 0;
5617 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005618
5619 return sizeof(struct fc_rdp_bbc_desc);
James Smart56204982016-03-31 14:12:32 -07005620}
5621
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005622static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005623lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
5624 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
James Smart56204982016-03-31 14:12:32 -07005625{
James Smart310429e2016-07-06 12:35:54 -07005626 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005627
5628 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5629
James Smart3aaaa312016-07-06 12:35:57 -07005630 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
5631 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
5632 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
5633 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005634
5635 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5636 flags |= RDP_OET_HIGH_ALARM;
5637 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5638 flags |= RDP_OET_LOW_ALARM;
5639 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5640 flags |= RDP_OET_HIGH_WARNING;
5641 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5642 flags |= RDP_OET_LOW_WARNING;
5643
James Smart56204982016-03-31 14:12:32 -07005644 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
5645 desc->oed_info.function_flags = cpu_to_be32(flags);
5646 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005647 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005648}
5649
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005650static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005651lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
5652 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07005653 uint8_t *page_a2)
5654{
James Smart310429e2016-07-06 12:35:54 -07005655 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005656
5657 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5658
James Smart3aaaa312016-07-06 12:35:57 -07005659 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
5660 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
5661 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
5662 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005663
5664 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5665 flags |= RDP_OET_HIGH_ALARM;
5666 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5667 flags |= RDP_OET_LOW_ALARM;
5668 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5669 flags |= RDP_OET_HIGH_WARNING;
5670 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5671 flags |= RDP_OET_LOW_WARNING;
5672
James Smart56204982016-03-31 14:12:32 -07005673 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
5674 desc->oed_info.function_flags = cpu_to_be32(flags);
5675 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005676 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005677}
5678
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005679static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005680lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
5681 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07005682 uint8_t *page_a2)
5683{
James Smart310429e2016-07-06 12:35:54 -07005684 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005685
5686 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5687
James Smart3aaaa312016-07-06 12:35:57 -07005688 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
5689 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5690 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5691 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005692
5693 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5694 flags |= RDP_OET_HIGH_ALARM;
5695 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5696 flags |= RDP_OET_LOW_ALARM;
5697 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5698 flags |= RDP_OET_HIGH_WARNING;
5699 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5700 flags |= RDP_OET_LOW_WARNING;
5701
James Smart56204982016-03-31 14:12:32 -07005702 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5703 desc->oed_info.function_flags = cpu_to_be32(flags);
5704 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005705 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005706}
5707
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005708static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005709lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5710 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07005711 uint8_t *page_a2)
5712{
James Smart310429e2016-07-06 12:35:54 -07005713 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005714
5715 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5716
James Smart3aaaa312016-07-06 12:35:57 -07005717 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5718 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5719 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5720 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005721
5722 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5723 flags |= RDP_OET_HIGH_ALARM;
5724 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5725 flags |= RDP_OET_LOW_ALARM;
5726 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5727 flags |= RDP_OET_HIGH_WARNING;
5728 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5729 flags |= RDP_OET_LOW_WARNING;
5730
James Smart56204982016-03-31 14:12:32 -07005731 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5732 desc->oed_info.function_flags = cpu_to_be32(flags);
5733 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005734 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005735}
5736
5737
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005738static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005739lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5740 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07005741 uint8_t *page_a2)
5742{
James Smart310429e2016-07-06 12:35:54 -07005743 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005744
5745 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5746
James Smart3aaaa312016-07-06 12:35:57 -07005747 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
5748 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
5749 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
5750 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005751
5752 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5753 flags |= RDP_OET_HIGH_ALARM;
5754 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
5755 flags |= RDP_OET_LOW_ALARM;
5756 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5757 flags |= RDP_OET_HIGH_WARNING;
5758 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
5759 flags |= RDP_OET_LOW_WARNING;
5760
James Smart56204982016-03-31 14:12:32 -07005761 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
5762 desc->oed_info.function_flags = cpu_to_be32(flags);
5763 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005764 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005765}
5766
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005767static uint32_t
James Smart56204982016-03-31 14:12:32 -07005768lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
5769 uint8_t *page_a0, struct lpfc_vport *vport)
5770{
5771 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
5772 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
5773 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
5774 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
James Smarta0f2d3e2017-02-12 13:52:31 -08005775 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
James Smart56204982016-03-31 14:12:32 -07005776 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
5777 desc->length = cpu_to_be32(sizeof(desc->opd_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005778 return sizeof(struct fc_rdp_opd_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005779}
5780
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005781static uint32_t
James Smart4258e982015-12-16 18:11:58 -05005782lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
5783{
5784 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
5785 return 0;
5786 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
5787
5788 desc->info.CorrectedBlocks =
5789 cpu_to_be32(stat->fecCorrBlkCount);
5790 desc->info.UncorrectableBlocks =
5791 cpu_to_be32(stat->fecUncorrBlkCount);
5792
5793 desc->length = cpu_to_be32(sizeof(desc->info));
5794
5795 return sizeof(struct fc_fec_rdp_desc);
5796}
5797
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005798static uint32_t
James Smart86478872015-05-21 13:55:21 -04005799lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5800{
5801 uint16_t rdp_cap = 0;
5802 uint16_t rdp_speed;
5803
5804 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
5805
James Smart81e75172015-12-16 18:11:59 -05005806 switch (phba->fc_linkspeed) {
5807 case LPFC_LINK_SPEED_1GHZ:
James Smart86478872015-05-21 13:55:21 -04005808 rdp_speed = RDP_PS_1GB;
5809 break;
James Smart81e75172015-12-16 18:11:59 -05005810 case LPFC_LINK_SPEED_2GHZ:
James Smart86478872015-05-21 13:55:21 -04005811 rdp_speed = RDP_PS_2GB;
5812 break;
James Smart81e75172015-12-16 18:11:59 -05005813 case LPFC_LINK_SPEED_4GHZ:
James Smart86478872015-05-21 13:55:21 -04005814 rdp_speed = RDP_PS_4GB;
5815 break;
James Smart81e75172015-12-16 18:11:59 -05005816 case LPFC_LINK_SPEED_8GHZ:
James Smart86478872015-05-21 13:55:21 -04005817 rdp_speed = RDP_PS_8GB;
5818 break;
James Smart81e75172015-12-16 18:11:59 -05005819 case LPFC_LINK_SPEED_10GHZ:
James Smart86478872015-05-21 13:55:21 -04005820 rdp_speed = RDP_PS_10GB;
5821 break;
James Smart81e75172015-12-16 18:11:59 -05005822 case LPFC_LINK_SPEED_16GHZ:
James Smart86478872015-05-21 13:55:21 -04005823 rdp_speed = RDP_PS_16GB;
5824 break;
James Smarta085e872015-12-16 18:12:02 -05005825 case LPFC_LINK_SPEED_32GHZ:
5826 rdp_speed = RDP_PS_32GB;
5827 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08005828 case LPFC_LINK_SPEED_64GHZ:
5829 rdp_speed = RDP_PS_64GB;
5830 break;
James Smart86478872015-05-21 13:55:21 -04005831 default:
5832 rdp_speed = RDP_PS_UNKNOWN;
5833 break;
5834 }
5835
5836 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
5837
James Smart1dc5ec22018-10-23 13:41:11 -07005838 if (phba->lmt & LMT_128Gb)
5839 rdp_cap |= RDP_PS_128GB;
James Smartfbd8a6b2018-02-22 08:18:45 -08005840 if (phba->lmt & LMT_64Gb)
5841 rdp_cap |= RDP_PS_64GB;
James Smartd38dd522015-08-31 16:48:17 -04005842 if (phba->lmt & LMT_32Gb)
5843 rdp_cap |= RDP_PS_32GB;
James Smart86478872015-05-21 13:55:21 -04005844 if (phba->lmt & LMT_16Gb)
5845 rdp_cap |= RDP_PS_16GB;
5846 if (phba->lmt & LMT_10Gb)
5847 rdp_cap |= RDP_PS_10GB;
5848 if (phba->lmt & LMT_8Gb)
5849 rdp_cap |= RDP_PS_8GB;
5850 if (phba->lmt & LMT_4Gb)
5851 rdp_cap |= RDP_PS_4GB;
5852 if (phba->lmt & LMT_2Gb)
5853 rdp_cap |= RDP_PS_2GB;
5854 if (phba->lmt & LMT_1Gb)
5855 rdp_cap |= RDP_PS_1GB;
5856
5857 if (rdp_cap == 0)
5858 rdp_cap = RDP_CAP_UNKNOWN;
James Smart56204982016-03-31 14:12:32 -07005859 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
5860 rdp_cap |= RDP_CAP_USER_CONFIGURED;
James Smart86478872015-05-21 13:55:21 -04005861
5862 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
5863 desc->length = cpu_to_be32(sizeof(desc->info));
James Smart6c92d1d2016-07-06 12:35:55 -07005864 return sizeof(struct fc_rdp_port_speed_desc);
James Smart86478872015-05-21 13:55:21 -04005865}
5866
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005867static uint32_t
James Smart86478872015-05-21 13:55:21 -04005868lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
James Smartcd46cde2017-03-04 09:30:37 -08005869 struct lpfc_vport *vport)
James Smart86478872015-05-21 13:55:21 -04005870{
5871
5872 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5873
James Smartcd46cde2017-03-04 09:30:37 -08005874 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
James Smart86478872015-05-21 13:55:21 -04005875 sizeof(desc->port_names.wwnn));
5876
James Smartcd46cde2017-03-04 09:30:37 -08005877 memcpy(desc->port_names.wwpn, &vport->fc_portname,
James Smart86478872015-05-21 13:55:21 -04005878 sizeof(desc->port_names.wwpn));
5879
5880 desc->length = cpu_to_be32(sizeof(desc->port_names));
James Smart6c92d1d2016-07-06 12:35:55 -07005881 return sizeof(struct fc_rdp_port_name_desc);
James Smart86478872015-05-21 13:55:21 -04005882}
5883
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005884static uint32_t
James Smart86478872015-05-21 13:55:21 -04005885lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5886 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5887{
5888
5889 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5890 if (vport->fc_flag & FC_FABRIC) {
5891 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
James Smartd9f492a2019-08-14 16:57:04 -07005892 sizeof(desc->port_names.wwnn));
James Smart86478872015-05-21 13:55:21 -04005893
5894 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
James Smartd9f492a2019-08-14 16:57:04 -07005895 sizeof(desc->port_names.wwpn));
James Smart86478872015-05-21 13:55:21 -04005896 } else { /* Point to Point */
5897 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
James Smartd9f492a2019-08-14 16:57:04 -07005898 sizeof(desc->port_names.wwnn));
James Smart86478872015-05-21 13:55:21 -04005899
James Smartd9f492a2019-08-14 16:57:04 -07005900 memcpy(desc->port_names.wwpn, &ndlp->nlp_portname,
5901 sizeof(desc->port_names.wwpn));
James Smart86478872015-05-21 13:55:21 -04005902 }
5903
5904 desc->length = cpu_to_be32(sizeof(desc->port_names));
James Smart6c92d1d2016-07-06 12:35:55 -07005905 return sizeof(struct fc_rdp_port_name_desc);
James Smart86478872015-05-21 13:55:21 -04005906}
5907
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005908static void
James Smart86478872015-05-21 13:55:21 -04005909lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5910 int status)
5911{
5912 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5913 struct lpfc_vport *vport = ndlp->vport;
5914 struct lpfc_iocbq *elsiocb;
James Smarteb8d68c2015-12-16 18:12:00 -05005915 struct ulp_bde64 *bpl;
James Smart86478872015-05-21 13:55:21 -04005916 IOCB_t *icmd;
5917 uint8_t *pcmd;
5918 struct ls_rjt *stat;
5919 struct fc_rdp_res_frame *rdp_res;
James Smart6c92d1d2016-07-06 12:35:55 -07005920 uint32_t cmdsize, len;
James Smart310429e2016-07-06 12:35:54 -07005921 uint16_t *flag_ptr;
James Smart6c92d1d2016-07-06 12:35:55 -07005922 int rc;
James Smart86478872015-05-21 13:55:21 -04005923
5924 if (status != SUCCESS)
5925 goto error;
James Smarteb8d68c2015-12-16 18:12:00 -05005926
5927 /* This will change once we know the true size of the RDP payload */
James Smart86478872015-05-21 13:55:21 -04005928 cmdsize = sizeof(struct fc_rdp_res_frame);
5929
5930 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5931 lpfc_max_els_tries, rdp_context->ndlp,
5932 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
5933 lpfc_nlp_put(ndlp);
5934 if (!elsiocb)
5935 goto free_rdp_context;
5936
5937 icmd = &elsiocb->iocb;
5938 icmd->ulpContext = rdp_context->rx_id;
5939 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5940
5941 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5942 "2171 Xmit RDP response tag x%x xri x%x, "
5943 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5944 elsiocb->iotag, elsiocb->iocb.ulpContext,
5945 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5946 ndlp->nlp_rpi);
5947 rdp_res = (struct fc_rdp_res_frame *)
5948 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5949 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5950 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
5951 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5952
James Smart310429e2016-07-06 12:35:54 -07005953 /* Update Alarm and Warning */
5954 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
5955 phba->sfp_alarm |= *flag_ptr;
5956 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
5957 phba->sfp_warning |= *flag_ptr;
5958
James Smart86478872015-05-21 13:55:21 -04005959 /* For RDP payload */
James Smart6c92d1d2016-07-06 12:35:55 -07005960 len = 8;
5961 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
5962 (len + pcmd), ELS_CMD_RDP);
James Smart86478872015-05-21 13:55:21 -04005963
James Smart6c92d1d2016-07-06 12:35:55 -07005964 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
James Smart86478872015-05-21 13:55:21 -04005965 rdp_context->page_a0, rdp_context->page_a2);
James Smart6c92d1d2016-07-06 12:35:55 -07005966 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
5967 phba);
5968 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
5969 (len + pcmd), &rdp_context->link_stat);
5970 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
James Smartcd46cde2017-03-04 09:30:37 -08005971 (len + pcmd), vport);
James Smart6c92d1d2016-07-06 12:35:55 -07005972 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
5973 (len + pcmd), vport, ndlp);
5974 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
James Smart4258e982015-12-16 18:11:58 -05005975 &rdp_context->link_stat);
James Smart6c92d1d2016-07-06 12:35:55 -07005976 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
5977 &rdp_context->link_stat, vport);
5978 len += lpfc_rdp_res_oed_temp_desc(phba,
5979 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5980 rdp_context->page_a2);
5981 len += lpfc_rdp_res_oed_voltage_desc(phba,
5982 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5983 rdp_context->page_a2);
5984 len += lpfc_rdp_res_oed_txbias_desc(phba,
5985 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5986 rdp_context->page_a2);
5987 len += lpfc_rdp_res_oed_txpower_desc(phba,
5988 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5989 rdp_context->page_a2);
5990 len += lpfc_rdp_res_oed_rxpower_desc(phba,
5991 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5992 rdp_context->page_a2);
5993 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
5994 rdp_context->page_a0, vport);
5995
James Smart6c92d1d2016-07-06 12:35:55 -07005996 rdp_res->length = cpu_to_be32(len - 8);
James Smart86478872015-05-21 13:55:21 -04005997 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5998
James Smarteb8d68c2015-12-16 18:12:00 -05005999 /* Now that we know the true size of the payload, update the BPL */
6000 bpl = (struct ulp_bde64 *)
6001 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
James Smart6c92d1d2016-07-06 12:35:55 -07006002 bpl->tus.f.bdeSize = len;
James Smarteb8d68c2015-12-16 18:12:00 -05006003 bpl->tus.f.bdeFlags = 0;
6004 bpl->tus.w = le32_to_cpu(bpl->tus.w);
6005
James Smart86478872015-05-21 13:55:21 -04006006 phba->fc_stat.elsXmitACC++;
6007 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6008 if (rc == IOCB_ERROR)
6009 lpfc_els_free_iocb(phba, elsiocb);
6010
6011 kfree(rdp_context);
6012
6013 return;
6014error:
6015 cmdsize = 2 * sizeof(uint32_t);
6016 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
6017 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
6018 lpfc_nlp_put(ndlp);
6019 if (!elsiocb)
6020 goto free_rdp_context;
6021
6022 icmd = &elsiocb->iocb;
6023 icmd->ulpContext = rdp_context->rx_id;
6024 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
6025 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6026
6027 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
6028 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6029 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6030
6031 phba->fc_stat.elsXmitLSRJT++;
6032 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6033 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6034
6035 if (rc == IOCB_ERROR)
6036 lpfc_els_free_iocb(phba, elsiocb);
6037free_rdp_context:
6038 kfree(rdp_context);
6039}
6040
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08006041static int
James Smart86478872015-05-21 13:55:21 -04006042lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
6043{
6044 LPFC_MBOXQ_t *mbox = NULL;
6045 int rc;
6046
6047 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6048 if (!mbox) {
6049 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
6050 "7105 failed to allocate mailbox memory");
6051 return 1;
6052 }
6053
6054 if (lpfc_sli4_dump_page_a0(phba, mbox))
6055 goto prep_mbox_fail;
6056 mbox->vport = rdp_context->ndlp->vport;
6057 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
James Smart3e1f0712018-11-29 16:09:29 -08006058 mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
James Smart86478872015-05-21 13:55:21 -04006059 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6060 if (rc == MBX_NOT_FINISHED)
6061 goto issue_mbox_fail;
6062
6063 return 0;
6064
6065prep_mbox_fail:
6066issue_mbox_fail:
6067 mempool_free(mbox, phba->mbox_mem_pool);
6068 return 1;
6069}
6070
6071/*
6072 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
6073 * @vport: pointer to a host virtual N_Port data structure.
6074 * @cmdiocb: pointer to lpfc command iocb data structure.
6075 * @ndlp: pointer to a node-list data structure.
6076 *
6077 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
6078 * IOCB. First, the payload of the unsolicited RDP is checked.
6079 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
6080 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
6081 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
6082 * gather all data and send RDP response.
6083 *
6084 * Return code
6085 * 0 - Sent the acc response
6086 * 1 - Sent the reject response.
6087 */
6088static int
6089lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6090 struct lpfc_nodelist *ndlp)
6091{
6092 struct lpfc_hba *phba = vport->phba;
6093 struct lpfc_dmabuf *pcmd;
6094 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
6095 struct fc_rdp_req_frame *rdp_req;
6096 struct lpfc_rdp_context *rdp_context;
6097 IOCB_t *cmd = NULL;
6098 struct ls_rjt stat;
6099
6100 if (phba->sli_rev < LPFC_SLI_REV4 ||
James Smart719162b2018-12-10 19:37:01 -08006101 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smarta0f2d3e2017-02-12 13:52:31 -08006102 LPFC_SLI_INTF_IF_TYPE_2) {
James Smart86478872015-05-21 13:55:21 -04006103 rjt_err = LSRJT_UNABLE_TPC;
6104 rjt_expl = LSEXP_REQ_UNSUPPORTED;
6105 goto error;
6106 }
6107
6108 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
6109 rjt_err = LSRJT_UNABLE_TPC;
6110 rjt_expl = LSEXP_REQ_UNSUPPORTED;
6111 goto error;
6112 }
6113
6114 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6115 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
6116
James Smart86478872015-05-21 13:55:21 -04006117 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6118 "2422 ELS RDP Request "
6119 "dec len %d tag x%x port_id %d len %d\n",
6120 be32_to_cpu(rdp_req->rdp_des_length),
6121 be32_to_cpu(rdp_req->nport_id_desc.tag),
6122 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
6123 be32_to_cpu(rdp_req->nport_id_desc.length));
6124
6125 if (sizeof(struct fc_rdp_nport_desc) !=
6126 be32_to_cpu(rdp_req->rdp_des_length))
6127 goto rjt_logerr;
6128 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
6129 goto rjt_logerr;
6130 if (RDP_NPORT_ID_SIZE !=
6131 be32_to_cpu(rdp_req->nport_id_desc.length))
6132 goto rjt_logerr;
Punit Vara699acd62015-12-16 18:12:07 -05006133 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
James Smart86478872015-05-21 13:55:21 -04006134 if (!rdp_context) {
6135 rjt_err = LSRJT_UNABLE_TPC;
6136 goto error;
6137 }
6138
James Smart86478872015-05-21 13:55:21 -04006139 cmd = &cmdiocb->iocb;
6140 rdp_context->ndlp = lpfc_nlp_get(ndlp);
6141 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
6142 rdp_context->rx_id = cmd->ulpContext;
6143 rdp_context->cmpl = lpfc_els_rdp_cmpl;
6144 if (lpfc_get_rdp_info(phba, rdp_context)) {
6145 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
6146 "2423 Unable to send mailbox");
6147 kfree(rdp_context);
6148 rjt_err = LSRJT_UNABLE_TPC;
6149 lpfc_nlp_put(ndlp);
6150 goto error;
6151 }
6152
6153 return 0;
6154
6155rjt_logerr:
6156 rjt_err = LSRJT_LOGICAL_ERR;
6157
6158error:
6159 memset(&stat, 0, sizeof(stat));
6160 stat.un.b.lsRjtRsnCode = rjt_err;
6161 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
6162 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6163 return 1;
6164}
6165
6166
James Smart8b017a32015-05-21 13:55:18 -04006167static void
6168lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6169{
6170 MAILBOX_t *mb;
6171 IOCB_t *icmd;
6172 uint8_t *pcmd;
6173 struct lpfc_iocbq *elsiocb;
6174 struct lpfc_nodelist *ndlp;
6175 struct ls_rjt *stat;
James Smart481ad962015-05-22 10:42:35 -04006176 union lpfc_sli4_cfg_shdr *shdr;
James Smart8b017a32015-05-21 13:55:18 -04006177 struct lpfc_lcb_context *lcb_context;
6178 struct fc_lcb_res_frame *lcb_res;
James Smart481ad962015-05-22 10:42:35 -04006179 uint32_t cmdsize, shdr_status, shdr_add_status;
James Smart8b017a32015-05-21 13:55:18 -04006180 int rc;
6181
6182 mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08006183 lcb_context = (struct lpfc_lcb_context *)pmb->ctx_ndlp;
James Smart8b017a32015-05-21 13:55:18 -04006184 ndlp = lcb_context->ndlp;
James Smart3e1f0712018-11-29 16:09:29 -08006185 pmb->ctx_ndlp = NULL;
6186 pmb->ctx_buf = NULL;
James Smart8b017a32015-05-21 13:55:18 -04006187
James Smart481ad962015-05-22 10:42:35 -04006188 shdr = (union lpfc_sli4_cfg_shdr *)
6189 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
6190 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6191 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
6192
6193 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
6194 "0194 SET_BEACON_CONFIG mailbox "
6195 "completed with status x%x add_status x%x,"
6196 " mbx status x%x\n",
6197 shdr_status, shdr_add_status, mb->mbxStatus);
6198
James Smart66e9e6b2018-06-26 08:24:27 -07006199 if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status ||
6200 (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) ||
6201 (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) {
James Smart8b017a32015-05-21 13:55:18 -04006202 mempool_free(pmb, phba->mbox_mem_pool);
6203 goto error;
6204 }
6205
6206 mempool_free(pmb, phba->mbox_mem_pool);
James Smart8b017a32015-05-21 13:55:18 -04006207 cmdsize = sizeof(struct fc_lcb_res_frame);
6208 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6209 lpfc_max_els_tries, ndlp,
6210 ndlp->nlp_DID, ELS_CMD_ACC);
6211
6212 /* Decrement the ndlp reference count from previous mbox command */
6213 lpfc_nlp_put(ndlp);
6214
6215 if (!elsiocb)
6216 goto free_lcb_context;
6217
6218 lcb_res = (struct fc_lcb_res_frame *)
6219 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6220
James Smart24bc3112018-07-31 17:23:23 -07006221 memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame));
James Smart8b017a32015-05-21 13:55:18 -04006222 icmd = &elsiocb->iocb;
6223 icmd->ulpContext = lcb_context->rx_id;
6224 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6225
6226 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6227 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
6228 lcb_res->lcb_sub_command = lcb_context->sub_command;
6229 lcb_res->lcb_type = lcb_context->type;
James Smart24bc3112018-07-31 17:23:23 -07006230 lcb_res->capability = lcb_context->capability;
James Smart8b017a32015-05-21 13:55:18 -04006231 lcb_res->lcb_frequency = lcb_context->frequency;
James Smart66e9e6b2018-06-26 08:24:27 -07006232 lcb_res->lcb_duration = lcb_context->duration;
James Smart8b017a32015-05-21 13:55:18 -04006233 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6234 phba->fc_stat.elsXmitACC++;
6235 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6236 if (rc == IOCB_ERROR)
6237 lpfc_els_free_iocb(phba, elsiocb);
6238
6239 kfree(lcb_context);
6240 return;
6241
6242error:
6243 cmdsize = sizeof(struct fc_lcb_res_frame);
6244 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6245 lpfc_max_els_tries, ndlp,
6246 ndlp->nlp_DID, ELS_CMD_LS_RJT);
6247 lpfc_nlp_put(ndlp);
6248 if (!elsiocb)
6249 goto free_lcb_context;
6250
6251 icmd = &elsiocb->iocb;
6252 icmd->ulpContext = lcb_context->rx_id;
6253 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6254 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6255
6256 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
6257 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6258 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6259
James Smartb114d902018-10-23 13:41:07 -07006260 if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
6261 stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
6262
James Smart8b017a32015-05-21 13:55:18 -04006263 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6264 phba->fc_stat.elsXmitLSRJT++;
6265 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6266 if (rc == IOCB_ERROR)
6267 lpfc_els_free_iocb(phba, elsiocb);
6268free_lcb_context:
6269 kfree(lcb_context);
6270}
6271
6272static int
6273lpfc_sli4_set_beacon(struct lpfc_vport *vport,
6274 struct lpfc_lcb_context *lcb_context,
6275 uint32_t beacon_state)
6276{
6277 struct lpfc_hba *phba = vport->phba;
James Smart66e9e6b2018-06-26 08:24:27 -07006278 union lpfc_sli4_cfg_shdr *cfg_shdr;
James Smart8b017a32015-05-21 13:55:18 -04006279 LPFC_MBOXQ_t *mbox = NULL;
6280 uint32_t len;
6281 int rc;
6282
6283 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6284 if (!mbox)
6285 return 1;
6286
James Smart66e9e6b2018-06-26 08:24:27 -07006287 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
James Smart8b017a32015-05-21 13:55:18 -04006288 len = sizeof(struct lpfc_mbx_set_beacon_config) -
6289 sizeof(struct lpfc_sli4_cfg_mhdr);
6290 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6291 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
6292 LPFC_SLI4_MBX_EMBED);
James Smart3e1f0712018-11-29 16:09:29 -08006293 mbox->ctx_ndlp = (void *)lcb_context;
James Smart8b017a32015-05-21 13:55:18 -04006294 mbox->vport = phba->pport;
6295 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
6296 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
6297 phba->sli4_hba.physical_port);
6298 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
6299 beacon_state);
James Smart66e9e6b2018-06-26 08:24:27 -07006300 mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */
6301
6302 /*
6303 * Check bv1s bit before issuing the mailbox
6304 * if bv1s == 1, LCB V1 supported
6305 * else, LCB V0 supported
6306 */
6307
6308 if (phba->sli4_hba.pc_sli4_params.bv1s) {
6309 /* COMMON_SET_BEACON_CONFIG_V1 */
6310 cfg_shdr->request.word9 = BEACON_VERSION_V1;
6311 lcb_context->capability |= LCB_CAPABILITY_DURATION;
6312 bf_set(lpfc_mbx_set_beacon_port_type,
6313 &mbox->u.mqe.un.beacon_config, 0);
6314 bf_set(lpfc_mbx_set_beacon_duration_v1,
6315 &mbox->u.mqe.un.beacon_config,
6316 be16_to_cpu(lcb_context->duration));
6317 } else {
6318 /* COMMON_SET_BEACON_CONFIG_V0 */
6319 if (be16_to_cpu(lcb_context->duration) != 0) {
6320 mempool_free(mbox, phba->mbox_mem_pool);
6321 return 1;
6322 }
6323 cfg_shdr->request.word9 = BEACON_VERSION_V0;
6324 lcb_context->capability &= ~(LCB_CAPABILITY_DURATION);
6325 bf_set(lpfc_mbx_set_beacon_state,
6326 &mbox->u.mqe.un.beacon_config, beacon_state);
6327 bf_set(lpfc_mbx_set_beacon_port_type,
6328 &mbox->u.mqe.un.beacon_config, 1);
6329 bf_set(lpfc_mbx_set_beacon_duration,
6330 &mbox->u.mqe.un.beacon_config,
6331 be16_to_cpu(lcb_context->duration));
6332 }
6333
James Smart8b017a32015-05-21 13:55:18 -04006334 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6335 if (rc == MBX_NOT_FINISHED) {
6336 mempool_free(mbox, phba->mbox_mem_pool);
6337 return 1;
6338 }
6339
6340 return 0;
6341}
6342
6343
6344/**
6345 * lpfc_els_rcv_lcb - Process an unsolicited LCB
6346 * @vport: pointer to a host virtual N_Port data structure.
6347 * @cmdiocb: pointer to lpfc command iocb data structure.
6348 * @ndlp: pointer to a node-list data structure.
6349 *
6350 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
6351 * First, the payload of the unsolicited LCB is checked.
6352 * Then based on Subcommand beacon will either turn on or off.
6353 *
6354 * Return code
6355 * 0 - Sent the acc response
6356 * 1 - Sent the reject response.
6357 **/
6358static int
6359lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6360 struct lpfc_nodelist *ndlp)
6361{
6362 struct lpfc_hba *phba = vport->phba;
6363 struct lpfc_dmabuf *pcmd;
James Smart8b017a32015-05-21 13:55:18 -04006364 uint8_t *lp;
6365 struct fc_lcb_request_frame *beacon;
6366 struct lpfc_lcb_context *lcb_context;
6367 uint8_t state, rjt_err;
6368 struct ls_rjt stat;
6369
James Smart8b017a32015-05-21 13:55:18 -04006370 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
6371 lp = (uint8_t *)pcmd->virt;
6372 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
6373
6374 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6375 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
6376 "type x%x frequency %x duration x%x\n",
6377 lp[0], lp[1], lp[2],
6378 beacon->lcb_command,
6379 beacon->lcb_sub_command,
6380 beacon->lcb_type,
6381 beacon->lcb_frequency,
6382 be16_to_cpu(beacon->lcb_duration));
6383
James Smartd6564e52017-06-15 22:56:50 -07006384 if (beacon->lcb_sub_command != LPFC_LCB_ON &&
6385 beacon->lcb_sub_command != LPFC_LCB_OFF) {
James Smart8b017a32015-05-21 13:55:18 -04006386 rjt_err = LSRJT_CMD_UNSUPPORTED;
6387 goto rjt;
6388 }
James Smart66e9e6b2018-06-26 08:24:27 -07006389
6390 if (phba->sli_rev < LPFC_SLI_REV4 ||
6391 phba->hba_flag & HBA_FCOE_MODE ||
6392 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
6393 LPFC_SLI_INTF_IF_TYPE_2)) {
James Smart8b017a32015-05-21 13:55:18 -04006394 rjt_err = LSRJT_CMD_UNSUPPORTED;
6395 goto rjt;
6396 }
6397
Sudip Mukherjeee7950422015-09-23 19:02:32 +05306398 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
6399 if (!lcb_context) {
6400 rjt_err = LSRJT_UNABLE_TPC;
6401 goto rjt;
6402 }
6403
James Smart8b017a32015-05-21 13:55:18 -04006404 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
6405 lcb_context->sub_command = beacon->lcb_sub_command;
James Smart66e9e6b2018-06-26 08:24:27 -07006406 lcb_context->capability = 0;
James Smart8b017a32015-05-21 13:55:18 -04006407 lcb_context->type = beacon->lcb_type;
6408 lcb_context->frequency = beacon->lcb_frequency;
James Smart66e9e6b2018-06-26 08:24:27 -07006409 lcb_context->duration = beacon->lcb_duration;
James Smart8b017a32015-05-21 13:55:18 -04006410 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6411 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
6412 lcb_context->ndlp = lpfc_nlp_get(ndlp);
6413 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
6414 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
6415 LOG_ELS, "0193 failed to send mail box");
Sudip Mukherjeee7950422015-09-23 19:02:32 +05306416 kfree(lcb_context);
James Smart8b017a32015-05-21 13:55:18 -04006417 lpfc_nlp_put(ndlp);
6418 rjt_err = LSRJT_UNABLE_TPC;
6419 goto rjt;
6420 }
6421 return 0;
6422rjt:
6423 memset(&stat, 0, sizeof(stat));
6424 stat.un.b.lsRjtRsnCode = rjt_err;
6425 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6426 return 1;
6427}
6428
6429
James Smarte59058c2008-08-24 21:49:00 -04006430/**
James Smart3621a712009-04-06 18:47:14 -04006431 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04006432 * @vport: pointer to a host virtual N_Port data structure.
6433 *
6434 * This routine cleans up any Registration State Change Notification
6435 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
6436 * @vport together with the host_lock is used to prevent multiple thread
6437 * trying to access the RSCN array on a same @vport at the same time.
6438 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006439void
James Smart2e0fef82007-06-17 19:56:36 -05006440lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006441{
James Smart2e0fef82007-06-17 19:56:36 -05006442 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6443 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006444 int i;
6445
James Smart7f5f3d02008-02-08 18:50:14 -05006446 spin_lock_irq(shost->host_lock);
6447 if (vport->fc_rscn_flush) {
6448 /* Another thread is walking fc_rscn_id_list on this vport */
6449 spin_unlock_irq(shost->host_lock);
6450 return;
6451 }
6452 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
6453 vport->fc_rscn_flush = 1;
6454 spin_unlock_irq(shost->host_lock);
6455
James Smart2e0fef82007-06-17 19:56:36 -05006456 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05006457 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05006458 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05006459 }
James Smart2e0fef82007-06-17 19:56:36 -05006460 spin_lock_irq(shost->host_lock);
6461 vport->fc_rscn_id_cnt = 0;
6462 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
6463 spin_unlock_irq(shost->host_lock);
6464 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05006465 /* Indicate we are done walking this fc_rscn_id_list */
6466 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05006467}
6468
James Smarte59058c2008-08-24 21:49:00 -04006469/**
James Smart3621a712009-04-06 18:47:14 -04006470 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04006471 * @vport: pointer to a host virtual N_Port data structure.
6472 * @did: remote destination port identifier.
6473 *
6474 * This routine checks whether there is any pending Registration State
6475 * Configuration Notification (RSCN) to a @did on @vport.
6476 *
6477 * Return code
6478 * None zero - The @did matched with a pending rscn
6479 * 0 - not able to match @did with a pending rscn
6480 **/
dea31012005-04-17 16:05:31 -05006481int
James Smart2e0fef82007-06-17 19:56:36 -05006482lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05006483{
6484 D_ID ns_did;
6485 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05006486 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05006487 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05006488 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05006489
6490 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05006491
6492 /* Never match fabric nodes for RSCNs */
6493 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05006494 return 0;
dea31012005-04-17 16:05:31 -05006495
6496 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05006497 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006498 return did;
dea31012005-04-17 16:05:31 -05006499
James Smart7f5f3d02008-02-08 18:50:14 -05006500 spin_lock_irq(shost->host_lock);
6501 if (vport->fc_rscn_flush) {
6502 /* Another thread is walking fc_rscn_id_list on this vport */
6503 spin_unlock_irq(shost->host_lock);
6504 return 0;
6505 }
6506 /* Indicate we are walking fc_rscn_id_list on this vport */
6507 vport->fc_rscn_flush = 1;
6508 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05006509 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05006510 lp = vport->fc_rscn_id_list[i]->virt;
6511 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6512 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05006513 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05006514 rscn_did.un.word = be32_to_cpu(*lp++);
6515 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05006516 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
6517 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04006518 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6519 && (ns_did.un.b.area == rscn_did.un.b.area)
6520 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05006521 goto return_did_out;
dea31012005-04-17 16:05:31 -05006522 break;
James Smarteaf15d52008-12-04 22:39:29 -05006523 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05006524 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6525 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05006526 goto return_did_out;
dea31012005-04-17 16:05:31 -05006527 break;
James Smarteaf15d52008-12-04 22:39:29 -05006528 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05006529 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05006530 goto return_did_out;
dea31012005-04-17 16:05:31 -05006531 break;
James Smarteaf15d52008-12-04 22:39:29 -05006532 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05006533 goto return_did_out;
dea31012005-04-17 16:05:31 -05006534 }
6535 }
James Smart92d7f7b2007-06-17 19:56:38 -05006536 }
James Smart7f5f3d02008-02-08 18:50:14 -05006537 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6538 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05006539 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05006540return_did_out:
6541 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6542 vport->fc_rscn_flush = 0;
6543 return did;
dea31012005-04-17 16:05:31 -05006544}
6545
James Smarte59058c2008-08-24 21:49:00 -04006546/**
James Smart3621a712009-04-06 18:47:14 -04006547 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04006548 * @vport: pointer to a host virtual N_Port data structure.
6549 *
6550 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
6551 * state machine for a @vport's nodes that are with pending RSCN (Registration
6552 * State Change Notification).
6553 *
6554 * Return code
6555 * 0 - Successful (currently alway return 0)
6556 **/
dea31012005-04-17 16:05:31 -05006557static int
James Smart2e0fef82007-06-17 19:56:36 -05006558lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006559{
James Smart685f0bf2007-04-25 09:53:08 -04006560 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05006561
James Smart0d2b6b82008-06-14 22:52:47 -04006562 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05006563 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05006564 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04006565 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
6566 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05006567 continue;
James Smart1c5b12f2017-04-21 16:05:03 -07006568
6569 /* NVME Target mode does not do RSCN Recovery. */
James Smart8c258642017-02-12 13:52:36 -08006570 if (vport->phba->nvmet_support)
6571 continue;
James Smart1c5b12f2017-04-21 16:05:03 -07006572
James Smartdea16bd2018-11-29 16:09:30 -08006573 /* If we are in the process of doing discovery on this
6574 * NPort, let it continue on its own.
6575 */
6576 switch (ndlp->nlp_state) {
6577 case NLP_STE_PLOGI_ISSUE:
6578 case NLP_STE_ADISC_ISSUE:
6579 case NLP_STE_REG_LOGIN_ISSUE:
6580 case NLP_STE_PRLI_ISSUE:
6581 case NLP_STE_LOGO_ISSUE:
6582 continue;
6583 }
6584
James Smarta6d10f22019-08-14 16:56:50 -07006585 /* Check to see if we need to NVME rescan this target
6586 * remoteport.
6587 */
6588 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6589 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
James Smart6f2589f2019-05-14 14:58:07 -07006590 lpfc_nvme_rescan_port(vport, ndlp);
James Smartdea16bd2018-11-29 16:09:30 -08006591
James Smart2e0fef82007-06-17 19:56:36 -05006592 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04006593 NLP_EVT_DEVICE_RECOVERY);
6594 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05006595 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006596 return 0;
dea31012005-04-17 16:05:31 -05006597}
6598
James Smarte59058c2008-08-24 21:49:00 -04006599/**
James Smart3621a712009-04-06 18:47:14 -04006600 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05006601 * @vport: pointer to a host virtual N_Port data structure.
6602 * @cmdiocb: pointer to lpfc command iocb data structure.
6603 *
6604 * lpfc_send_rscn_event sends an RSCN netlink event to management
6605 * applications.
6606 */
6607static void
6608lpfc_send_rscn_event(struct lpfc_vport *vport,
6609 struct lpfc_iocbq *cmdiocb)
6610{
6611 struct lpfc_dmabuf *pcmd;
6612 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6613 uint32_t *payload_ptr;
6614 uint32_t payload_len;
6615 struct lpfc_rscn_event_header *rscn_event_data;
6616
6617 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6618 payload_ptr = (uint32_t *) pcmd->virt;
6619 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
6620
6621 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
6622 payload_len, GFP_KERNEL);
6623 if (!rscn_event_data) {
6624 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6625 "0147 Failed to allocate memory for RSCN event\n");
6626 return;
6627 }
6628 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
6629 rscn_event_data->payload_length = payload_len;
6630 memcpy(rscn_event_data->rscn_payload, payload_ptr,
6631 payload_len);
6632
6633 fc_host_post_vendor_event(shost,
6634 fc_get_event_number(),
Ales Novak6599eaa2015-08-31 16:48:16 -04006635 sizeof(struct lpfc_rscn_event_header) + payload_len,
James Smartddcc50f2008-12-04 22:38:46 -05006636 (char *)rscn_event_data,
6637 LPFC_NL_VENDOR_ID);
6638
6639 kfree(rscn_event_data);
6640}
6641
6642/**
James Smart3621a712009-04-06 18:47:14 -04006643 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04006644 * @vport: pointer to a host virtual N_Port data structure.
6645 * @cmdiocb: pointer to lpfc command iocb data structure.
6646 * @ndlp: pointer to a node-list data structure.
6647 *
6648 * This routine processes an unsolicited RSCN (Registration State Change
6649 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
6650 * to invoke fc_host_post_event() routine to the FC transport layer. If the
6651 * discover state machine is about to begin discovery, it just accepts the
6652 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
6653 * contains N_Port IDs for other vports on this HBA, it just accepts the
6654 * RSCN and ignore processing it. If the state machine is in the recovery
6655 * state, the fc_rscn_id_list of this @vport is walked and the
6656 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
6657 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
6658 * routine is invoked to handle the RSCN event.
6659 *
6660 * Return code
6661 * 0 - Just sent the acc response
6662 * 1 - Sent the acc response and waited for name server completion
6663 **/
dea31012005-04-17 16:05:31 -05006664static int
James Smart2e0fef82007-06-17 19:56:36 -05006665lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04006666 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006667{
James Smart2e0fef82007-06-17 19:56:36 -05006668 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6669 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006670 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05006671 uint32_t *lp, *datap;
James Smart92d7f7b2007-06-17 19:56:38 -05006672 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05006673 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05006674 int rscn_id = 0, hba_id = 0;
James Smart2332e6e2019-11-04 16:57:01 -08006675 int i, tmo;
dea31012005-04-17 16:05:31 -05006676
dea31012005-04-17 16:05:31 -05006677 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6678 lp = (uint32_t *) pcmd->virt;
6679
James Smart92d7f7b2007-06-17 19:56:38 -05006680 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6681 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05006682 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04006683 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6684 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05006685 vport->fc_flag, payload_len, *lp,
6686 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05006687
6688 /* Send an RSCN event to the management application */
6689 lpfc_send_rscn_event(vport, cmdiocb);
6690
James Smartd2873e42006-08-18 17:46:43 -04006691 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05006692 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04006693 FCH_EVT_RSCN, lp[i]);
6694
James Smartf60cb932019-05-14 14:58:05 -07006695 /* Check if RSCN is coming from a direct-connected remote NPort */
6696 if (vport->fc_flag & FC_PT2PT) {
6697 /* If so, just ACC it, no other action needed for now */
6698 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6699 "2024 pt2pt RSCN %08x Data: x%x x%x\n",
6700 *lp, vport->fc_flag, payload_len);
6701 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart6f2589f2019-05-14 14:58:07 -07006702
James Smarta6d10f22019-08-14 16:56:50 -07006703 /* Check to see if we need to NVME rescan this target
6704 * remoteport.
6705 */
6706 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6707 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
James Smart6f2589f2019-05-14 14:58:07 -07006708 lpfc_nvme_rescan_port(vport, ndlp);
James Smartf60cb932019-05-14 14:58:05 -07006709 return 0;
6710 }
6711
dea31012005-04-17 16:05:31 -05006712 /* If we are about to begin discovery, just ACC the RSCN.
6713 * Discovery processing will satisfy it.
6714 */
James Smart2e0fef82007-06-17 19:56:36 -05006715 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05006716 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6717 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
6718 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6719
James Smart51ef4c22007-08-02 11:10:31 -04006720 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006721 return 0;
dea31012005-04-17 16:05:31 -05006722 }
6723
James Smart92d7f7b2007-06-17 19:56:38 -05006724 /* If this RSCN just contains NPortIDs for other vports on this HBA,
6725 * just ACC and ignore it.
6726 */
6727 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04006728 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05006729 i = payload_len;
6730 datap = lp;
6731 while (i > 0) {
6732 nportid = *datap++;
6733 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
6734 i -= sizeof(uint32_t);
6735 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04006736 if (lpfc_find_vport_by_did(phba, nportid))
6737 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05006738 }
6739 if (rscn_id == hba_id) {
6740 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04006741 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04006742 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04006743 "Data: x%x x%x x%x x%x\n",
6744 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05006745 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05006746 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6747 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6748 ndlp->nlp_DID, vport->port_state,
6749 ndlp->nlp_flag);
6750
James Smart92d7f7b2007-06-17 19:56:38 -05006751 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04006752 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05006753 return 0;
6754 }
6755 }
6756
James Smart7f5f3d02008-02-08 18:50:14 -05006757 spin_lock_irq(shost->host_lock);
6758 if (vport->fc_rscn_flush) {
6759 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05006760 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05006761 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04006762 /* Send back ACC */
6763 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05006764 return 0;
6765 }
6766 /* Indicate we are walking fc_rscn_id_list on this vport */
6767 vport->fc_rscn_flush = 1;
6768 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006769 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05006770 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05006771 /* If we are already processing an RSCN, save the received
6772 * RSCN payload buffer, cmdiocb->context2 to process later.
6773 */
James Smart2e0fef82007-06-17 19:56:36 -05006774 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05006775 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6776 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6777 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6778
James Smart09372822008-01-11 01:52:54 -05006779 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006780 vport->fc_flag |= FC_RSCN_DEFERRED;
James Smart2332e6e2019-11-04 16:57:01 -08006781
6782 /* Restart disctmo if its already running */
6783 if (vport->fc_flag & FC_DISC_TMO) {
6784 tmo = ((phba->fc_ratov * 3) + 3);
6785 mod_timer(&vport->fc_disctmo,
6786 jiffies + msecs_to_jiffies(1000 * tmo));
6787 }
James Smart92d7f7b2007-06-17 19:56:38 -05006788 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05006789 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05006790 vport->fc_flag |= FC_RSCN_MODE;
6791 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006792 if (rscn_cnt) {
6793 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
6794 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
6795 }
6796 if ((rscn_cnt) &&
6797 (payload_len + length <= LPFC_BPL_SIZE)) {
6798 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05006799 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05006800 memcpy(((uint8_t *)cmd) + length, lp,
6801 payload_len);
6802 } else {
6803 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
6804 vport->fc_rscn_id_cnt++;
6805 /* If we zero, cmdiocb->context2, the calling
6806 * routine will not try to free it.
6807 */
6808 cmdiocb->context2 = NULL;
6809 }
dea31012005-04-17 16:05:31 -05006810 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04006811 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6812 "0235 Deferred RSCN "
6813 "Data: x%x x%x x%x\n",
6814 vport->fc_rscn_id_cnt, vport->fc_flag,
6815 vport->port_state);
dea31012005-04-17 16:05:31 -05006816 } else {
James Smart2e0fef82007-06-17 19:56:36 -05006817 vport->fc_flag |= FC_RSCN_DISCOVERY;
6818 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05006819 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04006820 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6821 "0234 ReDiscovery RSCN "
6822 "Data: x%x x%x x%x\n",
6823 vport->fc_rscn_id_cnt, vport->fc_flag,
6824 vport->port_state);
dea31012005-04-17 16:05:31 -05006825 }
James Smart7f5f3d02008-02-08 18:50:14 -05006826 /* Indicate we are done walking fc_rscn_id_list on this vport */
6827 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05006828 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04006829 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006830 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05006831 lpfc_rscn_recovery_check(vport);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006832 return 0;
dea31012005-04-17 16:05:31 -05006833 }
James Smart858c9f62007-06-17 19:56:39 -05006834 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6835 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6836 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6837
James Smart2e0fef82007-06-17 19:56:36 -05006838 spin_lock_irq(shost->host_lock);
6839 vport->fc_flag |= FC_RSCN_MODE;
6840 spin_unlock_irq(shost->host_lock);
6841 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05006842 /* Indicate we are done walking fc_rscn_id_list on this vport */
6843 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05006844 /*
6845 * If we zero, cmdiocb->context2, the calling routine will
6846 * not try to free it.
6847 */
6848 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05006849 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05006850 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04006851 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006852 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05006853 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05006854 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05006855}
6856
James Smarte59058c2008-08-24 21:49:00 -04006857/**
James Smart3621a712009-04-06 18:47:14 -04006858 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04006859 * @vport: pointer to a host virtual N_Port data structure.
6860 *
6861 * This routine handles the Registration State Configuration Notification
6862 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
6863 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
6864 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
6865 * NameServer shall be issued. If CT command to the NameServer fails to be
6866 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
6867 * RSCN activities with the @vport.
6868 *
6869 * Return code
6870 * 0 - Cleaned up rscn on the @vport
6871 * 1 - Wait for plogi to name server before proceed
6872 **/
dea31012005-04-17 16:05:31 -05006873int
James Smart2e0fef82007-06-17 19:56:36 -05006874lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006875{
6876 struct lpfc_nodelist *ndlp;
James Smart7ea92eb2018-10-23 13:41:10 -07006877 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006878
James Smart92d7f7b2007-06-17 19:56:38 -05006879 /* Ignore RSCN if the port is being torn down. */
6880 if (vport->load_flag & FC_UNLOADING) {
6881 lpfc_els_flush_rscn(vport);
6882 return 0;
6883 }
6884
dea31012005-04-17 16:05:31 -05006885 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05006886 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05006887
6888 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04006889 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartb4b34172019-10-18 14:18:31 -07006890 "0215 RSCN processed Data: x%x x%x x%x x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04006891 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
James Smartb4b34172019-10-18 14:18:31 -07006892 vport->port_state, vport->num_disc_nodes,
6893 vport->gidft_inp);
dea31012005-04-17 16:05:31 -05006894
6895 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05006896 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05006897 vport->num_disc_nodes = 0;
6898
James Smart2e0fef82007-06-17 19:56:36 -05006899 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006900 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
6901 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
James Smart1c5b12f2017-04-21 16:05:03 -07006902 /* Good ndlp, issue CT Request to NameServer. Need to
6903 * know how many gidfts were issued. If none, then just
6904 * flush the RSCN. Otherwise, the outstanding requests
6905 * need to complete.
6906 */
James Smart7ea92eb2018-10-23 13:41:10 -07006907 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) {
6908 if (lpfc_issue_gidft(vport) > 0)
6909 return 1;
6910 } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) {
6911 if (lpfc_issue_gidpt(vport) > 0)
6912 return 1;
6913 } else {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006914 return 1;
James Smart7ea92eb2018-10-23 13:41:10 -07006915 }
dea31012005-04-17 16:05:31 -05006916 } else {
James Smart1c5b12f2017-04-21 16:05:03 -07006917 /* Nameserver login in question. Revalidate. */
James Smarte47c9092008-02-08 18:49:26 -05006918 if (ndlp) {
6919 ndlp = lpfc_enable_node(vport, ndlp,
6920 NLP_STE_PLOGI_ISSUE);
6921 if (!ndlp) {
6922 lpfc_els_flush_rscn(vport);
6923 return 0;
6924 }
6925 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05006926 } else {
James Smart9d3d3402017-04-21 16:05:00 -07006927 ndlp = lpfc_nlp_init(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006928 if (!ndlp) {
6929 lpfc_els_flush_rscn(vport);
6930 return 0;
6931 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006932 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05006933 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05006934 }
James Smarte47c9092008-02-08 18:49:26 -05006935 ndlp->nlp_type |= NLP_FABRIC;
6936 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
6937 /* Wait for NameServer login cmpl before we can
6938 * continue
6939 */
6940 return 1;
dea31012005-04-17 16:05:31 -05006941 }
6942
James Smart2e0fef82007-06-17 19:56:36 -05006943 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006944 return 0;
dea31012005-04-17 16:05:31 -05006945}
6946
James Smarte59058c2008-08-24 21:49:00 -04006947/**
James Smart3621a712009-04-06 18:47:14 -04006948 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04006949 * @vport: pointer to a host virtual N_Port data structure.
6950 * @cmdiocb: pointer to lpfc command iocb data structure.
6951 * @ndlp: pointer to a node-list data structure.
6952 *
6953 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
6954 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
6955 * point topology. As an unsolicited FLOGI should not be received in a loop
6956 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
6957 * lpfc_check_sparm() routine is invoked to check the parameters in the
6958 * unsolicited FLOGI. If parameters validation failed, the routine
6959 * lpfc_els_rsp_reject() shall be called with reject reason code set to
6960 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
6961 * FLOGI shall be compared with the Port WWN of the @vport to determine who
6962 * will initiate PLOGI. The higher lexicographical value party shall has
6963 * higher priority (as the winning port) and will initiate PLOGI and
6964 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
6965 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
6966 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
6967 *
6968 * Return code
6969 * 0 - Successfully processed the unsolicited flogi
6970 * 1 - Failed to process the unsolicited flogi
6971 **/
dea31012005-04-17 16:05:31 -05006972static int
James Smart2e0fef82007-06-17 19:56:36 -05006973lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04006974 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006975{
James Smart2e0fef82007-06-17 19:56:36 -05006976 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6977 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006978 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6979 uint32_t *lp = (uint32_t *) pcmd->virt;
6980 IOCB_t *icmd = &cmdiocb->iocb;
6981 struct serv_parm *sp;
6982 LPFC_MBOXQ_t *mbox;
dea31012005-04-17 16:05:31 -05006983 uint32_t cmd, did;
6984 int rc;
James Smarte74c03c2013-04-17 20:15:19 -04006985 uint32_t fc_flag = 0;
6986 uint32_t port_state = 0;
dea31012005-04-17 16:05:31 -05006987
6988 cmd = *lp++;
6989 sp = (struct serv_parm *) lp;
6990
6991 /* FLOGI received */
6992
James Smart2e0fef82007-06-17 19:56:36 -05006993 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05006994
James Smart76a95d72010-11-20 23:11:48 -05006995 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05006996 /* We should never receive a FLOGI in loop mode, ignore it */
6997 did = icmd->un.elsreq64.remoteID;
6998
6999 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
7000 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04007001 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7002 "0113 An FLOGI ELS command x%x was "
7003 "received from DID x%x in Loop Mode\n",
7004 cmd, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007005 return 1;
dea31012005-04-17 16:05:31 -05007006 }
7007
James Smartd6de08c2015-12-16 18:11:53 -05007008 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
dea31012005-04-17 16:05:31 -05007009
James Smartd6de08c2015-12-16 18:11:53 -05007010 /*
7011 * If our portname is greater than the remote portname,
7012 * then we initiate Nport login.
7013 */
7014
7015 rc = memcmp(&vport->fc_portname, &sp->portName,
7016 sizeof(struct lpfc_name));
7017
7018 if (!rc) {
7019 if (phba->sli_rev < LPFC_SLI_REV4) {
7020 mbox = mempool_alloc(phba->mbox_mem_pool,
7021 GFP_KERNEL);
7022 if (!mbox)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007023 return 1;
James Smartd6de08c2015-12-16 18:11:53 -05007024 lpfc_linkdown(phba);
7025 lpfc_init_link(phba, mbox,
7026 phba->cfg_topology,
7027 phba->cfg_link_speed);
7028 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
7029 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
7030 mbox->vport = vport;
7031 rc = lpfc_sli_issue_mbox(phba, mbox,
7032 MBX_NOWAIT);
7033 lpfc_set_loopback_flag(phba);
7034 if (rc == MBX_NOT_FINISHED)
7035 mempool_free(mbox, phba->mbox_mem_pool);
7036 return 1;
7037 }
James Smart939723a2012-05-09 21:19:03 -04007038
James Smartd6de08c2015-12-16 18:11:53 -05007039 /* abort the flogi coming back to ourselves
7040 * due to external loopback on the port.
James Smart939723a2012-05-09 21:19:03 -04007041 */
James Smartd6de08c2015-12-16 18:11:53 -05007042 lpfc_els_abort_flogi(phba);
7043 return 0;
7044
7045 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05007046 spin_lock_irq(shost->host_lock);
James Smartd6de08c2015-12-16 18:11:53 -05007047 vport->fc_flag |= FC_PT2PT_PLOGI;
James Smart2e0fef82007-06-17 19:56:36 -05007048 spin_unlock_irq(shost->host_lock);
James Smart939723a2012-05-09 21:19:03 -04007049
James Smartd6de08c2015-12-16 18:11:53 -05007050 /* If we have the high WWPN we can assign our own
7051 * myDID; otherwise, we have to WAIT for a PLOGI
7052 * from the remote NPort to find out what it
7053 * will be.
James Smart939723a2012-05-09 21:19:03 -04007054 */
James Smartd6de08c2015-12-16 18:11:53 -05007055 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -05007056 } else {
James Smartd6de08c2015-12-16 18:11:53 -05007057 vport->fc_myDID = PT2PT_RemoteID;
dea31012005-04-17 16:05:31 -05007058 }
7059
James Smartd6de08c2015-12-16 18:11:53 -05007060 /*
7061 * The vport state should go to LPFC_FLOGI only
7062 * AFTER we issue a FLOGI, not receive one.
7063 */
7064 spin_lock_irq(shost->host_lock);
7065 fc_flag = vport->fc_flag;
7066 port_state = vport->port_state;
7067 vport->fc_flag |= FC_PT2PT;
7068 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
James Smartd496b9a2018-10-23 13:41:08 -07007069
7070 /* Acking an unsol FLOGI. Count 1 for link bounce
7071 * work-around.
7072 */
7073 vport->rcv_flogi_cnt++;
James Smartd6de08c2015-12-16 18:11:53 -05007074 spin_unlock_irq(shost->host_lock);
7075 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7076 "3311 Rcv Flogi PS x%x new PS x%x "
7077 "fc_flag x%x new fc_flag x%x\n",
7078 port_state, vport->port_state,
7079 fc_flag, vport->fc_flag);
7080
7081 /*
7082 * We temporarily set fc_myDID to make it look like we are
7083 * a Fabric. This is done just so we end up with the right
7084 * did / sid on the FLOGI ACC rsp.
7085 */
7086 did = vport->fc_myDID;
7087 vport->fc_myDID = Fabric_DID;
7088
7089 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
James Smarteec3d312015-08-31 16:48:18 -04007090
James Smart0a9e9682018-11-29 16:09:36 -08007091 /* Defer ACC response until AFTER we issue a FLOGI */
7092 if (!(phba->hba_flag & HBA_FLOGI_ISSUED)) {
7093 phba->defer_flogi_acc_rx_id = cmdiocb->iocb.ulpContext;
7094 phba->defer_flogi_acc_ox_id =
7095 cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7096
7097 vport->fc_myDID = did;
7098
7099 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7100 "3344 Deferring FLOGI ACC: rx_id: x%x,"
7101 " ox_id: x%x, hba_flag x%x\n",
7102 phba->defer_flogi_acc_rx_id,
7103 phba->defer_flogi_acc_ox_id, phba->hba_flag);
7104
7105 phba->defer_flogi_acc_flag = true;
7106
7107 return 0;
7108 }
7109
dea31012005-04-17 16:05:31 -05007110 /* Send back ACC */
James Smartd6de08c2015-12-16 18:11:53 -05007111 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05007112
James Smart939723a2012-05-09 21:19:03 -04007113 /* Now lets put fc_myDID back to what its supposed to be */
7114 vport->fc_myDID = did;
7115
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007116 return 0;
dea31012005-04-17 16:05:31 -05007117}
7118
James Smarte59058c2008-08-24 21:49:00 -04007119/**
James Smart3621a712009-04-06 18:47:14 -04007120 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04007121 * @vport: pointer to a host virtual N_Port data structure.
7122 * @cmdiocb: pointer to lpfc command iocb data structure.
7123 * @ndlp: pointer to a node-list data structure.
7124 *
7125 * This routine processes Request Node Identification Data (RNID) IOCB
7126 * received as an ELS unsolicited event. Only when the RNID specified format
7127 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
7128 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
7129 * Accept (ACC) the RNID ELS command. All the other RNID formats are
7130 * rejected by invoking the lpfc_els_rsp_reject() routine.
7131 *
7132 * Return code
7133 * 0 - Successfully processed rnid iocb (currently always return 0)
7134 **/
dea31012005-04-17 16:05:31 -05007135static int
James Smart2e0fef82007-06-17 19:56:36 -05007136lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7137 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007138{
7139 struct lpfc_dmabuf *pcmd;
7140 uint32_t *lp;
dea31012005-04-17 16:05:31 -05007141 RNID *rn;
7142 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05007143
dea31012005-04-17 16:05:31 -05007144 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7145 lp = (uint32_t *) pcmd->virt;
7146
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07007147 lp++;
dea31012005-04-17 16:05:31 -05007148 rn = (RNID *) lp;
7149
7150 /* RNID received */
7151
7152 switch (rn->Format) {
7153 case 0:
7154 case RNID_TOPOLOGY_DISC:
7155 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05007156 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05007157 break;
7158 default:
7159 /* Reject this request because format not supported */
7160 stat.un.b.lsRjtRsvd0 = 0;
7161 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7162 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7163 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05007164 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7165 NULL);
dea31012005-04-17 16:05:31 -05007166 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007167 return 0;
dea31012005-04-17 16:05:31 -05007168}
7169
James Smarte59058c2008-08-24 21:49:00 -04007170/**
James Smart12265f62010-10-22 11:05:53 -04007171 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
7172 * @vport: pointer to a host virtual N_Port data structure.
7173 * @cmdiocb: pointer to lpfc command iocb data structure.
7174 * @ndlp: pointer to a node-list data structure.
7175 *
7176 * Return code
7177 * 0 - Successfully processed echo iocb (currently always return 0)
7178 **/
7179static int
7180lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7181 struct lpfc_nodelist *ndlp)
7182{
7183 uint8_t *pcmd;
7184
7185 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
7186
7187 /* skip over first word of echo command to find echo data */
7188 pcmd += sizeof(uint32_t);
7189
7190 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
7191 return 0;
7192}
7193
7194/**
James Smart3621a712009-04-06 18:47:14 -04007195 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04007196 * @vport: pointer to a host virtual N_Port data structure.
7197 * @cmdiocb: pointer to lpfc command iocb data structure.
7198 * @ndlp: pointer to a node-list data structure.
7199 *
7200 * This routine processes a Link Incident Report Registration(LIRR) IOCB
7201 * received as an ELS unsolicited event. Currently, this function just invokes
7202 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
7203 *
7204 * Return code
7205 * 0 - Successfully processed lirr iocb (currently always return 0)
7206 **/
dea31012005-04-17 16:05:31 -05007207static int
James Smart2e0fef82007-06-17 19:56:36 -05007208lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7209 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007210{
7211 struct ls_rjt stat;
7212
7213 /* For now, unconditionally reject this command */
7214 stat.un.b.lsRjtRsvd0 = 0;
7215 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7216 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7217 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05007218 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007219 return 0;
7220}
7221
James Smarte59058c2008-08-24 21:49:00 -04007222/**
James Smart5ffc2662009-11-18 15:39:44 -05007223 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
7224 * @vport: pointer to a host virtual N_Port data structure.
7225 * @cmdiocb: pointer to lpfc command iocb data structure.
7226 * @ndlp: pointer to a node-list data structure.
7227 *
7228 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
7229 * received as an ELS unsolicited event. A request to RRQ shall only
7230 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
7231 * Nx_Port N_Port_ID of the target Exchange is the same as the
7232 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
7233 * not accepted, an LS_RJT with reason code "Unable to perform
7234 * command request" and reason code explanation "Invalid Originator
7235 * S_ID" shall be returned. For now, we just unconditionally accept
7236 * RRQ from the target.
7237 **/
7238static void
7239lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7240 struct lpfc_nodelist *ndlp)
7241{
7242 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05007243 if (vport->phba->sli_rev == LPFC_SLI_REV4)
7244 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05007245}
7246
7247/**
James Smart12265f62010-10-22 11:05:53 -04007248 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
7249 * @phba: pointer to lpfc hba data structure.
7250 * @pmb: pointer to the driver internal queue element for mailbox command.
7251 *
7252 * This routine is the completion callback function for the MBX_READ_LNK_STAT
7253 * mailbox command. This callback function is to actually send the Accept
7254 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
7255 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
7256 * mailbox command, constructs the RPS response with the link statistics
7257 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
7258 * response to the RPS.
7259 *
7260 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7261 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7262 * will be stored into the context1 field of the IOCB for the completion
7263 * callback function to the RPS Accept Response ELS IOCB command.
7264 *
7265 **/
7266static void
7267lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7268{
7269 MAILBOX_t *mb;
7270 IOCB_t *icmd;
7271 struct RLS_RSP *rls_rsp;
7272 uint8_t *pcmd;
7273 struct lpfc_iocbq *elsiocb;
7274 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04007275 uint16_t oxid;
7276 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04007277 uint32_t cmdsize;
7278
7279 mb = &pmb->u.mb;
7280
James Smart3e1f0712018-11-29 16:09:29 -08007281 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
7282 rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff);
7283 oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff);
7284 pmb->ctx_buf = NULL;
7285 pmb->ctx_ndlp = NULL;
James Smart12265f62010-10-22 11:05:53 -04007286
7287 if (mb->mbxStatus) {
7288 mempool_free(pmb, phba->mbox_mem_pool);
7289 return;
7290 }
7291
7292 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
James Smart12265f62010-10-22 11:05:53 -04007293 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7294 lpfc_max_els_tries, ndlp,
7295 ndlp->nlp_DID, ELS_CMD_ACC);
7296
7297 /* Decrement the ndlp reference count from previous mbox command */
7298 lpfc_nlp_put(ndlp);
7299
James Smart37db57e2012-05-09 21:17:16 -04007300 if (!elsiocb) {
7301 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04007302 return;
James Smart37db57e2012-05-09 21:17:16 -04007303 }
James Smart12265f62010-10-22 11:05:53 -04007304
7305 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04007306 icmd->ulpContext = rxid;
7307 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04007308
7309 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7310 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7311 pcmd += sizeof(uint32_t); /* Skip past command */
7312 rls_rsp = (struct RLS_RSP *)pcmd;
7313
7314 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
7315 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
7316 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
7317 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
7318 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
7319 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
James Smart37db57e2012-05-09 21:17:16 -04007320 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04007321 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7322 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7323 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
7324 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
7325 elsiocb->iotag, elsiocb->iocb.ulpContext,
7326 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7327 ndlp->nlp_rpi);
7328 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7329 phba->fc_stat.elsXmitACC++;
7330 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
7331 lpfc_els_free_iocb(phba, elsiocb);
7332}
7333
7334/**
James Smart12265f62010-10-22 11:05:53 -04007335 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
7336 * @vport: pointer to a host virtual N_Port data structure.
7337 * @cmdiocb: pointer to lpfc command iocb data structure.
7338 * @ndlp: pointer to a node-list data structure.
7339 *
James Smart6cde2e3e2020-01-27 16:23:08 -08007340 * This routine processes Read Link Status (RLS) IOCB received as an
James Smart12265f62010-10-22 11:05:53 -04007341 * ELS unsolicited event. It first checks the remote port state. If the
7342 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7343 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7344 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
7345 * for reading the HBA link statistics. It is for the callback function,
7346 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
7347 * to actually sending out RPL Accept (ACC) response.
7348 *
7349 * Return codes
7350 * 0 - Successfully processed rls iocb (currently always return 0)
7351 **/
7352static int
7353lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7354 struct lpfc_nodelist *ndlp)
7355{
7356 struct lpfc_hba *phba = vport->phba;
7357 LPFC_MBOXQ_t *mbox;
James Smart12265f62010-10-22 11:05:53 -04007358 struct ls_rjt stat;
7359
7360 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7361 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
James Smart6cde2e3e2020-01-27 16:23:08 -08007362 /* reject the unsolicited RLS request and done with it */
James Smart12265f62010-10-22 11:05:53 -04007363 goto reject_out;
7364
James Smart12265f62010-10-22 11:05:53 -04007365 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
7366 if (mbox) {
7367 lpfc_read_lnk_stat(phba, mbox);
James Smart3e1f0712018-11-29 16:09:29 -08007368 mbox->ctx_buf = (void *)((unsigned long)
James Smart7851fe22011-07-22 18:36:52 -04007369 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
7370 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart3e1f0712018-11-29 16:09:29 -08007371 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
James Smart12265f62010-10-22 11:05:53 -04007372 mbox->vport = vport;
7373 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
7374 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
7375 != MBX_NOT_FINISHED)
7376 /* Mbox completion will send ELS Response */
7377 return 0;
7378 /* Decrement reference count used for the failed mbox
7379 * command.
7380 */
7381 lpfc_nlp_put(ndlp);
7382 mempool_free(mbox, phba->mbox_mem_pool);
7383 }
7384reject_out:
7385 /* issue rejection response */
7386 stat.un.b.lsRjtRsvd0 = 0;
7387 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7388 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7389 stat.un.b.vendorUnique = 0;
7390 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7391 return 0;
7392}
7393
7394/**
7395 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
7396 * @vport: pointer to a host virtual N_Port data structure.
7397 * @cmdiocb: pointer to lpfc command iocb data structure.
7398 * @ndlp: pointer to a node-list data structure.
7399 *
7400 * This routine processes Read Timout Value (RTV) IOCB received as an
7401 * ELS unsolicited event. It first checks the remote port state. If the
7402 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7403 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7404 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
7405 * Value (RTV) unsolicited IOCB event.
7406 *
7407 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7408 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7409 * will be stored into the context1 field of the IOCB for the completion
James Smart6cde2e3e2020-01-27 16:23:08 -08007410 * callback function to the RTV Accept Response ELS IOCB command.
James Smart12265f62010-10-22 11:05:53 -04007411 *
7412 * Return codes
7413 * 0 - Successfully processed rtv iocb (currently always return 0)
7414 **/
7415static int
7416lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7417 struct lpfc_nodelist *ndlp)
7418{
7419 struct lpfc_hba *phba = vport->phba;
7420 struct ls_rjt stat;
7421 struct RTV_RSP *rtv_rsp;
7422 uint8_t *pcmd;
7423 struct lpfc_iocbq *elsiocb;
7424 uint32_t cmdsize;
7425
7426
7427 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7428 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
James Smart6cde2e3e2020-01-27 16:23:08 -08007429 /* reject the unsolicited RTV request and done with it */
James Smart12265f62010-10-22 11:05:53 -04007430 goto reject_out;
7431
7432 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
7433 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7434 lpfc_max_els_tries, ndlp,
7435 ndlp->nlp_DID, ELS_CMD_ACC);
7436
7437 if (!elsiocb)
7438 return 1;
7439
7440 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
Colin Ian King8fd03fd2017-12-22 00:39:36 +00007441 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart12265f62010-10-22 11:05:53 -04007442 pcmd += sizeof(uint32_t); /* Skip past command */
7443
7444 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04007445 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
7446 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04007447
7448 rtv_rsp = (struct RTV_RSP *)pcmd;
7449
7450 /* populate RTV payload */
7451 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
7452 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
7453 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
7454 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
7455 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
7456
7457 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7458 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7459 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
7460 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
7461 "Data: x%x x%x x%x\n",
7462 elsiocb->iotag, elsiocb->iocb.ulpContext,
7463 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7464 ndlp->nlp_rpi,
7465 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
7466 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7467 phba->fc_stat.elsXmitACC++;
7468 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
7469 lpfc_els_free_iocb(phba, elsiocb);
7470 return 0;
7471
7472reject_out:
7473 /* issue rejection response */
7474 stat.un.b.lsRjtRsvd0 = 0;
7475 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7476 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7477 stat.un.b.vendorUnique = 0;
7478 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7479 return 0;
7480}
7481
James Smart6cde2e3e2020-01-27 16:23:08 -08007482/* lpfc_issue_els_rrq - Process an unsolicited rrq iocb
James Smart19ca7602010-11-20 23:11:55 -05007483 * @vport: pointer to a host virtual N_Port data structure.
7484 * @ndlp: pointer to a node-list data structure.
7485 * @did: DID of the target.
7486 * @rrq: Pointer to the rrq struct.
7487 *
7488 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
7489 * Successful the the completion handler will clear the RRQ.
7490 *
7491 * Return codes
7492 * 0 - Successfully sent rrq els iocb.
7493 * 1 - Failed to send rrq els iocb.
7494 **/
7495static int
7496lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7497 uint32_t did, struct lpfc_node_rrq *rrq)
7498{
7499 struct lpfc_hba *phba = vport->phba;
7500 struct RRQ *els_rrq;
James Smart19ca7602010-11-20 23:11:55 -05007501 struct lpfc_iocbq *elsiocb;
7502 uint8_t *pcmd;
7503 uint16_t cmdsize;
7504 int ret;
7505
7506
7507 if (ndlp != rrq->ndlp)
7508 ndlp = rrq->ndlp;
7509 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7510 return 1;
7511
7512 /* If ndlp is not NULL, we will bump the reference count on it */
7513 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
7514 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
7515 ELS_CMD_RRQ);
7516 if (!elsiocb)
7517 return 1;
7518
James Smart19ca7602010-11-20 23:11:55 -05007519 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7520
7521 /* For RRQ request, remainder of payload is Exchange IDs */
7522 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
7523 pcmd += sizeof(uint32_t);
7524 els_rrq = (struct RRQ *) pcmd;
7525
James Smartee0f4fe2012-05-09 21:19:14 -04007526 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
James Smart19ca7602010-11-20 23:11:55 -05007527 bf_set(rrq_rxid, els_rrq, rrq->rxid);
7528 bf_set(rrq_did, els_rrq, vport->fc_myDID);
7529 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
7530 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
7531
7532
7533 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7534 "Issue RRQ: did:x%x",
7535 did, rrq->xritag, rrq->rxid);
7536 elsiocb->context_un.rrq = rrq;
7537 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
7538 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7539
7540 if (ret == IOCB_ERROR) {
7541 lpfc_els_free_iocb(phba, elsiocb);
7542 return 1;
7543 }
7544 return 0;
7545}
7546
7547/**
7548 * lpfc_send_rrq - Sends ELS RRQ if needed.
7549 * @phba: pointer to lpfc hba data structure.
7550 * @rrq: pointer to the active rrq.
7551 *
7552 * This routine will call the lpfc_issue_els_rrq if the rrq is
7553 * still active for the xri. If this function returns a failure then
7554 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
7555 *
7556 * Returns 0 Success.
7557 * 1 Failure.
7558 **/
7559int
7560lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
7561{
7562 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
James Smartc8cb2612019-05-06 17:26:49 -07007563 rrq->nlp_DID);
7564 if (!ndlp)
7565 return 1;
7566
James Smart19ca7602010-11-20 23:11:55 -05007567 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
7568 return lpfc_issue_els_rrq(rrq->vport, ndlp,
7569 rrq->nlp_DID, rrq);
7570 else
7571 return 1;
7572}
7573
James Smarte59058c2008-08-24 21:49:00 -04007574/**
James Smart3621a712009-04-06 18:47:14 -04007575 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04007576 * @vport: pointer to a host virtual N_Port data structure.
7577 * @cmdsize: size of the ELS command.
7578 * @oldiocb: pointer to the original lpfc command iocb data structure.
7579 * @ndlp: pointer to a node-list data structure.
7580 *
7581 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
7582 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
7583 *
7584 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7585 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7586 * will be stored into the context1 field of the IOCB for the completion
7587 * callback function to the RPL Accept Response ELS command.
7588 *
7589 * Return code
7590 * 0 - Successfully issued ACC RPL ELS command
7591 * 1 - Failed to issue ACC RPL ELS command
7592 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05007593static int
James Smart2e0fef82007-06-17 19:56:36 -05007594lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
7595 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007596{
James Smart2e0fef82007-06-17 19:56:36 -05007597 struct lpfc_hba *phba = vport->phba;
7598 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007599 RPL_RSP rpl_rsp;
7600 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007601 uint8_t *pcmd;
7602
James Smart2e0fef82007-06-17 19:56:36 -05007603 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
7604 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007605
James Smart488d1462006-03-07 15:02:37 -05007606 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007607 return 1;
James Smart488d1462006-03-07 15:02:37 -05007608
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007609 icmd = &elsiocb->iocb;
7610 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04007611 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
7612 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007613
7614 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7615 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05007616 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007617 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7618 pcmd += sizeof(uint16_t);
7619
7620 /* Setup the RPL ACC payload */
7621 rpl_rsp.listLen = be32_to_cpu(1);
7622 rpl_rsp.index = 0;
7623 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05007624 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7625 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007626 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007627 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007628 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04007629 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7630 "0120 Xmit ELS RPL ACC response tag x%x "
7631 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7632 "rpi x%x\n",
7633 elsiocb->iotag, elsiocb->iocb.ulpContext,
7634 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7635 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05007636 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007637 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04007638 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7639 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007640 lpfc_els_free_iocb(phba, elsiocb);
7641 return 1;
7642 }
7643 return 0;
7644}
7645
James Smarte59058c2008-08-24 21:49:00 -04007646/**
James Smart3621a712009-04-06 18:47:14 -04007647 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04007648 * @vport: pointer to a host virtual N_Port data structure.
7649 * @cmdiocb: pointer to lpfc command iocb data structure.
7650 * @ndlp: pointer to a node-list data structure.
7651 *
7652 * This routine processes Read Port List (RPL) IOCB received as an ELS
7653 * unsolicited event. It first checks the remote port state. If the remote
7654 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7655 * invokes the lpfc_els_rsp_reject() routine to send reject response.
7656 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7657 * to accept the RPL.
7658 *
7659 * Return code
7660 * 0 - Successfully processed rpl iocb (currently always return 0)
7661 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007662static int
James Smart2e0fef82007-06-17 19:56:36 -05007663lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7664 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007665{
7666 struct lpfc_dmabuf *pcmd;
7667 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007668 uint32_t maxsize;
7669 uint16_t cmdsize;
7670 RPL *rpl;
7671 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05007672
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05007673 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7674 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04007675 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007676 stat.un.b.lsRjtRsvd0 = 0;
7677 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7678 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7679 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05007680 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7681 NULL);
James Smart90160e02008-08-24 21:49:45 -04007682 /* rejected the unsolicited RPL request and done with it */
7683 return 0;
dea31012005-04-17 16:05:31 -05007684 }
7685
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007686 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7687 lp = (uint32_t *) pcmd->virt;
7688 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007689 maxsize = be32_to_cpu(rpl->maxsize);
7690
7691 /* We support only one port */
7692 if ((rpl->index == 0) &&
7693 ((maxsize == 0) ||
7694 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
7695 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05007696 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007697 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
7698 }
James Smart2e0fef82007-06-17 19:56:36 -05007699 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05007700
7701 return 0;
7702}
7703
James Smarte59058c2008-08-24 21:49:00 -04007704/**
James Smart3621a712009-04-06 18:47:14 -04007705 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04007706 * @vport: pointer to a virtual N_Port data structure.
7707 * @cmdiocb: pointer to lpfc command iocb data structure.
7708 * @ndlp: pointer to a node-list data structure.
7709 *
7710 * This routine processes Fibre Channel Address Resolution Protocol
7711 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
7712 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
7713 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
7714 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
7715 * remote PortName is compared against the FC PortName stored in the @vport
7716 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
7717 * compared against the FC NodeName stored in the @vport data structure.
7718 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
7719 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
7720 * invoked to send out FARP Response to the remote node. Before sending the
7721 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
7722 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
7723 * routine is invoked to log into the remote port first.
7724 *
7725 * Return code
7726 * 0 - Either the FARP Match Mode not supported or successfully processed
7727 **/
dea31012005-04-17 16:05:31 -05007728static int
James Smart2e0fef82007-06-17 19:56:36 -05007729lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7730 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007731{
7732 struct lpfc_dmabuf *pcmd;
7733 uint32_t *lp;
7734 IOCB_t *icmd;
7735 FARP *fp;
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07007736 uint32_t cnt, did;
dea31012005-04-17 16:05:31 -05007737
7738 icmd = &cmdiocb->iocb;
7739 did = icmd->un.elsreq64.remoteID;
7740 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7741 lp = (uint32_t *) pcmd->virt;
7742
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07007743 lp++;
dea31012005-04-17 16:05:31 -05007744 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05007745 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04007746 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7747 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05007748 /* We will only support match on WWPN or WWNN */
7749 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007750 return 0;
dea31012005-04-17 16:05:31 -05007751 }
7752
7753 cnt = 0;
7754 /* If this FARP command is searching for my portname */
7755 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05007756 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05007757 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05007758 cnt = 1;
7759 }
7760
7761 /* If this FARP command is searching for my nodename */
7762 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05007763 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05007764 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05007765 cnt = 1;
7766 }
7767
7768 if (cnt) {
7769 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
7770 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7771 /* Log back into the node before sending the FARP. */
7772 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007773 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05007774 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04007775 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05007776 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05007777 }
7778
7779 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05007780 if (fp->Rflags & FARP_REQUEST_FARPR)
7781 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05007782 }
7783 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007784 return 0;
dea31012005-04-17 16:05:31 -05007785}
7786
James Smarte59058c2008-08-24 21:49:00 -04007787/**
James Smart3621a712009-04-06 18:47:14 -04007788 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04007789 * @vport: pointer to a host virtual N_Port data structure.
7790 * @cmdiocb: pointer to lpfc command iocb data structure.
7791 * @ndlp: pointer to a node-list data structure.
7792 *
7793 * This routine processes Fibre Channel Address Resolution Protocol
7794 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7795 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7796 * the FARP response request.
7797 *
7798 * Return code
7799 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7800 **/
dea31012005-04-17 16:05:31 -05007801static int
James Smart2e0fef82007-06-17 19:56:36 -05007802lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7803 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007804{
7805 struct lpfc_dmabuf *pcmd;
7806 uint32_t *lp;
7807 IOCB_t *icmd;
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07007808 uint32_t did;
dea31012005-04-17 16:05:31 -05007809
7810 icmd = &cmdiocb->iocb;
7811 did = icmd->un.elsreq64.remoteID;
7812 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7813 lp = (uint32_t *) pcmd->virt;
7814
Bart Van Asscheb27cbd52019-03-28 11:06:20 -07007815 lp++;
dea31012005-04-17 16:05:31 -05007816 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04007817 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7818 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05007819 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04007820 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05007821
7822 return 0;
7823}
7824
James Smarte59058c2008-08-24 21:49:00 -04007825/**
James Smart3621a712009-04-06 18:47:14 -04007826 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04007827 * @vport: pointer to a host virtual N_Port data structure.
7828 * @cmdiocb: pointer to lpfc command iocb data structure.
7829 * @fan_ndlp: pointer to a node-list data structure.
7830 *
7831 * This routine processes a Fabric Address Notification (FAN) IOCB
7832 * command received as an ELS unsolicited event. The FAN ELS command will
7833 * only be processed on a physical port (i.e., the @vport represents the
7834 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7835 * compared against those in the phba data structure. If any of those is
7836 * different, the lpfc_initial_flogi() routine is invoked to initialize
7837 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7838 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7839 * is invoked to register login to the fabric.
7840 *
7841 * Return code
7842 * 0 - Successfully processed fan iocb (currently always return 0).
7843 **/
dea31012005-04-17 16:05:31 -05007844static int
James Smart2e0fef82007-06-17 19:56:36 -05007845lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7846 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05007847{
James Smart2e0fef82007-06-17 19:56:36 -05007848 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04007849 uint32_t *lp;
7850 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007851
James Smart0d2b6b82008-06-14 22:52:47 -04007852 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7853 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7854 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007855 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04007856 if ((vport == phba->pport) &&
7857 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007858 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04007859 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007860 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04007861 sizeof(struct lpfc_name)))) {
7862 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05007863 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04007864 } else {
7865 /* FAN verified - skip FLOGI */
7866 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04007867 if (phba->sli_rev < LPFC_SLI_REV4)
7868 lpfc_issue_fabric_reglogin(vport);
James Smart1b511972011-12-13 13:23:09 -05007869 else {
7870 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7871 "3138 Need register VFI: (x%x/%x)\n",
7872 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -04007873 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -05007874 }
dea31012005-04-17 16:05:31 -05007875 }
dea31012005-04-17 16:05:31 -05007876 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007877 return 0;
dea31012005-04-17 16:05:31 -05007878}
7879
James Smarte59058c2008-08-24 21:49:00 -04007880/**
James Smart3621a712009-04-06 18:47:14 -04007881 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04007882 * @ptr: holder for the timer function associated data.
7883 *
7884 * This routine is invoked by the ELS timer after timeout. It posts the ELS
7885 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
7886 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
7887 * up the worker thread. It is for the worker thread to invoke the routine
7888 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
7889 **/
dea31012005-04-17 16:05:31 -05007890void
Kees Cookf22eb4d2017-09-06 20:24:26 -07007891lpfc_els_timeout(struct timer_list *t)
dea31012005-04-17 16:05:31 -05007892{
Kees Cookf22eb4d2017-09-06 20:24:26 -07007893 struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
James Smart2e0fef82007-06-17 19:56:36 -05007894 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04007895 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05007896 unsigned long iflag;
7897
James Smart2e0fef82007-06-17 19:56:36 -05007898 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04007899 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
James Smart06918ac2014-02-20 09:57:57 -05007900 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
James Smart2e0fef82007-06-17 19:56:36 -05007901 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04007902 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05007903
James Smart06918ac2014-02-20 09:57:57 -05007904 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
James Smart5e9d9b82008-06-14 22:52:53 -04007905 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05007906 return;
7907}
7908
James Smart2a9bf3d2010-06-07 15:24:45 -04007909
James Smarte59058c2008-08-24 21:49:00 -04007910/**
James Smart3621a712009-04-06 18:47:14 -04007911 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04007912 * @vport: pointer to a virtual N_Port data structure.
7913 *
7914 * This routine is the actual handler function that processes an ELS timeout
7915 * event. It walks the ELS ring to get and abort all the IOCBs (except the
7916 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
7917 * invoking the lpfc_sli_issue_abort_iotag() routine.
7918 **/
dea31012005-04-17 16:05:31 -05007919void
James Smart2e0fef82007-06-17 19:56:36 -05007920lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05007921{
James Smart2e0fef82007-06-17 19:56:36 -05007922 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05007923 struct lpfc_sli_ring *pring;
7924 struct lpfc_iocbq *tmp_iocb, *piocb;
7925 IOCB_t *cmd = NULL;
7926 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05007927 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05007928 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05007929 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04007930 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05007931
James Smart2a9bf3d2010-06-07 15:24:45 -04007932
dea31012005-04-17 16:05:31 -05007933 timeout = (uint32_t)(phba->fc_ratov << 1);
7934
James Smart895427b2017-02-12 13:52:30 -08007935 pring = lpfc_phba_elsring(phba);
Dick Kennedy1234a6d2017-09-29 17:34:29 -07007936 if (unlikely(!pring))
7937 return;
James Smart895427b2017-02-12 13:52:30 -08007938
James Smart06918ac2014-02-20 09:57:57 -05007939 if ((phba->pport->load_flag & FC_UNLOADING))
7940 return;
James Smart2a9bf3d2010-06-07 15:24:45 -04007941 spin_lock_irq(&phba->hbalock);
James Smart0976e1a2013-12-17 20:29:36 -05007942 if (phba->sli_rev == LPFC_SLI_REV4)
7943 spin_lock(&pring->ring_lock);
James Smart2a9bf3d2010-06-07 15:24:45 -04007944
James Smart06918ac2014-02-20 09:57:57 -05007945 if ((phba->pport->load_flag & FC_UNLOADING)) {
7946 if (phba->sli_rev == LPFC_SLI_REV4)
7947 spin_unlock(&pring->ring_lock);
7948 spin_unlock_irq(&phba->hbalock);
7949 return;
7950 }
7951
James Smart0976e1a2013-12-17 20:29:36 -05007952 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05007953 cmd = &piocb->iocb;
7954
James Smart2e0fef82007-06-17 19:56:36 -05007955 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
7956 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
7957 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05007958 continue;
James Smart2e0fef82007-06-17 19:56:36 -05007959
7960 if (piocb->vport != vport)
7961 continue;
7962
dea31012005-04-17 16:05:31 -05007963 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05007964 if (pcmd)
7965 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05007966
James Smart92d7f7b2007-06-17 19:56:38 -05007967 if (els_command == ELS_CMD_FARP ||
7968 els_command == ELS_CMD_FARPR ||
7969 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05007970 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05007971
dea31012005-04-17 16:05:31 -05007972 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05007973 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05007974 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05007975 else
dea31012005-04-17 16:05:31 -05007976 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05007977 continue;
7978 }
7979
James Smart2e0fef82007-06-17 19:56:36 -05007980 remote_ID = 0xffffffff;
7981 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05007982 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05007983 else {
7984 struct lpfc_nodelist *ndlp;
7985 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04007986 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05007987 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05007988 }
James Smart2a9bf3d2010-06-07 15:24:45 -04007989 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05007990 }
James Smart0976e1a2013-12-17 20:29:36 -05007991 if (phba->sli_rev == LPFC_SLI_REV4)
7992 spin_unlock(&pring->ring_lock);
James Smart2e0fef82007-06-17 19:56:36 -05007993 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04007994
James Smart2a9bf3d2010-06-07 15:24:45 -04007995 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
James Smart15026c92013-12-17 20:30:09 -05007996 cmd = &piocb->iocb;
James Smart2a9bf3d2010-06-07 15:24:45 -04007997 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7998 "0127 ELS timeout Data: x%x x%x x%x "
7999 "x%x\n", els_command,
8000 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
8001 spin_lock_irq(&phba->hbalock);
8002 list_del_init(&piocb->dlist);
8003 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
8004 spin_unlock_irq(&phba->hbalock);
8005 }
8006
James Smart895427b2017-02-12 13:52:30 -08008007 if (!list_empty(&pring->txcmplq))
James Smart06918ac2014-02-20 09:57:57 -05008008 if (!(phba->pport->load_flag & FC_UNLOADING))
8009 mod_timer(&vport->els_tmofunc,
8010 jiffies + msecs_to_jiffies(1000 * timeout));
dea31012005-04-17 16:05:31 -05008011}
8012
James Smarte59058c2008-08-24 21:49:00 -04008013/**
James Smart3621a712009-04-06 18:47:14 -04008014 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04008015 * @vport: pointer to a host virtual N_Port data structure.
8016 *
8017 * This routine is used to clean up all the outstanding ELS commands on a
8018 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
8019 * routine. After that, it walks the ELS transmit queue to remove all the
8020 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
8021 * the IOCBs with a non-NULL completion callback function, the callback
8022 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
8023 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
8024 * callback function, the IOCB will simply be released. Finally, it walks
8025 * the ELS transmit completion queue to issue an abort IOCB to any transmit
8026 * completion queue IOCB that is associated with the @vport and is not
8027 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
8028 * part of the discovery state machine) out to HBA by invoking the
8029 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
8030 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
8031 * the IOCBs are aborted when this function returns.
8032 **/
dea31012005-04-17 16:05:31 -05008033void
James Smart2e0fef82007-06-17 19:56:36 -05008034lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05008035{
James Smart0976e1a2013-12-17 20:29:36 -05008036 LIST_HEAD(abort_list);
James Smart2e0fef82007-06-17 19:56:36 -05008037 struct lpfc_hba *phba = vport->phba;
James Smart895427b2017-02-12 13:52:30 -08008038 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05008039 struct lpfc_iocbq *tmp_iocb, *piocb;
8040 IOCB_t *cmd = NULL;
James Smartd38b4a52019-09-21 20:59:00 -07008041 unsigned long iflags = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05008042
8043 lpfc_fabric_abort_vport(vport);
James Smartd38b4a52019-09-21 20:59:00 -07008044
James Smart0976e1a2013-12-17 20:29:36 -05008045 /*
8046 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
8047 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
8048 * ultimately grabs the ring_lock, the driver must splice the list into
8049 * a working list and release the locks before calling the abort.
8050 */
James Smartd38b4a52019-09-21 20:59:00 -07008051 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart895427b2017-02-12 13:52:30 -08008052 pring = lpfc_phba_elsring(phba);
Guilherme G. Piccoli53cf29d2017-05-17 19:02:17 -03008053
8054 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
8055 if (unlikely(!pring)) {
James Smartd38b4a52019-09-21 20:59:00 -07008056 spin_unlock_irqrestore(&phba->hbalock, iflags);
Guilherme G. Piccoli53cf29d2017-05-17 19:02:17 -03008057 return;
8058 }
8059
James Smart0976e1a2013-12-17 20:29:36 -05008060 if (phba->sli_rev == LPFC_SLI_REV4)
8061 spin_lock(&pring->ring_lock);
8062
James Smart6ede2dd2019-08-14 16:56:44 -07008063 /* First we need to issue aborts to outstanding cmds on txcmpl */
James Smart0976e1a2013-12-17 20:29:36 -05008064 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
8065 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
8066 continue;
8067
8068 if (piocb->vport != vport)
8069 continue;
James Smart6ede2dd2019-08-14 16:56:44 -07008070
James Smart15498dc2019-09-21 20:58:59 -07008071 if (piocb->iocb_flag & LPFC_DRIVER_ABORTED)
8072 continue;
8073
James Smart6ede2dd2019-08-14 16:56:44 -07008074 /* On the ELS ring we can have ELS_REQUESTs or
8075 * GEN_REQUESTs waiting for a response.
8076 */
8077 cmd = &piocb->iocb;
8078 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
8079 list_add_tail(&piocb->dlist, &abort_list);
8080
8081 /* If the link is down when flushing ELS commands
8082 * the firmware will not complete them till after
8083 * the link comes back up. This may confuse
8084 * discovery for the new link up, so we need to
8085 * change the compl routine to just clean up the iocb
8086 * and avoid any retry logic.
8087 */
8088 if (phba->link_state == LPFC_LINK_DOWN)
8089 piocb->iocb_cmpl = lpfc_cmpl_els_link_down;
8090 }
8091 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR)
8092 list_add_tail(&piocb->dlist, &abort_list);
James Smart0976e1a2013-12-17 20:29:36 -05008093 }
James Smart6ede2dd2019-08-14 16:56:44 -07008094
James Smart0976e1a2013-12-17 20:29:36 -05008095 if (phba->sli_rev == LPFC_SLI_REV4)
8096 spin_unlock(&pring->ring_lock);
James Smartd38b4a52019-09-21 20:59:00 -07008097 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart6ede2dd2019-08-14 16:56:44 -07008098
8099 /* Abort each txcmpl iocb on aborted list and remove the dlist links. */
James Smart0976e1a2013-12-17 20:29:36 -05008100 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
James Smartd38b4a52019-09-21 20:59:00 -07008101 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart0976e1a2013-12-17 20:29:36 -05008102 list_del_init(&piocb->dlist);
8103 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
James Smartd38b4a52019-09-21 20:59:00 -07008104 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart0976e1a2013-12-17 20:29:36 -05008105 }
8106 if (!list_empty(&abort_list))
8107 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8108 "3387 abort list for txq not empty\n");
8109 INIT_LIST_HEAD(&abort_list);
dea31012005-04-17 16:05:31 -05008110
James Smartd38b4a52019-09-21 20:59:00 -07008111 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart0976e1a2013-12-17 20:29:36 -05008112 if (phba->sli_rev == LPFC_SLI_REV4)
8113 spin_lock(&pring->ring_lock);
8114
James Smart6ede2dd2019-08-14 16:56:44 -07008115 /* No need to abort the txq list,
8116 * just queue them up for lpfc_sli_cancel_iocbs
8117 */
dea31012005-04-17 16:05:31 -05008118 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
8119 cmd = &piocb->iocb;
8120
8121 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
8122 continue;
8123 }
8124
8125 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04008126 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
8127 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
8128 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
8129 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05008130 continue;
dea31012005-04-17 16:05:31 -05008131
James Smart2e0fef82007-06-17 19:56:36 -05008132 if (piocb->vport != vport)
8133 continue;
8134
James Smart0976e1a2013-12-17 20:29:36 -05008135 list_del_init(&piocb->list);
8136 list_add_tail(&piocb->list, &abort_list);
dea31012005-04-17 16:05:31 -05008137 }
James Smart6ede2dd2019-08-14 16:56:44 -07008138
8139 /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */
8140 if (vport == phba->pport) {
8141 list_for_each_entry_safe(piocb, tmp_iocb,
8142 &phba->fabric_iocb_list, list) {
8143 cmd = &piocb->iocb;
8144 list_del_init(&piocb->list);
8145 list_add_tail(&piocb->list, &abort_list);
8146 }
8147 }
8148
James Smart0976e1a2013-12-17 20:29:36 -05008149 if (phba->sli_rev == LPFC_SLI_REV4)
8150 spin_unlock(&pring->ring_lock);
James Smartd38b4a52019-09-21 20:59:00 -07008151 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart2534ba72007-04-25 09:52:20 -04008152
James Smart6ede2dd2019-08-14 16:56:44 -07008153 /* Cancel all the IOCBs from the completions list */
James Smart0976e1a2013-12-17 20:29:36 -05008154 lpfc_sli_cancel_iocbs(phba, &abort_list,
8155 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04008156
dea31012005-04-17 16:05:31 -05008157 return;
8158}
8159
James Smarte59058c2008-08-24 21:49:00 -04008160/**
James Smart3621a712009-04-06 18:47:14 -04008161 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04008162 * @phba: pointer to lpfc hba data structure.
8163 *
8164 * This routine is used to clean up all the outstanding ELS commands on a
8165 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
8166 * routine. After that, it walks the ELS transmit queue to remove all the
8167 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
8168 * the IOCBs with the completion callback function associated, the callback
8169 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
8170 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
8171 * callback function associated, the IOCB will simply be released. Finally,
8172 * it walks the ELS transmit completion queue to issue an abort IOCB to any
8173 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
8174 * management plane IOCBs that are not part of the discovery state machine)
8175 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
8176 **/
James Smart549e55c2007-08-02 11:09:51 -04008177void
8178lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
8179{
James Smart0976e1a2013-12-17 20:29:36 -05008180 struct lpfc_vport *vport;
James Smart523128e2018-09-10 10:30:46 -07008181
8182 spin_lock_irq(&phba->port_list_lock);
James Smart0976e1a2013-12-17 20:29:36 -05008183 list_for_each_entry(vport, &phba->port_list, listentry)
8184 lpfc_els_flush_cmd(vport);
James Smart523128e2018-09-10 10:30:46 -07008185 spin_unlock_irq(&phba->port_list_lock);
James Smarta257bf92009-04-06 18:48:10 -04008186
James Smart549e55c2007-08-02 11:09:51 -04008187 return;
8188}
8189
James Smarte59058c2008-08-24 21:49:00 -04008190/**
James Smart3621a712009-04-06 18:47:14 -04008191 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04008192 * @phba: Pointer to hba context object.
8193 * @cmdiocbp: Pointer to command iocb which reported error.
8194 * @rspiocbp: Pointer to response iocb which reported error.
8195 *
8196 * This function sends an event when there is an ELS command
8197 * failure.
8198 **/
8199void
8200lpfc_send_els_failure_event(struct lpfc_hba *phba,
8201 struct lpfc_iocbq *cmdiocbp,
8202 struct lpfc_iocbq *rspiocbp)
8203{
8204 struct lpfc_vport *vport = cmdiocbp->vport;
8205 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8206 struct lpfc_lsrjt_event lsrjt_event;
8207 struct lpfc_fabric_event_header fabric_event;
8208 struct ls_rjt stat;
8209 struct lpfc_nodelist *ndlp;
8210 uint32_t *pcmd;
8211
8212 ndlp = cmdiocbp->context1;
8213 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
8214 return;
8215
8216 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
8217 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
8218 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
8219 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
8220 sizeof(struct lpfc_name));
8221 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
8222 sizeof(struct lpfc_name));
8223 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
8224 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04008225 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04008226 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
8227 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
8228 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
8229 fc_host_post_vendor_event(shost,
8230 fc_get_event_number(),
8231 sizeof(lsrjt_event),
8232 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05008233 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04008234 return;
8235 }
8236 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
8237 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
8238 fabric_event.event_type = FC_REG_FABRIC_EVENT;
8239 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
8240 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
8241 else
8242 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
8243 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
8244 sizeof(struct lpfc_name));
8245 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
8246 sizeof(struct lpfc_name));
8247 fc_host_post_vendor_event(shost,
8248 fc_get_event_number(),
8249 sizeof(fabric_event),
8250 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05008251 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04008252 return;
8253 }
8254
8255}
8256
8257/**
James Smart3621a712009-04-06 18:47:14 -04008258 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04008259 * @vport: Pointer to vport object.
8260 * @ndlp: Pointer FC node object.
8261 * @cmd: ELS command code.
8262 *
8263 * This function posts an event when there is an incoming
8264 * unsolicited ELS command.
8265 **/
8266static void
8267lpfc_send_els_event(struct lpfc_vport *vport,
8268 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05008269 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04008270{
James Smartddcc50f2008-12-04 22:38:46 -05008271 struct lpfc_els_event_header *els_data = NULL;
8272 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04008273 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8274
James Smartddcc50f2008-12-04 22:38:46 -05008275 if (*payload == ELS_CMD_LOGO) {
8276 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
8277 if (!logo_data) {
8278 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8279 "0148 Failed to allocate memory "
8280 "for LOGO event\n");
8281 return;
8282 }
8283 els_data = &logo_data->header;
8284 } else {
8285 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
8286 GFP_KERNEL);
8287 if (!els_data) {
8288 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8289 "0149 Failed to allocate memory "
8290 "for ELS event\n");
8291 return;
8292 }
8293 }
8294 els_data->event_type = FC_REG_ELS_EVENT;
8295 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04008296 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05008297 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04008298 break;
8299 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05008300 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04008301 break;
8302 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05008303 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
8304 break;
8305 case ELS_CMD_LOGO:
8306 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
8307 /* Copy the WWPN in the LOGO payload */
8308 memcpy(logo_data->logo_wwpn, &payload[2],
8309 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04008310 break;
8311 default:
Julia Lawalle9161412009-02-08 22:43:19 +01008312 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04008313 return;
8314 }
James Smartddcc50f2008-12-04 22:38:46 -05008315 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
8316 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
8317 if (*payload == ELS_CMD_LOGO) {
8318 fc_host_post_vendor_event(shost,
8319 fc_get_event_number(),
8320 sizeof(struct lpfc_logo_event),
8321 (char *)logo_data,
8322 LPFC_NL_VENDOR_ID);
8323 kfree(logo_data);
8324 } else {
8325 fc_host_post_vendor_event(shost,
8326 fc_get_event_number(),
8327 sizeof(struct lpfc_els_event_header),
8328 (char *)els_data,
8329 LPFC_NL_VENDOR_ID);
8330 kfree(els_data);
8331 }
James Smartea2151b2008-09-07 11:52:10 -04008332
8333 return;
8334}
8335
8336
James Smartdf3fe762020-02-10 09:31:55 -08008337DECLARE_ENUM2STR_LOOKUP(lpfc_get_tlv_dtag_nm, fc_ls_tlv_dtag,
8338 FC_LS_TLV_DTAG_INIT);
8339
8340DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm, fc_fpin_li_event_types,
8341 FC_FPIN_LI_EVT_TYPES_INIT);
8342
8343/**
8344 * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event.
8345 * @vport: Pointer to vport object.
8346 * @lnk_not: Pointer to the Link Integrity Notification Descriptor.
8347 *
8348 * This function processes a link integrity FPIN event by
8349 * logging a message
8350 **/
8351static void
8352lpfc_els_rcv_fpin_li(struct lpfc_vport *vport, struct fc_tlv_desc *tlv)
8353{
8354 struct fc_fn_li_desc *li = (struct fc_fn_li_desc *)tlv;
8355 const char *li_evt_str;
8356 u32 li_evt;
8357
8358 li_evt = be16_to_cpu(li->event_type);
8359 li_evt_str = lpfc_get_fpin_li_event_nm(li_evt);
8360
8361 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8362 "4680 FPIN Link Integrity %s (x%x) "
8363 "Detecting PN x%016llx Attached PN x%016llx "
8364 "Duration %d mSecs Count %d Port Cnt %d\n",
8365 li_evt_str, li_evt,
8366 be64_to_cpu(li->detecting_wwpn),
8367 be64_to_cpu(li->attached_wwpn),
8368 be32_to_cpu(li->event_threshold),
8369 be32_to_cpu(li->event_count),
8370 be32_to_cpu(li->pname_count));
8371}
8372
8373static void
8374lpfc_els_rcv_fpin(struct lpfc_vport *vport, struct fc_els_fpin *fpin,
8375 u32 fpin_length)
8376{
8377 struct fc_tlv_desc *tlv;
8378 const char *dtag_nm;
8379 uint32_t desc_cnt = 0, bytes_remain;
8380 u32 dtag;
8381
8382 /* FPINs handled only if we are in the right discovery state */
8383 if (vport->port_state < LPFC_DISC_AUTH)
8384 return;
8385
8386 /* make sure there is the full fpin header */
8387 if (fpin_length < sizeof(struct fc_els_fpin))
8388 return;
8389
8390 tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0];
8391 bytes_remain = fpin_length - offsetof(struct fc_els_fpin, fpin_desc);
8392 bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len));
8393
8394 /* process each descriptor */
8395 while (bytes_remain >= FC_TLV_DESC_HDR_SZ &&
8396 bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) {
8397
8398 dtag = be32_to_cpu(tlv->desc_tag);
8399 switch (dtag) {
8400 case ELS_DTAG_LNK_INTEGRITY:
8401 lpfc_els_rcv_fpin_li(vport, tlv);
8402 break;
8403 default:
8404 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
8405 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8406 "4678 skipped FPIN descriptor[%d]: "
8407 "tag x%x (%s)\n",
8408 desc_cnt, dtag, dtag_nm);
8409 break;
8410 }
8411
8412 desc_cnt++;
8413 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
8414 tlv = fc_tlv_next_desc(tlv);
8415 }
8416
8417 fc_host_fpin_rcv(lpfc_shost_from_vport(vport), fpin_length,
8418 (char *)fpin);
8419}
8420
James Smartea2151b2008-09-07 11:52:10 -04008421/**
James Smart3621a712009-04-06 18:47:14 -04008422 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04008423 * @phba: pointer to lpfc hba data structure.
8424 * @pring: pointer to a SLI ring.
8425 * @vport: pointer to a host virtual N_Port data structure.
8426 * @elsiocb: pointer to lpfc els command iocb data structure.
8427 *
8428 * This routine is used for processing the IOCB associated with a unsolicited
8429 * event. It first determines whether there is an existing ndlp that matches
8430 * the DID from the unsolicited IOCB. If not, it will create a new one with
8431 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
8432 * IOCB is then used to invoke the proper routine and to set up proper state
8433 * of the discovery state machine.
8434 **/
James Smarted957682007-06-17 19:56:37 -05008435static void
8436lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05008437 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05008438{
James Smart87af33f2007-10-27 13:37:43 -04008439 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05008440 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05008441 struct ls_rjt stat;
James Smartdf3fe762020-02-10 09:31:55 -08008442 uint32_t *payload, payload_len;
James Smart303f2f92013-01-03 15:43:11 -05008443 uint32_t cmd, did, newnode;
James Smartd496b9a2018-10-23 13:41:08 -07008444 uint8_t rjt_exp, rjt_err = 0, init_link = 0;
James Smarted957682007-06-17 19:56:37 -05008445 IOCB_t *icmd = &elsiocb->iocb;
James Smartd496b9a2018-10-23 13:41:08 -07008446 LPFC_MBOXQ_t *mbox;
dea31012005-04-17 16:05:31 -05008447
James Smarte47c9092008-02-08 18:49:26 -05008448 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05008449 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05008450
dea31012005-04-17 16:05:31 -05008451 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05008452 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
James Smartdf3fe762020-02-10 09:31:55 -08008453 payload_len = elsiocb->iocb.unsli3.rcvsli3.acc_len;
James Smart92d7f7b2007-06-17 19:56:38 -05008454 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05008455 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04008456 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05008457
James Smart858c9f62007-06-17 19:56:39 -05008458 did = icmd->un.rcvels.remoteID;
8459 if (icmd->ulpStatus) {
8460 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8461 "RCV Unsol ELS: status:x%x/x%x did:x%x",
8462 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05008463 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05008464 }
dea31012005-04-17 16:05:31 -05008465
8466 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05008467 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05008468 goto dropit;
dea31012005-04-17 16:05:31 -05008469
James Smartc8685952009-11-18 15:39:16 -05008470 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05008471 if (vport->load_flag & FC_UNLOADING)
8472 goto dropit;
8473
James Smart92494142011-02-16 12:39:44 -05008474 /* If NPort discovery is delayed drop incoming ELS */
8475 if ((vport->fc_flag & FC_DISC_DELAYED) &&
8476 (cmd != ELS_CMD_PLOGI))
8477 goto dropit;
8478
James Smart2e0fef82007-06-17 19:56:36 -05008479 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05008480 if (!ndlp) {
dea31012005-04-17 16:05:31 -05008481 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07008482 ndlp = lpfc_nlp_init(vport, did);
James Smarted957682007-06-17 19:56:37 -05008483 if (!ndlp)
dea31012005-04-17 16:05:31 -05008484 goto dropit;
James Smart98c9ea52007-10-27 13:37:33 -04008485 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05008486 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05008487 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05008488 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04008489 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
8490 ndlp = lpfc_enable_node(vport, ndlp,
8491 NLP_STE_UNUSED_NODE);
8492 if (!ndlp)
8493 goto dropit;
8494 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8495 newnode = 1;
8496 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
8497 ndlp->nlp_type |= NLP_FABRIC;
8498 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
8499 /* This is similar to the new node path */
8500 ndlp = lpfc_nlp_get(ndlp);
8501 if (!ndlp)
8502 goto dropit;
8503 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8504 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04008505 }
dea31012005-04-17 16:05:31 -05008506
8507 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05008508
James Smart12838e72014-09-03 12:57:19 -04008509 /*
8510 * Do not process any unsolicited ELS commands
8511 * if the ndlp is in DEV_LOSS
8512 */
James Smart466e8402015-05-21 13:55:28 -04008513 shost = lpfc_shost_from_vport(vport);
8514 spin_lock_irq(shost->host_lock);
8515 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
8516 spin_unlock_irq(shost->host_lock);
James Smart12838e72014-09-03 12:57:19 -04008517 goto dropit;
James Smart466e8402015-05-21 13:55:28 -04008518 }
8519 spin_unlock_irq(shost->host_lock);
James Smart12838e72014-09-03 12:57:19 -04008520
James Smart329f9bc2007-04-25 09:53:01 -04008521 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05008522 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05008523
8524 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
8525 cmd &= ELS_CMD_MASK;
8526 }
8527 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04008528 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8529 "0112 ELS command x%x received from NPORT x%x "
James Smarte74c03c2013-04-17 20:15:19 -04008530 "Data: x%x x%x x%x x%x\n",
8531 cmd, did, vport->port_state, vport->fc_flag,
8532 vport->fc_myDID, vport->fc_prevDID);
James Smarteec3d312015-08-31 16:48:18 -04008533
James Smart0a9e9682018-11-29 16:09:36 -08008534 /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */
James Smarteec3d312015-08-31 16:48:18 -04008535 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
James Smart0a9e9682018-11-29 16:09:36 -08008536 (cmd != ELS_CMD_FLOGI) &&
8537 !((cmd == ELS_CMD_PLOGI) && (vport->fc_flag & FC_PT2PT))) {
James Smart401304c2016-10-13 15:06:14 -07008538 rjt_err = LSRJT_LOGICAL_BSY;
James Smarteec3d312015-08-31 16:48:18 -04008539 rjt_exp = LSEXP_NOTHING_MORE;
8540 goto lsrjt;
8541 }
8542
dea31012005-04-17 16:05:31 -05008543 switch (cmd) {
8544 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05008545 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8546 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
8547 did, vport->port_state, ndlp->nlp_flag);
8548
dea31012005-04-17 16:05:31 -05008549 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05008550 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
James Smarte74c03c2013-04-17 20:15:19 -04008551 if (phba->sli_rev == LPFC_SLI_REV4 &&
8552 (phba->pport->fc_flag & FC_PT2PT)) {
8553 vport->fc_prevDID = vport->fc_myDID;
8554 /* Our DID needs to be updated before registering
8555 * the vfi. This is done in lpfc_rcv_plogi but
8556 * that is called after the reg_vfi.
8557 */
8558 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
8559 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8560 "3312 Remote port assigned DID x%x "
8561 "%x\n", vport->fc_myDID,
8562 vport->fc_prevDID);
8563 }
James Smart858c9f62007-06-17 19:56:39 -05008564
James Smartddcc50f2008-12-04 22:38:46 -05008565 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05008566
8567 /* If Nport discovery is delayed, reject PLOGIs */
8568 if (vport->fc_flag & FC_DISC_DELAYED) {
8569 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008570 rjt_exp = LSEXP_NOTHING_MORE;
James Smart92494142011-02-16 12:39:44 -05008571 break;
8572 }
James Smartd6de08c2015-12-16 18:11:53 -05008573
James Smart858c9f62007-06-17 19:56:39 -05008574 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05008575 if (!(phba->pport->fc_flag & FC_PT2PT) ||
8576 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
8577 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008578 rjt_exp = LSEXP_NOTHING_MORE;
James Smart1b32f6a2008-02-08 18:49:39 -05008579 break;
8580 }
dea31012005-04-17 16:05:31 -05008581 }
James Smart87af33f2007-10-27 13:37:43 -04008582
James Smart87af33f2007-10-27 13:37:43 -04008583 spin_lock_irq(shost->host_lock);
8584 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
8585 spin_unlock_irq(shost->host_lock);
8586
James Smart2e0fef82007-06-17 19:56:36 -05008587 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8588 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05008589
dea31012005-04-17 16:05:31 -05008590 break;
8591 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05008592 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8593 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
8594 did, vport->port_state, ndlp->nlp_flag);
8595
dea31012005-04-17 16:05:31 -05008596 phba->fc_stat.elsRcvFLOGI++;
James Smartd496b9a2018-10-23 13:41:08 -07008597
8598 /* If the driver believes fabric discovery is done and is ready,
8599 * bounce the link. There is some descrepancy.
8600 */
8601 if (vport->port_state >= LPFC_LOCAL_CFG_LINK &&
8602 vport->fc_flag & FC_PT2PT &&
8603 vport->rcv_flogi_cnt >= 1) {
8604 rjt_err = LSRJT_LOGICAL_BSY;
8605 rjt_exp = LSEXP_NOTHING_MORE;
8606 init_link++;
8607 goto lsrjt;
8608 }
8609
James Smart51ef4c22007-08-02 11:10:31 -04008610 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04008611 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008612 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05008613 break;
8614 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05008615 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8616 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
8617 did, vport->port_state, ndlp->nlp_flag);
8618
dea31012005-04-17 16:05:31 -05008619 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05008620 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05008621 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05008622 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008623 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008624 break;
8625 }
James Smart2e0fef82007-06-17 19:56:36 -05008626 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05008627 break;
8628 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05008629 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8630 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
8631 did, vport->port_state, ndlp->nlp_flag);
8632
dea31012005-04-17 16:05:31 -05008633 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05008634 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05008635 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05008636 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008637 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008638 break;
8639 }
James Smart2e0fef82007-06-17 19:56:36 -05008640 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05008641 break;
James Smart8b017a32015-05-21 13:55:18 -04008642 case ELS_CMD_LCB:
8643 phba->fc_stat.elsRcvLCB++;
8644 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
8645 break;
James Smart86478872015-05-21 13:55:21 -04008646 case ELS_CMD_RDP:
8647 phba->fc_stat.elsRcvRDP++;
8648 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
8649 break;
dea31012005-04-17 16:05:31 -05008650 case ELS_CMD_RSCN:
8651 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04008652 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04008653 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008654 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05008655 break;
8656 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05008657 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8658 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
8659 did, vport->port_state, ndlp->nlp_flag);
8660
James Smartddcc50f2008-12-04 22:38:46 -05008661 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05008662 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05008663 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05008664 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008665 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008666 break;
8667 }
James Smart2e0fef82007-06-17 19:56:36 -05008668 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8669 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05008670 break;
8671 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05008672 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8673 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
8674 did, vport->port_state, ndlp->nlp_flag);
8675
dea31012005-04-17 16:05:31 -05008676 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05008677 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05008678 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008679 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008680 break;
8681 }
James Smart2e0fef82007-06-17 19:56:36 -05008682 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8683 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05008684 break;
8685 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05008686 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8687 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
8688 did, vport->port_state, ndlp->nlp_flag);
8689
dea31012005-04-17 16:05:31 -05008690 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05008691 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05008692 break;
8693 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05008694 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8695 "RCV FARP: did:x%x/ste:x%x flg:x%x",
8696 did, vport->port_state, ndlp->nlp_flag);
8697
dea31012005-04-17 16:05:31 -05008698 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05008699 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05008700 break;
8701 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05008702 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8703 "RCV FAN: did:x%x/ste:x%x flg:x%x",
8704 did, vport->port_state, ndlp->nlp_flag);
8705
dea31012005-04-17 16:05:31 -05008706 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05008707 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05008708 break;
dea31012005-04-17 16:05:31 -05008709 case ELS_CMD_PRLI:
James Smarta0f2d3e2017-02-12 13:52:31 -08008710 case ELS_CMD_NVMEPRLI:
James Smart858c9f62007-06-17 19:56:39 -05008711 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8712 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
8713 did, vport->port_state, ndlp->nlp_flag);
8714
dea31012005-04-17 16:05:31 -05008715 phba->fc_stat.elsRcvPRLI++;
Dick Kennedya71e3cd2017-03-23 08:47:18 -04008716 if ((vport->port_state < LPFC_DISC_AUTH) &&
8717 (vport->fc_flag & FC_FABRIC)) {
James Smart858c9f62007-06-17 19:56:39 -05008718 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008719 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008720 break;
8721 }
James Smart2e0fef82007-06-17 19:56:36 -05008722 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05008723 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008724 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05008725 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8726 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
8727 did, vport->port_state, ndlp->nlp_flag);
8728
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008729 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05008730 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04008731 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008732 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008733 break;
James Smart12265f62010-10-22 11:05:53 -04008734 case ELS_CMD_RLS:
8735 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8736 "RCV RLS: did:x%x/ste:x%x flg:x%x",
8737 did, vport->port_state, ndlp->nlp_flag);
8738
8739 phba->fc_stat.elsRcvRLS++;
8740 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
8741 if (newnode)
8742 lpfc_nlp_put(ndlp);
8743 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008744 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05008745 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8746 "RCV RPL: did:x%x/ste:x%x flg:x%x",
8747 did, vport->port_state, ndlp->nlp_flag);
8748
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008749 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05008750 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04008751 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008752 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008753 break;
dea31012005-04-17 16:05:31 -05008754 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05008755 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8756 "RCV RNID: did:x%x/ste:x%x flg:x%x",
8757 did, vport->port_state, ndlp->nlp_flag);
8758
dea31012005-04-17 16:05:31 -05008759 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05008760 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04008761 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008762 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05008763 break;
James Smart12265f62010-10-22 11:05:53 -04008764 case ELS_CMD_RTV:
8765 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8766 "RCV RTV: did:x%x/ste:x%x flg:x%x",
8767 did, vport->port_state, ndlp->nlp_flag);
8768 phba->fc_stat.elsRcvRTV++;
8769 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
8770 if (newnode)
8771 lpfc_nlp_put(ndlp);
8772 break;
James Smart5ffc2662009-11-18 15:39:44 -05008773 case ELS_CMD_RRQ:
8774 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8775 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
8776 did, vport->port_state, ndlp->nlp_flag);
8777
8778 phba->fc_stat.elsRcvRRQ++;
8779 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
8780 if (newnode)
8781 lpfc_nlp_put(ndlp);
8782 break;
James Smart12265f62010-10-22 11:05:53 -04008783 case ELS_CMD_ECHO:
8784 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8785 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
8786 did, vport->port_state, ndlp->nlp_flag);
8787
8788 phba->fc_stat.elsRcvECHO++;
8789 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
8790 if (newnode)
8791 lpfc_nlp_put(ndlp);
8792 break;
James Smart303f2f92013-01-03 15:43:11 -05008793 case ELS_CMD_REC:
Colin Ian King8fd03fd2017-12-22 00:39:36 +00008794 /* receive this due to exchange closed */
8795 rjt_err = LSRJT_UNABLE_TPC;
8796 rjt_exp = LSEXP_INVALID_OX_RX;
James Smart303f2f92013-01-03 15:43:11 -05008797 break;
James Smart1a61e542019-04-05 16:04:23 -07008798 case ELS_CMD_FPIN:
James Smartdf3fe762020-02-10 09:31:55 -08008799 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8800 "RCV FPIN: did:x%x/ste:x%x flg:x%x",
8801 did, vport->port_state, ndlp->nlp_flag);
8802
8803 lpfc_els_rcv_fpin(vport, (struct fc_els_fpin *)payload,
8804 payload_len);
8805
8806 /* There are no replies, so no rjt codes */
James Smart1a61e542019-04-05 16:04:23 -07008807 break;
dea31012005-04-17 16:05:31 -05008808 default:
James Smart858c9f62007-06-17 19:56:39 -05008809 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8810 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
8811 cmd, did, vport->port_state);
8812
dea31012005-04-17 16:05:31 -05008813 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05008814 rjt_err = LSRJT_CMD_UNSUPPORTED;
James Smart303f2f92013-01-03 15:43:11 -05008815 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008816
8817 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04008818 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8819 "0115 Unknown ELS command x%x "
8820 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04008821 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008822 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05008823 break;
8824 }
8825
James Smarteec3d312015-08-31 16:48:18 -04008826lsrjt:
dea31012005-04-17 16:05:31 -05008827 /* check if need to LS_RJT received ELS cmd */
8828 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05008829 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05008830 stat.un.b.lsRjtRsnCode = rjt_err;
James Smart303f2f92013-01-03 15:43:11 -05008831 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
James Smart858c9f62007-06-17 19:56:39 -05008832 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
8833 NULL);
dea31012005-04-17 16:05:31 -05008834 }
8835
James Smartd7c255b2008-08-24 21:50:00 -04008836 lpfc_nlp_put(elsiocb->context1);
8837 elsiocb->context1 = NULL;
James Smartd496b9a2018-10-23 13:41:08 -07008838
8839 /* Special case. Driver received an unsolicited command that
8840 * unsupportable given the driver's current state. Reset the
8841 * link and start over.
8842 */
8843 if (init_link) {
8844 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8845 if (!mbox)
8846 return;
8847 lpfc_linkdown(phba);
8848 lpfc_init_link(phba, mbox,
8849 phba->cfg_topology,
8850 phba->cfg_link_speed);
8851 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
8852 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
8853 mbox->vport = vport;
8854 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
8855 MBX_NOT_FINISHED)
8856 mempool_free(mbox, phba->mbox_mem_pool);
8857 }
8858
James Smarted957682007-06-17 19:56:37 -05008859 return;
8860
8861dropit:
James Smart98c9ea52007-10-27 13:37:33 -04008862 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04008863 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8864 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05008865 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04008866 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05008867 phba->fc_stat.elsRcvDrop++;
8868}
8869
James Smarte59058c2008-08-24 21:49:00 -04008870/**
James Smart3621a712009-04-06 18:47:14 -04008871 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04008872 * @phba: pointer to lpfc hba data structure.
8873 * @pring: pointer to a SLI ring.
8874 * @elsiocb: pointer to lpfc els iocb data structure.
8875 *
8876 * This routine is used to process an unsolicited event received from a SLI
8877 * (Service Level Interface) ring. The actual processing of the data buffer
8878 * associated with the unsolicited event is done by invoking the routine
8879 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
8880 * SLI ring on which the unsolicited event was received.
8881 **/
James Smarted957682007-06-17 19:56:37 -05008882void
8883lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8884 struct lpfc_iocbq *elsiocb)
8885{
8886 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05008887 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05008888 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05008889 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
8890 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05008891
James Smartd7c255b2008-08-24 21:50:00 -04008892 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05008893 elsiocb->context2 = NULL;
8894 elsiocb->context3 = NULL;
8895
8896 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
8897 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
8898 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
James Smarte3d2b802012-08-14 14:25:43 -04008899 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
8900 IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05008901 phba->fc_stat.NoRcvBuf++;
8902 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05008903 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04008904 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05008905 return;
8906 }
8907
James Smart92d7f7b2007-06-17 19:56:38 -05008908 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
8909 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
8910 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
8911 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
8912 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04008913 else
8914 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04008915 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05008916 }
James Smart6d368e52011-05-24 11:44:12 -04008917
James Smart7f5f3d02008-02-08 18:50:14 -05008918 /* If there are no BDEs associated
8919 * with this IOCB, there is nothing to do.
8920 */
James Smarted957682007-06-17 19:56:37 -05008921 if (icmd->ulpBdeCount == 0)
8922 return;
8923
James Smart7f5f3d02008-02-08 18:50:14 -05008924 /* type of ELS cmd is first 32bit word
8925 * in packet
8926 */
James Smarted957682007-06-17 19:56:37 -05008927 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05008928 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05008929 } else {
8930 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
8931 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05008932 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
8933 paddr);
James Smarted957682007-06-17 19:56:37 -05008934 }
8935
James Smart92d7f7b2007-06-17 19:56:38 -05008936 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8937 /*
8938 * The different unsolicited event handlers would tell us
8939 * if they are done with "mp" by setting context2 to NULL.
8940 */
dea31012005-04-17 16:05:31 -05008941 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05008942 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
8943 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05008944 }
James Smarted957682007-06-17 19:56:37 -05008945
8946 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05008947 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05008948 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05008949 elsiocb->context2 = bdeBuf2;
8950 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05008951 /* free mp if we are done with it */
8952 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05008953 lpfc_in_buf_free(phba, elsiocb->context2);
8954 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05008955 }
dea31012005-04-17 16:05:31 -05008956 }
dea31012005-04-17 16:05:31 -05008957}
James Smart92d7f7b2007-06-17 19:56:38 -05008958
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08008959static void
James Smart4258e982015-12-16 18:11:58 -05008960lpfc_start_fdmi(struct lpfc_vport *vport)
8961{
James Smart4258e982015-12-16 18:11:58 -05008962 struct lpfc_nodelist *ndlp;
8963
8964 /* If this is the first time, allocate an ndlp and initialize
8965 * it. Otherwise, make sure the node is enabled and then do the
8966 * login.
8967 */
8968 ndlp = lpfc_findnode_did(vport, FDMI_DID);
8969 if (!ndlp) {
James Smart9d3d3402017-04-21 16:05:00 -07008970 ndlp = lpfc_nlp_init(vport, FDMI_DID);
James Smart4258e982015-12-16 18:11:58 -05008971 if (ndlp) {
James Smart4258e982015-12-16 18:11:58 -05008972 ndlp->nlp_type |= NLP_FABRIC;
8973 } else {
8974 return;
8975 }
8976 }
8977 if (!NLP_CHK_NODE_ACT(ndlp))
8978 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
8979
8980 if (ndlp) {
8981 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8982 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
8983 }
8984}
8985
James Smarte59058c2008-08-24 21:49:00 -04008986/**
James Smart3621a712009-04-06 18:47:14 -04008987 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04008988 * @phba: pointer to lpfc hba data structure.
8989 * @vport: pointer to a virtual N_Port data structure.
8990 *
8991 * This routine issues a Port Login (PLOGI) to the Name Server with
8992 * State Change Request (SCR) for a @vport. This routine will create an
8993 * ndlp for the Name Server associated to the @vport if such node does
8994 * not already exist. The PLOGI to Name Server is issued by invoking the
8995 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
8996 * (FDMI) is configured to the @vport, a FDMI node will be created and
8997 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
8998 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008999void
9000lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
9001{
James Smart4258e982015-12-16 18:11:58 -05009002 struct lpfc_nodelist *ndlp;
James Smart92494142011-02-16 12:39:44 -05009003 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9004
9005 /*
9006 * If lpfc_delay_discovery parameter is set and the clean address
9007 * bit is cleared and fc fabric parameters chenged, delay FC NPort
9008 * discovery.
9009 */
9010 spin_lock_irq(shost->host_lock);
9011 if (vport->fc_flag & FC_DISC_DELAYED) {
9012 spin_unlock_irq(shost->host_lock);
James Smart18775702013-04-17 20:19:25 -04009013 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
9014 "3334 Delay fc port discovery for %d seconds\n",
9015 phba->fc_ratov);
James Smart92494142011-02-16 12:39:44 -05009016 mod_timer(&vport->delayed_disc_tmo,
James Smart256ec0d2013-04-17 20:14:58 -04009017 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
James Smart92494142011-02-16 12:39:44 -05009018 return;
9019 }
9020 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05009021
9022 ndlp = lpfc_findnode_did(vport, NameServer_DID);
9023 if (!ndlp) {
James Smart9d3d3402017-04-21 16:05:00 -07009024 ndlp = lpfc_nlp_init(vport, NameServer_DID);
James Smart92d7f7b2007-06-17 19:56:38 -05009025 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05009026 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05009027 lpfc_disc_start(vport);
9028 return;
9029 }
9030 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04009031 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
9032 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05009033 return;
9034 }
James Smarte47c9092008-02-08 18:49:26 -05009035 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
9036 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
9037 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05009038 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05009039 lpfc_disc_start(vport);
9040 return;
9041 }
9042 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9043 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
9044 "0348 NameServer login: node freed\n");
9045 return;
9046 }
James Smart92d7f7b2007-06-17 19:56:38 -05009047 }
James Smart58da1ff2008-04-07 10:15:56 -04009048 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05009049
9050 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
9051
9052 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
9053 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04009054 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
9055 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05009056 return;
9057 }
9058
James Smart8663cbb2016-03-31 14:12:33 -07009059 if ((phba->cfg_enable_SmartSAN ||
9060 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
9061 (vport->load_flag & FC_ALLOW_FDMI))
James Smart4258e982015-12-16 18:11:58 -05009062 lpfc_start_fdmi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05009063}
9064
James Smarte59058c2008-08-24 21:49:00 -04009065/**
James Smart3621a712009-04-06 18:47:14 -04009066 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04009067 * @phba: pointer to lpfc hba data structure.
9068 * @pmb: pointer to the driver internal queue element for mailbox command.
9069 *
9070 * This routine is the completion callback function to register new vport
9071 * mailbox command. If the new vport mailbox command completes successfully,
9072 * the fabric registration login shall be performed on physical port (the
9073 * new vport created is actually a physical port, with VPI 0) or the port
9074 * login to Name Server for State Change Request (SCR) will be performed
9075 * on virtual port (real virtual port, with VPI greater than 0).
9076 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009077static void
9078lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
9079{
9080 struct lpfc_vport *vport = pmb->vport;
9081 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart3e1f0712018-11-29 16:09:29 -08009082 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smart04c68492009-05-22 14:52:52 -04009083 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05009084 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05009085
James Smart09372822008-01-11 01:52:54 -05009086 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05009087 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05009088 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05009089
9090 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04009091 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04009092 "0915 Register VPI failed : Status: x%x"
9093 " upd bit: x%x \n", mb->mbxStatus,
9094 mb->un.varRegVpi.upd);
9095 if (phba->sli_rev == LPFC_SLI_REV4 &&
9096 mb->un.varRegVpi.upd)
9097 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05009098
9099 switch (mb->mbxStatus) {
9100 case 0x11: /* unsupported feature */
9101 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05009102 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05009103 /* giving up on vport registration */
9104 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9105 spin_lock_irq(shost->host_lock);
9106 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
9107 spin_unlock_irq(shost->host_lock);
9108 lpfc_can_disctmo(vport);
9109 break;
James Smart695a8142010-01-26 23:08:03 -05009110 /* If reg_vpi fail with invalid VPI status, re-init VPI */
9111 case 0x20:
9112 spin_lock_irq(shost->host_lock);
9113 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9114 spin_unlock_irq(shost->host_lock);
9115 lpfc_init_vpi(phba, pmb, vport->vpi);
9116 pmb->vport = vport;
9117 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
9118 rc = lpfc_sli_issue_mbox(phba, pmb,
9119 MBX_NOWAIT);
9120 if (rc == MBX_NOT_FINISHED) {
9121 lpfc_printf_vlog(vport,
9122 KERN_ERR, LOG_MBOX,
9123 "2732 Failed to issue INIT_VPI"
9124 " mailbox command\n");
9125 } else {
9126 lpfc_nlp_put(ndlp);
9127 return;
9128 }
Bart Van Asschecd05c152019-03-28 11:06:18 -07009129 /* fall through */
James Smart92d7f7b2007-06-17 19:56:38 -05009130 default:
9131 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04009132 if (phba->sli_rev == LPFC_SLI_REV4)
9133 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05009134 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05009135 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05009136 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05009137 spin_unlock_irq(shost->host_lock);
James Smart5d181532017-03-04 09:30:25 -08009138 if (mb->mbxStatus == MBX_NOT_FINISHED)
9139 break;
9140 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
9141 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
9142 if (phba->sli_rev == LPFC_SLI_REV4)
9143 lpfc_issue_init_vfi(vport);
9144 else
9145 lpfc_initial_flogi(vport);
9146 } else {
James Smart7f5f3d02008-02-08 18:50:14 -05009147 lpfc_initial_fdisc(vport);
James Smart5d181532017-03-04 09:30:25 -08009148 }
James Smart92d7f7b2007-06-17 19:56:38 -05009149 break;
9150 }
James Smart92d7f7b2007-06-17 19:56:38 -05009151 } else {
James Smart695a8142010-01-26 23:08:03 -05009152 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05009153 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05009154 spin_unlock_irq(shost->host_lock);
9155 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04009156 if (phba->sli_rev < LPFC_SLI_REV4)
9157 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05009158 else {
James Smartfc2b9892010-02-26 14:15:29 -05009159 /*
9160 * If the physical port is instantiated using
9161 * FDISC, do not start vport discovery.
9162 */
9163 if (vport->port_state != LPFC_FDISC)
9164 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05009165 lpfc_do_scr_ns_plogi(phba, vport);
9166 }
9167 } else
James Smart92d7f7b2007-06-17 19:56:38 -05009168 lpfc_do_scr_ns_plogi(phba, vport);
9169 }
James Smart38b92ef2010-08-04 16:11:39 -04009170mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05009171 /* Now, we decrement the ndlp reference count held for this
9172 * callback function
9173 */
9174 lpfc_nlp_put(ndlp);
9175
James Smart92d7f7b2007-06-17 19:56:38 -05009176 mempool_free(pmb, phba->mbox_mem_pool);
9177 return;
9178}
9179
James Smarte59058c2008-08-24 21:49:00 -04009180/**
James Smart3621a712009-04-06 18:47:14 -04009181 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04009182 * @phba: pointer to lpfc hba data structure.
9183 * @vport: pointer to a host virtual N_Port data structure.
9184 * @ndlp: pointer to a node-list data structure.
9185 *
9186 * This routine registers the @vport as a new virtual port with a HBA.
9187 * It is done through a registering vpi mailbox command.
9188 **/
James Smart695a8142010-01-26 23:08:03 -05009189void
James Smart92d7f7b2007-06-17 19:56:38 -05009190lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
9191 struct lpfc_nodelist *ndlp)
9192{
James Smart09372822008-01-11 01:52:54 -05009193 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05009194 LPFC_MBOXQ_t *mbox;
9195
9196 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9197 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04009198 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05009199 mbox->vport = vport;
James Smart3e1f0712018-11-29 16:09:29 -08009200 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05009201 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04009202 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05009203 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05009204 /* mailbox command not success, decrement ndlp
9205 * reference count for this command
9206 */
9207 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05009208 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05009209
James Smarte8b62012007-08-02 11:10:09 -04009210 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
9211 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05009212 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05009213 }
9214 } else {
James Smarte8b62012007-08-02 11:10:09 -04009215 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
9216 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05009217 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05009218 }
James Smartfa4066b2008-01-11 01:53:27 -05009219 return;
9220
9221mbox_err_exit:
9222 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9223 spin_lock_irq(shost->host_lock);
9224 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
9225 spin_unlock_irq(shost->host_lock);
9226 return;
James Smart92d7f7b2007-06-17 19:56:38 -05009227}
9228
James Smarte59058c2008-08-24 21:49:00 -04009229/**
James Smart0c9ab6f2010-02-26 14:15:57 -05009230 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05009231 * @phba: pointer to lpfc hba data structure.
9232 *
James Smart0c9ab6f2010-02-26 14:15:57 -05009233 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05009234 **/
9235void
James Smart0c9ab6f2010-02-26 14:15:57 -05009236lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05009237{
9238 struct lpfc_vport **vports;
9239 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05009240 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05009241 int i;
James Smart695a8142010-01-26 23:08:03 -05009242
9243 /* Treat this failure as linkdown for all vports */
9244 link_state = phba->link_state;
9245 lpfc_linkdown(phba);
9246 phba->link_state = link_state;
9247
9248 vports = lpfc_create_vport_work_array(phba);
9249
9250 if (vports) {
9251 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9252 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
9253 if (ndlp)
9254 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
9255 lpfc_els_flush_cmd(vports[i]);
9256 }
9257 lpfc_destroy_vport_work_array(phba, vports);
9258 }
James Smart0c9ab6f2010-02-26 14:15:57 -05009259}
9260
9261/**
9262 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
9263 * @phba: pointer to lpfc hba data structure.
9264 *
9265 * This routine abort all pending discovery commands and
9266 * start a timer to retry FLOGI for the physical port
9267 * discovery.
9268 **/
9269void
9270lpfc_retry_pport_discovery(struct lpfc_hba *phba)
9271{
9272 struct lpfc_nodelist *ndlp;
9273 struct Scsi_Host *shost;
9274
9275 /* Cancel the all vports retry delay retry timers */
9276 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05009277
9278 /* If fabric require FLOGI, then re-instantiate physical login */
9279 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
9280 if (!ndlp)
9281 return;
9282
James Smart695a8142010-01-26 23:08:03 -05009283 shost = lpfc_shost_from_vport(phba->pport);
James Smart256ec0d2013-04-17 20:14:58 -04009284 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
James Smart695a8142010-01-26 23:08:03 -05009285 spin_lock_irq(shost->host_lock);
9286 ndlp->nlp_flag |= NLP_DELAY_TMO;
9287 spin_unlock_irq(shost->host_lock);
9288 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
9289 phba->pport->port_state = LPFC_FLOGI;
9290 return;
9291}
9292
9293/**
9294 * lpfc_fabric_login_reqd - Check if FLOGI required.
9295 * @phba: pointer to lpfc hba data structure.
9296 * @cmdiocb: pointer to FDISC command iocb.
9297 * @rspiocb: pointer to FDISC response iocb.
9298 *
9299 * This routine checks if a FLOGI is reguired for FDISC
9300 * to succeed.
9301 **/
9302static int
9303lpfc_fabric_login_reqd(struct lpfc_hba *phba,
9304 struct lpfc_iocbq *cmdiocb,
9305 struct lpfc_iocbq *rspiocb)
9306{
9307
9308 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
9309 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
9310 return 0;
9311 else
9312 return 1;
9313}
9314
9315/**
James Smart3621a712009-04-06 18:47:14 -04009316 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04009317 * @phba: pointer to lpfc hba data structure.
9318 * @cmdiocb: pointer to lpfc command iocb data structure.
9319 * @rspiocb: pointer to lpfc response iocb data structure.
9320 *
9321 * This routine is the completion callback function to a Fabric Discover
9322 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
9323 * single threaded, each FDISC completion callback function will reset
9324 * the discovery timer for all vports such that the timers will not get
9325 * unnecessary timeout. The function checks the FDISC IOCB status. If error
9326 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
9327 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
9328 * assigned to the vport has been changed with the completion of the FDISC
9329 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
9330 * are unregistered from the HBA, and then the lpfc_register_new_vport()
9331 * routine is invoked to register new vport with the HBA. Otherwise, the
9332 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
9333 * Server for State Change Request (SCR).
9334 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009335static void
9336lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9337 struct lpfc_iocbq *rspiocb)
9338{
9339 struct lpfc_vport *vport = cmdiocb->vport;
9340 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9341 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
9342 struct lpfc_nodelist *np;
9343 struct lpfc_nodelist *next_np;
9344 IOCB_t *irsp = &rspiocb->iocb;
9345 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05009346 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
9347 struct serv_parm *sp;
9348 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05009349
James Smarte8b62012007-08-02 11:10:09 -04009350 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9351 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
9352 irsp->ulpStatus, irsp->un.ulpWord[4],
9353 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05009354 /* Since all FDISCs are being single threaded, we
9355 * must reset the discovery timer for ALL vports
9356 * waiting to send FDISC when one completes.
9357 */
9358 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
9359 lpfc_set_disctmo(piocb->vport);
9360 }
9361
James Smart858c9f62007-06-17 19:56:39 -05009362 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9363 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
9364 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
9365
James Smart92d7f7b2007-06-17 19:56:38 -05009366 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05009367
9368 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
9369 lpfc_retry_pport_discovery(phba);
9370 goto out;
9371 }
9372
James Smart92d7f7b2007-06-17 19:56:38 -05009373 /* Check for retry */
9374 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
9375 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05009376 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04009377 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart6b5151f2012-01-18 16:24:06 -05009378 "0126 FDISC failed. (x%x/x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04009379 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04009380 goto fdisc_failed;
9381 }
James Smartd7c255b2008-08-24 21:50:00 -04009382 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05009383 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04009384 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04009385 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05009386 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04009387 vport->fc_flag |= FC_PUBLIC_LOOP;
9388 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05009389
James Smartd7c255b2008-08-24 21:50:00 -04009390 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
9391 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05009392 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04009393 if (!prsp)
9394 goto out;
James Smart92494142011-02-16 12:39:44 -05009395 sp = prsp->virt + sizeof(uint32_t);
9396 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
9397 memcpy(&vport->fabric_portname, &sp->portName,
9398 sizeof(struct lpfc_name));
9399 memcpy(&vport->fabric_nodename, &sp->nodeName,
9400 sizeof(struct lpfc_name));
9401 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04009402 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9403 /* If our NportID changed, we need to ensure all
9404 * remaining NPORTs get unreg_login'ed so we can
9405 * issue unreg_vpi.
9406 */
9407 list_for_each_entry_safe(np, next_np,
9408 &vport->fc_nodes, nlp_listp) {
9409 if (!NLP_CHK_NODE_ACT(ndlp) ||
9410 (np->nlp_state != NLP_STE_NPR_NODE) ||
9411 !(np->nlp_flag & NLP_NPR_ADISC))
9412 continue;
James Smart09372822008-01-11 01:52:54 -05009413 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04009414 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05009415 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04009416 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05009417 }
James Smart78730cf2010-04-06 15:06:30 -04009418 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04009419
9420 if (phba->sli_rev == LPFC_SLI_REV4)
9421 lpfc_sli4_unreg_all_rpis(vport);
9422
James Smartd7c255b2008-08-24 21:50:00 -04009423 lpfc_mbx_unreg_vpi(vport);
9424 spin_lock_irq(shost->host_lock);
9425 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05009426 if (phba->sli_rev == LPFC_SLI_REV4)
9427 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04009428 else
9429 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04009430 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04009431 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
9432 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9433 /*
9434 * Driver needs to re-reg VPI in order for f/w
9435 * to update the MAC address.
9436 */
9437 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04009438 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05009439 }
9440
James Smartecfd03c2010-02-12 14:41:27 -05009441 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
9442 lpfc_issue_init_vpi(vport);
9443 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04009444 lpfc_register_new_vport(phba, vport, ndlp);
9445 else
9446 lpfc_do_scr_ns_plogi(phba, vport);
9447 goto out;
9448fdisc_failed:
James Smart845d9e82017-05-15 15:20:38 -07009449 if (vport->fc_vport &&
9450 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
James Smartc84163d2015-05-21 13:55:22 -04009451 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smartd7c255b2008-08-24 21:50:00 -04009452 /* Cancel discovery timer */
9453 lpfc_can_disctmo(vport);
9454 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05009455out:
9456 lpfc_els_free_iocb(phba, cmdiocb);
9457}
9458
James Smarte59058c2008-08-24 21:49:00 -04009459/**
James Smart3621a712009-04-06 18:47:14 -04009460 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04009461 * @vport: pointer to a virtual N_Port data structure.
9462 * @ndlp: pointer to a node-list data structure.
9463 * @retry: number of retries to the command IOCB.
9464 *
9465 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
9466 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
9467 * routine to issue the IOCB, which makes sure only one outstanding fabric
9468 * IOCB will be sent off HBA at any given time.
9469 *
9470 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9471 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9472 * will be stored into the context1 field of the IOCB for the completion
9473 * callback function to the FDISC ELS command.
9474 *
9475 * Return code
9476 * 0 - Successfully issued fdisc iocb command
9477 * 1 - Failed to issue fdisc iocb command
9478 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01009479static int
James Smart92d7f7b2007-06-17 19:56:38 -05009480lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
9481 uint8_t retry)
9482{
9483 struct lpfc_hba *phba = vport->phba;
9484 IOCB_t *icmd;
9485 struct lpfc_iocbq *elsiocb;
9486 struct serv_parm *sp;
9487 uint8_t *pcmd;
9488 uint16_t cmdsize;
9489 int did = ndlp->nlp_DID;
9490 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05009491
James Smart5ffc2662009-11-18 15:39:44 -05009492 vport->port_state = LPFC_FDISC;
James Smart6b5151f2012-01-18 16:24:06 -05009493 vport->fc_myDID = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05009494 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
9495 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
9496 ELS_CMD_FDISC);
9497 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05009498 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04009499 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
9500 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05009501 return 1;
9502 }
9503
9504 icmd = &elsiocb->iocb;
9505 icmd->un.elsreq64.myID = 0;
9506 icmd->un.elsreq64.fl = 1;
9507
James Smart73d91e52011-10-10 21:32:10 -04009508 /*
9509 * SLI3 ports require a different context type value than SLI4.
9510 * Catch SLI3 ports here and override the prep.
9511 */
9512 if (phba->sli_rev == LPFC_SLI_REV3) {
James Smartf1126682009-06-10 17:22:44 -04009513 icmd->ulpCt_h = 1;
9514 icmd->ulpCt_l = 0;
9515 }
James Smart92d7f7b2007-06-17 19:56:38 -05009516
9517 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9518 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
9519 pcmd += sizeof(uint32_t); /* CSP Word 1 */
9520 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
9521 sp = (struct serv_parm *) pcmd;
9522 /* Setup CSPs accordingly for Fabric */
9523 sp->cmn.e_d_tov = 0;
9524 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05009525 sp->cmn.virtual_fabric_support = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05009526 sp->cls1.classValid = 0;
9527 sp->cls2.seqDelivery = 1;
9528 sp->cls3.seqDelivery = 1;
9529
9530 pcmd += sizeof(uint32_t); /* CSP Word 2 */
9531 pcmd += sizeof(uint32_t); /* CSP Word 3 */
9532 pcmd += sizeof(uint32_t); /* CSP Word 4 */
9533 pcmd += sizeof(uint32_t); /* Port Name */
9534 memcpy(pcmd, &vport->fc_portname, 8);
9535 pcmd += sizeof(uint32_t); /* Node Name */
9536 pcmd += sizeof(uint32_t); /* Node Name */
9537 memcpy(pcmd, &vport->fc_nodename, 8);
Dick Kennedy176de5b2017-08-23 16:55:40 -07009538 sp->cmn.valid_vendor_ver_level = 0;
James Smartaeb3c812017-04-21 16:05:02 -07009539 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
James Smart92d7f7b2007-06-17 19:56:38 -05009540 lpfc_set_disctmo(vport);
9541
9542 phba->fc_stat.elsXmitFDISC++;
9543 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
9544
James Smart858c9f62007-06-17 19:56:39 -05009545 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9546 "Issue FDISC: did:x%x",
9547 did, 0, 0);
9548
James Smart92d7f7b2007-06-17 19:56:38 -05009549 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
9550 if (rc == IOCB_ERROR) {
9551 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05009552 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04009553 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
9554 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05009555 return 1;
9556 }
9557 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05009558 return 0;
9559}
9560
James Smarte59058c2008-08-24 21:49:00 -04009561/**
James Smart3621a712009-04-06 18:47:14 -04009562 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04009563 * @phba: pointer to lpfc hba data structure.
9564 * @cmdiocb: pointer to lpfc command iocb data structure.
9565 * @rspiocb: pointer to lpfc response iocb data structure.
9566 *
9567 * This routine is the completion callback function to the issuing of a LOGO
9568 * ELS command off a vport. It frees the command IOCB and then decrement the
9569 * reference count held on ndlp for this completion function, indicating that
9570 * the reference to the ndlp is no long needed. Note that the
9571 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
9572 * callback function and an additional explicit ndlp reference decrementation
9573 * will trigger the actual release of the ndlp.
9574 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009575static void
9576lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9577 struct lpfc_iocbq *rspiocb)
9578{
9579 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05009580 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05009581 struct lpfc_nodelist *ndlp;
James Smart9589b0622011-04-16 11:03:17 -04009582 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05009583
James Smart9589b0622011-04-16 11:03:17 -04009584 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05009585 irsp = &rspiocb->iocb;
9586 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9587 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
9588 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05009589
9590 lpfc_els_free_iocb(phba, cmdiocb);
9591 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05009592
9593 /* Trigger the release of the ndlp after logo */
9594 lpfc_nlp_put(ndlp);
James Smart9589b0622011-04-16 11:03:17 -04009595
9596 /* NPIV LOGO completes to NPort <nlp_DID> */
9597 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9598 "2928 NPIV LOGO completes to NPort x%x "
9599 "Data: x%x x%x x%x x%x\n",
9600 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
9601 irsp->ulpTimeout, vport->num_disc_nodes);
9602
9603 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
9604 spin_lock_irq(shost->host_lock);
James Smart73dc0db2015-05-22 10:42:36 -04009605 vport->fc_flag &= ~FC_NDISC_ACTIVE;
James Smart9589b0622011-04-16 11:03:17 -04009606 vport->fc_flag &= ~FC_FABRIC;
9607 spin_unlock_irq(shost->host_lock);
James Smart73dc0db2015-05-22 10:42:36 -04009608 lpfc_can_disctmo(vport);
James Smart9589b0622011-04-16 11:03:17 -04009609 }
James Smart92d7f7b2007-06-17 19:56:38 -05009610}
9611
James Smarte59058c2008-08-24 21:49:00 -04009612/**
James Smart3621a712009-04-06 18:47:14 -04009613 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04009614 * @vport: pointer to a virtual N_Port data structure.
9615 * @ndlp: pointer to a node-list data structure.
9616 *
9617 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
9618 *
9619 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9620 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9621 * will be stored into the context1 field of the IOCB for the completion
9622 * callback function to the LOGO ELS command.
9623 *
9624 * Return codes
9625 * 0 - Successfully issued logo off the @vport
9626 * 1 - Failed to issue logo off the @vport
9627 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009628int
9629lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
9630{
9631 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9632 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05009633 struct lpfc_iocbq *elsiocb;
9634 uint8_t *pcmd;
9635 uint16_t cmdsize;
9636
9637 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
9638 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
9639 ELS_CMD_LOGO);
9640 if (!elsiocb)
9641 return 1;
9642
James Smart92d7f7b2007-06-17 19:56:38 -05009643 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9644 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
9645 pcmd += sizeof(uint32_t);
9646
9647 /* Fill in LOGO payload */
9648 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
9649 pcmd += sizeof(uint32_t);
9650 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
9651
James Smart858c9f62007-06-17 19:56:39 -05009652 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9653 "Issue LOGO npiv did:x%x flg:x%x",
9654 ndlp->nlp_DID, ndlp->nlp_flag, 0);
9655
James Smart92d7f7b2007-06-17 19:56:38 -05009656 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
9657 spin_lock_irq(shost->host_lock);
9658 ndlp->nlp_flag |= NLP_LOGO_SND;
9659 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04009660 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
9661 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05009662 spin_lock_irq(shost->host_lock);
9663 ndlp->nlp_flag &= ~NLP_LOGO_SND;
9664 spin_unlock_irq(shost->host_lock);
9665 lpfc_els_free_iocb(phba, elsiocb);
9666 return 1;
9667 }
9668 return 0;
9669}
9670
James Smarte59058c2008-08-24 21:49:00 -04009671/**
James Smart3621a712009-04-06 18:47:14 -04009672 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04009673 * @ptr: holder for the timer function associated data.
9674 *
9675 * This routine is invoked by the fabric iocb block timer after
9676 * timeout. It posts the fabric iocb block timeout event by setting the
9677 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
9678 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
9679 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
9680 * posted event WORKER_FABRIC_BLOCK_TMO.
9681 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009682void
Kees Cookf22eb4d2017-09-06 20:24:26 -07009683lpfc_fabric_block_timeout(struct timer_list *t)
James Smart92d7f7b2007-06-17 19:56:38 -05009684{
Kees Cookf22eb4d2017-09-06 20:24:26 -07009685 struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer);
James Smart92d7f7b2007-06-17 19:56:38 -05009686 unsigned long iflags;
9687 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04009688
James Smart92d7f7b2007-06-17 19:56:38 -05009689 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
9690 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
9691 if (!tmo_posted)
9692 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
9693 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
9694
James Smart5e9d9b82008-06-14 22:52:53 -04009695 if (!tmo_posted)
9696 lpfc_worker_wake_up(phba);
9697 return;
James Smart92d7f7b2007-06-17 19:56:38 -05009698}
9699
James Smarte59058c2008-08-24 21:49:00 -04009700/**
James Smart3621a712009-04-06 18:47:14 -04009701 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04009702 * @phba: pointer to lpfc hba data structure.
9703 *
9704 * This routine issues one fabric iocb from the driver internal list to
9705 * the HBA. It first checks whether it's ready to issue one fabric iocb to
9706 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
9707 * remove one pending fabric iocb from the driver internal list and invokes
9708 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
9709 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009710static void
9711lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
9712{
9713 struct lpfc_iocbq *iocb;
9714 unsigned long iflags;
9715 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05009716 IOCB_t *cmd;
9717
9718repeat:
9719 iocb = NULL;
9720 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05009721 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05009722 if (atomic_read(&phba->fabric_iocb_count) == 0) {
9723 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
9724 list);
9725 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05009726 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05009727 atomic_inc(&phba->fabric_iocb_count);
9728 }
9729 spin_unlock_irqrestore(&phba->hbalock, iflags);
9730 if (iocb) {
9731 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9732 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9733 iocb->iocb_flag |= LPFC_IO_FABRIC;
9734
James Smart858c9f62007-06-17 19:56:39 -05009735 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9736 "Fabric sched1: ste:x%x",
9737 iocb->vport->port_state, 0, 0);
9738
James Smart3772a992009-05-22 14:50:54 -04009739 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05009740
9741 if (ret == IOCB_ERROR) {
9742 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9743 iocb->fabric_iocb_cmpl = NULL;
9744 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9745 cmd = &iocb->iocb;
9746 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
9747 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
9748 iocb->iocb_cmpl(phba, iocb, iocb);
9749
9750 atomic_dec(&phba->fabric_iocb_count);
9751 goto repeat;
9752 }
9753 }
9754
9755 return;
9756}
9757
James Smarte59058c2008-08-24 21:49:00 -04009758/**
James Smart3621a712009-04-06 18:47:14 -04009759 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04009760 * @phba: pointer to lpfc hba data structure.
9761 *
9762 * This routine unblocks the issuing fabric iocb command. The function
9763 * will clear the fabric iocb block bit and then invoke the routine
9764 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
9765 * from the driver internal fabric iocb list.
9766 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009767void
9768lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
9769{
9770 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9771
9772 lpfc_resume_fabric_iocbs(phba);
9773 return;
9774}
9775
James Smarte59058c2008-08-24 21:49:00 -04009776/**
James Smart3621a712009-04-06 18:47:14 -04009777 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04009778 * @phba: pointer to lpfc hba data structure.
9779 *
9780 * This routine blocks the issuing fabric iocb for a specified amount of
9781 * time (currently 100 ms). This is done by set the fabric iocb block bit
9782 * and set up a timeout timer for 100ms. When the block bit is set, no more
9783 * fabric iocb will be issued out of the HBA.
9784 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009785static void
9786lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
9787{
9788 int blocked;
9789
9790 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05009791 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05009792 if (!blocked)
James Smart256ec0d2013-04-17 20:14:58 -04009793 mod_timer(&phba->fabric_block_timer,
9794 jiffies + msecs_to_jiffies(100));
James Smart92d7f7b2007-06-17 19:56:38 -05009795
9796 return;
9797}
9798
James Smarte59058c2008-08-24 21:49:00 -04009799/**
James Smart3621a712009-04-06 18:47:14 -04009800 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04009801 * @phba: pointer to lpfc hba data structure.
9802 * @cmdiocb: pointer to lpfc command iocb data structure.
9803 * @rspiocb: pointer to lpfc response iocb data structure.
9804 *
9805 * This routine is the callback function that is put to the fabric iocb's
9806 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
9807 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
9808 * function first restores and invokes the original iocb's callback function
9809 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
9810 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
9811 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009812static void
9813lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9814 struct lpfc_iocbq *rspiocb)
9815{
9816 struct ls_rjt stat;
9817
Shyam Sainie01ea5e2016-12-24 16:21:07 +05309818 BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
James Smart92d7f7b2007-06-17 19:56:38 -05009819
9820 switch (rspiocb->iocb.ulpStatus) {
9821 case IOSTAT_NPORT_RJT:
9822 case IOSTAT_FABRIC_RJT:
9823 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
9824 lpfc_block_fabric_iocbs(phba);
9825 }
9826 break;
9827
9828 case IOSTAT_NPORT_BSY:
9829 case IOSTAT_FABRIC_BSY:
9830 lpfc_block_fabric_iocbs(phba);
9831 break;
9832
9833 case IOSTAT_LS_RJT:
9834 stat.un.lsRjtError =
9835 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
9836 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
9837 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
9838 lpfc_block_fabric_iocbs(phba);
9839 break;
9840 }
9841
James Smarta0f2d3e2017-02-12 13:52:31 -08009842 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
James Smart92d7f7b2007-06-17 19:56:38 -05009843
9844 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
9845 cmdiocb->fabric_iocb_cmpl = NULL;
9846 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
9847 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
9848
9849 atomic_dec(&phba->fabric_iocb_count);
9850 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05009851 /* Post any pending iocbs to HBA */
9852 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05009853 }
9854}
9855
James Smarte59058c2008-08-24 21:49:00 -04009856/**
James Smart3621a712009-04-06 18:47:14 -04009857 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04009858 * @phba: pointer to lpfc hba data structure.
9859 * @iocb: pointer to lpfc command iocb data structure.
9860 *
9861 * This routine is used as the top-level API for issuing a fabric iocb command
9862 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
9863 * function makes sure that only one fabric bound iocb will be outstanding at
9864 * any given time. As such, this function will first check to see whether there
9865 * is already an outstanding fabric iocb on the wire. If so, it will put the
9866 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
9867 * issued later. Otherwise, it will issue the iocb on the wire and update the
9868 * fabric iocb count it indicate that there is one fabric iocb on the wire.
9869 *
9870 * Note, this implementation has a potential sending out fabric IOCBs out of
9871 * order. The problem is caused by the construction of the "ready" boolen does
9872 * not include the condition that the internal fabric IOCB list is empty. As
9873 * such, it is possible a fabric IOCB issued by this routine might be "jump"
9874 * ahead of the fabric IOCBs in the internal list.
9875 *
9876 * Return code
9877 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
9878 * IOCB_ERROR - failed to issue fabric iocb
9879 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01009880static int
James Smart92d7f7b2007-06-17 19:56:38 -05009881lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
9882{
9883 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05009884 int ready;
9885 int ret;
9886
James Smarta0f2d3e2017-02-12 13:52:31 -08009887 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
James Smart92d7f7b2007-06-17 19:56:38 -05009888
9889 spin_lock_irqsave(&phba->hbalock, iflags);
9890 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
9891 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9892
James Smart7f5f3d02008-02-08 18:50:14 -05009893 if (ready)
9894 /* Increment fabric iocb count to hold the position */
9895 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05009896 spin_unlock_irqrestore(&phba->hbalock, iflags);
9897 if (ready) {
9898 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9899 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9900 iocb->iocb_flag |= LPFC_IO_FABRIC;
9901
James Smart858c9f62007-06-17 19:56:39 -05009902 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9903 "Fabric sched2: ste:x%x",
9904 iocb->vport->port_state, 0, 0);
9905
James Smart3772a992009-05-22 14:50:54 -04009906 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05009907
9908 if (ret == IOCB_ERROR) {
9909 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9910 iocb->fabric_iocb_cmpl = NULL;
9911 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9912 atomic_dec(&phba->fabric_iocb_count);
9913 }
9914 } else {
9915 spin_lock_irqsave(&phba->hbalock, iflags);
9916 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
9917 spin_unlock_irqrestore(&phba->hbalock, iflags);
9918 ret = IOCB_SUCCESS;
9919 }
9920 return ret;
9921}
9922
James Smarte59058c2008-08-24 21:49:00 -04009923/**
James Smart3621a712009-04-06 18:47:14 -04009924 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04009925 * @vport: pointer to a virtual N_Port data structure.
9926 *
9927 * This routine aborts all the IOCBs associated with a @vport from the
9928 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9929 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9930 * list, removes each IOCB associated with the @vport off the list, set the
9931 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9932 * associated with the IOCB.
9933 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01009934static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05009935{
9936 LIST_HEAD(completions);
9937 struct lpfc_hba *phba = vport->phba;
9938 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05009939
9940 spin_lock_irq(&phba->hbalock);
9941 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9942 list) {
9943
9944 if (piocb->vport != vport)
9945 continue;
9946
9947 list_move_tail(&piocb->list, &completions);
9948 }
9949 spin_unlock_irq(&phba->hbalock);
9950
James Smarta257bf92009-04-06 18:48:10 -04009951 /* Cancel all the IOCBs from the completions list */
9952 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9953 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05009954}
9955
James Smarte59058c2008-08-24 21:49:00 -04009956/**
James Smart3621a712009-04-06 18:47:14 -04009957 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04009958 * @ndlp: pointer to a node-list data structure.
9959 *
9960 * This routine aborts all the IOCBs associated with an @ndlp from the
9961 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9962 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9963 * list, removes each IOCB associated with the @ndlp off the list, set the
9964 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9965 * associated with the IOCB.
9966 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009967void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
9968{
9969 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04009970 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05009971 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart895427b2017-02-12 13:52:30 -08009972 struct lpfc_sli_ring *pring;
9973
9974 pring = lpfc_phba_elsring(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05009975
Dick Kennedy1234a6d2017-09-29 17:34:29 -07009976 if (unlikely(!pring))
9977 return;
9978
James Smart92d7f7b2007-06-17 19:56:38 -05009979 spin_lock_irq(&phba->hbalock);
9980 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9981 list) {
9982 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
9983
9984 list_move_tail(&piocb->list, &completions);
9985 }
9986 }
9987 spin_unlock_irq(&phba->hbalock);
9988
James Smarta257bf92009-04-06 18:48:10 -04009989 /* Cancel all the IOCBs from the completions list */
9990 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9991 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05009992}
9993
James Smarte59058c2008-08-24 21:49:00 -04009994/**
James Smart3621a712009-04-06 18:47:14 -04009995 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04009996 * @phba: pointer to lpfc hba data structure.
9997 *
9998 * This routine aborts all the IOCBs currently on the driver internal
9999 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
10000 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
10001 * list, removes IOCBs off the list, set the status feild to
10002 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
10003 * the IOCB.
10004 **/
James Smart92d7f7b2007-06-17 19:56:38 -050010005void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
10006{
10007 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -050010008
10009 spin_lock_irq(&phba->hbalock);
10010 list_splice_init(&phba->fabric_iocb_list, &completions);
10011 spin_unlock_irq(&phba->hbalock);
10012
James Smarta257bf92009-04-06 18:48:10 -040010013 /* Cancel all the IOCBs from the completions list */
10014 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10015 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -050010016}
James Smart6fb120a2009-05-22 14:52:59 -040010017
10018/**
James Smart1151e3e2011-02-16 12:39:35 -050010019 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
10020 * @vport: pointer to lpfc vport data structure.
10021 *
10022 * This routine is invoked by the vport cleanup for deletions and the cleanup
10023 * for an ndlp on removal.
10024 **/
10025void
10026lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
10027{
10028 struct lpfc_hba *phba = vport->phba;
10029 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
10030 unsigned long iflag = 0;
10031
10032 spin_lock_irqsave(&phba->hbalock, iflag);
James Smart895427b2017-02-12 13:52:30 -080010033 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart1151e3e2011-02-16 12:39:35 -050010034 list_for_each_entry_safe(sglq_entry, sglq_next,
10035 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
10036 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
10037 sglq_entry->ndlp = NULL;
10038 }
James Smart895427b2017-02-12 13:52:30 -080010039 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart1151e3e2011-02-16 12:39:35 -050010040 spin_unlock_irqrestore(&phba->hbalock, iflag);
10041 return;
10042}
10043
10044/**
James Smart6fb120a2009-05-22 14:52:59 -040010045 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
10046 * @phba: pointer to lpfc hba data structure.
10047 * @axri: pointer to the els xri abort wcqe structure.
10048 *
10049 * This routine is invoked by the worker thread to process a SLI4 slow-path
10050 * ELS aborted xri.
10051 **/
10052void
10053lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
10054 struct sli4_wcqe_xri_aborted *axri)
10055{
10056 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -050010057 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -040010058 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -050010059
James Smart6fb120a2009-05-22 14:52:59 -040010060 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
10061 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -050010062 struct lpfc_nodelist *ndlp;
James Smart895427b2017-02-12 13:52:30 -080010063 struct lpfc_sli_ring *pring;
10064
10065 pring = lpfc_phba_elsring(phba);
James Smart6fb120a2009-05-22 14:52:59 -040010066
James Smart0f65ff62010-02-26 14:14:23 -050010067 spin_lock_irqsave(&phba->hbalock, iflag);
James Smart895427b2017-02-12 13:52:30 -080010068 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -040010069 list_for_each_entry_safe(sglq_entry, sglq_next,
10070 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
10071 if (sglq_entry->sli4_xritag == xri) {
10072 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -050010073 ndlp = sglq_entry->ndlp;
10074 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -040010075 list_add_tail(&sglq_entry->list,
James Smart895427b2017-02-12 13:52:30 -080010076 &phba->sli4_hba.lpfc_els_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -050010077 sglq_entry->state = SGL_FREED;
James Smart895427b2017-02-12 13:52:30 -080010078 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -040010079 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smartee0f4fe2012-05-09 21:19:14 -040010080 lpfc_set_rrq_active(phba, ndlp,
10081 sglq_entry->sli4_lxritag,
10082 rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -040010083
10084 /* Check if TXQ queue needs to be serviced */
Dick Kennedy1234a6d2017-09-29 17:34:29 -070010085 if (pring && !list_empty(&pring->txq))
James Smart589a52d2010-07-14 15:30:54 -040010086 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -040010087 return;
10088 }
10089 }
James Smart895427b2017-02-12 13:52:30 -080010090 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -040010091 lxri = lpfc_sli4_xri_inrange(phba, xri);
10092 if (lxri == NO_XRI) {
10093 spin_unlock_irqrestore(&phba->hbalock, iflag);
10094 return;
10095 }
James Smart895427b2017-02-12 13:52:30 -080010096 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -040010097 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -050010098 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
James Smart895427b2017-02-12 13:52:30 -080010099 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -050010100 spin_unlock_irqrestore(&phba->hbalock, iflag);
10101 return;
10102 }
10103 sglq_entry->state = SGL_XRI_ABORTED;
James Smart895427b2017-02-12 13:52:30 -080010104 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -050010105 spin_unlock_irqrestore(&phba->hbalock, iflag);
10106 return;
James Smart6fb120a2009-05-22 14:52:59 -040010107}
James Smart086a3452012-08-14 14:25:21 -040010108
10109/* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
10110 * @vport: pointer to virtual port object.
10111 * @ndlp: nodelist pointer for the impacted node.
10112 *
10113 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
10114 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
10115 * the driver is required to send a LOGO to the remote node before it
10116 * attempts to recover its login to the remote node.
10117 */
10118void
10119lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
10120 struct lpfc_nodelist *ndlp)
10121{
10122 struct Scsi_Host *shost;
10123 struct lpfc_hba *phba;
10124 unsigned long flags = 0;
10125
10126 shost = lpfc_shost_from_vport(vport);
10127 phba = vport->phba;
10128 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
10129 lpfc_printf_log(phba, KERN_INFO,
10130 LOG_SLI, "3093 No rport recovery needed. "
10131 "rport in state 0x%x\n", ndlp->nlp_state);
10132 return;
10133 }
James Smart30e196c2018-10-23 13:41:03 -070010134 lpfc_printf_log(phba, KERN_ERR,
10135 LOG_ELS | LOG_FCP_ERROR | LOG_NVME_IOERR,
James Smart086a3452012-08-14 14:25:21 -040010136 "3094 Start rport recovery on shost id 0x%x "
10137 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
10138 "flags 0x%x\n",
10139 shost->host_no, ndlp->nlp_DID,
10140 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
10141 ndlp->nlp_flag);
10142 /*
10143 * The rport is not responding. Remove the FCP-2 flag to prevent
10144 * an ADISC in the follow-up recovery code.
10145 */
10146 spin_lock_irqsave(shost->host_lock, flags);
10147 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
James Smart30e196c2018-10-23 13:41:03 -070010148 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
James Smart086a3452012-08-14 14:25:21 -040010149 spin_unlock_irqrestore(shost->host_lock, flags);
James Smart30e196c2018-10-23 13:41:03 -070010150 lpfc_unreg_rpi(vport, ndlp);
James Smart086a3452012-08-14 14:25:21 -040010151}
10152