blob: 6d84a10fef0791b8d70750192ffd63c8e9442de4 [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 Smart128bdda2018-01-30 15:59:03 -08004 * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term *
James Smartd080abe2017-02-12 13:52:39 -08005 * “Broadcom” refers to Broadcom Limited 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>
33
James Smartda0436e2009-05-22 14:51:39 -040034#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050035#include "lpfc_hw.h"
36#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040037#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040038#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050039#include "lpfc_disc.h"
40#include "lpfc_scsi.h"
41#include "lpfc.h"
42#include "lpfc_logmsg.h"
43#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050044#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050045#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050046
47static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
48 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050049static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
50 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010051static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
52static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
53 struct lpfc_nodelist *ndlp, uint8_t retry);
54static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
55 struct lpfc_iocbq *iocb);
James Smart92d7f7b2007-06-17 19:56:38 -050056
dea31012005-04-17 16:05:31 -050057static int lpfc_max_els_tries = 3;
58
James Smarte59058c2008-08-24 21:49:00 -040059/**
James Smart3621a712009-04-06 18:47:14 -040060 * lpfc_els_chk_latt - Check host link attention event for a vport
James Smarte59058c2008-08-24 21:49:00 -040061 * @vport: pointer to a host virtual N_Port data structure.
62 *
63 * This routine checks whether there is an outstanding host link
64 * attention event during the discovery process with the @vport. It is done
65 * by reading the HBA's Host Attention (HA) register. If there is any host
66 * link attention events during this @vport's discovery process, the @vport
67 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
68 * be issued if the link state is not already in host link cleared state,
69 * and a return code shall indicate whether the host link attention event
70 * had happened.
71 *
72 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
73 * state in LPFC_VPORT_READY, the request for checking host link attention
74 * event will be ignored and a return code shall indicate no host link
75 * attention event had happened.
76 *
77 * Return codes
78 * 0 - no host link attention event happened
79 * 1 - host link attention event happened
80 **/
James Smart858c9f62007-06-17 19:56:39 -050081int
James Smart2e0fef82007-06-17 19:56:36 -050082lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050083{
James Smart2e0fef82007-06-17 19:56:36 -050084 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
85 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050086 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050087
James Smart2e0fef82007-06-17 19:56:36 -050088 if (vport->port_state >= LPFC_VPORT_READY ||
James Smart3772a992009-05-22 14:50:54 -040089 phba->link_state == LPFC_LINK_DOWN ||
90 phba->sli_rev > LPFC_SLI_REV3)
dea31012005-04-17 16:05:31 -050091 return 0;
92
93 /* Read the HBA Host Attention Register */
James Smart9940b972011-03-11 16:06:12 -050094 if (lpfc_readl(phba->HAregaddr, &ha_copy))
95 return 1;
dea31012005-04-17 16:05:31 -050096
97 if (!(ha_copy & HA_LATT))
98 return 0;
99
100 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -0400101 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
102 "0237 Pending Link Event during "
103 "Discovery: State x%x\n",
104 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500105
106 /* CLEAR_LA should re-enable link attention events and
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300107 * we should then immediately take a LATT event. The
dea31012005-04-17 16:05:31 -0500108 * LATT processing should call lpfc_linkdown() which
109 * will cleanup any left over in-progress discovery
110 * events.
111 */
James Smart2e0fef82007-06-17 19:56:36 -0500112 spin_lock_irq(shost->host_lock);
113 vport->fc_flag |= FC_ABORT_DISCOVERY;
114 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500115
James Smart92d7f7b2007-06-17 19:56:38 -0500116 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500117 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500118
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500119 return 1;
dea31012005-04-17 16:05:31 -0500120}
121
James Smarte59058c2008-08-24 21:49:00 -0400122/**
James Smart3621a712009-04-06 18:47:14 -0400123 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400124 * @vport: pointer to a host virtual N_Port data structure.
125 * @expectRsp: flag indicating whether response is expected.
126 * @cmdSize: size of the ELS command.
127 * @retry: number of retries to the command IOCB when it fails.
128 * @ndlp: pointer to a node-list data structure.
129 * @did: destination identifier.
130 * @elscmd: the ELS command code.
131 *
132 * This routine is used for allocating a lpfc-IOCB data structure from
133 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
134 * passed into the routine for discovery state machine to issue an Extended
135 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
136 * and preparation routine that is used by all the discovery state machine
137 * routines and the ELS command-specific fields will be later set up by
138 * the individual discovery machine routines after calling this routine
139 * allocating and preparing a generic IOCB data structure. It fills in the
140 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
141 * payload and response payload (if expected). The reference count on the
142 * ndlp is incremented by 1 and the reference to the ndlp is put into
143 * context1 of the IOCB data structure for this IOCB to hold the ndlp
144 * reference for the command's callback function to access later.
145 *
146 * Return code
147 * Pointer to the newly allocated/prepared els iocb data structure
148 * NULL - when els iocb data structure allocation/preparation failed
149 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400150struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500151lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
152 uint16_t cmdSize, uint8_t retry,
153 struct lpfc_nodelist *ndlp, uint32_t did,
154 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500155{
James Smart2e0fef82007-06-17 19:56:36 -0500156 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400157 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500158 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
159 struct ulp_bde64 *bpl;
160 IOCB_t *icmd;
161
dea31012005-04-17 16:05:31 -0500162
James Smart2e0fef82007-06-17 19:56:36 -0500163 if (!lpfc_is_link_up(phba))
164 return NULL;
dea31012005-04-17 16:05:31 -0500165
dea31012005-04-17 16:05:31 -0500166 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400167 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500168
169 if (elsiocb == NULL)
170 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500171
James Smart0c287582009-06-10 17:22:56 -0400172 /*
173 * If this command is for fabric controller and HBA running
174 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
175 */
176 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400177 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400178 ((elscmd == ELS_CMD_FLOGI) ||
179 (elscmd == ELS_CMD_FDISC) ||
180 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500181 switch (elscmd) {
182 case ELS_CMD_FLOGI:
James Smartf0d9bcc2010-10-22 11:07:09 -0400183 elsiocb->iocb_flag |=
184 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500185 & LPFC_FIP_ELS_ID_MASK);
186 break;
187 case ELS_CMD_FDISC:
James Smartf0d9bcc2010-10-22 11:07:09 -0400188 elsiocb->iocb_flag |=
189 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500190 & LPFC_FIP_ELS_ID_MASK);
191 break;
192 case ELS_CMD_LOGO:
James Smartf0d9bcc2010-10-22 11:07:09 -0400193 elsiocb->iocb_flag |=
194 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500195 & LPFC_FIP_ELS_ID_MASK);
196 break;
197 }
James Smart0c287582009-06-10 17:22:56 -0400198 else
James Smartc8685952009-11-18 15:39:16 -0500199 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400200
dea31012005-04-17 16:05:31 -0500201 icmd = &elsiocb->iocb;
202
203 /* fill in BDEs for command */
204 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400205 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
206 if (pcmd)
207 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500208 if (!pcmd || !pcmd->virt)
209 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500210
211 INIT_LIST_HEAD(&pcmd->list);
212
213 /* Allocate buffer for response payload */
214 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500215 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500216 if (prsp)
217 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
218 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500219 if (!prsp || !prsp->virt)
220 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500221 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500222 } else
dea31012005-04-17 16:05:31 -0500223 prsp = NULL;
dea31012005-04-17 16:05:31 -0500224
225 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500226 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500227 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500228 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
229 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500230 if (!pbuflist || !pbuflist->virt)
231 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500232
233 INIT_LIST_HEAD(&pbuflist->list);
234
dea31012005-04-17 16:05:31 -0500235 if (expectRsp) {
James Smart939723a2012-05-09 21:19:03 -0400236 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
237 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
238 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart92d7f7b2007-06-17 19:56:38 -0500239 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
James Smart939723a2012-05-09 21:19:03 -0400240
241 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500242 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart88f43a02013-04-17 20:19:44 -0400243 if (elscmd == ELS_CMD_FLOGI)
244 icmd->ulpTimeout = FF_DEF_RATOV * 2;
245 else
246 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500247 } else {
James Smart939723a2012-05-09 21:19:03 -0400248 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
249 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
250 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
251 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
252 icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500253 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
254 }
dea31012005-04-17 16:05:31 -0500255 icmd->ulpBdeCount = 1;
256 icmd->ulpLe = 1;
257 icmd->ulpClass = CLASS3;
258
James Smart939723a2012-05-09 21:19:03 -0400259 /*
260 * If we have NPIV enabled, we want to send ELS traffic by VPI.
261 * For SLI4, since the driver controls VPIs we also want to include
262 * all ELS pt2pt protocol traffic as well.
263 */
264 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
265 ((phba->sli_rev == LPFC_SLI_REV4) &&
266 (vport->fc_flag & FC_PT2PT))) {
James Smart92d7f7b2007-06-17 19:56:38 -0500267
James Smart939723a2012-05-09 21:19:03 -0400268 if (expectRsp) {
269 icmd->un.elsreq64.myID = vport->fc_myDID;
270
271 /* For ELS_REQUEST64_CR, use the VPI by default */
272 icmd->ulpContext = phba->vpi_ids[vport->vpi];
273 }
274
James Smart92d7f7b2007-06-17 19:56:38 -0500275 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500276 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
277 if (elscmd == ELS_CMD_ECHO)
278 icmd->ulpCt_l = 0; /* context = invalid RPI */
279 else
280 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500281 }
282
dea31012005-04-17 16:05:31 -0500283 bpl = (struct ulp_bde64 *) pbuflist->virt;
284 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
285 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
286 bpl->tus.f.bdeSize = cmdSize;
287 bpl->tus.f.bdeFlags = 0;
288 bpl->tus.w = le32_to_cpu(bpl->tus.w);
289
290 if (expectRsp) {
291 bpl++;
292 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
293 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
294 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400295 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500296 bpl->tus.w = le32_to_cpu(bpl->tus.w);
297 }
298
James Smartfa4066b2008-01-11 01:53:27 -0500299 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400300 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500301 if (!elsiocb->context1)
302 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400303 elsiocb->context2 = pcmd;
304 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500305 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500306 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500307 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
308
309 if (prsp) {
310 list_add(&prsp->list, &pcmd->list);
311 }
dea31012005-04-17 16:05:31 -0500312 if (expectRsp) {
313 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400314 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
315 "0116 Xmit ELS command x%x to remote "
James Smarte74c03c2013-04-17 20:15:19 -0400316 "NPORT x%x I/O tag: x%x, port state:x%x"
317 " fc_flag:x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400318 elscmd, did, elsiocb->iotag,
James Smarte74c03c2013-04-17 20:15:19 -0400319 vport->port_state,
320 vport->fc_flag);
dea31012005-04-17 16:05:31 -0500321 } else {
322 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400323 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
324 "0117 Xmit ELS response x%x to remote "
James Smarte74c03c2013-04-17 20:15:19 -0400325 "NPORT x%x I/O tag: x%x, size: x%x "
326 "port_state x%x fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400327 elscmd, ndlp->nlp_DID, elsiocb->iotag,
James Smarte74c03c2013-04-17 20:15:19 -0400328 cmdSize, vport->port_state,
329 vport->fc_flag);
dea31012005-04-17 16:05:31 -0500330 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500331 return elsiocb;
dea31012005-04-17 16:05:31 -0500332
James Smartfa4066b2008-01-11 01:53:27 -0500333els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500334 if (expectRsp)
335 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500336 kfree(pbuflist);
337
338els_iocb_free_prsp_exit:
339 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
340 kfree(prsp);
341
342els_iocb_free_pcmb_exit:
343 kfree(pcmd);
344 lpfc_sli_release_iocbq(phba, elsiocb);
345 return NULL;
346}
dea31012005-04-17 16:05:31 -0500347
James Smarte59058c2008-08-24 21:49:00 -0400348/**
James Smart3621a712009-04-06 18:47:14 -0400349 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400350 * @vport: pointer to a host virtual N_Port data structure.
351 *
352 * This routine issues a fabric registration login for a @vport. An
353 * active ndlp node with Fabric_DID must already exist for this @vport.
354 * The routine invokes two mailbox commands to carry out fabric registration
355 * login through the HBA firmware: the first mailbox command requests the
356 * HBA to perform link configuration for the @vport; and the second mailbox
357 * command requests the HBA to perform the actual fabric registration login
358 * with the @vport.
359 *
360 * Return code
361 * 0 - successfully issued fabric registration login for @vport
362 * -ENXIO -- failed to issue fabric registration login for @vport
363 **/
James Smart3772a992009-05-22 14:50:54 -0400364int
James Smart92d7f7b2007-06-17 19:56:38 -0500365lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
366{
367 struct lpfc_hba *phba = vport->phba;
368 LPFC_MBOXQ_t *mbox;
369 struct lpfc_dmabuf *mp;
370 struct lpfc_nodelist *ndlp;
371 struct serv_parm *sp;
372 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400373 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500374
375 sp = &phba->fc_fabparam;
376 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500377 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400378 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500379 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400380 }
James Smart92d7f7b2007-06-17 19:56:38 -0500381
382 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400383 if (!mbox) {
384 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500385 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400386 }
James Smart92d7f7b2007-06-17 19:56:38 -0500387
388 vport->port_state = LPFC_FABRIC_CFG_LINK;
389 lpfc_config_link(phba, mbox);
390 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
391 mbox->vport = vport;
392
James Smart0b727fe2007-10-27 13:37:25 -0400393 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400394 if (rc == MBX_NOT_FINISHED) {
395 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500396 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400397 }
James Smart92d7f7b2007-06-17 19:56:38 -0500398
399 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400400 if (!mbox) {
401 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500402 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400403 }
James Smart40426292010-12-15 17:58:10 -0500404 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
405 ndlp->nlp_rpi);
James Smart98c9ea52007-10-27 13:37:33 -0400406 if (rc) {
407 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500408 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400409 }
James Smart92d7f7b2007-06-17 19:56:38 -0500410
411 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
412 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500413 /* increment the reference count on ndlp to hold reference
414 * for the callback routine.
415 */
James Smart92d7f7b2007-06-17 19:56:38 -0500416 mbox->context2 = lpfc_nlp_get(ndlp);
417
James Smart0b727fe2007-10-27 13:37:25 -0400418 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400419 if (rc == MBX_NOT_FINISHED) {
420 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500421 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400422 }
James Smart92d7f7b2007-06-17 19:56:38 -0500423
424 return 0;
425
426fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500427 /* decrement the reference count on ndlp just incremented
428 * for the failed mbox command.
429 */
James Smart92d7f7b2007-06-17 19:56:38 -0500430 lpfc_nlp_put(ndlp);
431 mp = (struct lpfc_dmabuf *) mbox->context1;
432 lpfc_mbuf_free(phba, mp->virt, mp->phys);
433 kfree(mp);
434fail_free_mbox:
435 mempool_free(mbox, phba->mbox_mem_pool);
436
437fail:
438 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400439 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400440 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500441 return -ENXIO;
442}
443
James Smarte59058c2008-08-24 21:49:00 -0400444/**
James Smart6fb120a2009-05-22 14:52:59 -0400445 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
446 * @vport: pointer to a host virtual N_Port data structure.
447 *
448 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
James Smart1b511972011-12-13 13:23:09 -0500449 * the @vport. This mailbox command is necessary for SLI4 port only.
James Smart6fb120a2009-05-22 14:52:59 -0400450 *
451 * Return code
452 * 0 - successfully issued REG_VFI for @vport
453 * A failure code otherwise.
454 **/
James Smart1b511972011-12-13 13:23:09 -0500455int
James Smart6fb120a2009-05-22 14:52:59 -0400456lpfc_issue_reg_vfi(struct lpfc_vport *vport)
457{
458 struct lpfc_hba *phba = vport->phba;
James Smartd6de08c2015-12-16 18:11:53 -0500459 LPFC_MBOXQ_t *mboxq = NULL;
James Smart6fb120a2009-05-22 14:52:59 -0400460 struct lpfc_nodelist *ndlp;
James Smartd6de08c2015-12-16 18:11:53 -0500461 struct lpfc_dmabuf *dmabuf = NULL;
James Smart6fb120a2009-05-22 14:52:59 -0400462 int rc = 0;
463
James Smart939723a2012-05-09 21:19:03 -0400464 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
James Smart1b511972011-12-13 13:23:09 -0500465 if ((phba->sli_rev == LPFC_SLI_REV4) &&
James Smart939723a2012-05-09 21:19:03 -0400466 !(phba->link_flag & LS_LOOPBACK_MODE) &&
467 !(vport->fc_flag & FC_PT2PT)) {
James Smart1b511972011-12-13 13:23:09 -0500468 ndlp = lpfc_findnode_did(vport, Fabric_DID);
469 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
470 rc = -ENODEV;
471 goto fail;
472 }
James Smart6fb120a2009-05-22 14:52:59 -0400473 }
474
James Smart6fb120a2009-05-22 14:52:59 -0400475 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
476 if (!mboxq) {
477 rc = -ENOMEM;
James Smartd6de08c2015-12-16 18:11:53 -0500478 goto fail;
James Smart6fb120a2009-05-22 14:52:59 -0400479 }
James Smartd6de08c2015-12-16 18:11:53 -0500480
481 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
482 if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
483 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
484 if (!dmabuf) {
485 rc = -ENOMEM;
486 goto fail;
487 }
488 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
489 if (!dmabuf->virt) {
490 rc = -ENOMEM;
491 goto fail;
492 }
493 memcpy(dmabuf->virt, &phba->fc_fabparam,
494 sizeof(struct serv_parm));
495 }
496
James Smart6fb120a2009-05-22 14:52:59 -0400497 vport->port_state = LPFC_FABRIC_CFG_LINK;
James Smartd6de08c2015-12-16 18:11:53 -0500498 if (dmabuf)
499 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
500 else
501 lpfc_reg_vfi(mboxq, vport, 0);
James Smartae05ebe2013-03-01 16:35:38 -0500502
James Smart6fb120a2009-05-22 14:52:59 -0400503 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
504 mboxq->vport = vport;
505 mboxq->context1 = dmabuf;
506 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
507 if (rc == MBX_NOT_FINISHED) {
508 rc = -ENXIO;
James Smartd6de08c2015-12-16 18:11:53 -0500509 goto fail;
James Smart6fb120a2009-05-22 14:52:59 -0400510 }
511 return 0;
512
James Smart6fb120a2009-05-22 14:52:59 -0400513fail:
James Smartd6de08c2015-12-16 18:11:53 -0500514 if (mboxq)
515 mempool_free(mboxq, phba->mbox_mem_pool);
516 if (dmabuf) {
517 if (dmabuf->virt)
518 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
519 kfree(dmabuf);
520 }
521
James Smart6fb120a2009-05-22 14:52:59 -0400522 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
523 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
524 "0289 Issue Register VFI failed: Err %d\n", rc);
525 return rc;
526}
527
528/**
James Smart1b511972011-12-13 13:23:09 -0500529 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
530 * @vport: pointer to a host virtual N_Port data structure.
531 *
532 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
533 * the @vport. This mailbox command is necessary for SLI4 port only.
534 *
535 * Return code
536 * 0 - successfully issued REG_VFI for @vport
537 * A failure code otherwise.
538 **/
539int
540lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
541{
542 struct lpfc_hba *phba = vport->phba;
543 struct Scsi_Host *shost;
544 LPFC_MBOXQ_t *mboxq;
545 int rc;
546
547 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
548 if (!mboxq) {
549 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
550 "2556 UNREG_VFI mbox allocation failed"
551 "HBA state x%x\n", phba->pport->port_state);
552 return -ENOMEM;
553 }
554
555 lpfc_unreg_vfi(mboxq, vport);
556 mboxq->vport = vport;
557 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
558
559 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
560 if (rc == MBX_NOT_FINISHED) {
561 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
562 "2557 UNREG_VFI issue mbox failed rc x%x "
563 "HBA state x%x\n",
564 rc, phba->pport->port_state);
565 mempool_free(mboxq, phba->mbox_mem_pool);
566 return -EIO;
567 }
568
569 shost = lpfc_shost_from_vport(vport);
570 spin_lock_irq(shost->host_lock);
571 vport->fc_flag &= ~FC_VFI_REGISTERED;
572 spin_unlock_irq(shost->host_lock);
573 return 0;
574}
575
576/**
James Smart92494142011-02-16 12:39:44 -0500577 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
578 * @vport: pointer to a host virtual N_Port data structure.
579 * @sp: pointer to service parameter data structure.
580 *
581 * This routine is called from FLOGI/FDISC completion handler functions.
582 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
583 * node nodename is changed in the completion service parameter else return
584 * 0. This function also set flag in the vport data structure to delay
585 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
586 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
587 * node nodename is changed in the completion service parameter.
588 *
589 * Return code
590 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
591 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
592 *
593 **/
594static uint8_t
595lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
596 struct serv_parm *sp)
597{
James Smart8eb8b962016-07-06 12:36:08 -0700598 struct lpfc_hba *phba = vport->phba;
James Smart92494142011-02-16 12:39:44 -0500599 uint8_t fabric_param_changed = 0;
600 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
601
602 if ((vport->fc_prevDID != vport->fc_myDID) ||
603 memcmp(&vport->fabric_portname, &sp->portName,
604 sizeof(struct lpfc_name)) ||
605 memcmp(&vport->fabric_nodename, &sp->nodeName,
James Smartaeb3c812017-04-21 16:05:02 -0700606 sizeof(struct lpfc_name)) ||
607 (vport->vport_flag & FAWWPN_PARAM_CHG)) {
James Smart92494142011-02-16 12:39:44 -0500608 fabric_param_changed = 1;
James Smartaeb3c812017-04-21 16:05:02 -0700609 vport->vport_flag &= ~FAWWPN_PARAM_CHG;
610 }
James Smart92494142011-02-16 12:39:44 -0500611 /*
612 * Word 1 Bit 31 in common service parameter is overloaded.
613 * Word 1 Bit 31 in FLOGI request is multiple NPort request
614 * Word 1 Bit 31 in FLOGI response is clean address bit
615 *
616 * If fabric parameter is changed and clean address bit is
617 * cleared delay nport discovery if
618 * - vport->fc_prevDID != 0 (not initial discovery) OR
619 * - lpfc_delay_discovery module parameter is set.
620 */
621 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
James Smart8eb8b962016-07-06 12:36:08 -0700622 (vport->fc_prevDID || phba->cfg_delay_discovery)) {
James Smart92494142011-02-16 12:39:44 -0500623 spin_lock_irq(shost->host_lock);
624 vport->fc_flag |= FC_DISC_DELAYED;
625 spin_unlock_irq(shost->host_lock);
626 }
627
628 return fabric_param_changed;
629}
630
631
632/**
James Smart3621a712009-04-06 18:47:14 -0400633 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400634 * @vport: pointer to a host virtual N_Port data structure.
635 * @ndlp: pointer to a node-list data structure.
636 * @sp: pointer to service parameter data structure.
637 * @irsp: pointer to the IOCB within the lpfc response IOCB.
638 *
639 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
640 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
641 * port in a fabric topology. It properly sets up the parameters to the @ndlp
642 * from the IOCB response. It also check the newly assigned N_Port ID to the
643 * @vport against the previously assigned N_Port ID. If it is different from
644 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
645 * is invoked on all the remaining nodes with the @vport to unregister the
646 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
647 * is invoked to register login to the fabric.
648 *
649 * Return code
650 * 0 - Success (currently, always return 0)
651 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500652static int
James Smart2e0fef82007-06-17 19:56:36 -0500653lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
654 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500655{
James Smart2e0fef82007-06-17 19:56:36 -0500656 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
657 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500658 struct lpfc_nodelist *np;
659 struct lpfc_nodelist *next_np;
James Smart92494142011-02-16 12:39:44 -0500660 uint8_t fabric_param_changed;
dea31012005-04-17 16:05:31 -0500661
James Smart2e0fef82007-06-17 19:56:36 -0500662 spin_lock_irq(shost->host_lock);
663 vport->fc_flag |= FC_FABRIC;
664 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500665
666 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
667 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
668 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
669
James Smart12265f62010-10-22 11:05:53 -0400670 phba->fc_edtovResol = sp->cmn.edtovResolution;
dea31012005-04-17 16:05:31 -0500671 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
672
James Smart76a95d72010-11-20 23:11:48 -0500673 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500674 spin_lock_irq(shost->host_lock);
675 vport->fc_flag |= FC_PUBLIC_LOOP;
676 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500677 }
678
James Smart2e0fef82007-06-17 19:56:36 -0500679 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500680 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500681 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500682 ndlp->nlp_class_sup = 0;
683 if (sp->cls1.classValid)
684 ndlp->nlp_class_sup |= FC_COS_CLASS1;
685 if (sp->cls2.classValid)
686 ndlp->nlp_class_sup |= FC_COS_CLASS2;
687 if (sp->cls3.classValid)
688 ndlp->nlp_class_sup |= FC_COS_CLASS3;
689 if (sp->cls4.classValid)
690 ndlp->nlp_class_sup |= FC_COS_CLASS4;
691 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
692 sp->cmn.bbRcvSizeLsb;
James Smart92494142011-02-16 12:39:44 -0500693
694 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
James Smart4258e982015-12-16 18:11:58 -0500695 if (fabric_param_changed) {
696 /* Reset FDMI attribute masks based on config parameter */
James Smart8663cbb2016-03-31 14:12:33 -0700697 if (phba->cfg_enable_SmartSAN ||
698 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
James Smart4258e982015-12-16 18:11:58 -0500699 /* Setup appropriate attribute masks */
700 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -0700701 if (phba->cfg_enable_SmartSAN)
James Smart4258e982015-12-16 18:11:58 -0500702 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
703 else
704 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -0700705 } else {
706 vport->fdmi_hba_mask = 0;
707 vport->fdmi_port_mask = 0;
James Smart4258e982015-12-16 18:11:58 -0500708 }
709
710 }
James Smart92494142011-02-16 12:39:44 -0500711 memcpy(&vport->fabric_portname, &sp->portName,
712 sizeof(struct lpfc_name));
713 memcpy(&vport->fabric_nodename, &sp->nodeName,
714 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500715 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
716
James Smart92d7f7b2007-06-17 19:56:38 -0500717 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
718 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400719 lpfc_printf_vlog(vport, KERN_WARNING,
720 LOG_ELS | LOG_VPORT,
721 "1816 FLOGI NPIV supported, "
722 "response data 0x%x\n",
723 sp->cmn.response_multiple_NPort);
James Smart1b511972011-12-13 13:23:09 -0500724 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500725 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500726 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500727 } else {
728 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400729 to call reg_vnpid atleast for the physcial host */
730 lpfc_printf_vlog(vport, KERN_WARNING,
731 LOG_ELS | LOG_VPORT,
732 "1817 Fabric does not support NPIV "
733 "- configuring single port mode.\n");
James Smart1b511972011-12-13 13:23:09 -0500734 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500735 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500736 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500737 }
738 }
739
James Smartae05ebe2013-03-01 16:35:38 -0500740 /*
741 * For FC we need to do some special processing because of the SLI
742 * Port's default settings of the Common Service Parameters.
743 */
James Smartd6de08c2015-12-16 18:11:53 -0500744 if ((phba->sli_rev == LPFC_SLI_REV4) &&
745 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
James Smartae05ebe2013-03-01 16:35:38 -0500746 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
James Smartd6de08c2015-12-16 18:11:53 -0500747 if (fabric_param_changed)
James Smartae05ebe2013-03-01 16:35:38 -0500748 lpfc_unregister_fcf_prep(phba);
749
750 /* This should just update the VFI CSPs*/
751 if (vport->fc_flag & FC_VFI_REGISTERED)
752 lpfc_issue_reg_vfi(vport);
753 }
754
James Smart92494142011-02-16 12:39:44 -0500755 if (fabric_param_changed &&
James Smart92d7f7b2007-06-17 19:56:38 -0500756 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
757
758 /* If our NportID changed, we need to ensure all
759 * remaining NPORTs get unreg_login'ed.
760 */
761 list_for_each_entry_safe(np, next_np,
762 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400763 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500764 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500765 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
766 !(np->nlp_flag & NLP_NPR_ADISC))
767 continue;
768 spin_lock_irq(shost->host_lock);
769 np->nlp_flag &= ~NLP_NPR_ADISC;
770 spin_unlock_irq(shost->host_lock);
771 lpfc_unreg_rpi(vport, np);
772 }
James Smart78730cf2010-04-06 15:06:30 -0400773 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -0400774
James Smart5248a742011-07-22 18:37:06 -0400775 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart5af5eee2010-10-22 11:06:38 -0400776 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500777 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500778 spin_lock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -0500779 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
780 spin_unlock_irq(shost->host_lock);
781 }
James Smart27aa1b72012-05-09 21:18:49 -0400782
783 /*
784 * For SLI3 and SLI4, the VPI needs to be reregistered in
785 * response to this fabric parameter change event.
786 */
787 spin_lock_irq(shost->host_lock);
788 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
789 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -0400790 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
791 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
792 /*
793 * Driver needs to re-reg VPI in order for f/w
794 * to update the MAC address.
795 */
James Smart9589b0622011-04-16 11:03:17 -0400796 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart38b92ef2010-08-04 16:11:39 -0400797 lpfc_register_new_vport(phba, vport, ndlp);
798 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500799 }
800
James Smart6fb120a2009-05-22 14:52:59 -0400801 if (phba->sli_rev < LPFC_SLI_REV4) {
802 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
803 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
804 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
805 lpfc_register_new_vport(phba, vport, ndlp);
806 else
807 lpfc_issue_fabric_reglogin(vport);
808 } else {
809 ndlp->nlp_type |= NLP_FABRIC;
810 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500811 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
812 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400813 lpfc_start_fdiscs(phba);
814 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500815 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500816 lpfc_issue_init_vpi(vport);
James Smart1b511972011-12-13 13:23:09 -0500817 else {
818 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
819 "3135 Need register VFI: (x%x/%x)\n",
820 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -0400821 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -0500822 }
James Smart92d7f7b2007-06-17 19:56:38 -0500823 }
dea31012005-04-17 16:05:31 -0500824 return 0;
dea31012005-04-17 16:05:31 -0500825}
James Smart1b511972011-12-13 13:23:09 -0500826
James Smarte59058c2008-08-24 21:49:00 -0400827/**
James Smart3621a712009-04-06 18:47:14 -0400828 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400829 * @vport: pointer to a host virtual N_Port data structure.
830 * @ndlp: pointer to a node-list data structure.
831 * @sp: pointer to service parameter data structure.
832 *
833 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
834 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
835 * in a point-to-point topology. First, the @vport's N_Port Name is compared
836 * with the received N_Port Name: if the @vport's N_Port Name is greater than
837 * the received N_Port Name lexicographically, this node shall assign local
838 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
839 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
840 * this node shall just wait for the remote node to issue PLOGI and assign
841 * N_Port IDs.
842 *
843 * Return code
844 * 0 - Success
845 * -ENXIO - Fail
846 **/
dea31012005-04-17 16:05:31 -0500847static int
James Smart2e0fef82007-06-17 19:56:36 -0500848lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
849 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500850{
James Smart2e0fef82007-06-17 19:56:36 -0500851 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
852 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500853 LPFC_MBOXQ_t *mbox;
854 int rc;
855
James Smart2e0fef82007-06-17 19:56:36 -0500856 spin_lock_irq(shost->host_lock);
857 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
James Smartd6de08c2015-12-16 18:11:53 -0500858 vport->fc_flag |= FC_PT2PT;
James Smart2e0fef82007-06-17 19:56:36 -0500859 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500860
James Smartd33d0eb2017-11-20 16:00:34 -0800861 /* If we are pt2pt with another NPort, force NPIV off! */
862 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
863
James Smartd6de08c2015-12-16 18:11:53 -0500864 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
865 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
866 lpfc_unregister_fcf_prep(phba);
867
868 spin_lock_irq(shost->host_lock);
869 vport->fc_flag &= ~FC_VFI_REGISTERED;
870 spin_unlock_irq(shost->host_lock);
871 phba->fc_topology_changed = 0;
872 }
873
James Smart2e0fef82007-06-17 19:56:36 -0500874 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500875 sizeof(vport->fc_portname));
James Smart2eb68622012-09-29 11:32:27 -0400876
dea31012005-04-17 16:05:31 -0500877 if (rc >= 0) {
878 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500879 spin_lock_irq(shost->host_lock);
880 vport->fc_flag |= FC_PT2PT_PLOGI;
881 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500882
883 /*
James Smartd6de08c2015-12-16 18:11:53 -0500884 * N_Port ID cannot be 0, set our Id to LocalID
885 * the other side will be RemoteID.
dea31012005-04-17 16:05:31 -0500886 */
887
888 /* not equal */
889 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500890 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500891
James Smarte47c9092008-02-08 18:49:26 -0500892 /* Decrement ndlp reference count indicating that ndlp can be
893 * safely released when other references to it are done.
894 */
James Smart329f9bc2007-04-25 09:53:01 -0400895 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500896
James Smart2e0fef82007-06-17 19:56:36 -0500897 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500898 if (!ndlp) {
899 /*
900 * Cannot find existing Fabric ndlp, so allocate a
901 * new one
902 */
James Smart9d3d3402017-04-21 16:05:00 -0700903 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500904 if (!ndlp)
905 goto fail;
James Smarte47c9092008-02-08 18:49:26 -0500906 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
907 ndlp = lpfc_enable_node(vport, ndlp,
908 NLP_STE_UNUSED_NODE);
909 if(!ndlp)
910 goto fail;
dea31012005-04-17 16:05:31 -0500911 }
912
913 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500914 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500915 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500916 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500917 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500918 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
919 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500920 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500921 spin_unlock_irq(shost->host_lock);
James Smartd33d0eb2017-11-20 16:00:34 -0800922
923 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
924 if (!mbox)
925 goto fail;
926
927 lpfc_config_link(phba, mbox);
928
929 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
930 mbox->vport = vport;
931 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
932 if (rc == MBX_NOT_FINISHED) {
933 mempool_free(mbox, phba->mbox_mem_pool);
934 goto fail;
935 }
936 } else {
James Smarte47c9092008-02-08 18:49:26 -0500937 /* This side will wait for the PLOGI, decrement ndlp reference
938 * count indicating that ndlp can be released when other
939 * references to it are done.
940 */
James Smart329f9bc2007-04-25 09:53:01 -0400941 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500942
James Smartd33d0eb2017-11-20 16:00:34 -0800943 /* Start discovery - this should just do CLEAR_LA */
944 lpfc_disc_start(vport);
James Smarte74c03c2013-04-17 20:15:19 -0400945 }
dea31012005-04-17 16:05:31 -0500946
dea31012005-04-17 16:05:31 -0500947 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500948fail:
dea31012005-04-17 16:05:31 -0500949 return -ENXIO;
950}
951
James Smarte59058c2008-08-24 21:49:00 -0400952/**
James Smart3621a712009-04-06 18:47:14 -0400953 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400954 * @phba: pointer to lpfc hba data structure.
955 * @cmdiocb: pointer to lpfc command iocb data structure.
956 * @rspiocb: pointer to lpfc response iocb data structure.
957 *
958 * This routine is the top-level completion callback function for issuing
959 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
960 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
961 * retry has been made (either immediately or delayed with lpfc_els_retry()
962 * returning 1), the command IOCB will be released and function returned.
963 * If the retry attempt has been given up (possibly reach the maximum
964 * number of retries), one additional decrement of ndlp reference shall be
965 * invoked before going out after releasing the command IOCB. This will
966 * actually release the remote node (Note, lpfc_els_free_iocb() will also
967 * invoke one decrement of ndlp reference count). If no error reported in
968 * the IOCB status, the command Port ID field is used to determine whether
969 * this is a point-to-point topology or a fabric topology: if the Port ID
970 * field is assigned, it is a fabric topology; otherwise, it is a
971 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
972 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
973 * specific topology completion conditions.
974 **/
dea31012005-04-17 16:05:31 -0500975static void
James Smart329f9bc2007-04-25 09:53:01 -0400976lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
977 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500978{
James Smart2e0fef82007-06-17 19:56:36 -0500979 struct lpfc_vport *vport = cmdiocb->vport;
980 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500981 IOCB_t *irsp = &rspiocb->iocb;
982 struct lpfc_nodelist *ndlp = cmdiocb->context1;
983 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
984 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500985 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500986 int rc;
987
988 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500989 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500990 /* One additional decrement on node reference count to
991 * trigger the release of the node
992 */
James Smart329f9bc2007-04-25 09:53:01 -0400993 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500994 goto out;
995 }
996
James Smart858c9f62007-06-17 19:56:39 -0500997 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
998 "FLOGI cmpl: status:x%x/x%x state:x%x",
999 irsp->ulpStatus, irsp->un.ulpWord[4],
1000 vport->port_state);
1001
dea31012005-04-17 16:05:31 -05001002 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -05001003 /*
James Smarta93ff372010-10-22 11:06:08 -04001004 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -05001005 * due to new FCF discovery
1006 */
1007 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart80c17842012-03-01 22:35:45 -05001008 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1009 if (phba->link_state < LPFC_LINK_UP)
1010 goto stop_rr_fcf_flogi;
1011 if ((phba->fcoe_cvl_eventtag_attn ==
1012 phba->fcoe_cvl_eventtag) &&
1013 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -04001014 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1015 IOERR_SLI_ABORTED))
James Smart80c17842012-03-01 22:35:45 -05001016 goto stop_rr_fcf_flogi;
1017 else
1018 phba->fcoe_cvl_eventtag_attn =
1019 phba->fcoe_cvl_eventtag;
James Smart0c9ab6f2010-02-26 14:15:57 -05001020 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001021 "2611 FLOGI failed on FCF (x%x), "
1022 "status:x%x/x%x, tmo:x%x, perform "
1023 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -04001024 phba->fcf.current_rec.fcf_indx,
1025 irsp->ulpStatus, irsp->un.ulpWord[4],
1026 irsp->ulpTimeout);
James Smart7d791df2011-07-22 18:37:52 -04001027 lpfc_sli4_set_fcf_flogi_fail(phba,
1028 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001029 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -04001030 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1031 if (rc)
1032 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001033 }
1034
James Smart80c17842012-03-01 22:35:45 -05001035stop_rr_fcf_flogi:
James Smart38b92ef2010-08-04 16:11:39 -04001036 /* FLOGI failure */
James Smartc73455e2017-11-20 16:00:28 -08001037 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1038 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1039 IOERR_LOOP_OPEN_FAILURE)))
1040 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1041 "2858 FLOGI failure Status:x%x/x%x "
1042 "TMO:x%x Data x%x x%x\n",
1043 irsp->ulpStatus, irsp->un.ulpWord[4],
1044 irsp->ulpTimeout, phba->hba_flag,
1045 phba->fcf.fcf_flag);
James Smart38b92ef2010-08-04 16:11:39 -04001046
dea31012005-04-17 16:05:31 -05001047 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001048 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001049 goto out;
James Smart2e0fef82007-06-17 19:56:36 -05001050
James Smartae9e28f2017-05-15 15:20:51 -07001051 /* If this is not a loop open failure, bail out */
1052 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1053 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1054 IOERR_LOOP_OPEN_FAILURE)))
1055 goto flogifail;
1056
James Smartc73455e2017-11-20 16:00:28 -08001057 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
1058 "0150 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1059 irsp->ulpStatus, irsp->un.ulpWord[4],
1060 irsp->ulpTimeout);
1061
dea31012005-04-17 16:05:31 -05001062 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -05001063 spin_lock_irq(shost->host_lock);
1064 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1065 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001066
James Smart329f9bc2007-04-25 09:53:01 -04001067 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -05001068 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1069 * alpa map would take too long otherwise.
1070 */
James Smart1b511972011-12-13 13:23:09 -05001071 if (phba->alpa_map[0] == 0)
James Smart3de2a652007-08-02 11:09:59 -04001072 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smartff78d8f2011-12-13 13:21:35 -05001073 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1074 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
James Smarte74c03c2013-04-17 20:15:19 -04001075 (vport->fc_prevDID != vport->fc_myDID) ||
1076 phba->fc_topology_changed)) {
1077 if (vport->fc_flag & FC_VFI_REGISTERED) {
1078 if (phba->fc_topology_changed) {
1079 lpfc_unregister_fcf_prep(phba);
1080 spin_lock_irq(shost->host_lock);
1081 vport->fc_flag &= ~FC_VFI_REGISTERED;
1082 spin_unlock_irq(shost->host_lock);
1083 phba->fc_topology_changed = 0;
1084 } else {
1085 lpfc_sli4_unreg_all_rpis(vport);
1086 }
1087 }
James Smart342b59c2016-03-31 14:12:31 -07001088
1089 /* Do not register VFI if the driver aborted FLOGI */
1090 if (!lpfc_error_lost_link(irsp))
1091 lpfc_issue_reg_vfi(vport);
James Smartff78d8f2011-12-13 13:21:35 -05001092 lpfc_nlp_put(ndlp);
1093 goto out;
dea31012005-04-17 16:05:31 -05001094 }
dea31012005-04-17 16:05:31 -05001095 goto flogifail;
1096 }
James Smart695a8142010-01-26 23:08:03 -05001097 spin_lock_irq(shost->host_lock);
1098 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04001099 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -05001100 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001101
1102 /*
1103 * The FLogI succeeded. Sync the data for the CPU before
1104 * accessing it.
1105 */
1106 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04001107 if (!prsp)
1108 goto out;
dea31012005-04-17 16:05:31 -05001109 sp = prsp->virt + sizeof(uint32_t);
1110
1111 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -04001112 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smart88f43a02013-04-17 20:19:44 -04001113 "0101 FLOGI completes successfully, I/O tag:x%x, "
1114 "Data: x%x x%x x%x x%x x%x x%x\n", cmdiocb->iotag,
James Smarte8b62012007-08-02 11:10:09 -04001115 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
James Smarte74c03c2013-04-17 20:15:19 -04001116 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1117 vport->port_state, vport->fc_flag);
dea31012005-04-17 16:05:31 -05001118
James Smart2e0fef82007-06-17 19:56:36 -05001119 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -05001120 /*
1121 * If Common Service Parameters indicate Nport
1122 * we are point to point, if Fport we are Fabric.
1123 */
1124 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -05001125 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -05001126 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001127 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -04001128 else {
1129 lpfc_printf_vlog(vport, KERN_ERR,
1130 LOG_FIP | LOG_ELS,
1131 "2831 FLOGI response with cleared Fabric "
1132 "bit fcf_index 0x%x "
1133 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1134 "Fabric Name "
1135 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1136 phba->fcf.current_rec.fcf_indx,
1137 phba->fcf.current_rec.switch_name[0],
1138 phba->fcf.current_rec.switch_name[1],
1139 phba->fcf.current_rec.switch_name[2],
1140 phba->fcf.current_rec.switch_name[3],
1141 phba->fcf.current_rec.switch_name[4],
1142 phba->fcf.current_rec.switch_name[5],
1143 phba->fcf.current_rec.switch_name[6],
1144 phba->fcf.current_rec.switch_name[7],
1145 phba->fcf.current_rec.fabric_name[0],
1146 phba->fcf.current_rec.fabric_name[1],
1147 phba->fcf.current_rec.fabric_name[2],
1148 phba->fcf.current_rec.fabric_name[3],
1149 phba->fcf.current_rec.fabric_name[4],
1150 phba->fcf.current_rec.fabric_name[5],
1151 phba->fcf.current_rec.fabric_name[6],
1152 phba->fcf.current_rec.fabric_name[7]);
1153 lpfc_nlp_put(ndlp);
1154 spin_lock_irq(&phba->hbalock);
1155 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001156 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -04001157 spin_unlock_irq(&phba->hbalock);
1158 goto out;
1159 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001160 if (!rc) {
1161 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -04001162 if (phba->hba_flag & HBA_FIP_SUPPORT)
1163 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1164 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001165 "2769 FLOGI to FCF (x%x) "
1166 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -04001167 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001168 spin_lock_irq(&phba->hbalock);
1169 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001170 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -05001171 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001172 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001173 }
dea31012005-04-17 16:05:31 -05001174 }
1175
1176flogifail:
James Smart8fe5c162015-08-31 16:48:19 -04001177 spin_lock_irq(&phba->hbalock);
1178 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1179 spin_unlock_irq(&phba->hbalock);
James Smartd6de08c2015-12-16 18:11:53 -05001180
James Smart329f9bc2007-04-25 09:53:01 -04001181 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001182
James Smart858c9f62007-06-17 19:56:39 -05001183 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001184 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001185 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001186
1187 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001188 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001189 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04001190 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1191 IOERR_SLI_ABORTED) &&
1192 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1193 IOERR_SLI_DOWN))) &&
James Smart87af33f2007-10-27 13:37:43 -04001194 (phba->link_state != LPFC_CLEAR_LA)) {
1195 /* If FLOGI failed enable link interrupt. */
1196 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001197 }
dea31012005-04-17 16:05:31 -05001198out:
1199 lpfc_els_free_iocb(phba, cmdiocb);
1200}
1201
James Smarte59058c2008-08-24 21:49:00 -04001202/**
James Smart3621a712009-04-06 18:47:14 -04001203 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001204 * @vport: pointer to a host virtual N_Port data structure.
1205 * @ndlp: pointer to a node-list data structure.
1206 * @retry: number of retries to the command IOCB.
1207 *
1208 * This routine issues a Fabric Login (FLOGI) Request ELS command
1209 * for a @vport. The initiator service parameters are put into the payload
1210 * of the FLOGI Request IOCB and the top-level callback function pointer
1211 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1212 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1213 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1214 *
1215 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1216 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1217 * will be stored into the context1 field of the IOCB for the completion
1218 * callback function to the FLOGI ELS command.
1219 *
1220 * Return code
1221 * 0 - successfully issued flogi iocb for @vport
1222 * 1 - failed to issue flogi iocb for @vport
1223 **/
dea31012005-04-17 16:05:31 -05001224static int
James Smart2e0fef82007-06-17 19:56:36 -05001225lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001226 uint8_t retry)
1227{
James Smart2e0fef82007-06-17 19:56:36 -05001228 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001229 struct serv_parm *sp;
1230 IOCB_t *icmd;
1231 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001232 uint8_t *pcmd;
1233 uint16_t cmdsize;
1234 uint32_t tmo;
1235 int rc;
1236
James Smart92d7f7b2007-06-17 19:56:38 -05001237 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001238 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1239 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001240
James Smart488d1462006-03-07 15:02:37 -05001241 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001242 return 1;
dea31012005-04-17 16:05:31 -05001243
1244 icmd = &elsiocb->iocb;
1245 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1246
1247 /* For FLOGI request, remainder of payload is service parameters */
1248 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001249 pcmd += sizeof(uint32_t);
1250 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001251 sp = (struct serv_parm *) pcmd;
1252
1253 /* Setup CSPs accordingly for Fabric */
1254 sp->cmn.e_d_tov = 0;
1255 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05001256 sp->cmn.virtual_fabric_support = 0;
dea31012005-04-17 16:05:31 -05001257 sp->cls1.classValid = 0;
dea31012005-04-17 16:05:31 -05001258 if (sp->cmn.fcphLow < FC_PH3)
1259 sp->cmn.fcphLow = FC_PH3;
1260 if (sp->cmn.fcphHigh < FC_PH3)
1261 sp->cmn.fcphHigh = FC_PH3;
1262
James Smartc31098c2011-04-16 11:03:33 -04001263 if (phba->sli_rev == LPFC_SLI_REV4) {
1264 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1265 LPFC_SLI_INTF_IF_TYPE_0) {
1266 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1267 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1268 /* FLOGI needs to be 3 for WQE FCFI */
1269 /* Set the fcfi to the fcfi we registered with */
1270 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1271 }
James Smart0f378872012-10-31 14:45:01 -04001272 /* Can't do SLI4 class2 without support sequence coalescing */
1273 sp->cls2.classValid = 0;
1274 sp->cls2.seqDelivery = 0;
James Smart5248a742011-07-22 18:37:06 -04001275 } else {
James Smart0f378872012-10-31 14:45:01 -04001276 /* Historical, setting sequential-delivery bit for SLI3 */
1277 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1278 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
James Smart5248a742011-07-22 18:37:06 -04001279 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1280 sp->cmn.request_multiple_Nport = 1;
1281 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1282 icmd->ulpCt_h = 1;
1283 icmd->ulpCt_l = 0;
1284 } else
1285 sp->cmn.request_multiple_Nport = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001286 }
1287
James Smart76a95d72010-11-20 23:11:48 -05001288 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001289 icmd->un.elsreq64.myID = 0;
1290 icmd->un.elsreq64.fl = 1;
1291 }
1292
dea31012005-04-17 16:05:31 -05001293 tmo = phba->fc_ratov;
1294 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001295 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001296 phba->fc_ratov = tmo;
1297
1298 phba->fc_stat.elsXmitFLOGI++;
1299 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001300
1301 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1302 "Issue FLOGI: opt:x%x",
1303 phba->sli3_options, 0, 0);
1304
James Smart92d7f7b2007-06-17 19:56:38 -05001305 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001306 if (rc == IOCB_ERROR) {
1307 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001308 return 1;
dea31012005-04-17 16:05:31 -05001309 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001310 return 0;
dea31012005-04-17 16:05:31 -05001311}
1312
James Smarte59058c2008-08-24 21:49:00 -04001313/**
James Smart3621a712009-04-06 18:47:14 -04001314 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001315 * @phba: pointer to lpfc hba data structure.
1316 *
1317 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1318 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1319 * list and issues an abort IOCB commond on each outstanding IOCB that
1320 * contains a active Fabric_DID ndlp. Note that this function is to issue
1321 * the abort IOCB command on all the outstanding IOCBs, thus when this
1322 * function returns, it does not guarantee all the IOCBs are actually aborted.
1323 *
1324 * Return code
Daniel Mack3ad2f3fb2010-02-03 08:01:28 +08001325 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001326 **/
dea31012005-04-17 16:05:31 -05001327int
James Smart2e0fef82007-06-17 19:56:36 -05001328lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001329{
1330 struct lpfc_sli_ring *pring;
1331 struct lpfc_iocbq *iocb, *next_iocb;
1332 struct lpfc_nodelist *ndlp;
1333 IOCB_t *icmd;
1334
1335 /* Abort outstanding I/O on NPort <nlp_DID> */
1336 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001337 "0201 Abort outstanding I/O on NPort x%x\n",
1338 Fabric_DID);
dea31012005-04-17 16:05:31 -05001339
James Smart895427b2017-02-12 13:52:30 -08001340 pring = lpfc_phba_elsring(phba);
dea31012005-04-17 16:05:31 -05001341
1342 /*
1343 * Check the txcmplq for an iocb that matches the nport the driver is
1344 * searching for.
1345 */
James Smart2e0fef82007-06-17 19:56:36 -05001346 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001347 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1348 icmd = &iocb->iocb;
James Smart1b511972011-12-13 13:23:09 -05001349 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
dea31012005-04-17 16:05:31 -05001350 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001351 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1352 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001353 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001354 }
1355 }
James Smart2e0fef82007-06-17 19:56:36 -05001356 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001357
1358 return 0;
1359}
1360
James Smarte59058c2008-08-24 21:49:00 -04001361/**
James Smart3621a712009-04-06 18:47:14 -04001362 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001363 * @vport: pointer to a host virtual N_Port data structure.
1364 *
1365 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1366 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1367 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1368 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1369 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1370 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1371 * @vport.
1372 *
1373 * Return code
1374 * 0 - failed to issue initial flogi for @vport
1375 * 1 - successfully issued initial flogi for @vport
1376 **/
dea31012005-04-17 16:05:31 -05001377int
James Smart2e0fef82007-06-17 19:56:36 -05001378lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001379{
1380 struct lpfc_nodelist *ndlp;
1381
James Smart98c9ea52007-10-27 13:37:33 -04001382 vport->port_state = LPFC_FLOGI;
1383 lpfc_set_disctmo(vport);
1384
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001385 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001386 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001387 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001388 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07001389 ndlp = lpfc_nlp_init(vport, Fabric_DID);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001390 if (!ndlp)
1391 return 0;
James Smart6fb120a2009-05-22 14:52:59 -04001392 /* Set the node type */
1393 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001394 /* Put ndlp onto node list */
1395 lpfc_enqueue_node(vport, ndlp);
1396 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1397 /* re-setup ndlp without removing from node list */
1398 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1399 if (!ndlp)
1400 return 0;
dea31012005-04-17 16:05:31 -05001401 }
James Smart87af33f2007-10-27 13:37:43 -04001402
James Smart5ac6b302010-10-22 11:05:36 -04001403 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001404 /* This decrement of reference count to node shall kick off
1405 * the release of the node.
1406 */
James Smart329f9bc2007-04-25 09:53:01 -04001407 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001408 return 0;
1409 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001410 return 1;
dea31012005-04-17 16:05:31 -05001411}
1412
James Smarte59058c2008-08-24 21:49:00 -04001413/**
James Smart3621a712009-04-06 18:47:14 -04001414 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001415 * @vport: pointer to a host virtual N_Port data structure.
1416 *
1417 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1418 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1419 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1420 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1421 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1422 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1423 * @vport.
1424 *
1425 * Return code
1426 * 0 - failed to issue initial fdisc for @vport
1427 * 1 - successfully issued initial fdisc for @vport
1428 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001429int
1430lpfc_initial_fdisc(struct lpfc_vport *vport)
1431{
James Smart92d7f7b2007-06-17 19:56:38 -05001432 struct lpfc_nodelist *ndlp;
1433
1434 /* First look for the Fabric ndlp */
1435 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1436 if (!ndlp) {
1437 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07001438 ndlp = lpfc_nlp_init(vport, Fabric_DID);
James Smart92d7f7b2007-06-17 19:56:38 -05001439 if (!ndlp)
1440 return 0;
James Smarte47c9092008-02-08 18:49:26 -05001441 /* Put ndlp onto node list */
1442 lpfc_enqueue_node(vport, ndlp);
1443 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1444 /* re-setup ndlp without removing from node list */
1445 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1446 if (!ndlp)
1447 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001448 }
James Smarte47c9092008-02-08 18:49:26 -05001449
James Smart92d7f7b2007-06-17 19:56:38 -05001450 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001451 /* decrement node reference count to trigger the release of
1452 * the node.
1453 */
James Smart92d7f7b2007-06-17 19:56:38 -05001454 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001455 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001456 }
1457 return 1;
1458}
James Smart87af33f2007-10-27 13:37:43 -04001459
James Smarte59058c2008-08-24 21:49:00 -04001460/**
James Smart3621a712009-04-06 18:47:14 -04001461 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001462 * @vport: pointer to a host virtual N_Port data structure.
1463 *
1464 * This routine checks whether there are more remaining Port Logins
1465 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1466 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1467 * to issue ELS PLOGIs up to the configured discover threads with the
1468 * @vport (@vport->cfg_discovery_threads). The function also decrement
1469 * the @vport's num_disc_node by 1 if it is not already 0.
1470 **/
James Smart87af33f2007-10-27 13:37:43 -04001471void
James Smart2e0fef82007-06-17 19:56:36 -05001472lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001473{
James Smart2e0fef82007-06-17 19:56:36 -05001474 if (vport->num_disc_nodes)
1475 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001476
1477 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001478 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1479 "0232 Continue discovery with %d PLOGIs to go "
1480 "Data: x%x x%x x%x\n",
1481 vport->num_disc_nodes, vport->fc_plogi_cnt,
1482 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001483 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001484 if (vport->fc_flag & FC_NLP_MORE)
1485 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -04001486 lpfc_els_disc_plogi(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001487
dea31012005-04-17 16:05:31 -05001488 return;
1489}
1490
James Smarte59058c2008-08-24 21:49:00 -04001491/**
James Smart3621a712009-04-06 18:47:14 -04001492 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001493 * @phba: pointer to lpfc hba data structure.
1494 * @prsp: pointer to response IOCB payload.
1495 * @ndlp: pointer to a node-list data structure.
1496 *
1497 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1498 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1499 * The following cases are considered N_Port confirmed:
1500 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1501 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1502 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1503 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1504 * 1) if there is a node on vport list other than the @ndlp with the same
1505 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1506 * on that node to release the RPI associated with the node; 2) if there is
1507 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1508 * into, a new node shall be allocated (or activated). In either case, the
1509 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1510 * be released and the new_ndlp shall be put on to the vport node list and
1511 * its pointer returned as the confirmed node.
1512 *
1513 * Note that before the @ndlp got "released", the keepDID from not-matching
1514 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1515 * of the @ndlp. This is because the release of @ndlp is actually to put it
1516 * into an inactive state on the vport node list and the vport node list
1517 * management algorithm does not allow two node with a same DID.
1518 *
1519 * Return code
1520 * pointer to the PLOGI N_Port @ndlp
1521 **/
James Smart488d1462006-03-07 15:02:37 -05001522static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001523lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001524 struct lpfc_nodelist *ndlp)
1525{
James Smarta0f2d3e2017-02-12 13:52:31 -08001526 struct lpfc_vport *vport = ndlp->vport;
James Smart953ceed2015-05-22 10:42:37 -04001527 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05001528 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001529 struct lpfc_rport_data *rdata;
1530 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001531 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001532 uint8_t name[sizeof(struct lpfc_name)];
James Smarte5abba42015-05-21 13:55:27 -04001533 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
James Smart953ceed2015-05-22 10:42:37 -04001534 uint16_t keep_nlp_state;
Dick Kennedy4adc0412017-08-23 16:55:37 -07001535 struct lpfc_nvme_rport *keep_nrport = NULL;
James Smart38b92ef2010-08-04 16:11:39 -04001536 int put_node;
1537 int put_rport;
James Smartcff261f2013-12-17 20:29:47 -05001538 unsigned long *active_rrqs_xri_bitmap = NULL;
James Smart488d1462006-03-07 15:02:37 -05001539
James Smart2fb9bd82006-12-02 13:33:57 -05001540 /* Fabric nodes can have the same WWPN so we don't bother searching
1541 * by WWPN. Just return the ndlp that was given to us.
1542 */
1543 if (ndlp->nlp_type & NLP_FABRIC)
1544 return ndlp;
1545
James Smart92d7f7b2007-06-17 19:56:38 -05001546 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001547 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001548
James Smart685f0bf2007-04-25 09:53:08 -04001549 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001550 * we have for that ndlp. If not, we have some work to do.
1551 */
James Smart2e0fef82007-06-17 19:56:36 -05001552 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001553
James Smarte47c9092008-02-08 18:49:26 -05001554 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001555 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001556 if (phba->sli_rev == LPFC_SLI_REV4) {
1557 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1558 GFP_KERNEL);
1559 if (active_rrqs_xri_bitmap)
1560 memset(active_rrqs_xri_bitmap, 0,
1561 phba->cfg_rrq_xri_bitmap_sz);
1562 }
James Smart488d1462006-03-07 15:02:37 -05001563
James Smart34f5ad82012-08-03 12:35:03 -04001564 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1565 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1566 ndlp, ndlp->nlp_DID, new_ndlp);
1567
James Smart488d1462006-03-07 15:02:37 -05001568 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001569 rc = memcmp(&ndlp->nlp_portname, name,
1570 sizeof(struct lpfc_name));
James Smartcff261f2013-12-17 20:29:47 -05001571 if (!rc) {
1572 if (active_rrqs_xri_bitmap)
1573 mempool_free(active_rrqs_xri_bitmap,
1574 phba->active_rrq_pool);
James Smart92795652006-07-06 15:50:02 -04001575 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001576 }
James Smart9d3d3402017-04-21 16:05:00 -07001577 new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
James Smartcff261f2013-12-17 20:29:47 -05001578 if (!new_ndlp) {
1579 if (active_rrqs_xri_bitmap)
1580 mempool_free(active_rrqs_xri_bitmap,
1581 phba->active_rrq_pool);
James Smart488d1462006-03-07 15:02:37 -05001582 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001583 }
James Smarte47c9092008-02-08 18:49:26 -05001584 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001585 rc = memcmp(&ndlp->nlp_portname, name,
1586 sizeof(struct lpfc_name));
James Smartcff261f2013-12-17 20:29:47 -05001587 if (!rc) {
1588 if (active_rrqs_xri_bitmap)
1589 mempool_free(active_rrqs_xri_bitmap,
1590 phba->active_rrq_pool);
James Smart58da1ff2008-04-07 10:15:56 -04001591 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001592 }
James Smarte47c9092008-02-08 18:49:26 -05001593 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1594 NLP_STE_UNUSED_NODE);
James Smartcff261f2013-12-17 20:29:47 -05001595 if (!new_ndlp) {
1596 if (active_rrqs_xri_bitmap)
1597 mempool_free(active_rrqs_xri_bitmap,
1598 phba->active_rrq_pool);
James Smarte47c9092008-02-08 18:49:26 -05001599 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001600 }
James Smart58da1ff2008-04-07 10:15:56 -04001601 keepDID = new_ndlp->nlp_DID;
James Smartcff261f2013-12-17 20:29:47 -05001602 if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap)
1603 memcpy(active_rrqs_xri_bitmap,
1604 new_ndlp->active_rrqs_xri_bitmap,
1605 phba->cfg_rrq_xri_bitmap_sz);
James Smart19ca7602010-11-20 23:11:55 -05001606 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001607 keepDID = new_ndlp->nlp_DID;
James Smartcff261f2013-12-17 20:29:47 -05001608 if (phba->sli_rev == LPFC_SLI_REV4 &&
1609 active_rrqs_xri_bitmap)
1610 memcpy(active_rrqs_xri_bitmap,
1611 new_ndlp->active_rrqs_xri_bitmap,
1612 phba->cfg_rrq_xri_bitmap_sz);
James Smart19ca7602010-11-20 23:11:55 -05001613 }
James Smart488d1462006-03-07 15:02:37 -05001614
James Smart2e0fef82007-06-17 19:56:36 -05001615 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001616 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001617 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001618 if (phba->sli_rev == LPFC_SLI_REV4)
James Smartcff261f2013-12-17 20:29:47 -05001619 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1620 ndlp->active_rrqs_xri_bitmap,
1621 phba->cfg_rrq_xri_bitmap_sz);
James Smart0ff10d42008-01-11 01:52:36 -05001622
James Smart953ceed2015-05-22 10:42:37 -04001623 spin_lock_irq(shost->host_lock);
James Smarte5abba42015-05-21 13:55:27 -04001624 keep_nlp_flag = new_ndlp->nlp_flag;
1625 new_ndlp->nlp_flag = ndlp->nlp_flag;
1626 ndlp->nlp_flag = keep_nlp_flag;
James Smart953ceed2015-05-22 10:42:37 -04001627 spin_unlock_irq(shost->host_lock);
James Smart0ff10d42008-01-11 01:52:36 -05001628
James Smart953ceed2015-05-22 10:42:37 -04001629 /* Set nlp_states accordingly */
1630 keep_nlp_state = new_ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001631 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001632
Dick Kennedy4adc0412017-08-23 16:55:37 -07001633 /* interchange the nvme remoteport structs */
1634 keep_nrport = new_ndlp->nrport;
1635 new_ndlp->nrport = ndlp->nrport;
1636
James Smart2e0fef82007-06-17 19:56:36 -05001637 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001638 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1639 /* The new_ndlp is replacing ndlp totally, so we need
1640 * to put ndlp on UNUSED list and try to free it.
1641 */
James Smart34f5ad82012-08-03 12:35:03 -04001642 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1643 "3179 PLOGI confirm NEW: %x %x\n",
1644 new_ndlp->nlp_DID, keepDID);
James Smart0ff10d42008-01-11 01:52:36 -05001645
1646 /* Fix up the rport accordingly */
1647 rport = ndlp->rport;
1648 if (rport) {
1649 rdata = rport->dd_data;
1650 if (rdata->pnode == ndlp) {
James Smart466e8402015-05-21 13:55:28 -04001651 /* break the link before dropping the ref */
James Smart0ff10d42008-01-11 01:52:36 -05001652 ndlp->rport = NULL;
James Smart466e8402015-05-21 13:55:28 -04001653 lpfc_nlp_put(ndlp);
James Smart0ff10d42008-01-11 01:52:36 -05001654 rdata->pnode = lpfc_nlp_get(new_ndlp);
1655 new_ndlp->rport = rport;
1656 }
1657 new_ndlp->nlp_type = ndlp->nlp_type;
1658 }
Dick Kennedy4adc0412017-08-23 16:55:37 -07001659
1660 /* Fix up the nvme rport */
1661 if (ndlp->nrport) {
1662 ndlp->nrport = NULL;
1663 lpfc_nlp_put(ndlp);
James Smarta3da8252018-03-05 12:04:06 -08001664 new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
Dick Kennedy4adc0412017-08-23 16:55:37 -07001665 }
1666
James Smart58da1ff2008-04-07 10:15:56 -04001667 /* We shall actually free the ndlp with both nlp_DID and
1668 * nlp_portname fields equals 0 to avoid any ndlp on the
1669 * nodelist never to be used.
1670 */
1671 if (ndlp->nlp_DID == 0) {
1672 spin_lock_irq(&phba->ndlp_lock);
1673 NLP_SET_FREE_REQ(ndlp);
1674 spin_unlock_irq(&phba->ndlp_lock);
1675 }
James Smart0ff10d42008-01-11 01:52:36 -05001676
James Smart58da1ff2008-04-07 10:15:56 -04001677 /* Two ndlps cannot have the same did on the nodelist */
1678 ndlp->nlp_DID = keepDID;
James Smart49382502017-11-20 16:00:38 -08001679 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
James Smartcff261f2013-12-17 20:29:47 -05001680 if (phba->sli_rev == LPFC_SLI_REV4 &&
1681 active_rrqs_xri_bitmap)
1682 memcpy(ndlp->active_rrqs_xri_bitmap,
1683 active_rrqs_xri_bitmap,
1684 phba->cfg_rrq_xri_bitmap_sz);
James Smarte5abba42015-05-21 13:55:27 -04001685
1686 if (!NLP_CHK_NODE_ACT(ndlp))
1687 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001688 }
James Smart92795652006-07-06 15:50:02 -04001689 else {
James Smart34f5ad82012-08-03 12:35:03 -04001690 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1691 "3180 PLOGI confirm SWAP: %x %x\n",
1692 new_ndlp->nlp_DID, keepDID);
1693
James Smart2e0fef82007-06-17 19:56:36 -05001694 lpfc_unreg_rpi(vport, ndlp);
James Smart34f5ad82012-08-03 12:35:03 -04001695
James Smart58da1ff2008-04-07 10:15:56 -04001696 /* Two ndlps cannot have the same did */
1697 ndlp->nlp_DID = keepDID;
James Smartcff261f2013-12-17 20:29:47 -05001698 if (phba->sli_rev == LPFC_SLI_REV4 &&
1699 active_rrqs_xri_bitmap)
1700 memcpy(ndlp->active_rrqs_xri_bitmap,
1701 active_rrqs_xri_bitmap,
1702 phba->cfg_rrq_xri_bitmap_sz);
James Smart34f5ad82012-08-03 12:35:03 -04001703
James Smart953ceed2015-05-22 10:42:37 -04001704 /* Since we are switching over to the new_ndlp,
1705 * reset the old ndlp state
James Smart34f5ad82012-08-03 12:35:03 -04001706 */
1707 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1708 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
James Smart953ceed2015-05-22 10:42:37 -04001709 keep_nlp_state = NLP_STE_NPR_NODE;
1710 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
James Smart34f5ad82012-08-03 12:35:03 -04001711
Dick Kennedy4adc0412017-08-23 16:55:37 -07001712 /* Previous ndlp no longer active with nvme host transport.
1713 * Remove reference from earlier registration unless the
1714 * nvme host took care of it.
1715 */
1716 if (ndlp->nrport)
1717 lpfc_nlp_put(ndlp);
1718 ndlp->nrport = keep_nrport;
1719
James Smart38b92ef2010-08-04 16:11:39 -04001720 /* Fix up the rport accordingly */
1721 rport = ndlp->rport;
1722 if (rport) {
1723 rdata = rport->dd_data;
1724 put_node = rdata->pnode != NULL;
1725 put_rport = ndlp->rport != NULL;
1726 rdata->pnode = NULL;
1727 ndlp->rport = NULL;
1728 if (put_node)
1729 lpfc_nlp_put(ndlp);
1730 if (put_rport)
1731 put_device(&rport->dev);
1732 }
James Smart92795652006-07-06 15:50:02 -04001733 }
James Smartcff261f2013-12-17 20:29:47 -05001734 if (phba->sli_rev == LPFC_SLI_REV4 &&
1735 active_rrqs_xri_bitmap)
1736 mempool_free(active_rrqs_xri_bitmap,
1737 phba->active_rrq_pool);
James Smart488d1462006-03-07 15:02:37 -05001738 return new_ndlp;
1739}
1740
James Smarte59058c2008-08-24 21:49:00 -04001741/**
James Smart3621a712009-04-06 18:47:14 -04001742 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001743 * @vport: pointer to a host virtual N_Port data structure.
1744 *
1745 * This routine checks whether more Registration State Change
1746 * Notifications (RSCNs) came in while the discovery state machine was in
1747 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1748 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1749 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1750 * handling the RSCNs.
1751 **/
James Smart87af33f2007-10-27 13:37:43 -04001752void
1753lpfc_end_rscn(struct lpfc_vport *vport)
1754{
1755 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1756
1757 if (vport->fc_flag & FC_RSCN_MODE) {
1758 /*
1759 * Check to see if more RSCNs came in while we were
1760 * processing this one.
1761 */
1762 if (vport->fc_rscn_id_cnt ||
1763 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1764 lpfc_els_handle_rscn(vport);
1765 else {
1766 spin_lock_irq(shost->host_lock);
1767 vport->fc_flag &= ~FC_RSCN_MODE;
1768 spin_unlock_irq(shost->host_lock);
1769 }
1770 }
1771}
1772
James Smarte59058c2008-08-24 21:49:00 -04001773/**
James Smart19ca7602010-11-20 23:11:55 -05001774 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1775 * @phba: pointer to lpfc hba data structure.
1776 * @cmdiocb: pointer to lpfc command iocb data structure.
1777 * @rspiocb: pointer to lpfc response iocb data structure.
1778 *
1779 * This routine will call the clear rrq function to free the rrq and
1780 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1781 * exist then the clear_rrq is still called because the rrq needs to
1782 * be freed.
1783 **/
1784
1785static void
1786lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1787 struct lpfc_iocbq *rspiocb)
1788{
1789 struct lpfc_vport *vport = cmdiocb->vport;
1790 IOCB_t *irsp;
1791 struct lpfc_nodelist *ndlp;
1792 struct lpfc_node_rrq *rrq;
1793
1794 /* we pass cmdiocb to state machine which needs rspiocb as well */
1795 rrq = cmdiocb->context_un.rrq;
1796 cmdiocb->context_un.rsp_iocb = rspiocb;
1797
1798 irsp = &rspiocb->iocb;
1799 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1800 "RRQ cmpl: status:x%x/x%x did:x%x",
1801 irsp->ulpStatus, irsp->un.ulpWord[4],
1802 irsp->un.elsreq64.remoteID);
1803
1804 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1805 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1806 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1807 "2882 RRQ completes to NPort x%x "
1808 "with no ndlp. Data: x%x x%x x%x\n",
1809 irsp->un.elsreq64.remoteID,
1810 irsp->ulpStatus, irsp->un.ulpWord[4],
1811 irsp->ulpIoTag);
1812 goto out;
1813 }
1814
1815 /* rrq completes to NPort <nlp_DID> */
1816 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1817 "2880 RRQ completes to NPort x%x "
1818 "Data: x%x x%x x%x x%x x%x\n",
1819 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1820 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1821
1822 if (irsp->ulpStatus) {
1823 /* Check for retry */
1824 /* RRQ failed Don't print the vport to vport rjts */
1825 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1826 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1827 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1828 (phba)->pport->cfg_log_verbose & LOG_ELS)
1829 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1830 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1831 ndlp->nlp_DID, irsp->ulpStatus,
1832 irsp->un.ulpWord[4]);
1833 }
1834out:
1835 if (rrq)
1836 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1837 lpfc_els_free_iocb(phba, cmdiocb);
1838 return;
1839}
1840/**
James Smart3621a712009-04-06 18:47:14 -04001841 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001842 * @phba: pointer to lpfc hba data structure.
1843 * @cmdiocb: pointer to lpfc command iocb data structure.
1844 * @rspiocb: pointer to lpfc response iocb data structure.
1845 *
1846 * This routine is the completion callback function for issuing the Port
1847 * Login (PLOGI) command. For PLOGI completion, there must be an active
1848 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001849 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001850 * ignored and command IOCB released. The PLOGI response IOCB status is
1851 * checked for error conditons. If there is error status reported, PLOGI
1852 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1853 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1854 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1855 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1856 * there are additional N_Port nodes with the vport that need to perform
1857 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1858 * PLOGIs.
1859 **/
dea31012005-04-17 16:05:31 -05001860static void
James Smart2e0fef82007-06-17 19:56:36 -05001861lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1862 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001863{
James Smart2e0fef82007-06-17 19:56:36 -05001864 struct lpfc_vport *vport = cmdiocb->vport;
1865 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001866 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001867 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001868 struct lpfc_dmabuf *prsp;
James Smarteb016562014-09-03 12:58:06 -04001869 int disc, rc;
dea31012005-04-17 16:05:31 -05001870
dea31012005-04-17 16:05:31 -05001871 /* we pass cmdiocb to state machine which needs rspiocb as well */
1872 cmdiocb->context_un.rsp_iocb = rspiocb;
1873
1874 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001875 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1876 "PLOGI cmpl: status:x%x/x%x did:x%x",
1877 irsp->ulpStatus, irsp->un.ulpWord[4],
1878 irsp->un.elsreq64.remoteID);
1879
James Smart2e0fef82007-06-17 19:56:36 -05001880 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001881 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001882 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1883 "0136 PLOGI completes to NPort x%x "
1884 "with no ndlp. Data: x%x x%x x%x\n",
1885 irsp->un.elsreq64.remoteID,
1886 irsp->ulpStatus, irsp->un.ulpWord[4],
1887 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001888 goto out;
James Smarted957682007-06-17 19:56:37 -05001889 }
dea31012005-04-17 16:05:31 -05001890
1891 /* Since ndlp can be freed in the disc state machine, note if this node
1892 * is being used during discovery.
1893 */
James Smart2e0fef82007-06-17 19:56:36 -05001894 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001895 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001896 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001897 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001898 rc = 0;
1899
1900 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001901 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta0f2d3e2017-02-12 13:52:31 -08001902 "0102 PLOGI completes to NPort x%06x "
James Smarte8b62012007-08-02 11:10:09 -04001903 "Data: x%x x%x x%x x%x x%x\n",
James Smarta0f2d3e2017-02-12 13:52:31 -08001904 ndlp->nlp_DID, ndlp->nlp_fc4_type,
1905 irsp->ulpStatus, irsp->un.ulpWord[4],
1906 disc, vport->num_disc_nodes);
1907
dea31012005-04-17 16:05:31 -05001908 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001909 if (lpfc_els_chk_latt(vport)) {
1910 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001911 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001912 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001913 goto out;
1914 }
1915
dea31012005-04-17 16:05:31 -05001916 if (irsp->ulpStatus) {
1917 /* Check for retry */
1918 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1919 /* ELS command is being retried */
1920 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001921 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001922 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001923 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001924 }
1925 goto out;
1926 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001927 /* PLOGI failed Don't print the vport to vport rjts */
1928 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1929 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1930 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1931 (phba)->pport->cfg_log_verbose & LOG_ELS)
1932 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001933 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1934 ndlp->nlp_DID, irsp->ulpStatus,
1935 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001936 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001937 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001938 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001939 else
James Smart2e0fef82007-06-17 19:56:36 -05001940 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001941 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001942 } else {
1943 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001944 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001945 cmdiocb->context2)->list.next,
1946 struct lpfc_dmabuf, list);
1947 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001948 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001949 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001950 }
1951
James Smart2e0fef82007-06-17 19:56:36 -05001952 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001953 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001954 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001955
James Smart2e0fef82007-06-17 19:56:36 -05001956 if (vport->num_disc_nodes == 0) {
1957 spin_lock_irq(shost->host_lock);
1958 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1959 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001960
James Smart2e0fef82007-06-17 19:56:36 -05001961 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001962 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001963 }
1964 }
1965
1966out:
1967 lpfc_els_free_iocb(phba, cmdiocb);
1968 return;
1969}
1970
James Smarte59058c2008-08-24 21:49:00 -04001971/**
James Smart3621a712009-04-06 18:47:14 -04001972 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001973 * @vport: pointer to a host virtual N_Port data structure.
1974 * @did: destination port identifier.
1975 * @retry: number of retries to the command IOCB.
1976 *
1977 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1978 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1979 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1980 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1981 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1982 *
1983 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1984 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1985 * will be stored into the context1 field of the IOCB for the completion
1986 * callback function to the PLOGI ELS command.
1987 *
1988 * Return code
1989 * 0 - Successfully issued a plogi for @vport
1990 * 1 - failed to issue a plogi for @vport
1991 **/
dea31012005-04-17 16:05:31 -05001992int
James Smart2e0fef82007-06-17 19:56:36 -05001993lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001994{
James Smart2e0fef82007-06-17 19:56:36 -05001995 struct lpfc_hba *phba = vport->phba;
Dick Kennedy8db1c2b2017-08-23 16:55:36 -07001996 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05001997 struct serv_parm *sp;
James Smart98c9ea52007-10-27 13:37:33 -04001998 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001999 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002000 uint8_t *pcmd;
2001 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002002 int ret;
dea31012005-04-17 16:05:31 -05002003
James Smart98c9ea52007-10-27 13:37:33 -04002004 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002005 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
2006 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04002007
James Smarte47c9092008-02-08 18:49:26 -05002008 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05002009 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04002010 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05002011 ELS_CMD_PLOGI);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002012 if (!elsiocb)
2013 return 1;
dea31012005-04-17 16:05:31 -05002014
Dick Kennedy8db1c2b2017-08-23 16:55:36 -07002015 shost = lpfc_shost_from_vport(vport);
2016 spin_lock_irq(shost->host_lock);
2017 ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
2018 spin_unlock_irq(shost->host_lock);
2019
dea31012005-04-17 16:05:31 -05002020 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2021
2022 /* For PLOGI request, remainder of payload is service parameters */
2023 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05002024 pcmd += sizeof(uint32_t);
2025 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05002026 sp = (struct serv_parm *) pcmd;
2027
James Smart5ac6b302010-10-22 11:05:36 -04002028 /*
2029 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2030 * to device on remote loops work.
2031 */
2032 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
2033 sp->cmn.altBbCredit = 1;
2034
dea31012005-04-17 16:05:31 -05002035 if (sp->cmn.fcphLow < FC_PH_4_3)
2036 sp->cmn.fcphLow = FC_PH_4_3;
2037
2038 if (sp->cmn.fcphHigh < FC_PH3)
2039 sp->cmn.fcphHigh = FC_PH3;
2040
James Smarte0165f22016-12-19 15:07:20 -08002041 sp->cmn.valid_vendor_ver_level = 0;
James Smart8c258642017-02-12 13:52:36 -08002042 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
James Smart44fd7fe2017-08-23 16:55:47 -07002043 sp->cmn.bbRcvSizeMsb &= 0xF;
James Smarte0165f22016-12-19 15:07:20 -08002044
James Smart858c9f62007-06-17 19:56:39 -05002045 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2046 "Issue PLOGI: did:x%x",
2047 did, 0, 0);
2048
James Smart8c258642017-02-12 13:52:36 -08002049 /* If our firmware supports this feature, convey that
2050 * information to the target using the vendor specific field.
2051 */
2052 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2053 sp->cmn.valid_vendor_ver_level = 1;
2054 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2055 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2056 }
2057
dea31012005-04-17 16:05:31 -05002058 phba->fc_stat.elsXmitPLOGI++;
2059 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04002060 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002061
2062 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002063 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002064 return 1;
dea31012005-04-17 16:05:31 -05002065 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002066 return 0;
dea31012005-04-17 16:05:31 -05002067}
2068
James Smarte59058c2008-08-24 21:49:00 -04002069/**
James Smart3621a712009-04-06 18:47:14 -04002070 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04002071 * @phba: pointer to lpfc hba data structure.
2072 * @cmdiocb: pointer to lpfc command iocb data structure.
2073 * @rspiocb: pointer to lpfc response iocb data structure.
2074 *
2075 * This routine is the completion callback function for a Process Login
2076 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2077 * status. If there is error status reported, PRLI retry shall be attempted
2078 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2079 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2080 * ndlp to mark the PRLI completion.
2081 **/
dea31012005-04-17 16:05:31 -05002082static void
James Smart2e0fef82007-06-17 19:56:36 -05002083lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2084 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002085{
James Smart2e0fef82007-06-17 19:56:36 -05002086 struct lpfc_vport *vport = cmdiocb->vport;
2087 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002088 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002089 struct lpfc_nodelist *ndlp;
2090
dea31012005-04-17 16:05:31 -05002091 /* we pass cmdiocb to state machine which needs rspiocb as well */
2092 cmdiocb->context_un.rsp_iocb = rspiocb;
2093
2094 irsp = &(rspiocb->iocb);
2095 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05002096 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002097 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart9de416a2017-12-08 17:18:07 -08002098
2099 /* Driver supports multiple FC4 types. Counters matter. */
2100 vport->fc_prli_sent--;
2101 ndlp->fc4_prli_sent--;
James Smart2e0fef82007-06-17 19:56:36 -05002102 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002103
James Smart858c9f62007-06-17 19:56:39 -05002104 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2105 "PRLI cmpl: status:x%x/x%x did:x%x",
2106 irsp->ulpStatus, irsp->un.ulpWord[4],
2107 ndlp->nlp_DID);
James Smarta0f2d3e2017-02-12 13:52:31 -08002108
dea31012005-04-17 16:05:31 -05002109 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002110 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta0f2d3e2017-02-12 13:52:31 -08002111 "0103 PRLI completes to NPort x%06x "
James Smarte8b62012007-08-02 11:10:09 -04002112 "Data: x%x x%x x%x x%x\n",
2113 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
James Smarta0f2d3e2017-02-12 13:52:31 -08002114 vport->num_disc_nodes, ndlp->fc4_prli_sent);
dea31012005-04-17 16:05:31 -05002115
dea31012005-04-17 16:05:31 -05002116 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002117 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002118 goto out;
2119
2120 if (irsp->ulpStatus) {
2121 /* Check for retry */
2122 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2123 /* ELS command is being retried */
2124 goto out;
2125 }
James Smart31200462017-05-15 15:20:42 -07002126
dea31012005-04-17 16:05:31 -05002127 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05002128 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart31200462017-05-15 15:20:42 -07002129 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2130 "data: x%x\n",
James Smarte40a02c2010-02-26 14:13:54 -05002131 ndlp->nlp_DID, irsp->ulpStatus,
James Smart31200462017-05-15 15:20:42 -07002132 irsp->un.ulpWord[4], ndlp->fc4_prli_sent);
2133
dea31012005-04-17 16:05:31 -05002134 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002135 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002136 goto out;
James Smarte47c9092008-02-08 18:49:26 -05002137 else
James Smart2e0fef82007-06-17 19:56:36 -05002138 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002139 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05002140 } else
James Smarta0f2d3e2017-02-12 13:52:31 -08002141 /* Good status, call state machine. However, if another
2142 * PRLI is outstanding, don't call the state machine
2143 * because final disposition to Mapped or Unmapped is
2144 * completed there.
2145 */
James Smart2e0fef82007-06-17 19:56:36 -05002146 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002147 NLP_EVT_CMPL_PRLI);
James Smarta0f2d3e2017-02-12 13:52:31 -08002148
dea31012005-04-17 16:05:31 -05002149out:
2150 lpfc_els_free_iocb(phba, cmdiocb);
2151 return;
2152}
2153
James Smarte59058c2008-08-24 21:49:00 -04002154/**
James Smart3621a712009-04-06 18:47:14 -04002155 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04002156 * @vport: pointer to a host virtual N_Port data structure.
2157 * @ndlp: pointer to a node-list data structure.
2158 * @retry: number of retries to the command IOCB.
2159 *
2160 * This routine issues a Process Login (PRLI) ELS command for the
2161 * @vport. The PRLI service parameters are set up in the payload of the
2162 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2163 * is put to the IOCB completion callback func field before invoking the
2164 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2165 *
2166 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2167 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2168 * will be stored into the context1 field of the IOCB for the completion
2169 * callback function to the PRLI ELS command.
2170 *
2171 * Return code
2172 * 0 - successfully issued prli iocb command for @vport
2173 * 1 - failed to issue prli iocb command for @vport
2174 **/
dea31012005-04-17 16:05:31 -05002175int
James Smart2e0fef82007-06-17 19:56:36 -05002176lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002177 uint8_t retry)
2178{
James Smart2e0fef82007-06-17 19:56:36 -05002179 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2180 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002181 PRLI *npr;
James Smarta0f2d3e2017-02-12 13:52:31 -08002182 struct lpfc_nvme_prli *npr_nvme;
dea31012005-04-17 16:05:31 -05002183 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002184 uint8_t *pcmd;
2185 uint16_t cmdsize;
James Smarta0f2d3e2017-02-12 13:52:31 -08002186 u32 local_nlp_type, elscmd;
dea31012005-04-17 16:05:31 -05002187
Dick Kennedy991f0c02017-08-23 16:55:39 -07002188 /*
2189 * If we are in RSCN mode, the FC4 types supported from a
2190 * previous GFT_ID command may not be accurate. So, if we
2191 * are a NVME Initiator, always look for the possibility of
2192 * the remote NPort beng a NVME Target.
2193 */
2194 if (phba->sli_rev == LPFC_SLI_REV4 &&
2195 vport->fc_flag & FC_RSCN_MODE &&
2196 vport->nvmei_support)
2197 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
James Smarta0f2d3e2017-02-12 13:52:31 -08002198 local_nlp_type = ndlp->nlp_fc4_type;
2199
James Smart9de416a2017-12-08 17:18:07 -08002200 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2201 * fields here before any of them can complete.
2202 */
2203 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2204 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
2205 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
2206 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
2207 ndlp->nvme_fb_size = 0;
2208
James Smarta0f2d3e2017-02-12 13:52:31 -08002209 send_next_prli:
2210 if (local_nlp_type & NLP_FC4_FCP) {
2211 /* Payload is 4 + 16 = 20 x14 bytes. */
2212 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2213 elscmd = ELS_CMD_PRLI;
2214 } else if (local_nlp_type & NLP_FC4_NVME) {
2215 /* Payload is 4 + 20 = 24 x18 bytes. */
2216 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2217 elscmd = ELS_CMD_NVMEPRLI;
2218 } else {
2219 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2220 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2221 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2222 return 1;
2223 }
James Smart09559e82017-06-15 22:56:46 -07002224
2225 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2226 * FC4 type, implicitly LOGO.
2227 */
2228 if (phba->sli_rev == LPFC_SLI_REV3 &&
2229 ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2230 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2231 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2232 ndlp->nlp_type);
2233 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2234 return 1;
2235 }
2236
James Smart2e0fef82007-06-17 19:56:36 -05002237 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
James Smarta0f2d3e2017-02-12 13:52:31 -08002238 ndlp->nlp_DID, elscmd);
James Smart488d1462006-03-07 15:02:37 -05002239 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002240 return 1;
dea31012005-04-17 16:05:31 -05002241
dea31012005-04-17 16:05:31 -05002242 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2243
2244 /* For PRLI request, remainder of payload is service parameters */
James Smarta0f2d3e2017-02-12 13:52:31 -08002245 memset(pcmd, 0, cmdsize);
dea31012005-04-17 16:05:31 -05002246
James Smarta0f2d3e2017-02-12 13:52:31 -08002247 if (local_nlp_type & NLP_FC4_FCP) {
2248 /* Remainder of payload is FCP PRLI parameter page.
2249 * Note: this data structure is defined as
2250 * BE/LE in the structure definition so no
2251 * byte swap call is made.
2252 */
2253 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2254 pcmd += sizeof(uint32_t);
2255 npr = (PRLI *)pcmd;
2256
2257 /*
2258 * If our firmware version is 3.20 or later,
2259 * set the following bits for FC-TAPE support.
2260 */
2261 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2262 npr->ConfmComplAllowed = 1;
2263 npr->Retry = 1;
2264 npr->TaskRetryIdReq = 1;
2265 }
2266 npr->estabImagePair = 1;
2267 npr->readXferRdyDis = 1;
2268 if (vport->cfg_first_burst_size)
2269 npr->writeXferRdyDis = 1;
2270
2271 /* For FCP support */
2272 npr->prliType = PRLI_FCP_TYPE;
2273 npr->initiatorFunc = 1;
2274 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2275
2276 /* Remove FCP type - processed. */
2277 local_nlp_type &= ~NLP_FC4_FCP;
2278 } else if (local_nlp_type & NLP_FC4_NVME) {
2279 /* Remainder of payload is NVME PRLI parameter page.
2280 * This data structure is the newer definition that
2281 * uses bf macros so a byte swap is required.
2282 */
2283 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2284 pcmd += sizeof(uint32_t);
2285 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2286 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2287 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2288
2289 /* Only initiators request first burst. */
2290 if ((phba->cfg_nvme_enable_fb) &&
2291 !phba->nvmet_support)
2292 bf_set(prli_fba, npr_nvme, 1);
2293
James Smart8c258642017-02-12 13:52:36 -08002294 if (phba->nvmet_support) {
2295 bf_set(prli_tgt, npr_nvme, 1);
2296 bf_set(prli_disc, npr_nvme, 1);
James Smart8c258642017-02-12 13:52:36 -08002297 } else {
2298 bf_set(prli_init, npr_nvme, 1);
James Smarta5ff0682018-01-30 15:58:56 -08002299 bf_set(prli_conf, npr_nvme, 1);
James Smart8c258642017-02-12 13:52:36 -08002300 }
James Smarta5ff0682018-01-30 15:58:56 -08002301
James Smarta0f2d3e2017-02-12 13:52:31 -08002302 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2303 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2304 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2305
2306 /* Remove NVME type - processed. */
2307 local_nlp_type &= ~NLP_FC4_NVME;
dea31012005-04-17 16:05:31 -05002308 }
dea31012005-04-17 16:05:31 -05002309
James Smart858c9f62007-06-17 19:56:39 -05002310 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2311 "Issue PRLI: did:x%x",
2312 ndlp->nlp_DID, 0, 0);
2313
dea31012005-04-17 16:05:31 -05002314 phba->fc_stat.elsXmitPRLI++;
2315 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05002316 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002317 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart9de416a2017-12-08 17:18:07 -08002318
2319 /* The vport counters are used for lpfc_scan_finished, but
2320 * the ndlp is used to track outstanding PRLIs for different
2321 * FC4 types.
2322 */
2323 vport->fc_prli_sent++;
2324 ndlp->fc4_prli_sent++;
James Smart2e0fef82007-06-17 19:56:36 -05002325 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002326 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2327 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002328 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002329 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002330 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002331 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002332 return 1;
dea31012005-04-17 16:05:31 -05002333 }
James Smarta0f2d3e2017-02-12 13:52:31 -08002334
James Smarta0f2d3e2017-02-12 13:52:31 -08002335
2336 /* The driver supports 2 FC4 types. Make sure
2337 * a PRLI is issued for all types before exiting.
2338 */
James Smart09559e82017-06-15 22:56:46 -07002339 if (phba->sli_rev == LPFC_SLI_REV4 &&
2340 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
James Smarta0f2d3e2017-02-12 13:52:31 -08002341 goto send_next_prli;
2342
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002343 return 0;
dea31012005-04-17 16:05:31 -05002344}
2345
James Smarte59058c2008-08-24 21:49:00 -04002346/**
James Smart3621a712009-04-06 18:47:14 -04002347 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04002348 * @vport: pointer to a host virtual N_Port data structure.
2349 *
2350 * This routine performs Registration State Change Notification (RSCN)
2351 * discovery for a @vport. If the @vport's node port recovery count is not
2352 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2353 * the nodes that need recovery. If none of the PLOGI were needed through
2354 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2355 * invoked to check and handle possible more RSCN came in during the period
2356 * of processing the current ones.
2357 **/
2358static void
2359lpfc_rscn_disc(struct lpfc_vport *vport)
2360{
2361 lpfc_can_disctmo(vport);
2362
2363 /* RSCN discovery */
2364 /* go thru NPR nodes and issue ELS PLOGIs */
2365 if (vport->fc_npr_cnt)
2366 if (lpfc_els_disc_plogi(vport))
2367 return;
2368
2369 lpfc_end_rscn(vport);
2370}
2371
2372/**
James Smart3621a712009-04-06 18:47:14 -04002373 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002374 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2375 *
2376 * This function is called when the final ADISC is completed during discovery.
2377 * This function handles clearing link attention or issuing reg_vpi depending
2378 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2379 * discovery.
2380 * This function is called with no locks held.
2381 **/
2382static void
2383lpfc_adisc_done(struct lpfc_vport *vport)
2384{
2385 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2386 struct lpfc_hba *phba = vport->phba;
2387
2388 /*
2389 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2390 * and continue discovery.
2391 */
2392 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002393 !(vport->fc_flag & FC_RSCN_MODE) &&
2394 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smartd454c912014-12-30 12:08:58 -05002395 /* The ADISCs are complete. Doesn't matter if they
2396 * succeeded or failed because the ADISC completion
2397 * routine guarantees to call the state machine and
2398 * the RPI is either unregistered (failed ADISC response)
2399 * or the RPI is still valid and the node is marked
2400 * mapped for a target. The exchanges should be in the
2401 * correct state. This code is specific to SLI3.
2402 */
2403 lpfc_issue_clear_la(phba, vport);
James Smart90160e02008-08-24 21:49:45 -04002404 lpfc_issue_reg_vpi(phba, vport);
2405 return;
2406 }
2407 /*
2408 * For SLI2, we need to set port_state to READY
2409 * and continue discovery.
2410 */
2411 if (vport->port_state < LPFC_VPORT_READY) {
2412 /* If we get here, there is nothing to ADISC */
James Smart85c0f172015-04-07 15:07:12 -04002413 lpfc_issue_clear_la(phba, vport);
James Smart90160e02008-08-24 21:49:45 -04002414 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2415 vport->num_disc_nodes = 0;
2416 /* go thru NPR list, issue ELS PLOGIs */
2417 if (vport->fc_npr_cnt)
2418 lpfc_els_disc_plogi(vport);
2419 if (!vport->num_disc_nodes) {
2420 spin_lock_irq(shost->host_lock);
2421 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2422 spin_unlock_irq(shost->host_lock);
2423 lpfc_can_disctmo(vport);
2424 lpfc_end_rscn(vport);
2425 }
2426 }
2427 vport->port_state = LPFC_VPORT_READY;
2428 } else
2429 lpfc_rscn_disc(vport);
2430}
2431
2432/**
James Smart3621a712009-04-06 18:47:14 -04002433 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002434 * @vport: pointer to a host virtual N_Port data structure.
2435 *
2436 * This routine determines whether there are more ndlps on a @vport
2437 * node list need to have Address Discover (ADISC) issued. If so, it will
2438 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2439 * remaining nodes which need to have ADISC sent.
2440 **/
James Smart0ff10d42008-01-11 01:52:36 -05002441void
James Smart2e0fef82007-06-17 19:56:36 -05002442lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002443{
James Smart2e0fef82007-06-17 19:56:36 -05002444 if (vport->num_disc_nodes)
2445 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002446 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002447 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2448 "0210 Continue discovery with %d ADISCs to go "
2449 "Data: x%x x%x x%x\n",
2450 vport->num_disc_nodes, vport->fc_adisc_cnt,
2451 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002452 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002453 if (vport->fc_flag & FC_NLP_MORE) {
2454 lpfc_set_disctmo(vport);
2455 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smarteb016562014-09-03 12:58:06 -04002456 lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002457 }
James Smart90160e02008-08-24 21:49:45 -04002458 if (!vport->num_disc_nodes)
2459 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002460 return;
2461}
2462
James Smarte59058c2008-08-24 21:49:00 -04002463/**
James Smart3621a712009-04-06 18:47:14 -04002464 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002465 * @phba: pointer to lpfc hba data structure.
2466 * @cmdiocb: pointer to lpfc command iocb data structure.
2467 * @rspiocb: pointer to lpfc response iocb data structure.
2468 *
2469 * This routine is the completion function for issuing the Address Discover
2470 * (ADISC) command. It first checks to see whether link went down during
2471 * the discovery process. If so, the node will be marked as node port
2472 * recovery for issuing discover IOCB by the link attention handler and
2473 * exit. Otherwise, the response status is checked. If error was reported
2474 * in the response status, the ADISC command shall be retried by invoking
2475 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2476 * the response status, the state machine is invoked to set transition
2477 * with respect to NLP_EVT_CMPL_ADISC event.
2478 **/
dea31012005-04-17 16:05:31 -05002479static void
James Smart2e0fef82007-06-17 19:56:36 -05002480lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2481 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002482{
James Smart2e0fef82007-06-17 19:56:36 -05002483 struct lpfc_vport *vport = cmdiocb->vport;
2484 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002485 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002486 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002487 int disc;
dea31012005-04-17 16:05:31 -05002488
2489 /* we pass cmdiocb to state machine which needs rspiocb as well */
2490 cmdiocb->context_un.rsp_iocb = rspiocb;
2491
2492 irsp = &(rspiocb->iocb);
2493 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002494
James Smart858c9f62007-06-17 19:56:39 -05002495 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2496 "ADISC cmpl: status:x%x/x%x did:x%x",
2497 irsp->ulpStatus, irsp->un.ulpWord[4],
2498 ndlp->nlp_DID);
2499
dea31012005-04-17 16:05:31 -05002500 /* Since ndlp can be freed in the disc state machine, note if this node
2501 * is being used during discovery.
2502 */
James Smart2e0fef82007-06-17 19:56:36 -05002503 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002504 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002505 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002506 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002507 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002508 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2509 "0104 ADISC completes to NPort x%x "
2510 "Data: x%x x%x x%x x%x x%x\n",
2511 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2512 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002513 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002514 if (lpfc_els_chk_latt(vport)) {
2515 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002516 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002517 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002518 goto out;
2519 }
2520
2521 if (irsp->ulpStatus) {
2522 /* Check for retry */
2523 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2524 /* ELS command is being retried */
2525 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002526 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002527 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002528 spin_unlock_irq(shost->host_lock);
2529 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002530 }
2531 goto out;
2532 }
2533 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002534 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2535 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2536 ndlp->nlp_DID, irsp->ulpStatus,
2537 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002538 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002539 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002540 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002541 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002542 } else
dea31012005-04-17 16:05:31 -05002543 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002544 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002545 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002546
James Smart90160e02008-08-24 21:49:45 -04002547 /* Check to see if there are more ADISCs to be sent */
2548 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002549 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002550out:
2551 lpfc_els_free_iocb(phba, cmdiocb);
2552 return;
2553}
2554
James Smarte59058c2008-08-24 21:49:00 -04002555/**
James Smart3621a712009-04-06 18:47:14 -04002556 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002557 * @vport: pointer to a virtual N_Port data structure.
2558 * @ndlp: pointer to a node-list data structure.
2559 * @retry: number of retries to the command IOCB.
2560 *
2561 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2562 * @vport. It prepares the payload of the ADISC ELS command, updates the
2563 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2564 * to issue the ADISC ELS command.
2565 *
2566 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2567 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2568 * will be stored into the context1 field of the IOCB for the completion
2569 * callback function to the ADISC ELS command.
2570 *
2571 * Return code
2572 * 0 - successfully issued adisc
2573 * 1 - failed to issue adisc
2574 **/
dea31012005-04-17 16:05:31 -05002575int
James Smart2e0fef82007-06-17 19:56:36 -05002576lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002577 uint8_t retry)
2578{
James Smart2e0fef82007-06-17 19:56:36 -05002579 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2580 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002581 ADISC *ap;
dea31012005-04-17 16:05:31 -05002582 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002583 uint8_t *pcmd;
2584 uint16_t cmdsize;
2585
James Smart92d7f7b2007-06-17 19:56:38 -05002586 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002587 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2588 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002589 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002590 return 1;
dea31012005-04-17 16:05:31 -05002591
dea31012005-04-17 16:05:31 -05002592 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2593
2594 /* For ADISC request, remainder of payload is service parameters */
2595 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002596 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002597
2598 /* Fill in ADISC payload */
2599 ap = (ADISC *) pcmd;
2600 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002601 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2602 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002603 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002604
James Smart858c9f62007-06-17 19:56:39 -05002605 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2606 "Issue ADISC: did:x%x",
2607 ndlp->nlp_DID, 0, 0);
2608
dea31012005-04-17 16:05:31 -05002609 phba->fc_stat.elsXmitADISC++;
2610 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002611 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002612 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002613 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002614 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2615 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002616 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002617 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002618 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002619 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002620 return 1;
dea31012005-04-17 16:05:31 -05002621 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002622 return 0;
dea31012005-04-17 16:05:31 -05002623}
2624
James Smarte59058c2008-08-24 21:49:00 -04002625/**
James Smart3621a712009-04-06 18:47:14 -04002626 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002627 * @phba: pointer to lpfc hba data structure.
2628 * @cmdiocb: pointer to lpfc command iocb data structure.
2629 * @rspiocb: pointer to lpfc response iocb data structure.
2630 *
2631 * This routine is the completion function for issuing the ELS Logout (LOGO)
2632 * command. If no error status was reported from the LOGO response, the
2633 * state machine of the associated ndlp shall be invoked for transition with
2634 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2635 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2636 **/
dea31012005-04-17 16:05:31 -05002637static void
James Smart2e0fef82007-06-17 19:56:36 -05002638lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2639 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002640{
James Smart2e0fef82007-06-17 19:56:36 -05002641 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2642 struct lpfc_vport *vport = ndlp->vport;
2643 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002644 IOCB_t *irsp;
James Smart92494142011-02-16 12:39:44 -05002645 struct lpfcMboxq *mbox;
James Smart086a3452012-08-14 14:25:21 -04002646 unsigned long flags;
2647 uint32_t skip_recovery = 0;
dea31012005-04-17 16:05:31 -05002648
dea31012005-04-17 16:05:31 -05002649 /* we pass cmdiocb to state machine which needs rspiocb as well */
2650 cmdiocb->context_un.rsp_iocb = rspiocb;
2651
2652 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002653 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002654 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002655 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002656
James Smart858c9f62007-06-17 19:56:39 -05002657 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2658 "LOGO cmpl: status:x%x/x%x did:x%x",
2659 irsp->ulpStatus, irsp->un.ulpWord[4],
2660 ndlp->nlp_DID);
James Smart086a3452012-08-14 14:25:21 -04002661
dea31012005-04-17 16:05:31 -05002662 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002663 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2664 "0105 LOGO completes to NPort x%x "
2665 "Data: x%x x%x x%x x%x\n",
2666 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2667 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002668
James Smart086a3452012-08-14 14:25:21 -04002669 if (lpfc_els_chk_latt(vport)) {
2670 skip_recovery = 1;
2671 goto out;
2672 }
2673
2674 /* Check to see if link went down during discovery */
James Smart92d7f7b2007-06-17 19:56:38 -05002675 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2676 /* NLP_EVT_DEVICE_RM should unregister the RPI
2677 * which should abort all outstanding IOs.
2678 */
2679 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2680 NLP_EVT_DEVICE_RM);
James Smart086a3452012-08-14 14:25:21 -04002681 skip_recovery = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002682 goto out;
2683 }
2684
dea31012005-04-17 16:05:31 -05002685 if (irsp->ulpStatus) {
2686 /* Check for retry */
James Smart086a3452012-08-14 14:25:21 -04002687 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
dea31012005-04-17 16:05:31 -05002688 /* ELS command is being retried */
James Smart086a3452012-08-14 14:25:21 -04002689 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002690 goto out;
James Smart086a3452012-08-14 14:25:21 -04002691 }
dea31012005-04-17 16:05:31 -05002692 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002693 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2694 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2695 ndlp->nlp_DID, irsp->ulpStatus,
2696 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002697 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart086a3452012-08-14 14:25:21 -04002698 if (lpfc_error_lost_link(irsp)) {
2699 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002700 goto out;
James Smart086a3452012-08-14 14:25:21 -04002701 }
2702 }
2703
2704 /* Call state machine. This will unregister the rpi if needed. */
2705 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2706
dea31012005-04-17 16:05:31 -05002707out:
2708 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92494142011-02-16 12:39:44 -05002709 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2710 if ((vport->fc_flag & FC_PT2PT) &&
2711 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2712 phba->pport->fc_myDID = 0;
James Smarta0f2d3e2017-02-12 13:52:31 -08002713
James Smart01649562017-02-12 13:52:32 -08002714 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
James Smart8c258642017-02-12 13:52:36 -08002715 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smartd613b6a2017-02-12 13:52:37 -08002716 if (phba->nvmet_support)
2717 lpfc_nvmet_update_targetport(phba);
2718 else
James Smart8c258642017-02-12 13:52:36 -08002719 lpfc_nvme_update_localport(phba->pport);
James Smart8c258642017-02-12 13:52:36 -08002720 }
James Smarta0f2d3e2017-02-12 13:52:31 -08002721
James Smart92494142011-02-16 12:39:44 -05002722 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2723 if (mbox) {
2724 lpfc_config_link(phba, mbox);
2725 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2726 mbox->vport = vport;
2727 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2728 MBX_NOT_FINISHED) {
2729 mempool_free(mbox, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04002730 skip_recovery = 1;
James Smart92494142011-02-16 12:39:44 -05002731 }
2732 }
2733 }
James Smart086a3452012-08-14 14:25:21 -04002734
2735 /*
2736 * If the node is a target, the handling attempts to recover the port.
2737 * For any other port type, the rpi is unregistered as an implicit
2738 * LOGO.
2739 */
2740 if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) {
2741 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2742 spin_lock_irqsave(shost->host_lock, flags);
2743 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2744 spin_unlock_irqrestore(shost->host_lock, flags);
2745
2746 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2747 "3187 LOGO completes to NPort x%x: Start "
2748 "Recovery Data: x%x x%x x%x x%x\n",
2749 ndlp->nlp_DID, irsp->ulpStatus,
2750 irsp->un.ulpWord[4], irsp->ulpTimeout,
2751 vport->num_disc_nodes);
2752 lpfc_disc_start(vport);
2753 }
dea31012005-04-17 16:05:31 -05002754 return;
2755}
2756
James Smarte59058c2008-08-24 21:49:00 -04002757/**
James Smart3621a712009-04-06 18:47:14 -04002758 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002759 * @vport: pointer to a virtual N_Port data structure.
2760 * @ndlp: pointer to a node-list data structure.
2761 * @retry: number of retries to the command IOCB.
2762 *
2763 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2764 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2765 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2766 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2767 *
2768 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2769 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2770 * will be stored into the context1 field of the IOCB for the completion
2771 * callback function to the LOGO ELS command.
2772 *
2773 * Return code
2774 * 0 - successfully issued logo
2775 * 1 - failed to issue logo
2776 **/
dea31012005-04-17 16:05:31 -05002777int
James Smart2e0fef82007-06-17 19:56:36 -05002778lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002779 uint8_t retry)
2780{
James Smart2e0fef82007-06-17 19:56:36 -05002781 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2782 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002783 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002784 uint8_t *pcmd;
2785 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002786 int rc;
dea31012005-04-17 16:05:31 -05002787
James Smart98c9ea52007-10-27 13:37:33 -04002788 spin_lock_irq(shost->host_lock);
2789 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2790 spin_unlock_irq(shost->host_lock);
2791 return 0;
2792 }
2793 spin_unlock_irq(shost->host_lock);
2794
James Smart92d7f7b2007-06-17 19:56:38 -05002795 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002796 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2797 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002798 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002799 return 1;
dea31012005-04-17 16:05:31 -05002800
dea31012005-04-17 16:05:31 -05002801 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2802 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002803 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002804
2805 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002806 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002807 pcmd += sizeof(uint32_t);
2808 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002809
James Smart858c9f62007-06-17 19:56:39 -05002810 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2811 "Issue LOGO: did:x%x",
2812 ndlp->nlp_DID, 0, 0);
2813
James Smart086a3452012-08-14 14:25:21 -04002814 /*
2815 * If we are issuing a LOGO, we may try to recover the remote NPort
2816 * by issuing a PLOGI later. Even though we issue ELS cmds by the
2817 * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
2818 * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
2819 * for that ELS cmd. To avoid this situation, lets get rid of the
2820 * RPI right now, before any ELS cmds are sent.
2821 */
2822 spin_lock_irq(shost->host_lock);
2823 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
2824 spin_unlock_irq(shost->host_lock);
2825 if (lpfc_unreg_rpi(vport, ndlp)) {
2826 lpfc_els_free_iocb(phba, elsiocb);
2827 return 0;
2828 }
2829
dea31012005-04-17 16:05:31 -05002830 phba->fc_stat.elsXmitLOGO++;
2831 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002832 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002833 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart086a3452012-08-14 14:25:21 -04002834 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
James Smart2e0fef82007-06-17 19:56:36 -05002835 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002836 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002837
2838 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002839 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002840 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002841 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002842 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002843 return 1;
dea31012005-04-17 16:05:31 -05002844 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002845 return 0;
dea31012005-04-17 16:05:31 -05002846}
2847
James Smarte59058c2008-08-24 21:49:00 -04002848/**
James Smart3621a712009-04-06 18:47:14 -04002849 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002850 * @phba: pointer to lpfc hba data structure.
2851 * @cmdiocb: pointer to lpfc command iocb data structure.
2852 * @rspiocb: pointer to lpfc response iocb data structure.
2853 *
2854 * This routine is a generic completion callback function for ELS commands.
2855 * Specifically, it is the callback function which does not need to perform
2856 * any command specific operations. It is currently used by the ELS command
2857 * issuing routines for the ELS State Change Request (SCR),
2858 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2859 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2860 * certain debug loggings, this callback function simply invokes the
2861 * lpfc_els_chk_latt() routine to check whether link went down during the
2862 * discovery process.
2863 **/
dea31012005-04-17 16:05:31 -05002864static void
James Smart2e0fef82007-06-17 19:56:36 -05002865lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2866 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002867{
James Smart2e0fef82007-06-17 19:56:36 -05002868 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002869 IOCB_t *irsp;
2870
2871 irsp = &rspiocb->iocb;
2872
James Smart858c9f62007-06-17 19:56:39 -05002873 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2874 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2875 irsp->ulpStatus, irsp->un.ulpWord[4],
2876 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002877 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002878 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2879 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2880 irsp->ulpIoTag, irsp->ulpStatus,
2881 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002882 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002883 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002884 lpfc_els_free_iocb(phba, cmdiocb);
2885 return;
2886}
2887
James Smarte59058c2008-08-24 21:49:00 -04002888/**
James Smart3621a712009-04-06 18:47:14 -04002889 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002890 * @vport: pointer to a host virtual N_Port data structure.
2891 * @nportid: N_Port identifier to the remote node.
2892 * @retry: number of retries to the command IOCB.
2893 *
2894 * This routine issues a State Change Request (SCR) to a fabric node
2895 * on a @vport. The remote node @nportid is passed into the function. It
2896 * first search the @vport node list to find the matching ndlp. If no such
2897 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2898 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2899 * routine is invoked to send the SCR IOCB.
2900 *
2901 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2902 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2903 * will be stored into the context1 field of the IOCB for the completion
2904 * callback function to the SCR ELS command.
2905 *
2906 * Return code
2907 * 0 - Successfully issued scr command
2908 * 1 - Failed to issue scr command
2909 **/
dea31012005-04-17 16:05:31 -05002910int
James Smart2e0fef82007-06-17 19:56:36 -05002911lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002912{
James Smart2e0fef82007-06-17 19:56:36 -05002913 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002914 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002915 uint8_t *pcmd;
2916 uint16_t cmdsize;
2917 struct lpfc_nodelist *ndlp;
2918
James Smart92d7f7b2007-06-17 19:56:38 -05002919 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002920
James Smarte47c9092008-02-08 18:49:26 -05002921 ndlp = lpfc_findnode_did(vport, nportid);
2922 if (!ndlp) {
James Smart9d3d3402017-04-21 16:05:00 -07002923 ndlp = lpfc_nlp_init(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002924 if (!ndlp)
2925 return 1;
James Smarte47c9092008-02-08 18:49:26 -05002926 lpfc_enqueue_node(vport, ndlp);
2927 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2928 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2929 if (!ndlp)
2930 return 1;
2931 }
dea31012005-04-17 16:05:31 -05002932
James Smart2e0fef82007-06-17 19:56:36 -05002933 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2934 ndlp->nlp_DID, ELS_CMD_SCR);
2935
James Smart488d1462006-03-07 15:02:37 -05002936 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002937 /* This will trigger the release of the node just
2938 * allocated
2939 */
James Smart329f9bc2007-04-25 09:53:01 -04002940 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002941 return 1;
dea31012005-04-17 16:05:31 -05002942 }
2943
dea31012005-04-17 16:05:31 -05002944 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2945
2946 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002947 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002948
2949 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002950 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002951 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2952
James Smart858c9f62007-06-17 19:56:39 -05002953 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2954 "Issue SCR: did:x%x",
2955 ndlp->nlp_DID, 0, 0);
2956
dea31012005-04-17 16:05:31 -05002957 phba->fc_stat.elsXmitSCR++;
2958 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002959 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2960 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002961 /* The additional lpfc_nlp_put will cause the following
2962 * lpfc_els_free_iocb routine to trigger the rlease of
2963 * the node.
2964 */
James Smart329f9bc2007-04-25 09:53:01 -04002965 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002966 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002967 return 1;
dea31012005-04-17 16:05:31 -05002968 }
James Smartfa4066b2008-01-11 01:53:27 -05002969 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2970 * trigger the release of node.
2971 */
James Smartb7e50c52017-11-20 16:00:37 -08002972 if (!(vport->fc_flag & FC_PT2PT))
2973 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002974 return 0;
dea31012005-04-17 16:05:31 -05002975}
2976
James Smarte59058c2008-08-24 21:49:00 -04002977/**
James Smart3621a712009-04-06 18:47:14 -04002978 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002979 * @vport: pointer to a host virtual N_Port data structure.
2980 * @nportid: N_Port identifier to the remote node.
2981 * @retry: number of retries to the command IOCB.
2982 *
2983 * This routine issues a Fibre Channel Address Resolution Response
2984 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2985 * is passed into the function. It first search the @vport node list to find
2986 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2987 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2988 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2989 *
2990 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2991 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2992 * will be stored into the context1 field of the IOCB for the completion
2993 * callback function to the PARPR ELS command.
2994 *
2995 * Return code
2996 * 0 - Successfully issued farpr command
2997 * 1 - Failed to issue farpr command
2998 **/
dea31012005-04-17 16:05:31 -05002999static int
James Smart2e0fef82007-06-17 19:56:36 -05003000lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05003001{
James Smart2e0fef82007-06-17 19:56:36 -05003002 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003003 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003004 FARP *fp;
3005 uint8_t *pcmd;
3006 uint32_t *lp;
3007 uint16_t cmdsize;
3008 struct lpfc_nodelist *ondlp;
3009 struct lpfc_nodelist *ndlp;
3010
James Smart92d7f7b2007-06-17 19:56:38 -05003011 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05003012
James Smarte47c9092008-02-08 18:49:26 -05003013 ndlp = lpfc_findnode_did(vport, nportid);
3014 if (!ndlp) {
James Smart9d3d3402017-04-21 16:05:00 -07003015 ndlp = lpfc_nlp_init(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05003016 if (!ndlp)
3017 return 1;
James Smarte47c9092008-02-08 18:49:26 -05003018 lpfc_enqueue_node(vport, ndlp);
3019 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3020 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3021 if (!ndlp)
3022 return 1;
3023 }
James Smart2e0fef82007-06-17 19:56:36 -05003024
3025 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3026 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05003027 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05003028 /* This will trigger the release of the node just
3029 * allocated
3030 */
James Smart329f9bc2007-04-25 09:53:01 -04003031 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003032 return 1;
dea31012005-04-17 16:05:31 -05003033 }
3034
dea31012005-04-17 16:05:31 -05003035 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3036
3037 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05003038 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003039
3040 /* Fill in FARPR payload */
3041 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05003042 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05003043 lp = (uint32_t *) pcmd;
3044 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05003045 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003046 fp->Rflags = 0;
3047 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
3048
James Smart92d7f7b2007-06-17 19:56:38 -05003049 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
3050 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003051 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05003052 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05003053 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003054 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003055 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05003056 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003057 }
3058
James Smart858c9f62007-06-17 19:56:39 -05003059 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3060 "Issue FARPR: did:x%x",
3061 ndlp->nlp_DID, 0, 0);
3062
dea31012005-04-17 16:05:31 -05003063 phba->fc_stat.elsXmitFARPR++;
3064 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04003065 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3066 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05003067 /* The additional lpfc_nlp_put will cause the following
3068 * lpfc_els_free_iocb routine to trigger the release of
3069 * the node.
3070 */
James Smart329f9bc2007-04-25 09:53:01 -04003071 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003072 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003073 return 1;
dea31012005-04-17 16:05:31 -05003074 }
James Smartfa4066b2008-01-11 01:53:27 -05003075 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3076 * trigger the release of the node.
3077 */
James Smart329f9bc2007-04-25 09:53:01 -04003078 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003079 return 0;
dea31012005-04-17 16:05:31 -05003080}
3081
James Smarte59058c2008-08-24 21:49:00 -04003082/**
James Smart3621a712009-04-06 18:47:14 -04003083 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04003084 * @vport: pointer to a host virtual N_Port data structure.
3085 * @nlp: pointer to a node-list data structure.
3086 *
3087 * This routine cancels the timer with a delayed IOCB-command retry for
3088 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3089 * removes the ELS retry event if it presents. In addition, if the
3090 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3091 * commands are sent for the @vport's nodes that require issuing discovery
3092 * ADISC.
3093 **/
dea31012005-04-17 16:05:31 -05003094void
James Smart2e0fef82007-06-17 19:56:36 -05003095lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05003096{
James Smart2e0fef82007-06-17 19:56:36 -05003097 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05003098 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05003099
James Smart0d2b6b82008-06-14 22:52:47 -04003100 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3101 return;
James Smart2e0fef82007-06-17 19:56:36 -05003102 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05003103 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003104 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05003105 del_timer_sync(&nlp->nlp_delayfunc);
3106 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05003107 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05003108 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05003109 /* Decrement nlp reference count held for the delayed retry */
3110 evtp = &nlp->els_retry_evt;
3111 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3112 }
James Smartfdcebe22006-03-07 15:04:01 -05003113 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05003114 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05003115 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05003116 spin_unlock_irq(shost->host_lock);
3117 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04003118 if (vport->port_state < LPFC_VPORT_READY) {
3119 /* Check if there are more ADISCs to be sent */
3120 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04003121 } else {
3122 /* Check if there are more PLOGIs to be sent */
3123 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04003124 if (vport->num_disc_nodes == 0) {
3125 spin_lock_irq(shost->host_lock);
3126 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3127 spin_unlock_irq(shost->host_lock);
3128 lpfc_can_disctmo(vport);
3129 lpfc_end_rscn(vport);
3130 }
James Smartfdcebe22006-03-07 15:04:01 -05003131 }
3132 }
3133 }
3134 return;
3135}
3136
James Smarte59058c2008-08-24 21:49:00 -04003137/**
James Smart3621a712009-04-06 18:47:14 -04003138 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04003139 * @ptr: holder for the pointer to the timer function associated data (ndlp).
3140 *
3141 * This routine is invoked by the ndlp delayed-function timer to check
3142 * whether there is any pending ELS retry event(s) with the node. If not, it
3143 * simply returns. Otherwise, if there is at least one ELS delayed event, it
3144 * adds the delayed events to the HBA work list and invokes the
3145 * lpfc_worker_wake_up() routine to wake up worker thread to process the
3146 * event. Note that lpfc_nlp_get() is called before posting the event to
3147 * the work list to hold reference count of ndlp so that it guarantees the
3148 * reference to ndlp will still be available when the worker thread gets
3149 * to the event associated with the ndlp.
3150 **/
James Smartfdcebe22006-03-07 15:04:01 -05003151void
Kees Cookf22eb4d2017-09-06 20:24:26 -07003152lpfc_els_retry_delay(struct timer_list *t)
dea31012005-04-17 16:05:31 -05003153{
Kees Cookf22eb4d2017-09-06 20:24:26 -07003154 struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
James Smart2e0fef82007-06-17 19:56:36 -05003155 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05003156 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05003157 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05003158 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05003159
James Smart92d7f7b2007-06-17 19:56:38 -05003160 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003161 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003162 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003163 return;
3164 }
3165
James Smartfa4066b2008-01-11 01:53:27 -05003166 /* We need to hold the node by incrementing the reference
3167 * count until the queued work is done
3168 */
3169 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04003170 if (evtp->evt_arg1) {
3171 evtp->evt = LPFC_EVT_ELS_RETRY;
3172 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05003173 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04003174 }
James Smart92d7f7b2007-06-17 19:56:38 -05003175 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003176 return;
3177}
3178
James Smarte59058c2008-08-24 21:49:00 -04003179/**
James Smart3621a712009-04-06 18:47:14 -04003180 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04003181 * @ndlp: pointer to a node-list data structure.
3182 *
3183 * This routine is the worker-thread handler for processing the @ndlp delayed
3184 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3185 * the last ELS command from the associated ndlp and invokes the proper ELS
3186 * function according to the delayed ELS command to retry the command.
3187 **/
dea31012005-04-17 16:05:31 -05003188void
3189lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3190{
James Smart2e0fef82007-06-17 19:56:36 -05003191 struct lpfc_vport *vport = ndlp->vport;
3192 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarteb016562014-09-03 12:58:06 -04003193 uint32_t cmd, retry;
dea31012005-04-17 16:05:31 -05003194
James Smart2e0fef82007-06-17 19:56:36 -05003195 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003196 cmd = ndlp->nlp_last_elscmd;
3197 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05003198
3199 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05003200 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003201 return;
3202 }
3203
3204 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003205 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05003206 /*
3207 * If a discovery event readded nlp_delayfunc after timer
3208 * firing and before processing the timer, cancel the
3209 * nlp_delayfunc.
3210 */
3211 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05003212 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04003213 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05003214
3215 switch (cmd) {
3216 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003217 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05003218 break;
3219 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003220 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003221 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003222 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003223 }
dea31012005-04-17 16:05:31 -05003224 break;
3225 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05003226 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003227 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003228 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003229 }
dea31012005-04-17 16:05:31 -05003230 break;
3231 case ELS_CMD_PRLI:
James Smarta0f2d3e2017-02-12 13:52:31 -08003232 case ELS_CMD_NVMEPRLI:
James Smart2e0fef82007-06-17 19:56:36 -05003233 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003234 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003235 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003236 }
dea31012005-04-17 16:05:31 -05003237 break;
3238 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05003239 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003240 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04003241 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003242 }
dea31012005-04-17 16:05:31 -05003243 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003244 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05003245 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3246 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05003247 break;
dea31012005-04-17 16:05:31 -05003248 }
3249 return;
3250}
3251
James Smarte59058c2008-08-24 21:49:00 -04003252/**
James Smart3621a712009-04-06 18:47:14 -04003253 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04003254 * @phba: pointer to lpfc hba data structure.
3255 * @cmdiocb: pointer to lpfc command iocb data structure.
3256 * @rspiocb: pointer to lpfc response iocb data structure.
3257 *
3258 * This routine makes a retry decision on an ELS command IOCB, which has
3259 * failed. The following ELS IOCBs use this function for retrying the command
3260 * when previously issued command responsed with error status: FLOGI, PLOGI,
3261 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3262 * returned error status, it makes the decision whether a retry shall be
3263 * issued for the command, and whether a retry shall be made immediately or
3264 * delayed. In the former case, the corresponding ELS command issuing-function
3265 * is called to retry the command. In the later case, the ELS command shall
3266 * be posted to the ndlp delayed event and delayed function timer set to the
3267 * ndlp for the delayed command issusing.
3268 *
3269 * Return code
3270 * 0 - No retry of els command is made
3271 * 1 - Immediate or delayed retry of els command is made
3272 **/
dea31012005-04-17 16:05:31 -05003273static int
James Smart2e0fef82007-06-17 19:56:36 -05003274lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3275 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003276{
James Smart2e0fef82007-06-17 19:56:36 -05003277 struct lpfc_vport *vport = cmdiocb->vport;
3278 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3279 IOCB_t *irsp = &rspiocb->iocb;
3280 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3281 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05003282 uint32_t *elscmd;
3283 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05003284 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04003285 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003286 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05003287 uint32_t did;
dea31012005-04-17 16:05:31 -05003288
James Smart488d1462006-03-07 15:02:37 -05003289
dea31012005-04-17 16:05:31 -05003290 /* Note: context2 may be 0 for internal driver abort
3291 * of delays ELS command.
3292 */
3293
3294 if (pcmd && pcmd->virt) {
3295 elscmd = (uint32_t *) (pcmd->virt);
3296 cmd = *elscmd++;
3297 }
3298
James Smarte47c9092008-02-08 18:49:26 -05003299 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05003300 did = ndlp->nlp_DID;
3301 else {
3302 /* We should only hit this case for retrying PLOGI */
3303 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003304 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05003305 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3306 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05003307 return 1;
3308 }
3309
James Smart858c9f62007-06-17 19:56:39 -05003310 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3311 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3312 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3313
dea31012005-04-17 16:05:31 -05003314 switch (irsp->ulpStatus) {
3315 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05003316 break;
James Smart1151e3e2011-02-16 12:39:35 -05003317 case IOSTAT_REMOTE_STOP:
3318 if (phba->sli_rev == LPFC_SLI_REV4) {
3319 /* This IO was aborted by the target, we don't
3320 * know the rxid and because we did not send the
3321 * ABTS we cannot generate and RRQ.
3322 */
3323 lpfc_set_rrq_active(phba, ndlp,
James Smartee0f4fe2012-05-09 21:19:14 -04003324 cmdiocb->sli4_lxritag, 0, 0);
James Smart1151e3e2011-02-16 12:39:35 -05003325 }
3326 break;
dea31012005-04-17 16:05:31 -05003327 case IOSTAT_LOCAL_REJECT:
James Smarte3d2b802012-08-14 14:25:43 -04003328 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
dea31012005-04-17 16:05:31 -05003329 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05003330 if (cmd == ELS_CMD_FLOGI) {
3331 if (PCI_DEVICE_ID_HORNET ==
3332 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05003333 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05003334 phba->pport->fc_myDID = 0;
3335 phba->alpa_map[0] = 0;
3336 phba->alpa_map[1] = 0;
3337 }
3338 }
James Smart2e0fef82007-06-17 19:56:36 -05003339 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003340 delay = 1000;
dea31012005-04-17 16:05:31 -05003341 retry = 1;
3342 break;
3343
James Smart92d7f7b2007-06-17 19:56:38 -05003344 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05003345 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3346 "0124 Retry illegal cmd x%x "
3347 "retry:x%x delay:x%x\n",
3348 cmd, cmdiocb->retry, delay);
3349 retry = 1;
3350 /* All command's retry policy */
3351 maxretry = 8;
3352 if (cmdiocb->retry > 2)
3353 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05003354 break;
3355
dea31012005-04-17 16:05:31 -05003356 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04003357 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05003358 retry = 1;
3359 if (cmdiocb->retry > 100)
3360 delay = 100;
3361 maxretry = 250;
3362 break;
3363
3364 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05003365 delay = 100;
dea31012005-04-17 16:05:31 -05003366 retry = 1;
3367 break;
3368
James Smart858c9f62007-06-17 19:56:39 -05003369 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05003370 case IOERR_INVALID_RPI:
James Smart5b5b36a2013-01-03 15:43:19 -05003371 if (cmd == ELS_CMD_PLOGI &&
3372 did == NameServer_DID) {
3373 /* Continue forever if plogi to */
3374 /* the nameserver fails */
3375 maxretry = 0;
3376 delay = 100;
3377 }
dea31012005-04-17 16:05:31 -05003378 retry = 1;
3379 break;
3380 }
3381 break;
3382
3383 case IOSTAT_NPORT_RJT:
3384 case IOSTAT_FABRIC_RJT:
3385 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3386 retry = 1;
3387 break;
3388 }
3389 break;
3390
3391 case IOSTAT_NPORT_BSY:
3392 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04003393 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05003394 retry = 1;
3395 break;
3396
3397 case IOSTAT_LS_RJT:
3398 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3399 /* Added for Vendor specifc support
3400 * Just keep retrying for these Rsn / Exp codes
3401 */
3402 switch (stat.un.b.lsRjtRsnCode) {
3403 case LSRJT_UNABLE_TPC:
James Smartdea37e82017-06-01 21:07:07 -07003404 /* The driver has a VALID PLOGI but the rport has
3405 * rejected the PRLI - can't do it now. Delay
3406 * for 1 second and try again - don't care about
3407 * the explanation.
3408 */
3409 if (cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) {
3410 delay = 1000;
3411 maxretry = lpfc_max_els_tries + 1;
3412 retry = 1;
3413 break;
3414 }
3415
3416 /* Legacy bug fix code for targets with PLOGI delays. */
dea31012005-04-17 16:05:31 -05003417 if (stat.un.b.lsRjtRsnCodeExp ==
3418 LSEXP_CMD_IN_PROGRESS) {
3419 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003420 delay = 1000;
dea31012005-04-17 16:05:31 -05003421 maxretry = 48;
3422 }
3423 retry = 1;
3424 break;
3425 }
James Smartffc95492010-06-07 15:23:17 -04003426 if (stat.un.b.lsRjtRsnCodeExp ==
3427 LSEXP_CANT_GIVE_DATA) {
3428 if (cmd == ELS_CMD_PLOGI) {
3429 delay = 1000;
3430 maxretry = 48;
3431 }
3432 retry = 1;
3433 break;
3434 }
James Smartdea37e82017-06-01 21:07:07 -07003435 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003436 delay = 1000;
dea31012005-04-17 16:05:31 -05003437 maxretry = lpfc_max_els_tries + 1;
3438 retry = 1;
3439 break;
3440 }
James Smart92d7f7b2007-06-17 19:56:38 -05003441 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3442 (cmd == ELS_CMD_FDISC) &&
3443 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04003444 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3445 "0125 FDISC Failed (x%x). "
3446 "Fabric out of resources\n",
3447 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003448 lpfc_vport_set_state(vport,
3449 FC_VPORT_NO_FABRIC_RSCS);
3450 }
dea31012005-04-17 16:05:31 -05003451 break;
3452
3453 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003454 if ((cmd == ELS_CMD_PLOGI) ||
James Smarta0f2d3e2017-02-12 13:52:31 -08003455 (cmd == ELS_CMD_PRLI) ||
3456 (cmd == ELS_CMD_NVMEPRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003457 delay = 1000;
dea31012005-04-17 16:05:31 -05003458 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003459 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003460 /* FDISC retry policy */
3461 maxretry = 48;
3462 if (cmdiocb->retry >= 32)
3463 delay = 1000;
dea31012005-04-17 16:05:31 -05003464 }
3465 retry = 1;
3466 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003467
3468 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05003469 /* There are some cases where switches return this
3470 * error when they are not ready and should be returning
3471 * Logical Busy. We should delay every time.
3472 */
3473 if (cmd == ELS_CMD_FDISC &&
3474 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3475 maxretry = 3;
3476 delay = 1000;
3477 retry = 1;
James Smart44fd7fe2017-08-23 16:55:47 -07003478 } else if (cmd == ELS_CMD_FLOGI &&
3479 stat.un.b.lsRjtRsnCodeExp ==
3480 LSEXP_NOTHING_MORE) {
3481 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
3482 retry = 1;
3483 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3484 "0820 FLOGI Failed (x%x). "
3485 "BBCredit Not Supported\n",
3486 stat.un.lsRjtError);
James Smart7f5f3d02008-02-08 18:50:14 -05003487 }
James Smart44fd7fe2017-08-23 16:55:47 -07003488 break;
3489
James Smart92d7f7b2007-06-17 19:56:38 -05003490 case LSRJT_PROTOCOL_ERR:
3491 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3492 (cmd == ELS_CMD_FDISC) &&
3493 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3494 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3495 ) {
James Smarte8b62012007-08-02 11:10:09 -04003496 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04003497 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04003498 "Fabric Detected Bad WWN\n",
3499 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003500 lpfc_vport_set_state(vport,
3501 FC_VPORT_FABRIC_REJ_WWN);
3502 }
3503 break;
James Smart7bdedb32016-07-06 12:36:00 -07003504 case LSRJT_VENDOR_UNIQUE:
3505 if ((stat.un.b.vendorUnique == 0x45) &&
3506 (cmd == ELS_CMD_FLOGI)) {
3507 goto out_retry;
3508 }
3509 break;
Dick Kennedy8db1c2b2017-08-23 16:55:36 -07003510 case LSRJT_CMD_UNSUPPORTED:
3511 /* lpfc nvmet returns this type of LS_RJT when it
3512 * receives an FCP PRLI because lpfc nvmet only
3513 * support NVME. ELS request is terminated for FCP4
3514 * on this rport.
3515 */
3516 if (stat.un.b.lsRjtRsnCodeExp ==
3517 LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) {
3518 spin_lock_irq(shost->host_lock);
3519 ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
3520 spin_unlock_irq(shost->host_lock);
3521 retry = 0;
3522 goto out_retry;
3523 }
3524 break;
dea31012005-04-17 16:05:31 -05003525 }
3526 break;
3527
3528 case IOSTAT_INTERMED_RSP:
3529 case IOSTAT_BA_RJT:
3530 break;
3531
3532 default:
3533 break;
3534 }
3535
James Smart488d1462006-03-07 15:02:37 -05003536 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05003537 retry = 1;
dea31012005-04-17 16:05:31 -05003538
James Smartdf9e1b52011-12-13 13:22:17 -05003539 if ((cmd == ELS_CMD_FLOGI) &&
James Smart76a95d72010-11-20 23:11:48 -05003540 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05003541 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003542 /* FLOGI retry policy */
3543 retry = 1;
James Smartdf9e1b52011-12-13 13:22:17 -05003544 /* retry FLOGI forever */
James Smart6eae4302015-04-07 15:07:23 -04003545 if (phba->link_flag != LS_LOOPBACK_MODE)
3546 maxretry = 0;
3547 else
3548 maxretry = 2;
3549
James Smart6669f9b2009-10-02 15:16:45 -04003550 if (cmdiocb->retry >= 100)
3551 delay = 5000;
3552 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04003553 delay = 1000;
James Smartdf9e1b52011-12-13 13:22:17 -05003554 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3555 /* retry FDISCs every second up to devloss */
3556 retry = 1;
3557 maxretry = vport->cfg_devloss_tmo;
3558 delay = 1000;
James Smart98c9ea52007-10-27 13:37:33 -04003559 }
3560
James Smart6669f9b2009-10-02 15:16:45 -04003561 cmdiocb->retry++;
3562 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003563 phba->fc_stat.elsRetryExceeded++;
3564 retry = 0;
3565 }
3566
James Smarted957682007-06-17 19:56:37 -05003567 if ((vport->load_flag & FC_UNLOADING) != 0)
3568 retry = 0;
3569
James Smart7bdedb32016-07-06 12:36:00 -07003570out_retry:
dea31012005-04-17 16:05:31 -05003571 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003572 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3573 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3574 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3575 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3576 "2849 Stop retry ELS command "
3577 "x%x to remote NPORT x%x, "
3578 "Data: x%x x%x\n", cmd, did,
3579 cmdiocb->retry, delay);
3580 return 0;
3581 }
3582 }
dea31012005-04-17 16:05:31 -05003583
3584 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003585 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3586 "0107 Retry ELS command x%x to remote "
3587 "NPORT x%x Data: x%x x%x\n",
3588 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003589
James Smart858c9f62007-06-17 19:56:39 -05003590 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3591 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04003592 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3593 IOERR_NO_RESOURCES))) {
James Smart858c9f62007-06-17 19:56:39 -05003594 /* Don't reset timer for no resources */
3595
dea31012005-04-17 16:05:31 -05003596 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003597 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003598 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003599 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003600 }
3601
3602 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003603 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003604 phba->fc_stat.elsDelayRetry++;
3605 ndlp->nlp_retry = cmdiocb->retry;
3606
James Smart92d7f7b2007-06-17 19:56:38 -05003607 /* delay is specified in milliseconds */
3608 mod_timer(&ndlp->nlp_delayfunc,
3609 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003610 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003611 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003612 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003613
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003614 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smarta0f2d3e2017-02-12 13:52:31 -08003615 if ((cmd == ELS_CMD_PRLI) ||
3616 (cmd == ELS_CMD_NVMEPRLI))
James Smart858c9f62007-06-17 19:56:39 -05003617 lpfc_nlp_set_state(vport, ndlp,
James Smart4c1b64b2012-09-29 11:31:11 -04003618 NLP_STE_PRLI_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003619 else
3620 lpfc_nlp_set_state(vport, ndlp,
3621 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003622 ndlp->nlp_last_elscmd = cmd;
3623
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003624 return 1;
dea31012005-04-17 16:05:31 -05003625 }
3626 switch (cmd) {
3627 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003628 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003629 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003630 case ELS_CMD_FDISC:
3631 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3632 return 1;
dea31012005-04-17 16:05:31 -05003633 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003634 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003635 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003636 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003637 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003638 }
James Smart2e0fef82007-06-17 19:56:36 -05003639 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003640 return 1;
dea31012005-04-17 16:05:31 -05003641 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003642 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003643 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3644 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003645 return 1;
dea31012005-04-17 16:05:31 -05003646 case ELS_CMD_PRLI:
James Smarta0f2d3e2017-02-12 13:52:31 -08003647 case ELS_CMD_NVMEPRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003648 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003649 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3650 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003651 return 1;
dea31012005-04-17 16:05:31 -05003652 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003653 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04003654 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003655 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003656 return 1;
dea31012005-04-17 16:05:31 -05003657 }
3658 }
dea31012005-04-17 16:05:31 -05003659 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003660 if (logerr) {
3661 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3662 "0137 No retry ELS command x%x to remote "
3663 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3664 cmd, did, irsp->ulpStatus,
3665 irsp->un.ulpWord[4]);
3666 }
3667 else {
3668 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003669 "0108 No retry ELS command x%x to remote "
3670 "NPORT x%x Retried:%d Error:x%x/%x\n",
3671 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3672 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003673 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003674 return 0;
dea31012005-04-17 16:05:31 -05003675}
3676
James Smarte59058c2008-08-24 21:49:00 -04003677/**
James Smart3621a712009-04-06 18:47:14 -04003678 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003679 * @phba: pointer to lpfc hba data structure.
3680 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3681 *
3682 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3683 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3684 * checks to see whether there is a lpfc DMA buffer associated with the
3685 * response of the command IOCB. If so, it will be released before releasing
3686 * the lpfc DMA buffer associated with the IOCB itself.
3687 *
3688 * Return code
3689 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3690 **/
James Smart09372822008-01-11 01:52:54 -05003691static int
James Smart87af33f2007-10-27 13:37:43 -04003692lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3693{
3694 struct lpfc_dmabuf *buf_ptr;
3695
James Smarte59058c2008-08-24 21:49:00 -04003696 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003697 if (!list_empty(&buf_ptr1->list)) {
3698 list_remove_head(&buf_ptr1->list, buf_ptr,
3699 struct lpfc_dmabuf,
3700 list);
3701 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3702 kfree(buf_ptr);
3703 }
3704 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3705 kfree(buf_ptr1);
3706 return 0;
3707}
3708
James Smarte59058c2008-08-24 21:49:00 -04003709/**
James Smart3621a712009-04-06 18:47:14 -04003710 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003711 * @phba: pointer to lpfc hba data structure.
3712 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3713 *
3714 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3715 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3716 * pool.
3717 *
3718 * Return code
3719 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3720 **/
James Smart09372822008-01-11 01:52:54 -05003721static int
James Smart87af33f2007-10-27 13:37:43 -04003722lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3723{
3724 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3725 kfree(buf_ptr);
3726 return 0;
3727}
3728
James Smarte59058c2008-08-24 21:49:00 -04003729/**
James Smart3621a712009-04-06 18:47:14 -04003730 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003731 * @phba: pointer to lpfc hba data structure.
3732 * @elsiocb: pointer to lpfc els command iocb data structure.
3733 *
3734 * This routine frees a command IOCB and its associated resources. The
3735 * command IOCB data structure contains the reference to various associated
3736 * resources, these fields must be set to NULL if the associated reference
3737 * not present:
3738 * context1 - reference to ndlp
3739 * context2 - reference to cmd
3740 * context2->next - reference to rsp
3741 * context3 - reference to bpl
3742 *
3743 * It first properly decrements the reference count held on ndlp for the
3744 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3745 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3746 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3747 * adds the DMA buffer the @phba data structure for the delayed release.
3748 * If reference to the Buffer Pointer List (BPL) is present, the
3749 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3750 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3751 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3752 *
3753 * Return code
3754 * 0 - Success (currently, always return 0)
3755 **/
James Smart87af33f2007-10-27 13:37:43 -04003756int
James Smart329f9bc2007-04-25 09:53:01 -04003757lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003758{
3759 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003760 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003761
James Smarta8adb832007-10-27 13:37:53 -04003762 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3763 if (ndlp) {
3764 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3765 lpfc_nlp_put(ndlp);
3766
3767 /* If the ndlp is not being used by another discovery
3768 * thread, free it.
3769 */
3770 if (!lpfc_nlp_not_used(ndlp)) {
3771 /* If ndlp is being used by another discovery
3772 * thread, just clear NLP_DEFER_RM
3773 */
3774 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3775 }
3776 }
3777 else
3778 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003779 elsiocb->context1 = NULL;
3780 }
dea31012005-04-17 16:05:31 -05003781 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3782 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003783 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3784 /* Firmware could still be in progress of DMAing
3785 * payload, so don't free data buffer till after
3786 * a hbeat.
3787 */
3788 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3789 buf_ptr = elsiocb->context2;
3790 elsiocb->context2 = NULL;
3791 if (buf_ptr) {
3792 buf_ptr1 = NULL;
3793 spin_lock_irq(&phba->hbalock);
3794 if (!list_empty(&buf_ptr->list)) {
3795 list_remove_head(&buf_ptr->list,
3796 buf_ptr1, struct lpfc_dmabuf,
3797 list);
3798 INIT_LIST_HEAD(&buf_ptr1->list);
3799 list_add_tail(&buf_ptr1->list,
3800 &phba->elsbuf);
3801 phba->elsbuf_cnt++;
3802 }
3803 INIT_LIST_HEAD(&buf_ptr->list);
3804 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3805 phba->elsbuf_cnt++;
3806 spin_unlock_irq(&phba->hbalock);
3807 }
3808 } else {
3809 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3810 lpfc_els_free_data(phba, buf_ptr1);
Johannes Thumshirn8667f512017-01-10 12:05:54 +01003811 elsiocb->context2 = NULL;
James Smart0ff10d42008-01-11 01:52:36 -05003812 }
dea31012005-04-17 16:05:31 -05003813 }
3814
3815 if (elsiocb->context3) {
3816 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003817 lpfc_els_free_bpl(phba, buf_ptr);
Johannes Thumshirn8667f512017-01-10 12:05:54 +01003818 elsiocb->context3 = NULL;
dea31012005-04-17 16:05:31 -05003819 }
James Bottomley604a3e32005-10-29 10:28:33 -05003820 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003821 return 0;
3822}
3823
James Smarte59058c2008-08-24 21:49:00 -04003824/**
James Smart3621a712009-04-06 18:47:14 -04003825 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003826 * @phba: pointer to lpfc hba data structure.
3827 * @cmdiocb: pointer to lpfc command iocb data structure.
3828 * @rspiocb: pointer to lpfc response iocb data structure.
3829 *
3830 * This routine is the completion callback function to the Logout (LOGO)
3831 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3832 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3833 * release the ndlp if it has the last reference remaining (reference count
3834 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3835 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3836 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3837 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3838 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3839 * IOCB data structure.
3840 **/
dea31012005-04-17 16:05:31 -05003841static void
James Smart2e0fef82007-06-17 19:56:36 -05003842lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3843 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003844{
James Smart2e0fef82007-06-17 19:56:36 -05003845 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3846 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003847 IOCB_t *irsp;
3848
3849 irsp = &rspiocb->iocb;
3850 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3851 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3852 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003853 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003854 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3855 "0109 ACC to LOGO completes to NPort x%x "
3856 "Data: x%x x%x x%x\n",
3857 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3858 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003859
3860 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3861 /* NPort Recovery mode or node is just allocated */
3862 if (!lpfc_nlp_not_used(ndlp)) {
3863 /* If the ndlp is being used by another discovery
3864 * thread, just unregister the RPI.
3865 */
3866 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003867 } else {
3868 /* Indicate the node has already released, should
3869 * not reference to it from within lpfc_els_free_iocb.
3870 */
3871 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003872 }
dea31012005-04-17 16:05:31 -05003873 }
James Smart73d91e52011-10-10 21:32:10 -04003874
3875 /*
3876 * The driver received a LOGO from the rport and has ACK'd it.
James Smartdf9e1b52011-12-13 13:22:17 -05003877 * At this point, the driver is done so release the IOCB
James Smart73d91e52011-10-10 21:32:10 -04003878 */
dea31012005-04-17 16:05:31 -05003879 lpfc_els_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05003880}
3881
James Smarte59058c2008-08-24 21:49:00 -04003882/**
James Smart3621a712009-04-06 18:47:14 -04003883 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003884 * @phba: pointer to lpfc hba data structure.
3885 * @pmb: pointer to the driver internal queue element for mailbox command.
3886 *
3887 * This routine is the completion callback function for unregister default
3888 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3889 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3890 * decrements the ndlp reference count held for this completion callback
3891 * function. After that, it invokes the lpfc_nlp_not_used() to check
3892 * whether there is only one reference left on the ndlp. If so, it will
3893 * perform one more decrement and trigger the release of the ndlp.
3894 **/
James Smart858c9f62007-06-17 19:56:39 -05003895void
3896lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3897{
3898 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3899 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3900
3901 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003902 pmb->context2 = NULL;
3903
James Smart858c9f62007-06-17 19:56:39 -05003904 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3905 kfree(mp);
3906 mempool_free(pmb, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04003907 if (ndlp) {
James Smartbe6bb942015-04-07 15:07:22 -04003908 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3909 "0006 rpi%x DID:%x flg:%x %d map:%x %p\n",
3910 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01003911 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04003912 ndlp->nlp_usg_map, ndlp);
James Smart086a3452012-08-14 14:25:21 -04003913 if (NLP_CHK_NODE_ACT(ndlp)) {
3914 lpfc_nlp_put(ndlp);
3915 /* This is the end of the default RPI cleanup logic for
3916 * this ndlp. If no other discovery threads are using
3917 * this ndlp, free all resources associated with it.
3918 */
3919 lpfc_nlp_not_used(ndlp);
3920 } else {
3921 lpfc_drop_node(ndlp->vport, ndlp);
3922 }
James Smarta8adb832007-10-27 13:37:53 -04003923 }
James Smart3772a992009-05-22 14:50:54 -04003924
James Smart858c9f62007-06-17 19:56:39 -05003925 return;
3926}
3927
James Smarte59058c2008-08-24 21:49:00 -04003928/**
James Smart3621a712009-04-06 18:47:14 -04003929 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003930 * @phba: pointer to lpfc hba data structure.
3931 * @cmdiocb: pointer to lpfc command iocb data structure.
3932 * @rspiocb: pointer to lpfc response iocb data structure.
3933 *
3934 * This routine is the completion callback function for ELS Response IOCB
3935 * command. In normal case, this callback function just properly sets the
3936 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3937 * field in the command IOCB is not NULL, the referred mailbox command will
3938 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3939 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3940 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3941 * routine shall be invoked trying to release the ndlp if no other threads
3942 * are currently referring it.
3943 **/
dea31012005-04-17 16:05:31 -05003944static void
James Smart858c9f62007-06-17 19:56:39 -05003945lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003946 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003947{
James Smart2e0fef82007-06-17 19:56:36 -05003948 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3949 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3950 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003951 IOCB_t *irsp;
3952 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003953 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003954 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003955 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003956
James Smart33ccf8d2006-08-17 11:57:58 -04003957 irsp = &rspiocb->iocb;
3958
dea31012005-04-17 16:05:31 -05003959 if (cmdiocb->context_un.mbox)
3960 mbox = cmdiocb->context_un.mbox;
3961
James Smartfa4066b2008-01-11 01:53:27 -05003962 /* First determine if this is a LS_RJT cmpl. Note, this callback
3963 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3964 */
James Smart87af33f2007-10-27 13:37:43 -04003965 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003966 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3967 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003968 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3fb2010-02-03 08:01:28 +08003969 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003970 */
3971 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3972 ls_rjt = 1;
3973 }
3974
dea31012005-04-17 16:05:31 -05003975 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003976 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003977 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003978 mp = (struct lpfc_dmabuf *) mbox->context1;
3979 if (mp) {
3980 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3981 kfree(mp);
3982 }
James Smart329f9bc2007-04-25 09:53:01 -04003983 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003984 }
James Smart58da1ff2008-04-07 10:15:56 -04003985 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3986 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003987 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003988 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003989 /* Indicate the node has already released,
3990 * should not reference to it from within
3991 * the routine lpfc_els_free_iocb.
3992 */
3993 cmdiocb->context1 = NULL;
3994 }
dea31012005-04-17 16:05:31 -05003995 goto out;
3996 }
3997
James Smart858c9f62007-06-17 19:56:39 -05003998 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003999 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05004000 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04004001 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05004002 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04004003 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4004 "0110 ELS response tag x%x completes "
4005 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
4006 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
4007 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
4008 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4009 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004010 if (mbox) {
4011 if ((rspiocb->iocb.ulpStatus == 0)
4012 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
Dick Kennedy1fe68472017-08-23 16:55:30 -07004013 if (!lpfc_unreg_rpi(vport, ndlp) &&
4014 (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4015 ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE)) {
4016 lpfc_printf_vlog(vport, KERN_INFO,
4017 LOG_DISCOVERY,
4018 "0314 PLOGI recov DID x%x "
4019 "Data: x%x x%x x%x\n",
4020 ndlp->nlp_DID, ndlp->nlp_state,
4021 ndlp->nlp_rpi, ndlp->nlp_flag);
4022 mp = mbox->context1;
4023 if (mp) {
4024 lpfc_mbuf_free(phba, mp->virt,
4025 mp->phys);
4026 kfree(mp);
4027 }
4028 mempool_free(mbox, phba->mbox_mem_pool);
4029 goto out;
4030 }
4031
James Smarte47c9092008-02-08 18:49:26 -05004032 /* Increment reference count to ndlp to hold the
4033 * reference to ndlp for the callback function.
4034 */
James Smart329f9bc2007-04-25 09:53:01 -04004035 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05004036 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05004037 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
4038 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4039 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4040 }
4041 else {
4042 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
4043 ndlp->nlp_prev_state = ndlp->nlp_state;
4044 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05004045 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05004046 }
James Smart4b7789b72015-12-16 18:11:55 -05004047
4048 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
James Smart0b727fe2007-10-27 13:37:25 -04004049 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05004050 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05004051 goto out;
James Smart4b7789b72015-12-16 18:11:55 -05004052
4053 /* Decrement the ndlp reference count we
4054 * set for this failed mailbox command.
4055 */
4056 lpfc_nlp_put(ndlp);
4057 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
James Smart98c9ea52007-10-27 13:37:33 -04004058
4059 /* ELS rsp: Cannot issue reg_login for <NPortid> */
4060 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4061 "0138 ELS rsp: Cannot issue reg_login for x%x "
4062 "Data: x%x x%x x%x\n",
4063 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4064 ndlp->nlp_rpi);
4065
James Smartfa4066b2008-01-11 01:53:27 -05004066 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04004067 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05004068 /* Indicate node has already been released,
4069 * should not reference to it from within
4070 * the routine lpfc_els_free_iocb.
4071 */
4072 cmdiocb->context1 = NULL;
4073 }
dea31012005-04-17 16:05:31 -05004074 } else {
James Smart858c9f62007-06-17 19:56:39 -05004075 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
4076 if (!lpfc_error_lost_link(irsp) &&
4077 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05004078 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04004079 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05004080 /* Indicate node has already been
4081 * released, should not reference
4082 * to it from within the routine
4083 * lpfc_els_free_iocb.
4084 */
4085 cmdiocb->context1 = NULL;
4086 }
dea31012005-04-17 16:05:31 -05004087 }
4088 }
James Smart14691152006-12-02 13:34:28 -05004089 mp = (struct lpfc_dmabuf *) mbox->context1;
4090 if (mp) {
4091 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4092 kfree(mp);
4093 }
4094 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004095 }
4096out:
James Smart58da1ff2008-04-07 10:15:56 -04004097 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05004098 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05004099 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05004100 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04004101
4102 /* If the node is not being used by another discovery thread,
4103 * and we are sending a reject, we are done with it.
4104 * Release driver reference count here and free associated
4105 * resources.
4106 */
4107 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05004108 if (lpfc_nlp_not_used(ndlp))
4109 /* Indicate node has already been released,
4110 * should not reference to it from within
4111 * the routine lpfc_els_free_iocb.
4112 */
4113 cmdiocb->context1 = NULL;
James Smart4b7789b72015-12-16 18:11:55 -05004114
dea31012005-04-17 16:05:31 -05004115 }
James Smart87af33f2007-10-27 13:37:43 -04004116
dea31012005-04-17 16:05:31 -05004117 lpfc_els_free_iocb(phba, cmdiocb);
4118 return;
4119}
4120
James Smarte59058c2008-08-24 21:49:00 -04004121/**
James Smart3621a712009-04-06 18:47:14 -04004122 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004123 * @vport: pointer to a host virtual N_Port data structure.
4124 * @flag: the els command code to be accepted.
4125 * @oldiocb: pointer to the original lpfc command iocb data structure.
4126 * @ndlp: pointer to a node-list data structure.
4127 * @mbox: pointer to the driver internal queue element for mailbox command.
4128 *
4129 * This routine prepares and issues an Accept (ACC) response IOCB
4130 * command. It uses the @flag to properly set up the IOCB field for the
4131 * specific ACC response command to be issued and invokes the
4132 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
4133 * @mbox pointer is passed in, it will be put into the context_un.mbox
4134 * field of the IOCB for the completion callback function to issue the
4135 * mailbox command to the HBA later when callback is invoked.
4136 *
4137 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4138 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4139 * will be stored into the context1 field of the IOCB for the completion
4140 * callback function to the corresponding response ELS IOCB command.
4141 *
4142 * Return code
4143 * 0 - Successfully issued acc response
4144 * 1 - Failed to issue acc response
4145 **/
dea31012005-04-17 16:05:31 -05004146int
James Smart2e0fef82007-06-17 19:56:36 -05004147lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
4148 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04004149 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05004150{
James Smart2e0fef82007-06-17 19:56:36 -05004151 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4152 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004153 IOCB_t *icmd;
4154 IOCB_t *oldcmd;
4155 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004156 uint8_t *pcmd;
James Smartd6de08c2015-12-16 18:11:53 -05004157 struct serv_parm *sp;
dea31012005-04-17 16:05:31 -05004158 uint16_t cmdsize;
4159 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04004160 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05004161
dea31012005-04-17 16:05:31 -05004162 oldcmd = &oldiocb->iocb;
4163
4164 switch (flag) {
4165 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05004166 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05004167 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4168 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004169 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05004170 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004171 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05004172 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004173 return 1;
dea31012005-04-17 16:05:31 -05004174 }
James Smart2e0fef82007-06-17 19:56:36 -05004175
dea31012005-04-17 16:05:31 -05004176 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004177 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4178 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05004179 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4180 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004181 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05004182
4183 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4184 "Issue ACC: did:x%x flg:x%x",
4185 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05004186 break;
James Smartd6de08c2015-12-16 18:11:53 -05004187 case ELS_CMD_FLOGI:
dea31012005-04-17 16:05:31 -05004188 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05004189 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05004190 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4191 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004192 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004193 return 1;
James Smart488d1462006-03-07 15:02:37 -05004194
dea31012005-04-17 16:05:31 -05004195 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004196 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4197 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05004198 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4199
4200 if (mbox)
4201 elsiocb->context_un.mbox = mbox;
4202
4203 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004204 pcmd += sizeof(uint32_t);
James Smartd6de08c2015-12-16 18:11:53 -05004205 sp = (struct serv_parm *)pcmd;
4206
4207 if (flag == ELS_CMD_FLOGI) {
4208 /* Copy the received service parameters back */
4209 memcpy(sp, &phba->fc_fabparam,
4210 sizeof(struct serv_parm));
4211
4212 /* Clear the F_Port bit */
4213 sp->cmn.fPort = 0;
4214
4215 /* Mark all class service parameters as invalid */
4216 sp->cls1.classValid = 0;
4217 sp->cls2.classValid = 0;
4218 sp->cls3.classValid = 0;
4219 sp->cls4.classValid = 0;
4220
4221 /* Copy our worldwide names */
4222 memcpy(&sp->portName, &vport->fc_sparam.portName,
4223 sizeof(struct lpfc_name));
4224 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4225 sizeof(struct lpfc_name));
James Smart8c258642017-02-12 13:52:36 -08004226 } else {
James Smartd6de08c2015-12-16 18:11:53 -05004227 memcpy(pcmd, &vport->fc_sparam,
4228 sizeof(struct serv_parm));
James Smarte0165f22016-12-19 15:07:20 -08004229
James Smart8c258642017-02-12 13:52:36 -08004230 sp->cmn.valid_vendor_ver_level = 0;
4231 memset(sp->un.vendorVersion, 0,
4232 sizeof(sp->un.vendorVersion));
James Smart44fd7fe2017-08-23 16:55:47 -07004233 sp->cmn.bbRcvSizeMsb &= 0xF;
James Smart8c258642017-02-12 13:52:36 -08004234
4235 /* If our firmware supports this feature, convey that
4236 * info to the target using the vendor specific field.
4237 */
4238 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4239 sp->cmn.valid_vendor_ver_level = 1;
4240 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4241 sp->un.vv.flags =
4242 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4243 }
4244 }
4245
James Smart858c9f62007-06-17 19:56:39 -05004246 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smartd6de08c2015-12-16 18:11:53 -05004247 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
James Smart858c9f62007-06-17 19:56:39 -05004248 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05004249 break;
James Smart82d9a2a2006-04-15 11:53:05 -04004250 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05004251 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05004252 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04004253 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4254 if (!elsiocb)
4255 return 1;
4256
4257 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004258 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4259 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04004260 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4261
4262 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05004263 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04004264 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4265 els_pkt_ptr = (ELS_PKT *) pcmd;
4266 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05004267
4268 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4269 "Issue ACC PRLO: did:x%x flg:x%x",
4270 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04004271 break;
dea31012005-04-17 16:05:31 -05004272 default:
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004273 return 1;
dea31012005-04-17 16:05:31 -05004274 }
dea31012005-04-17 16:05:31 -05004275 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004276 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4277 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
James Smarte6446432012-05-09 21:16:42 -04004278 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
4279 "fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04004280 elsiocb->iotag, elsiocb->iocb.ulpContext,
4281 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
James Smarte6446432012-05-09 21:16:42 -04004282 ndlp->nlp_rpi, vport->fc_flag);
dea31012005-04-17 16:05:31 -05004283 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05004284 spin_lock_irq(shost->host_lock);
James Smart7c5e5182015-05-22 10:42:43 -04004285 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4286 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4287 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05004288 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004289 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4290 } else {
James Smart858c9f62007-06-17 19:56:39 -05004291 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004292 }
4293
4294 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004295 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004296 if (rc == IOCB_ERROR) {
4297 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004298 return 1;
dea31012005-04-17 16:05:31 -05004299 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004300 return 0;
dea31012005-04-17 16:05:31 -05004301}
4302
James Smarte59058c2008-08-24 21:49:00 -04004303/**
James Smart3621a712009-04-06 18:47:14 -04004304 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004305 * @vport: pointer to a virtual N_Port data structure.
4306 * @rejectError:
4307 * @oldiocb: pointer to the original lpfc command iocb data structure.
4308 * @ndlp: pointer to a node-list data structure.
4309 * @mbox: pointer to the driver internal queue element for mailbox command.
4310 *
4311 * This routine prepares and issue an Reject (RJT) response IOCB
4312 * command. If a @mbox pointer is passed in, it will be put into the
4313 * context_un.mbox field of the IOCB for the completion callback function
4314 * to issue to the HBA later.
4315 *
4316 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4317 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4318 * will be stored into the context1 field of the IOCB for the completion
4319 * callback function to the reject response ELS IOCB command.
4320 *
4321 * Return code
4322 * 0 - Successfully issued reject response
4323 * 1 - Failed to issue reject response
4324 **/
dea31012005-04-17 16:05:31 -05004325int
James Smart2e0fef82007-06-17 19:56:36 -05004326lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05004327 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4328 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05004329{
James Smart2e0fef82007-06-17 19:56:36 -05004330 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004331 IOCB_t *icmd;
4332 IOCB_t *oldcmd;
4333 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004334 uint8_t *pcmd;
4335 uint16_t cmdsize;
4336 int rc;
4337
James Smart92d7f7b2007-06-17 19:56:38 -05004338 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05004339 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4340 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05004341 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004342 return 1;
dea31012005-04-17 16:05:31 -05004343
4344 icmd = &elsiocb->iocb;
4345 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004346 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4347 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05004348 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4349
4350 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05004351 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004352 *((uint32_t *) (pcmd)) = rejectError;
4353
James Smart51ef4c22007-08-02 11:10:31 -04004354 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05004355 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05004356
dea31012005-04-17 16:05:31 -05004357 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004358 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4359 "0129 Xmit ELS RJT x%x response tag x%x "
4360 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4361 "rpi x%x\n",
4362 rejectError, elsiocb->iotag,
4363 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4364 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004365 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4366 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4367 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4368
dea31012005-04-17 16:05:31 -05004369 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05004370 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004371 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04004372
dea31012005-04-17 16:05:31 -05004373 if (rc == IOCB_ERROR) {
4374 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004375 return 1;
dea31012005-04-17 16:05:31 -05004376 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004377 return 0;
dea31012005-04-17 16:05:31 -05004378}
4379
James Smarte59058c2008-08-24 21:49:00 -04004380/**
James Smart3621a712009-04-06 18:47:14 -04004381 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004382 * @vport: pointer to a virtual N_Port data structure.
4383 * @oldiocb: pointer to the original lpfc command iocb data structure.
4384 * @ndlp: pointer to a node-list data structure.
4385 *
4386 * This routine prepares and issues an Accept (ACC) response to Address
4387 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4388 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4389 *
4390 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4391 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4392 * will be stored into the context1 field of the IOCB for the completion
4393 * callback function to the ADISC Accept response ELS IOCB command.
4394 *
4395 * Return code
4396 * 0 - Successfully issued acc adisc response
4397 * 1 - Failed to issue adisc acc response
4398 **/
dea31012005-04-17 16:05:31 -05004399int
James Smart2e0fef82007-06-17 19:56:36 -05004400lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4401 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004402{
James Smart2e0fef82007-06-17 19:56:36 -05004403 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004404 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05004405 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004406 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004407 uint8_t *pcmd;
4408 uint16_t cmdsize;
4409 int rc;
4410
James Smart92d7f7b2007-06-17 19:56:38 -05004411 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05004412 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4413 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004414 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004415 return 1;
dea31012005-04-17 16:05:31 -05004416
dea31012005-04-17 16:05:31 -05004417 icmd = &elsiocb->iocb;
4418 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004419 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4420 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04004421
4422 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004423 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4424 "0130 Xmit ADISC ACC response iotag x%x xri: "
4425 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4426 elsiocb->iotag, elsiocb->iocb.ulpContext,
4427 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4428 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004429 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4430
4431 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004432 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004433
4434 ap = (ADISC *) (pcmd);
4435 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05004436 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4437 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05004438 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05004439
James Smart858c9f62007-06-17 19:56:39 -05004440 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4441 "Issue ACC ADISC: did:x%x flg:x%x",
4442 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4443
dea31012005-04-17 16:05:31 -05004444 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004445 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004446 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004447 if (rc == IOCB_ERROR) {
4448 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004449 return 1;
dea31012005-04-17 16:05:31 -05004450 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004451 return 0;
dea31012005-04-17 16:05:31 -05004452}
4453
James Smarte59058c2008-08-24 21:49:00 -04004454/**
James Smart3621a712009-04-06 18:47:14 -04004455 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004456 * @vport: pointer to a virtual N_Port data structure.
4457 * @oldiocb: pointer to the original lpfc command iocb data structure.
4458 * @ndlp: pointer to a node-list data structure.
4459 *
4460 * This routine prepares and issues an Accept (ACC) response to Process
4461 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4462 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4463 *
4464 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4465 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4466 * will be stored into the context1 field of the IOCB for the completion
4467 * callback function to the PRLI Accept response ELS IOCB command.
4468 *
4469 * Return code
4470 * 0 - Successfully issued acc prli response
4471 * 1 - Failed to issue acc prli response
4472 **/
dea31012005-04-17 16:05:31 -05004473int
James Smart2e0fef82007-06-17 19:56:36 -05004474lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04004475 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004476{
James Smart2e0fef82007-06-17 19:56:36 -05004477 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004478 PRLI *npr;
James Smarta0f2d3e2017-02-12 13:52:31 -08004479 struct lpfc_nvme_prli *npr_nvme;
dea31012005-04-17 16:05:31 -05004480 lpfc_vpd_t *vpd;
4481 IOCB_t *icmd;
4482 IOCB_t *oldcmd;
4483 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004484 uint8_t *pcmd;
4485 uint16_t cmdsize;
James Smarta0f2d3e2017-02-12 13:52:31 -08004486 uint32_t prli_fc4_req, *req_payload;
4487 struct lpfc_dmabuf *req_buf;
dea31012005-04-17 16:05:31 -05004488 int rc;
James Smarta0f2d3e2017-02-12 13:52:31 -08004489 u32 elsrspcmd;
dea31012005-04-17 16:05:31 -05004490
James Smarta0f2d3e2017-02-12 13:52:31 -08004491 /* Need the incoming PRLI payload to determine if the ACC is for an
4492 * FC4 or NVME PRLI type. The PRLI type is at word 1.
4493 */
4494 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
4495 req_payload = (((uint32_t *)req_buf->virt) + 1);
4496
4497 /* PRLI type payload is at byte 3 for FCP or NVME. */
4498 prli_fc4_req = be32_to_cpu(*req_payload);
4499 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
4500 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4501 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
4502 prli_fc4_req, *((uint32_t *)req_payload));
4503
4504 if (prli_fc4_req == PRLI_FCP_TYPE) {
4505 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
4506 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
4507 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4508 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
4509 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
4510 } else {
4511 return 1;
4512 }
4513
James Smart2e0fef82007-06-17 19:56:36 -05004514 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smarta0f2d3e2017-02-12 13:52:31 -08004515 ndlp->nlp_DID, elsrspcmd);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004516 if (!elsiocb)
4517 return 1;
dea31012005-04-17 16:05:31 -05004518
dea31012005-04-17 16:05:31 -05004519 icmd = &elsiocb->iocb;
4520 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004521 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4522 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4523
James Smart5b8bd0c2007-04-25 09:52:49 -04004524 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004525 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4526 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4527 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4528 elsiocb->iotag, elsiocb->iocb.ulpContext,
4529 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4530 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004531 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
James Smarta0f2d3e2017-02-12 13:52:31 -08004532 memset(pcmd, 0, cmdsize);
dea31012005-04-17 16:05:31 -05004533
James Smartc07f10c2017-04-21 16:04:54 -07004534 *((uint32_t *)(pcmd)) = elsrspcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004535 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004536
4537 /* For PRLI, remainder of payload is PRLI parameter page */
dea31012005-04-17 16:05:31 -05004538 vpd = &phba->vpd;
James Smarta0f2d3e2017-02-12 13:52:31 -08004539
4540 if (prli_fc4_req == PRLI_FCP_TYPE) {
4541 /*
4542 * If the remote port is a target and our firmware version
4543 * is 3.20 or later, set the following bits for FC-TAPE
4544 * support.
4545 */
4546 npr = (PRLI *) pcmd;
4547 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4548 (vpd->rev.feaLevelHigh >= 0x02)) {
4549 npr->ConfmComplAllowed = 1;
4550 npr->Retry = 1;
4551 npr->TaskRetryIdReq = 1;
4552 }
4553 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4554 npr->estabImagePair = 1;
4555 npr->readXferRdyDis = 1;
dea31012005-04-17 16:05:31 -05004556 npr->ConfmComplAllowed = 1;
James Smarta0f2d3e2017-02-12 13:52:31 -08004557 npr->prliType = PRLI_FCP_TYPE;
4558 npr->initiatorFunc = 1;
4559 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4560 /* Respond with an NVME PRLI Type */
4561 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
4562 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
4563 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
4564 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
James Smart8c258642017-02-12 13:52:36 -08004565 if (phba->nvmet_support) {
4566 bf_set(prli_tgt, npr_nvme, 1);
4567 bf_set(prli_disc, npr_nvme, 1);
4568 if (phba->cfg_nvme_enable_fb) {
4569 bf_set(prli_fba, npr_nvme, 1);
4570
4571 /* TBD. Target mode needs to post buffers
4572 * that support the configured first burst
4573 * byte size.
4574 */
4575 bf_set(prli_fb_sz, npr_nvme,
4576 phba->cfg_nvmet_fb_size);
4577 }
4578 } else {
4579 bf_set(prli_init, npr_nvme, 1);
4580 }
dea31012005-04-17 16:05:31 -05004581
James Smarta0f2d3e2017-02-12 13:52:31 -08004582 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
4583 "6015 NVME issue PRLI ACC word1 x%08x "
4584 "word4 x%08x word5 x%08x flag x%x, "
4585 "fcp_info x%x nlp_type x%x\n",
4586 npr_nvme->word1, npr_nvme->word4,
4587 npr_nvme->word5, ndlp->nlp_flag,
4588 ndlp->nlp_fcp_info, ndlp->nlp_type);
4589 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
4590 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
4591 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
4592 } else
4593 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4594 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
4595 prli_fc4_req, ndlp->nlp_fc4_type,
4596 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05004597
James Smart858c9f62007-06-17 19:56:39 -05004598 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4599 "Issue ACC PRLI: did:x%x flg:x%x",
4600 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4601
dea31012005-04-17 16:05:31 -05004602 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004603 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004604
James Smart3772a992009-05-22 14:50:54 -04004605 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004606 if (rc == IOCB_ERROR) {
4607 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004608 return 1;
dea31012005-04-17 16:05:31 -05004609 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004610 return 0;
dea31012005-04-17 16:05:31 -05004611}
4612
James Smarte59058c2008-08-24 21:49:00 -04004613/**
James Smart3621a712009-04-06 18:47:14 -04004614 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004615 * @vport: pointer to a virtual N_Port data structure.
4616 * @format: rnid command format.
4617 * @oldiocb: pointer to the original lpfc command iocb data structure.
4618 * @ndlp: pointer to a node-list data structure.
4619 *
4620 * This routine issues a Request Node Identification Data (RNID) Accept
4621 * (ACC) response. It constructs the RNID ACC response command according to
4622 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4623 * issue the response. Note that this command does not need to hold the ndlp
4624 * reference count for the callback. So, the ndlp reference count taken by
4625 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4626 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4627 * there is no ndlp reference available.
4628 *
4629 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4630 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4631 * will be stored into the context1 field of the IOCB for the completion
4632 * callback function. However, for the RNID Accept Response ELS command,
4633 * this is undone later by this routine after the IOCB is allocated.
4634 *
4635 * Return code
4636 * 0 - Successfully issued acc rnid response
4637 * 1 - Failed to issue acc rnid response
4638 **/
dea31012005-04-17 16:05:31 -05004639static int
James Smart2e0fef82007-06-17 19:56:36 -05004640lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004641 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004642{
James Smart2e0fef82007-06-17 19:56:36 -05004643 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004644 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004645 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004646 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004647 uint8_t *pcmd;
4648 uint16_t cmdsize;
4649 int rc;
4650
James Smart92d7f7b2007-06-17 19:56:38 -05004651 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4652 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004653 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004654 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004655
James Smart2e0fef82007-06-17 19:56:36 -05004656 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4657 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004658 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004659 return 1;
dea31012005-04-17 16:05:31 -05004660
dea31012005-04-17 16:05:31 -05004661 icmd = &elsiocb->iocb;
4662 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004663 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4664 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4665
James Smart5b8bd0c2007-04-25 09:52:49 -04004666 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004667 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4668 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4669 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004670 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004671 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004672 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004673
James Smart92d7f7b2007-06-17 19:56:38 -05004674 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004675 rn = (RNID *) (pcmd);
4676 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004677 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4678 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4679 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004680 switch (format) {
4681 case 0:
4682 rn->SpecificLen = 0;
4683 break;
4684 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004685 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004686 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004687 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004688 rn->un.topologyDisc.unitType = RNID_HBA;
4689 rn->un.topologyDisc.physPort = 0;
4690 rn->un.topologyDisc.attachedNodes = 0;
4691 break;
4692 default:
4693 rn->CommonLen = 0;
4694 rn->SpecificLen = 0;
4695 break;
4696 }
4697
James Smart858c9f62007-06-17 19:56:39 -05004698 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4699 "Issue ACC RNID: did:x%x flg:x%x",
4700 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4701
dea31012005-04-17 16:05:31 -05004702 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004703 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004704
James Smart3772a992009-05-22 14:50:54 -04004705 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004706 if (rc == IOCB_ERROR) {
4707 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004708 return 1;
dea31012005-04-17 16:05:31 -05004709 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004710 return 0;
dea31012005-04-17 16:05:31 -05004711}
4712
James Smarte59058c2008-08-24 21:49:00 -04004713/**
James Smart19ca7602010-11-20 23:11:55 -05004714 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4715 * @vport: pointer to a virtual N_Port data structure.
4716 * @iocb: pointer to the lpfc command iocb data structure.
4717 * @ndlp: pointer to a node-list data structure.
4718 *
4719 * Return
4720 **/
4721static void
4722lpfc_els_clear_rrq(struct lpfc_vport *vport,
James Smarta0f2d3e2017-02-12 13:52:31 -08004723 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
James Smart19ca7602010-11-20 23:11:55 -05004724{
4725 struct lpfc_hba *phba = vport->phba;
4726 uint8_t *pcmd;
4727 struct RRQ *rrq;
4728 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004729 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004730 struct lpfc_node_rrq *prrq;
4731
4732
4733 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4734 pcmd += sizeof(uint32_t);
4735 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004736 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b0622011-04-16 11:03:17 -04004737 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05004738
4739 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4740 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4741 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004742 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b0622011-04-16 11:03:17 -04004743 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05004744 rxid,
4745 iocb->iotag, iocb->iocb.ulpContext);
4746
4747 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4748 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4749 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004750 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b0622011-04-16 11:03:17 -04004751 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05004752 else
4753 xri = rxid;
4754 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004755 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004756 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004757 return;
4758}
4759
4760/**
James Smart12265f62010-10-22 11:05:53 -04004761 * lpfc_els_rsp_echo_acc - Issue echo acc response
4762 * @vport: pointer to a virtual N_Port data structure.
4763 * @data: pointer to echo data to return in the accept.
4764 * @oldiocb: pointer to the original lpfc command iocb data structure.
4765 * @ndlp: pointer to a node-list data structure.
4766 *
4767 * Return code
4768 * 0 - Successfully issued acc echo response
4769 * 1 - Failed to issue acc echo response
4770 **/
4771static int
4772lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4773 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4774{
4775 struct lpfc_hba *phba = vport->phba;
4776 struct lpfc_iocbq *elsiocb;
James Smart12265f62010-10-22 11:05:53 -04004777 uint8_t *pcmd;
4778 uint16_t cmdsize;
4779 int rc;
4780
James Smart12265f62010-10-22 11:05:53 -04004781 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4782
James Smartbf086112011-08-21 21:48:13 -04004783 /* The accumulated length can exceed the BPL_SIZE. For
4784 * now, use this as the limit
4785 */
4786 if (cmdsize > LPFC_BPL_SIZE)
4787 cmdsize = LPFC_BPL_SIZE;
James Smart12265f62010-10-22 11:05:53 -04004788 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4789 ndlp->nlp_DID, ELS_CMD_ACC);
4790 if (!elsiocb)
4791 return 1;
4792
James Smart7851fe22011-07-22 18:36:52 -04004793 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4794 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4795
James Smart12265f62010-10-22 11:05:53 -04004796 /* Xmit ECHO ACC response tag <ulpIoTag> */
4797 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4798 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4799 elsiocb->iotag, elsiocb->iocb.ulpContext);
4800 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4801 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4802 pcmd += sizeof(uint32_t);
4803 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4804
4805 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4806 "Issue ACC ECHO: did:x%x flg:x%x",
4807 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4808
4809 phba->fc_stat.elsXmitACC++;
4810 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart12265f62010-10-22 11:05:53 -04004811
4812 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4813 if (rc == IOCB_ERROR) {
4814 lpfc_els_free_iocb(phba, elsiocb);
4815 return 1;
4816 }
4817 return 0;
4818}
4819
4820/**
James Smart3621a712009-04-06 18:47:14 -04004821 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004822 * @vport: pointer to a host virtual N_Port data structure.
4823 *
4824 * This routine issues Address Discover (ADISC) ELS commands to those
4825 * N_Ports which are in node port recovery state and ADISC has not been issued
4826 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4827 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4828 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4829 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4830 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4831 * IOCBs quit for later pick up. On the other hand, after walking through
4832 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4833 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4834 * no more ADISC need to be sent.
4835 *
4836 * Return code
4837 * The number of N_Ports with adisc issued.
4838 **/
dea31012005-04-17 16:05:31 -05004839int
James Smart2e0fef82007-06-17 19:56:36 -05004840lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004841{
James Smart2e0fef82007-06-17 19:56:36 -05004842 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004843 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004844 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004845
James Smart685f0bf2007-04-25 09:53:08 -04004846 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004847 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004848 if (!NLP_CHK_NODE_ACT(ndlp))
4849 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004850 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4851 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4852 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004853 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004854 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004855 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004856 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004857 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4858 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004859 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004860 vport->num_disc_nodes++;
4861 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004862 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004863 spin_lock_irq(shost->host_lock);
4864 vport->fc_flag |= FC_NLP_MORE;
4865 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004866 break;
dea31012005-04-17 16:05:31 -05004867 }
4868 }
4869 }
4870 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004871 spin_lock_irq(shost->host_lock);
4872 vport->fc_flag &= ~FC_NLP_MORE;
4873 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004874 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004875 return sentadisc;
dea31012005-04-17 16:05:31 -05004876}
4877
James Smarte59058c2008-08-24 21:49:00 -04004878/**
James Smart3621a712009-04-06 18:47:14 -04004879 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004880 * @vport: pointer to a host virtual N_Port data structure.
4881 *
4882 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4883 * which are in node port recovery state, with a @vport. Each time an ELS
4884 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4885 * the per @vport number of discover count (num_disc_nodes) shall be
4886 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4887 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4888 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4889 * later pick up. On the other hand, after walking through all the ndlps with
4890 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4891 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4892 * PLOGI need to be sent.
4893 *
4894 * Return code
4895 * The number of N_Ports with plogi issued.
4896 **/
dea31012005-04-17 16:05:31 -05004897int
James Smart2e0fef82007-06-17 19:56:36 -05004898lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004899{
James Smart2e0fef82007-06-17 19:56:36 -05004900 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004901 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004902 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004903
James Smart2e0fef82007-06-17 19:56:36 -05004904 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4905 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004906 if (!NLP_CHK_NODE_ACT(ndlp))
4907 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004908 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
James Smart8b017a32015-05-21 13:55:18 -04004909 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4910 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4911 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
James Smart685f0bf2007-04-25 09:53:08 -04004912 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004913 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4914 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004915 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004916 vport->num_disc_nodes++;
4917 if (vport->num_disc_nodes >=
James Smart8b017a32015-05-21 13:55:18 -04004918 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004919 spin_lock_irq(shost->host_lock);
4920 vport->fc_flag |= FC_NLP_MORE;
4921 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004922 break;
dea31012005-04-17 16:05:31 -05004923 }
4924 }
4925 }
James Smart87af33f2007-10-27 13:37:43 -04004926 if (sentplogi) {
4927 lpfc_set_disctmo(vport);
4928 }
4929 else {
James Smart2e0fef82007-06-17 19:56:36 -05004930 spin_lock_irq(shost->host_lock);
4931 vport->fc_flag &= ~FC_NLP_MORE;
4932 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004933 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004934 return sentplogi;
dea31012005-04-17 16:05:31 -05004935}
4936
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08004937static uint32_t
James Smart86478872015-05-21 13:55:21 -04004938lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
4939 uint32_t word0)
4940{
4941
4942 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
4943 desc->payload.els_req = word0;
4944 desc->length = cpu_to_be32(sizeof(desc->payload));
James Smart6c92d1d2016-07-06 12:35:55 -07004945
4946 return sizeof(struct fc_rdp_link_service_desc);
James Smart86478872015-05-21 13:55:21 -04004947}
4948
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08004949static uint32_t
James Smart86478872015-05-21 13:55:21 -04004950lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
4951 uint8_t *page_a0, uint8_t *page_a2)
4952{
4953 uint16_t wavelength;
4954 uint16_t temperature;
4955 uint16_t rx_power;
4956 uint16_t tx_bias;
4957 uint16_t tx_power;
4958 uint16_t vcc;
4959 uint16_t flag = 0;
4960 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
4961 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
4962
4963 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
4964
4965 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
4966 &page_a0[SSF_TRANSCEIVER_CODE_B4];
4967 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
4968 &page_a0[SSF_TRANSCEIVER_CODE_B5];
4969
4970 if ((trasn_code_byte4->fc_sw_laser) ||
4971 (trasn_code_byte5->fc_sw_laser_sl) ||
4972 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
4973 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
4974 } else if (trasn_code_byte4->fc_lw_laser) {
4975 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
4976 page_a0[SSF_WAVELENGTH_B0];
4977 if (wavelength == SFP_WAVELENGTH_LC1310)
4978 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
4979 if (wavelength == SFP_WAVELENGTH_LL1550)
4980 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
4981 }
4982 /* check if its SFP+ */
4983 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
4984 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
4985 << SFP_FLAG_CT_SHIFT;
4986
4987 /* check if its OPTICAL */
4988 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
4989 SFP_FLAG_IS_OPTICAL_PORT : 0)
4990 << SFP_FLAG_IS_OPTICAL_SHIFT;
4991
4992 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
4993 page_a2[SFF_TEMPERATURE_B0]);
4994 vcc = (page_a2[SFF_VCC_B1] << 8 |
4995 page_a2[SFF_VCC_B0]);
4996 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
4997 page_a2[SFF_TXPOWER_B0]);
4998 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
4999 page_a2[SFF_TX_BIAS_CURRENT_B0]);
5000 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
5001 page_a2[SFF_RXPOWER_B0]);
5002 desc->sfp_info.temperature = cpu_to_be16(temperature);
5003 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
5004 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
5005 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
5006 desc->sfp_info.vcc = cpu_to_be16(vcc);
5007
5008 desc->sfp_info.flags = cpu_to_be16(flag);
5009 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005010
5011 return sizeof(struct fc_rdp_sfp_desc);
James Smart86478872015-05-21 13:55:21 -04005012}
5013
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005014static uint32_t
James Smart86478872015-05-21 13:55:21 -04005015lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
5016 READ_LNK_VAR *stat)
5017{
5018 uint32_t type;
5019
5020 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
5021
5022 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
5023
5024 desc->info.port_type = cpu_to_be32(type);
5025
5026 desc->info.link_status.link_failure_cnt =
5027 cpu_to_be32(stat->linkFailureCnt);
5028 desc->info.link_status.loss_of_synch_cnt =
5029 cpu_to_be32(stat->lossSyncCnt);
5030 desc->info.link_status.loss_of_signal_cnt =
5031 cpu_to_be32(stat->lossSignalCnt);
5032 desc->info.link_status.primitive_seq_proto_err =
5033 cpu_to_be32(stat->primSeqErrCnt);
5034 desc->info.link_status.invalid_trans_word =
5035 cpu_to_be32(stat->invalidXmitWord);
5036 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
5037
5038 desc->length = cpu_to_be32(sizeof(desc->info));
James Smart6c92d1d2016-07-06 12:35:55 -07005039
5040 return sizeof(struct fc_rdp_link_error_status_desc);
James Smart86478872015-05-21 13:55:21 -04005041}
5042
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005043static uint32_t
James Smart56204982016-03-31 14:12:32 -07005044lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
5045 struct lpfc_vport *vport)
5046{
James Smart3aaaa312016-07-06 12:35:57 -07005047 uint32_t bbCredit;
5048
James Smart56204982016-03-31 14:12:32 -07005049 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
5050
James Smart3aaaa312016-07-06 12:35:57 -07005051 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
5052 (vport->fc_sparam.cmn.bbCreditMsb << 8);
5053 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
5054 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
5055 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
5056 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
5057 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
5058 } else {
James Smart56204982016-03-31 14:12:32 -07005059 desc->bbc_info.attached_port_bbc = 0;
James Smart3aaaa312016-07-06 12:35:57 -07005060 }
James Smart56204982016-03-31 14:12:32 -07005061
5062 desc->bbc_info.rtt = 0;
5063 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005064
5065 return sizeof(struct fc_rdp_bbc_desc);
James Smart56204982016-03-31 14:12:32 -07005066}
5067
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005068static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005069lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
5070 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
James Smart56204982016-03-31 14:12:32 -07005071{
James Smart310429e2016-07-06 12:35:54 -07005072 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005073
5074 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5075
James Smart3aaaa312016-07-06 12:35:57 -07005076 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
5077 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
5078 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
5079 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005080
5081 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5082 flags |= RDP_OET_HIGH_ALARM;
5083 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5084 flags |= RDP_OET_LOW_ALARM;
5085 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5086 flags |= RDP_OET_HIGH_WARNING;
5087 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5088 flags |= RDP_OET_LOW_WARNING;
5089
James Smart56204982016-03-31 14:12:32 -07005090 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
5091 desc->oed_info.function_flags = cpu_to_be32(flags);
5092 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005093 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005094}
5095
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005096static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005097lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
5098 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07005099 uint8_t *page_a2)
5100{
James Smart310429e2016-07-06 12:35:54 -07005101 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005102
5103 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5104
James Smart3aaaa312016-07-06 12:35:57 -07005105 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
5106 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
5107 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
5108 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005109
5110 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5111 flags |= RDP_OET_HIGH_ALARM;
5112 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5113 flags |= RDP_OET_LOW_ALARM;
5114 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5115 flags |= RDP_OET_HIGH_WARNING;
5116 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5117 flags |= RDP_OET_LOW_WARNING;
5118
James Smart56204982016-03-31 14:12:32 -07005119 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
5120 desc->oed_info.function_flags = cpu_to_be32(flags);
5121 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005122 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005123}
5124
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005125static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005126lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
5127 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07005128 uint8_t *page_a2)
5129{
James Smart310429e2016-07-06 12:35:54 -07005130 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005131
5132 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5133
James Smart3aaaa312016-07-06 12:35:57 -07005134 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
5135 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5136 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5137 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005138
5139 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5140 flags |= RDP_OET_HIGH_ALARM;
5141 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5142 flags |= RDP_OET_LOW_ALARM;
5143 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5144 flags |= RDP_OET_HIGH_WARNING;
5145 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5146 flags |= RDP_OET_LOW_WARNING;
5147
James Smart56204982016-03-31 14:12:32 -07005148 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5149 desc->oed_info.function_flags = cpu_to_be32(flags);
5150 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005151 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005152}
5153
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005154static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005155lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5156 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07005157 uint8_t *page_a2)
5158{
James Smart310429e2016-07-06 12:35:54 -07005159 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005160
5161 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5162
James Smart3aaaa312016-07-06 12:35:57 -07005163 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5164 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5165 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5166 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005167
5168 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5169 flags |= RDP_OET_HIGH_ALARM;
5170 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5171 flags |= RDP_OET_LOW_ALARM;
5172 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5173 flags |= RDP_OET_HIGH_WARNING;
5174 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5175 flags |= RDP_OET_LOW_WARNING;
5176
James Smart56204982016-03-31 14:12:32 -07005177 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5178 desc->oed_info.function_flags = cpu_to_be32(flags);
5179 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005180 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005181}
5182
5183
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005184static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005185lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5186 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07005187 uint8_t *page_a2)
5188{
James Smart310429e2016-07-06 12:35:54 -07005189 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005190
5191 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5192
James Smart3aaaa312016-07-06 12:35:57 -07005193 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
5194 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
5195 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
5196 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005197
5198 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5199 flags |= RDP_OET_HIGH_ALARM;
5200 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
5201 flags |= RDP_OET_LOW_ALARM;
5202 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5203 flags |= RDP_OET_HIGH_WARNING;
5204 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
5205 flags |= RDP_OET_LOW_WARNING;
5206
James Smart56204982016-03-31 14:12:32 -07005207 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
5208 desc->oed_info.function_flags = cpu_to_be32(flags);
5209 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005210 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005211}
5212
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005213static uint32_t
James Smart56204982016-03-31 14:12:32 -07005214lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
5215 uint8_t *page_a0, struct lpfc_vport *vport)
5216{
5217 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
5218 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
5219 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
5220 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
James Smarta0f2d3e2017-02-12 13:52:31 -08005221 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
James Smart56204982016-03-31 14:12:32 -07005222 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
5223 desc->length = cpu_to_be32(sizeof(desc->opd_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005224 return sizeof(struct fc_rdp_opd_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005225}
5226
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005227static uint32_t
James Smart4258e982015-12-16 18:11:58 -05005228lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
5229{
5230 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
5231 return 0;
5232 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
5233
5234 desc->info.CorrectedBlocks =
5235 cpu_to_be32(stat->fecCorrBlkCount);
5236 desc->info.UncorrectableBlocks =
5237 cpu_to_be32(stat->fecUncorrBlkCount);
5238
5239 desc->length = cpu_to_be32(sizeof(desc->info));
5240
5241 return sizeof(struct fc_fec_rdp_desc);
5242}
5243
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005244static uint32_t
James Smart86478872015-05-21 13:55:21 -04005245lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5246{
5247 uint16_t rdp_cap = 0;
5248 uint16_t rdp_speed;
5249
5250 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
5251
James Smart81e75172015-12-16 18:11:59 -05005252 switch (phba->fc_linkspeed) {
5253 case LPFC_LINK_SPEED_1GHZ:
James Smart86478872015-05-21 13:55:21 -04005254 rdp_speed = RDP_PS_1GB;
5255 break;
James Smart81e75172015-12-16 18:11:59 -05005256 case LPFC_LINK_SPEED_2GHZ:
James Smart86478872015-05-21 13:55:21 -04005257 rdp_speed = RDP_PS_2GB;
5258 break;
James Smart81e75172015-12-16 18:11:59 -05005259 case LPFC_LINK_SPEED_4GHZ:
James Smart86478872015-05-21 13:55:21 -04005260 rdp_speed = RDP_PS_4GB;
5261 break;
James Smart81e75172015-12-16 18:11:59 -05005262 case LPFC_LINK_SPEED_8GHZ:
James Smart86478872015-05-21 13:55:21 -04005263 rdp_speed = RDP_PS_8GB;
5264 break;
James Smart81e75172015-12-16 18:11:59 -05005265 case LPFC_LINK_SPEED_10GHZ:
James Smart86478872015-05-21 13:55:21 -04005266 rdp_speed = RDP_PS_10GB;
5267 break;
James Smart81e75172015-12-16 18:11:59 -05005268 case LPFC_LINK_SPEED_16GHZ:
James Smart86478872015-05-21 13:55:21 -04005269 rdp_speed = RDP_PS_16GB;
5270 break;
James Smarta085e872015-12-16 18:12:02 -05005271 case LPFC_LINK_SPEED_32GHZ:
5272 rdp_speed = RDP_PS_32GB;
5273 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08005274 case LPFC_LINK_SPEED_64GHZ:
5275 rdp_speed = RDP_PS_64GB;
5276 break;
James Smart86478872015-05-21 13:55:21 -04005277 default:
5278 rdp_speed = RDP_PS_UNKNOWN;
5279 break;
5280 }
5281
5282 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
5283
James Smartfbd8a6b2018-02-22 08:18:45 -08005284 if (phba->lmt & LMT_64Gb)
5285 rdp_cap |= RDP_PS_64GB;
James Smartd38dd522015-08-31 16:48:17 -04005286 if (phba->lmt & LMT_32Gb)
5287 rdp_cap |= RDP_PS_32GB;
James Smart86478872015-05-21 13:55:21 -04005288 if (phba->lmt & LMT_16Gb)
5289 rdp_cap |= RDP_PS_16GB;
5290 if (phba->lmt & LMT_10Gb)
5291 rdp_cap |= RDP_PS_10GB;
5292 if (phba->lmt & LMT_8Gb)
5293 rdp_cap |= RDP_PS_8GB;
5294 if (phba->lmt & LMT_4Gb)
5295 rdp_cap |= RDP_PS_4GB;
5296 if (phba->lmt & LMT_2Gb)
5297 rdp_cap |= RDP_PS_2GB;
5298 if (phba->lmt & LMT_1Gb)
5299 rdp_cap |= RDP_PS_1GB;
5300
5301 if (rdp_cap == 0)
5302 rdp_cap = RDP_CAP_UNKNOWN;
James Smart56204982016-03-31 14:12:32 -07005303 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
5304 rdp_cap |= RDP_CAP_USER_CONFIGURED;
James Smart86478872015-05-21 13:55:21 -04005305
5306 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
5307 desc->length = cpu_to_be32(sizeof(desc->info));
James Smart6c92d1d2016-07-06 12:35:55 -07005308 return sizeof(struct fc_rdp_port_speed_desc);
James Smart86478872015-05-21 13:55:21 -04005309}
5310
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005311static uint32_t
James Smart86478872015-05-21 13:55:21 -04005312lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
James Smartcd46cde2017-03-04 09:30:37 -08005313 struct lpfc_vport *vport)
James Smart86478872015-05-21 13:55:21 -04005314{
5315
5316 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5317
James Smartcd46cde2017-03-04 09:30:37 -08005318 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
James Smart86478872015-05-21 13:55:21 -04005319 sizeof(desc->port_names.wwnn));
5320
James Smartcd46cde2017-03-04 09:30:37 -08005321 memcpy(desc->port_names.wwpn, &vport->fc_portname,
James Smart86478872015-05-21 13:55:21 -04005322 sizeof(desc->port_names.wwpn));
5323
5324 desc->length = cpu_to_be32(sizeof(desc->port_names));
James Smart6c92d1d2016-07-06 12:35:55 -07005325 return sizeof(struct fc_rdp_port_name_desc);
James Smart86478872015-05-21 13:55:21 -04005326}
5327
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005328static uint32_t
James Smart86478872015-05-21 13:55:21 -04005329lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5330 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5331{
5332
5333 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5334 if (vport->fc_flag & FC_FABRIC) {
5335 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
5336 sizeof(desc->port_names.wwnn));
5337
5338 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
5339 sizeof(desc->port_names.wwpn));
5340 } else { /* Point to Point */
5341 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
5342 sizeof(desc->port_names.wwnn));
5343
5344 memcpy(desc->port_names.wwnn, &ndlp->nlp_portname,
5345 sizeof(desc->port_names.wwpn));
5346 }
5347
5348 desc->length = cpu_to_be32(sizeof(desc->port_names));
James Smart6c92d1d2016-07-06 12:35:55 -07005349 return sizeof(struct fc_rdp_port_name_desc);
James Smart86478872015-05-21 13:55:21 -04005350}
5351
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005352static void
James Smart86478872015-05-21 13:55:21 -04005353lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5354 int status)
5355{
5356 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5357 struct lpfc_vport *vport = ndlp->vport;
5358 struct lpfc_iocbq *elsiocb;
James Smarteb8d68c2015-12-16 18:12:00 -05005359 struct ulp_bde64 *bpl;
James Smart86478872015-05-21 13:55:21 -04005360 IOCB_t *icmd;
5361 uint8_t *pcmd;
5362 struct ls_rjt *stat;
5363 struct fc_rdp_res_frame *rdp_res;
James Smart6c92d1d2016-07-06 12:35:55 -07005364 uint32_t cmdsize, len;
James Smart310429e2016-07-06 12:35:54 -07005365 uint16_t *flag_ptr;
James Smart6c92d1d2016-07-06 12:35:55 -07005366 int rc;
James Smart86478872015-05-21 13:55:21 -04005367
5368 if (status != SUCCESS)
5369 goto error;
James Smarteb8d68c2015-12-16 18:12:00 -05005370
5371 /* This will change once we know the true size of the RDP payload */
James Smart86478872015-05-21 13:55:21 -04005372 cmdsize = sizeof(struct fc_rdp_res_frame);
5373
5374 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5375 lpfc_max_els_tries, rdp_context->ndlp,
5376 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
5377 lpfc_nlp_put(ndlp);
5378 if (!elsiocb)
5379 goto free_rdp_context;
5380
5381 icmd = &elsiocb->iocb;
5382 icmd->ulpContext = rdp_context->rx_id;
5383 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5384
5385 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5386 "2171 Xmit RDP response tag x%x xri x%x, "
5387 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5388 elsiocb->iotag, elsiocb->iocb.ulpContext,
5389 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5390 ndlp->nlp_rpi);
5391 rdp_res = (struct fc_rdp_res_frame *)
5392 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5393 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5394 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
5395 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5396
James Smart310429e2016-07-06 12:35:54 -07005397 /* Update Alarm and Warning */
5398 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
5399 phba->sfp_alarm |= *flag_ptr;
5400 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
5401 phba->sfp_warning |= *flag_ptr;
5402
James Smart86478872015-05-21 13:55:21 -04005403 /* For RDP payload */
James Smart6c92d1d2016-07-06 12:35:55 -07005404 len = 8;
5405 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
5406 (len + pcmd), ELS_CMD_RDP);
James Smart86478872015-05-21 13:55:21 -04005407
James Smart6c92d1d2016-07-06 12:35:55 -07005408 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
James Smart86478872015-05-21 13:55:21 -04005409 rdp_context->page_a0, rdp_context->page_a2);
James Smart6c92d1d2016-07-06 12:35:55 -07005410 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
5411 phba);
5412 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
5413 (len + pcmd), &rdp_context->link_stat);
5414 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
James Smartcd46cde2017-03-04 09:30:37 -08005415 (len + pcmd), vport);
James Smart6c92d1d2016-07-06 12:35:55 -07005416 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
5417 (len + pcmd), vport, ndlp);
5418 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
James Smart4258e982015-12-16 18:11:58 -05005419 &rdp_context->link_stat);
James Smart6c92d1d2016-07-06 12:35:55 -07005420 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
5421 &rdp_context->link_stat, vport);
5422 len += lpfc_rdp_res_oed_temp_desc(phba,
5423 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5424 rdp_context->page_a2);
5425 len += lpfc_rdp_res_oed_voltage_desc(phba,
5426 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5427 rdp_context->page_a2);
5428 len += lpfc_rdp_res_oed_txbias_desc(phba,
5429 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5430 rdp_context->page_a2);
5431 len += lpfc_rdp_res_oed_txpower_desc(phba,
5432 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5433 rdp_context->page_a2);
5434 len += lpfc_rdp_res_oed_rxpower_desc(phba,
5435 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5436 rdp_context->page_a2);
5437 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
5438 rdp_context->page_a0, vport);
5439
James Smart6c92d1d2016-07-06 12:35:55 -07005440 rdp_res->length = cpu_to_be32(len - 8);
James Smart86478872015-05-21 13:55:21 -04005441 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5442
James Smarteb8d68c2015-12-16 18:12:00 -05005443 /* Now that we know the true size of the payload, update the BPL */
5444 bpl = (struct ulp_bde64 *)
5445 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
James Smart6c92d1d2016-07-06 12:35:55 -07005446 bpl->tus.f.bdeSize = len;
James Smarteb8d68c2015-12-16 18:12:00 -05005447 bpl->tus.f.bdeFlags = 0;
5448 bpl->tus.w = le32_to_cpu(bpl->tus.w);
5449
James Smart86478872015-05-21 13:55:21 -04005450 phba->fc_stat.elsXmitACC++;
5451 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5452 if (rc == IOCB_ERROR)
5453 lpfc_els_free_iocb(phba, elsiocb);
5454
5455 kfree(rdp_context);
5456
5457 return;
5458error:
5459 cmdsize = 2 * sizeof(uint32_t);
5460 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
5461 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
5462 lpfc_nlp_put(ndlp);
5463 if (!elsiocb)
5464 goto free_rdp_context;
5465
5466 icmd = &elsiocb->iocb;
5467 icmd->ulpContext = rdp_context->rx_id;
5468 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5469 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5470
5471 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
5472 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5473 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5474
5475 phba->fc_stat.elsXmitLSRJT++;
5476 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5477 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5478
5479 if (rc == IOCB_ERROR)
5480 lpfc_els_free_iocb(phba, elsiocb);
5481free_rdp_context:
5482 kfree(rdp_context);
5483}
5484
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005485static int
James Smart86478872015-05-21 13:55:21 -04005486lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
5487{
5488 LPFC_MBOXQ_t *mbox = NULL;
5489 int rc;
5490
5491 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5492 if (!mbox) {
5493 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
5494 "7105 failed to allocate mailbox memory");
5495 return 1;
5496 }
5497
5498 if (lpfc_sli4_dump_page_a0(phba, mbox))
5499 goto prep_mbox_fail;
5500 mbox->vport = rdp_context->ndlp->vport;
5501 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
5502 mbox->context2 = (struct lpfc_rdp_context *) rdp_context;
5503 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5504 if (rc == MBX_NOT_FINISHED)
5505 goto issue_mbox_fail;
5506
5507 return 0;
5508
5509prep_mbox_fail:
5510issue_mbox_fail:
5511 mempool_free(mbox, phba->mbox_mem_pool);
5512 return 1;
5513}
5514
5515/*
5516 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
5517 * @vport: pointer to a host virtual N_Port data structure.
5518 * @cmdiocb: pointer to lpfc command iocb data structure.
5519 * @ndlp: pointer to a node-list data structure.
5520 *
5521 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
5522 * IOCB. First, the payload of the unsolicited RDP is checked.
5523 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
5524 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
5525 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
5526 * gather all data and send RDP response.
5527 *
5528 * Return code
5529 * 0 - Sent the acc response
5530 * 1 - Sent the reject response.
5531 */
5532static int
5533lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5534 struct lpfc_nodelist *ndlp)
5535{
5536 struct lpfc_hba *phba = vport->phba;
5537 struct lpfc_dmabuf *pcmd;
5538 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
5539 struct fc_rdp_req_frame *rdp_req;
5540 struct lpfc_rdp_context *rdp_context;
5541 IOCB_t *cmd = NULL;
5542 struct ls_rjt stat;
5543
5544 if (phba->sli_rev < LPFC_SLI_REV4 ||
James Smarta0f2d3e2017-02-12 13:52:31 -08005545 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
5546 LPFC_SLI_INTF_IF_TYPE_2) {
James Smart86478872015-05-21 13:55:21 -04005547 rjt_err = LSRJT_UNABLE_TPC;
5548 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5549 goto error;
5550 }
5551
5552 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
5553 rjt_err = LSRJT_UNABLE_TPC;
5554 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5555 goto error;
5556 }
5557
5558 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5559 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
5560
James Smart86478872015-05-21 13:55:21 -04005561 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5562 "2422 ELS RDP Request "
5563 "dec len %d tag x%x port_id %d len %d\n",
5564 be32_to_cpu(rdp_req->rdp_des_length),
5565 be32_to_cpu(rdp_req->nport_id_desc.tag),
5566 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
5567 be32_to_cpu(rdp_req->nport_id_desc.length));
5568
5569 if (sizeof(struct fc_rdp_nport_desc) !=
5570 be32_to_cpu(rdp_req->rdp_des_length))
5571 goto rjt_logerr;
5572 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
5573 goto rjt_logerr;
5574 if (RDP_NPORT_ID_SIZE !=
5575 be32_to_cpu(rdp_req->nport_id_desc.length))
5576 goto rjt_logerr;
Punit Vara699acd62015-12-16 18:12:07 -05005577 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
James Smart86478872015-05-21 13:55:21 -04005578 if (!rdp_context) {
5579 rjt_err = LSRJT_UNABLE_TPC;
5580 goto error;
5581 }
5582
James Smart86478872015-05-21 13:55:21 -04005583 cmd = &cmdiocb->iocb;
5584 rdp_context->ndlp = lpfc_nlp_get(ndlp);
5585 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
5586 rdp_context->rx_id = cmd->ulpContext;
5587 rdp_context->cmpl = lpfc_els_rdp_cmpl;
5588 if (lpfc_get_rdp_info(phba, rdp_context)) {
5589 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
5590 "2423 Unable to send mailbox");
5591 kfree(rdp_context);
5592 rjt_err = LSRJT_UNABLE_TPC;
5593 lpfc_nlp_put(ndlp);
5594 goto error;
5595 }
5596
5597 return 0;
5598
5599rjt_logerr:
5600 rjt_err = LSRJT_LOGICAL_ERR;
5601
5602error:
5603 memset(&stat, 0, sizeof(stat));
5604 stat.un.b.lsRjtRsnCode = rjt_err;
5605 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
5606 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5607 return 1;
5608}
5609
5610
James Smart8b017a32015-05-21 13:55:18 -04005611static void
5612lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5613{
5614 MAILBOX_t *mb;
5615 IOCB_t *icmd;
5616 uint8_t *pcmd;
5617 struct lpfc_iocbq *elsiocb;
5618 struct lpfc_nodelist *ndlp;
5619 struct ls_rjt *stat;
James Smart481ad962015-05-22 10:42:35 -04005620 union lpfc_sli4_cfg_shdr *shdr;
James Smart8b017a32015-05-21 13:55:18 -04005621 struct lpfc_lcb_context *lcb_context;
5622 struct fc_lcb_res_frame *lcb_res;
James Smart481ad962015-05-22 10:42:35 -04005623 uint32_t cmdsize, shdr_status, shdr_add_status;
James Smart8b017a32015-05-21 13:55:18 -04005624 int rc;
5625
5626 mb = &pmb->u.mb;
James Smart8b017a32015-05-21 13:55:18 -04005627 lcb_context = (struct lpfc_lcb_context *)pmb->context1;
5628 ndlp = lcb_context->ndlp;
5629 pmb->context1 = NULL;
5630 pmb->context2 = NULL;
5631
James Smart481ad962015-05-22 10:42:35 -04005632 shdr = (union lpfc_sli4_cfg_shdr *)
5633 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
5634 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5635 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5636
5637 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
5638 "0194 SET_BEACON_CONFIG mailbox "
5639 "completed with status x%x add_status x%x,"
5640 " mbx status x%x\n",
5641 shdr_status, shdr_add_status, mb->mbxStatus);
5642
5643 if (mb->mbxStatus && !(shdr_status &&
5644 shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)) {
James Smart8b017a32015-05-21 13:55:18 -04005645 mempool_free(pmb, phba->mbox_mem_pool);
5646 goto error;
5647 }
5648
5649 mempool_free(pmb, phba->mbox_mem_pool);
James Smart8b017a32015-05-21 13:55:18 -04005650 cmdsize = sizeof(struct fc_lcb_res_frame);
5651 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5652 lpfc_max_els_tries, ndlp,
5653 ndlp->nlp_DID, ELS_CMD_ACC);
5654
5655 /* Decrement the ndlp reference count from previous mbox command */
5656 lpfc_nlp_put(ndlp);
5657
5658 if (!elsiocb)
5659 goto free_lcb_context;
5660
5661 lcb_res = (struct fc_lcb_res_frame *)
5662 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5663
5664 icmd = &elsiocb->iocb;
5665 icmd->ulpContext = lcb_context->rx_id;
5666 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5667
5668 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5669 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
5670 lcb_res->lcb_sub_command = lcb_context->sub_command;
5671 lcb_res->lcb_type = lcb_context->type;
5672 lcb_res->lcb_frequency = lcb_context->frequency;
5673 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5674 phba->fc_stat.elsXmitACC++;
5675 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5676 if (rc == IOCB_ERROR)
5677 lpfc_els_free_iocb(phba, elsiocb);
5678
5679 kfree(lcb_context);
5680 return;
5681
5682error:
5683 cmdsize = sizeof(struct fc_lcb_res_frame);
5684 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5685 lpfc_max_els_tries, ndlp,
5686 ndlp->nlp_DID, ELS_CMD_LS_RJT);
5687 lpfc_nlp_put(ndlp);
5688 if (!elsiocb)
5689 goto free_lcb_context;
5690
5691 icmd = &elsiocb->iocb;
5692 icmd->ulpContext = lcb_context->rx_id;
5693 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5694 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5695
5696 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
5697 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5698 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5699
5700 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5701 phba->fc_stat.elsXmitLSRJT++;
5702 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5703 if (rc == IOCB_ERROR)
5704 lpfc_els_free_iocb(phba, elsiocb);
5705free_lcb_context:
5706 kfree(lcb_context);
5707}
5708
5709static int
5710lpfc_sli4_set_beacon(struct lpfc_vport *vport,
5711 struct lpfc_lcb_context *lcb_context,
5712 uint32_t beacon_state)
5713{
5714 struct lpfc_hba *phba = vport->phba;
5715 LPFC_MBOXQ_t *mbox = NULL;
5716 uint32_t len;
5717 int rc;
5718
5719 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5720 if (!mbox)
5721 return 1;
5722
5723 len = sizeof(struct lpfc_mbx_set_beacon_config) -
5724 sizeof(struct lpfc_sli4_cfg_mhdr);
5725 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5726 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
5727 LPFC_SLI4_MBX_EMBED);
5728 mbox->context1 = (void *)lcb_context;
5729 mbox->vport = phba->pport;
5730 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
5731 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
5732 phba->sli4_hba.physical_port);
5733 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
5734 beacon_state);
5735 bf_set(lpfc_mbx_set_beacon_port_type, &mbox->u.mqe.un.beacon_config, 1);
5736 bf_set(lpfc_mbx_set_beacon_duration, &mbox->u.mqe.un.beacon_config, 0);
5737 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5738 if (rc == MBX_NOT_FINISHED) {
5739 mempool_free(mbox, phba->mbox_mem_pool);
5740 return 1;
5741 }
5742
5743 return 0;
5744}
5745
5746
5747/**
5748 * lpfc_els_rcv_lcb - Process an unsolicited LCB
5749 * @vport: pointer to a host virtual N_Port data structure.
5750 * @cmdiocb: pointer to lpfc command iocb data structure.
5751 * @ndlp: pointer to a node-list data structure.
5752 *
5753 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
5754 * First, the payload of the unsolicited LCB is checked.
5755 * Then based on Subcommand beacon will either turn on or off.
5756 *
5757 * Return code
5758 * 0 - Sent the acc response
5759 * 1 - Sent the reject response.
5760 **/
5761static int
5762lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5763 struct lpfc_nodelist *ndlp)
5764{
5765 struct lpfc_hba *phba = vport->phba;
5766 struct lpfc_dmabuf *pcmd;
James Smart8b017a32015-05-21 13:55:18 -04005767 uint8_t *lp;
5768 struct fc_lcb_request_frame *beacon;
5769 struct lpfc_lcb_context *lcb_context;
5770 uint8_t state, rjt_err;
5771 struct ls_rjt stat;
5772
James Smart8b017a32015-05-21 13:55:18 -04005773 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
5774 lp = (uint8_t *)pcmd->virt;
5775 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
5776
5777 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5778 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
5779 "type x%x frequency %x duration x%x\n",
5780 lp[0], lp[1], lp[2],
5781 beacon->lcb_command,
5782 beacon->lcb_sub_command,
5783 beacon->lcb_type,
5784 beacon->lcb_frequency,
5785 be16_to_cpu(beacon->lcb_duration));
5786
5787 if (phba->sli_rev < LPFC_SLI_REV4 ||
5788 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
5789 LPFC_SLI_INTF_IF_TYPE_2)) {
5790 rjt_err = LSRJT_CMD_UNSUPPORTED;
5791 goto rjt;
5792 }
James Smart8b017a32015-05-21 13:55:18 -04005793
5794 if (phba->hba_flag & HBA_FCOE_MODE) {
5795 rjt_err = LSRJT_CMD_UNSUPPORTED;
5796 goto rjt;
5797 }
James Smartd6564e52017-06-15 22:56:50 -07005798 if (beacon->lcb_sub_command != LPFC_LCB_ON &&
5799 beacon->lcb_sub_command != LPFC_LCB_OFF) {
James Smart8b017a32015-05-21 13:55:18 -04005800 rjt_err = LSRJT_CMD_UNSUPPORTED;
5801 goto rjt;
5802 }
James Smartd6564e52017-06-15 22:56:50 -07005803 if (beacon->lcb_sub_command == LPFC_LCB_ON &&
5804 be16_to_cpu(beacon->lcb_duration) != 0) {
James Smart8b017a32015-05-21 13:55:18 -04005805 rjt_err = LSRJT_CMD_UNSUPPORTED;
5806 goto rjt;
5807 }
5808
Sudip Mukherjeee7950422015-09-23 19:02:32 +05305809 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
5810 if (!lcb_context) {
5811 rjt_err = LSRJT_UNABLE_TPC;
5812 goto rjt;
5813 }
5814
James Smart8b017a32015-05-21 13:55:18 -04005815 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
5816 lcb_context->sub_command = beacon->lcb_sub_command;
5817 lcb_context->type = beacon->lcb_type;
5818 lcb_context->frequency = beacon->lcb_frequency;
5819 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
5820 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
5821 lcb_context->ndlp = lpfc_nlp_get(ndlp);
5822 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
5823 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
5824 LOG_ELS, "0193 failed to send mail box");
Sudip Mukherjeee7950422015-09-23 19:02:32 +05305825 kfree(lcb_context);
James Smart8b017a32015-05-21 13:55:18 -04005826 lpfc_nlp_put(ndlp);
5827 rjt_err = LSRJT_UNABLE_TPC;
5828 goto rjt;
5829 }
5830 return 0;
5831rjt:
5832 memset(&stat, 0, sizeof(stat));
5833 stat.un.b.lsRjtRsnCode = rjt_err;
5834 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5835 return 1;
5836}
5837
5838
James Smarte59058c2008-08-24 21:49:00 -04005839/**
James Smart3621a712009-04-06 18:47:14 -04005840 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04005841 * @vport: pointer to a host virtual N_Port data structure.
5842 *
5843 * This routine cleans up any Registration State Change Notification
5844 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
5845 * @vport together with the host_lock is used to prevent multiple thread
5846 * trying to access the RSCN array on a same @vport at the same time.
5847 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005848void
James Smart2e0fef82007-06-17 19:56:36 -05005849lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005850{
James Smart2e0fef82007-06-17 19:56:36 -05005851 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5852 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005853 int i;
5854
James Smart7f5f3d02008-02-08 18:50:14 -05005855 spin_lock_irq(shost->host_lock);
5856 if (vport->fc_rscn_flush) {
5857 /* Another thread is walking fc_rscn_id_list on this vport */
5858 spin_unlock_irq(shost->host_lock);
5859 return;
5860 }
5861 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
5862 vport->fc_rscn_flush = 1;
5863 spin_unlock_irq(shost->host_lock);
5864
James Smart2e0fef82007-06-17 19:56:36 -05005865 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05005866 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05005867 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05005868 }
James Smart2e0fef82007-06-17 19:56:36 -05005869 spin_lock_irq(shost->host_lock);
5870 vport->fc_rscn_id_cnt = 0;
5871 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
5872 spin_unlock_irq(shost->host_lock);
5873 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05005874 /* Indicate we are done walking this fc_rscn_id_list */
5875 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05005876}
5877
James Smarte59058c2008-08-24 21:49:00 -04005878/**
James Smart3621a712009-04-06 18:47:14 -04005879 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04005880 * @vport: pointer to a host virtual N_Port data structure.
5881 * @did: remote destination port identifier.
5882 *
5883 * This routine checks whether there is any pending Registration State
5884 * Configuration Notification (RSCN) to a @did on @vport.
5885 *
5886 * Return code
5887 * None zero - The @did matched with a pending rscn
5888 * 0 - not able to match @did with a pending rscn
5889 **/
dea31012005-04-17 16:05:31 -05005890int
James Smart2e0fef82007-06-17 19:56:36 -05005891lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05005892{
5893 D_ID ns_did;
5894 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05005895 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05005896 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05005897 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005898
5899 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05005900
5901 /* Never match fabric nodes for RSCNs */
5902 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05005903 return 0;
dea31012005-04-17 16:05:31 -05005904
5905 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05005906 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005907 return did;
dea31012005-04-17 16:05:31 -05005908
James Smart7f5f3d02008-02-08 18:50:14 -05005909 spin_lock_irq(shost->host_lock);
5910 if (vport->fc_rscn_flush) {
5911 /* Another thread is walking fc_rscn_id_list on this vport */
5912 spin_unlock_irq(shost->host_lock);
5913 return 0;
5914 }
5915 /* Indicate we are walking fc_rscn_id_list on this vport */
5916 vport->fc_rscn_flush = 1;
5917 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05005918 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05005919 lp = vport->fc_rscn_id_list[i]->virt;
5920 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5921 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05005922 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05005923 rscn_did.un.word = be32_to_cpu(*lp++);
5924 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05005925 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
5926 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04005927 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5928 && (ns_did.un.b.area == rscn_did.un.b.area)
5929 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05005930 goto return_did_out;
dea31012005-04-17 16:05:31 -05005931 break;
James Smarteaf15d52008-12-04 22:39:29 -05005932 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05005933 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5934 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05005935 goto return_did_out;
dea31012005-04-17 16:05:31 -05005936 break;
James Smarteaf15d52008-12-04 22:39:29 -05005937 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05005938 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05005939 goto return_did_out;
dea31012005-04-17 16:05:31 -05005940 break;
James Smarteaf15d52008-12-04 22:39:29 -05005941 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05005942 goto return_did_out;
dea31012005-04-17 16:05:31 -05005943 }
5944 }
James Smart92d7f7b2007-06-17 19:56:38 -05005945 }
James Smart7f5f3d02008-02-08 18:50:14 -05005946 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5947 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005948 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05005949return_did_out:
5950 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5951 vport->fc_rscn_flush = 0;
5952 return did;
dea31012005-04-17 16:05:31 -05005953}
5954
James Smarte59058c2008-08-24 21:49:00 -04005955/**
James Smart3621a712009-04-06 18:47:14 -04005956 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04005957 * @vport: pointer to a host virtual N_Port data structure.
5958 *
5959 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
5960 * state machine for a @vport's nodes that are with pending RSCN (Registration
5961 * State Change Notification).
5962 *
5963 * Return code
5964 * 0 - Successful (currently alway return 0)
5965 **/
dea31012005-04-17 16:05:31 -05005966static int
James Smart2e0fef82007-06-17 19:56:36 -05005967lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005968{
James Smart685f0bf2007-04-25 09:53:08 -04005969 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05005970
James Smart0d2b6b82008-06-14 22:52:47 -04005971 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05005972 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005973 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04005974 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
5975 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05005976 continue;
James Smart1c5b12f2017-04-21 16:05:03 -07005977
5978 /* NVME Target mode does not do RSCN Recovery. */
James Smart8c258642017-02-12 13:52:36 -08005979 if (vport->phba->nvmet_support)
5980 continue;
James Smart1c5b12f2017-04-21 16:05:03 -07005981
James Smart2e0fef82007-06-17 19:56:36 -05005982 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04005983 NLP_EVT_DEVICE_RECOVERY);
5984 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05005985 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005986 return 0;
dea31012005-04-17 16:05:31 -05005987}
5988
James Smarte59058c2008-08-24 21:49:00 -04005989/**
James Smart3621a712009-04-06 18:47:14 -04005990 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05005991 * @vport: pointer to a host virtual N_Port data structure.
5992 * @cmdiocb: pointer to lpfc command iocb data structure.
5993 *
5994 * lpfc_send_rscn_event sends an RSCN netlink event to management
5995 * applications.
5996 */
5997static void
5998lpfc_send_rscn_event(struct lpfc_vport *vport,
5999 struct lpfc_iocbq *cmdiocb)
6000{
6001 struct lpfc_dmabuf *pcmd;
6002 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6003 uint32_t *payload_ptr;
6004 uint32_t payload_len;
6005 struct lpfc_rscn_event_header *rscn_event_data;
6006
6007 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6008 payload_ptr = (uint32_t *) pcmd->virt;
6009 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
6010
6011 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
6012 payload_len, GFP_KERNEL);
6013 if (!rscn_event_data) {
6014 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6015 "0147 Failed to allocate memory for RSCN event\n");
6016 return;
6017 }
6018 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
6019 rscn_event_data->payload_length = payload_len;
6020 memcpy(rscn_event_data->rscn_payload, payload_ptr,
6021 payload_len);
6022
6023 fc_host_post_vendor_event(shost,
6024 fc_get_event_number(),
Ales Novak6599eaa2015-08-31 16:48:16 -04006025 sizeof(struct lpfc_rscn_event_header) + payload_len,
James Smartddcc50f2008-12-04 22:38:46 -05006026 (char *)rscn_event_data,
6027 LPFC_NL_VENDOR_ID);
6028
6029 kfree(rscn_event_data);
6030}
6031
6032/**
James Smart3621a712009-04-06 18:47:14 -04006033 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04006034 * @vport: pointer to a host virtual N_Port data structure.
6035 * @cmdiocb: pointer to lpfc command iocb data structure.
6036 * @ndlp: pointer to a node-list data structure.
6037 *
6038 * This routine processes an unsolicited RSCN (Registration State Change
6039 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
6040 * to invoke fc_host_post_event() routine to the FC transport layer. If the
6041 * discover state machine is about to begin discovery, it just accepts the
6042 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
6043 * contains N_Port IDs for other vports on this HBA, it just accepts the
6044 * RSCN and ignore processing it. If the state machine is in the recovery
6045 * state, the fc_rscn_id_list of this @vport is walked and the
6046 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
6047 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
6048 * routine is invoked to handle the RSCN event.
6049 *
6050 * Return code
6051 * 0 - Just sent the acc response
6052 * 1 - Sent the acc response and waited for name server completion
6053 **/
dea31012005-04-17 16:05:31 -05006054static int
James Smart2e0fef82007-06-17 19:56:36 -05006055lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04006056 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006057{
James Smart2e0fef82007-06-17 19:56:36 -05006058 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6059 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006060 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05006061 uint32_t *lp, *datap;
James Smart92d7f7b2007-06-17 19:56:38 -05006062 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05006063 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05006064 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04006065 int i;
dea31012005-04-17 16:05:31 -05006066
dea31012005-04-17 16:05:31 -05006067 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6068 lp = (uint32_t *) pcmd->virt;
6069
James Smart92d7f7b2007-06-17 19:56:38 -05006070 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6071 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05006072 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04006073 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6074 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05006075 vport->fc_flag, payload_len, *lp,
6076 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05006077
6078 /* Send an RSCN event to the management application */
6079 lpfc_send_rscn_event(vport, cmdiocb);
6080
James Smartd2873e42006-08-18 17:46:43 -04006081 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05006082 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04006083 FCH_EVT_RSCN, lp[i]);
6084
dea31012005-04-17 16:05:31 -05006085 /* If we are about to begin discovery, just ACC the RSCN.
6086 * Discovery processing will satisfy it.
6087 */
James Smart2e0fef82007-06-17 19:56:36 -05006088 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05006089 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6090 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
6091 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6092
James Smart51ef4c22007-08-02 11:10:31 -04006093 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006094 return 0;
dea31012005-04-17 16:05:31 -05006095 }
6096
James Smart92d7f7b2007-06-17 19:56:38 -05006097 /* If this RSCN just contains NPortIDs for other vports on this HBA,
6098 * just ACC and ignore it.
6099 */
6100 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04006101 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05006102 i = payload_len;
6103 datap = lp;
6104 while (i > 0) {
6105 nportid = *datap++;
6106 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
6107 i -= sizeof(uint32_t);
6108 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04006109 if (lpfc_find_vport_by_did(phba, nportid))
6110 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05006111 }
6112 if (rscn_id == hba_id) {
6113 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04006114 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04006115 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04006116 "Data: x%x x%x x%x x%x\n",
6117 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05006118 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05006119 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6120 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6121 ndlp->nlp_DID, vport->port_state,
6122 ndlp->nlp_flag);
6123
James Smart92d7f7b2007-06-17 19:56:38 -05006124 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04006125 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05006126 return 0;
6127 }
6128 }
6129
James Smart7f5f3d02008-02-08 18:50:14 -05006130 spin_lock_irq(shost->host_lock);
6131 if (vport->fc_rscn_flush) {
6132 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05006133 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05006134 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04006135 /* Send back ACC */
6136 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05006137 return 0;
6138 }
6139 /* Indicate we are walking fc_rscn_id_list on this vport */
6140 vport->fc_rscn_flush = 1;
6141 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006142 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05006143 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05006144 /* If we are already processing an RSCN, save the received
6145 * RSCN payload buffer, cmdiocb->context2 to process later.
6146 */
James Smart2e0fef82007-06-17 19:56:36 -05006147 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05006148 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6149 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6150 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6151
James Smart09372822008-01-11 01:52:54 -05006152 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006153 vport->fc_flag |= FC_RSCN_DEFERRED;
6154 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05006155 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05006156 vport->fc_flag |= FC_RSCN_MODE;
6157 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006158 if (rscn_cnt) {
6159 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
6160 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
6161 }
6162 if ((rscn_cnt) &&
6163 (payload_len + length <= LPFC_BPL_SIZE)) {
6164 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05006165 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05006166 memcpy(((uint8_t *)cmd) + length, lp,
6167 payload_len);
6168 } else {
6169 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
6170 vport->fc_rscn_id_cnt++;
6171 /* If we zero, cmdiocb->context2, the calling
6172 * routine will not try to free it.
6173 */
6174 cmdiocb->context2 = NULL;
6175 }
dea31012005-04-17 16:05:31 -05006176 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04006177 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6178 "0235 Deferred RSCN "
6179 "Data: x%x x%x x%x\n",
6180 vport->fc_rscn_id_cnt, vport->fc_flag,
6181 vport->port_state);
dea31012005-04-17 16:05:31 -05006182 } else {
James Smart2e0fef82007-06-17 19:56:36 -05006183 vport->fc_flag |= FC_RSCN_DISCOVERY;
6184 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05006185 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04006186 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6187 "0234 ReDiscovery RSCN "
6188 "Data: x%x x%x x%x\n",
6189 vport->fc_rscn_id_cnt, vport->fc_flag,
6190 vport->port_state);
dea31012005-04-17 16:05:31 -05006191 }
James Smart7f5f3d02008-02-08 18:50:14 -05006192 /* Indicate we are done walking fc_rscn_id_list on this vport */
6193 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05006194 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04006195 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006196 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05006197 lpfc_rscn_recovery_check(vport);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006198 return 0;
dea31012005-04-17 16:05:31 -05006199 }
James Smart858c9f62007-06-17 19:56:39 -05006200 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6201 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6202 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6203
James Smart2e0fef82007-06-17 19:56:36 -05006204 spin_lock_irq(shost->host_lock);
6205 vport->fc_flag |= FC_RSCN_MODE;
6206 spin_unlock_irq(shost->host_lock);
6207 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05006208 /* Indicate we are done walking fc_rscn_id_list on this vport */
6209 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05006210 /*
6211 * If we zero, cmdiocb->context2, the calling routine will
6212 * not try to free it.
6213 */
6214 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05006215 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05006216 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04006217 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006218 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05006219 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05006220 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05006221}
6222
James Smarte59058c2008-08-24 21:49:00 -04006223/**
James Smart3621a712009-04-06 18:47:14 -04006224 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04006225 * @vport: pointer to a host virtual N_Port data structure.
6226 *
6227 * This routine handles the Registration State Configuration Notification
6228 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
6229 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
6230 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
6231 * NameServer shall be issued. If CT command to the NameServer fails to be
6232 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
6233 * RSCN activities with the @vport.
6234 *
6235 * Return code
6236 * 0 - Cleaned up rscn on the @vport
6237 * 1 - Wait for plogi to name server before proceed
6238 **/
dea31012005-04-17 16:05:31 -05006239int
James Smart2e0fef82007-06-17 19:56:36 -05006240lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006241{
6242 struct lpfc_nodelist *ndlp;
6243
James Smart92d7f7b2007-06-17 19:56:38 -05006244 /* Ignore RSCN if the port is being torn down. */
6245 if (vport->load_flag & FC_UNLOADING) {
6246 lpfc_els_flush_rscn(vport);
6247 return 0;
6248 }
6249
dea31012005-04-17 16:05:31 -05006250 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05006251 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05006252
6253 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04006254 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6255 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
6256 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
6257 vport->port_state);
dea31012005-04-17 16:05:31 -05006258
6259 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05006260 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05006261 vport->num_disc_nodes = 0;
6262
James Smart2e0fef82007-06-17 19:56:36 -05006263 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006264 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
6265 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
James Smart1c5b12f2017-04-21 16:05:03 -07006266 /* Good ndlp, issue CT Request to NameServer. Need to
6267 * know how many gidfts were issued. If none, then just
6268 * flush the RSCN. Otherwise, the outstanding requests
6269 * need to complete.
6270 */
James Smart1c5b12f2017-04-21 16:05:03 -07006271 if (lpfc_issue_gidft(vport) > 0)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006272 return 1;
dea31012005-04-17 16:05:31 -05006273 } else {
James Smart1c5b12f2017-04-21 16:05:03 -07006274 /* Nameserver login in question. Revalidate. */
James Smarte47c9092008-02-08 18:49:26 -05006275 if (ndlp) {
6276 ndlp = lpfc_enable_node(vport, ndlp,
6277 NLP_STE_PLOGI_ISSUE);
6278 if (!ndlp) {
6279 lpfc_els_flush_rscn(vport);
6280 return 0;
6281 }
6282 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05006283 } else {
James Smart9d3d3402017-04-21 16:05:00 -07006284 ndlp = lpfc_nlp_init(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006285 if (!ndlp) {
6286 lpfc_els_flush_rscn(vport);
6287 return 0;
6288 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006289 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05006290 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05006291 }
James Smarte47c9092008-02-08 18:49:26 -05006292 ndlp->nlp_type |= NLP_FABRIC;
6293 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
6294 /* Wait for NameServer login cmpl before we can
6295 * continue
6296 */
6297 return 1;
dea31012005-04-17 16:05:31 -05006298 }
6299
James Smart2e0fef82007-06-17 19:56:36 -05006300 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006301 return 0;
dea31012005-04-17 16:05:31 -05006302}
6303
James Smarte59058c2008-08-24 21:49:00 -04006304/**
James Smart3621a712009-04-06 18:47:14 -04006305 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04006306 * @vport: pointer to a host virtual N_Port data structure.
6307 * @cmdiocb: pointer to lpfc command iocb data structure.
6308 * @ndlp: pointer to a node-list data structure.
6309 *
6310 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
6311 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
6312 * point topology. As an unsolicited FLOGI should not be received in a loop
6313 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
6314 * lpfc_check_sparm() routine is invoked to check the parameters in the
6315 * unsolicited FLOGI. If parameters validation failed, the routine
6316 * lpfc_els_rsp_reject() shall be called with reject reason code set to
6317 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
6318 * FLOGI shall be compared with the Port WWN of the @vport to determine who
6319 * will initiate PLOGI. The higher lexicographical value party shall has
6320 * higher priority (as the winning port) and will initiate PLOGI and
6321 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
6322 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
6323 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
6324 *
6325 * Return code
6326 * 0 - Successfully processed the unsolicited flogi
6327 * 1 - Failed to process the unsolicited flogi
6328 **/
dea31012005-04-17 16:05:31 -05006329static int
James Smart2e0fef82007-06-17 19:56:36 -05006330lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04006331 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006332{
James Smart2e0fef82007-06-17 19:56:36 -05006333 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6334 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006335 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6336 uint32_t *lp = (uint32_t *) pcmd->virt;
6337 IOCB_t *icmd = &cmdiocb->iocb;
6338 struct serv_parm *sp;
6339 LPFC_MBOXQ_t *mbox;
dea31012005-04-17 16:05:31 -05006340 uint32_t cmd, did;
6341 int rc;
James Smarte74c03c2013-04-17 20:15:19 -04006342 uint32_t fc_flag = 0;
6343 uint32_t port_state = 0;
dea31012005-04-17 16:05:31 -05006344
6345 cmd = *lp++;
6346 sp = (struct serv_parm *) lp;
6347
6348 /* FLOGI received */
6349
James Smart2e0fef82007-06-17 19:56:36 -05006350 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05006351
James Smart76a95d72010-11-20 23:11:48 -05006352 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05006353 /* We should never receive a FLOGI in loop mode, ignore it */
6354 did = icmd->un.elsreq64.remoteID;
6355
6356 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
6357 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04006358 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6359 "0113 An FLOGI ELS command x%x was "
6360 "received from DID x%x in Loop Mode\n",
6361 cmd, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006362 return 1;
dea31012005-04-17 16:05:31 -05006363 }
6364
James Smartd6de08c2015-12-16 18:11:53 -05006365 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
dea31012005-04-17 16:05:31 -05006366
James Smartd6de08c2015-12-16 18:11:53 -05006367 /*
6368 * If our portname is greater than the remote portname,
6369 * then we initiate Nport login.
6370 */
6371
6372 rc = memcmp(&vport->fc_portname, &sp->portName,
6373 sizeof(struct lpfc_name));
6374
6375 if (!rc) {
6376 if (phba->sli_rev < LPFC_SLI_REV4) {
6377 mbox = mempool_alloc(phba->mbox_mem_pool,
6378 GFP_KERNEL);
6379 if (!mbox)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006380 return 1;
James Smartd6de08c2015-12-16 18:11:53 -05006381 lpfc_linkdown(phba);
6382 lpfc_init_link(phba, mbox,
6383 phba->cfg_topology,
6384 phba->cfg_link_speed);
6385 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
6386 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
6387 mbox->vport = vport;
6388 rc = lpfc_sli_issue_mbox(phba, mbox,
6389 MBX_NOWAIT);
6390 lpfc_set_loopback_flag(phba);
6391 if (rc == MBX_NOT_FINISHED)
6392 mempool_free(mbox, phba->mbox_mem_pool);
6393 return 1;
6394 }
James Smart939723a2012-05-09 21:19:03 -04006395
James Smartd6de08c2015-12-16 18:11:53 -05006396 /* abort the flogi coming back to ourselves
6397 * due to external loopback on the port.
James Smart939723a2012-05-09 21:19:03 -04006398 */
James Smartd6de08c2015-12-16 18:11:53 -05006399 lpfc_els_abort_flogi(phba);
6400 return 0;
6401
6402 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05006403 spin_lock_irq(shost->host_lock);
James Smartd6de08c2015-12-16 18:11:53 -05006404 vport->fc_flag |= FC_PT2PT_PLOGI;
James Smart2e0fef82007-06-17 19:56:36 -05006405 spin_unlock_irq(shost->host_lock);
James Smart939723a2012-05-09 21:19:03 -04006406
James Smartd6de08c2015-12-16 18:11:53 -05006407 /* If we have the high WWPN we can assign our own
6408 * myDID; otherwise, we have to WAIT for a PLOGI
6409 * from the remote NPort to find out what it
6410 * will be.
James Smart939723a2012-05-09 21:19:03 -04006411 */
James Smartd6de08c2015-12-16 18:11:53 -05006412 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -05006413 } else {
James Smartd6de08c2015-12-16 18:11:53 -05006414 vport->fc_myDID = PT2PT_RemoteID;
dea31012005-04-17 16:05:31 -05006415 }
6416
James Smartd6de08c2015-12-16 18:11:53 -05006417 /*
6418 * The vport state should go to LPFC_FLOGI only
6419 * AFTER we issue a FLOGI, not receive one.
6420 */
6421 spin_lock_irq(shost->host_lock);
6422 fc_flag = vport->fc_flag;
6423 port_state = vport->port_state;
6424 vport->fc_flag |= FC_PT2PT;
6425 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6426 spin_unlock_irq(shost->host_lock);
6427 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6428 "3311 Rcv Flogi PS x%x new PS x%x "
6429 "fc_flag x%x new fc_flag x%x\n",
6430 port_state, vport->port_state,
6431 fc_flag, vport->fc_flag);
6432
6433 /*
6434 * We temporarily set fc_myDID to make it look like we are
6435 * a Fabric. This is done just so we end up with the right
6436 * did / sid on the FLOGI ACC rsp.
6437 */
6438 did = vport->fc_myDID;
6439 vport->fc_myDID = Fabric_DID;
6440
6441 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
James Smarteec3d312015-08-31 16:48:18 -04006442
dea31012005-04-17 16:05:31 -05006443 /* Send back ACC */
James Smartd6de08c2015-12-16 18:11:53 -05006444 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006445
James Smart939723a2012-05-09 21:19:03 -04006446 /* Now lets put fc_myDID back to what its supposed to be */
6447 vport->fc_myDID = did;
6448
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006449 return 0;
dea31012005-04-17 16:05:31 -05006450}
6451
James Smarte59058c2008-08-24 21:49:00 -04006452/**
James Smart3621a712009-04-06 18:47:14 -04006453 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04006454 * @vport: pointer to a host virtual N_Port data structure.
6455 * @cmdiocb: pointer to lpfc command iocb data structure.
6456 * @ndlp: pointer to a node-list data structure.
6457 *
6458 * This routine processes Request Node Identification Data (RNID) IOCB
6459 * received as an ELS unsolicited event. Only when the RNID specified format
6460 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
6461 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
6462 * Accept (ACC) the RNID ELS command. All the other RNID formats are
6463 * rejected by invoking the lpfc_els_rsp_reject() routine.
6464 *
6465 * Return code
6466 * 0 - Successfully processed rnid iocb (currently always return 0)
6467 **/
dea31012005-04-17 16:05:31 -05006468static int
James Smart2e0fef82007-06-17 19:56:36 -05006469lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6470 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006471{
6472 struct lpfc_dmabuf *pcmd;
6473 uint32_t *lp;
dea31012005-04-17 16:05:31 -05006474 RNID *rn;
6475 struct ls_rjt stat;
James Smarteb016562014-09-03 12:58:06 -04006476 uint32_t cmd;
dea31012005-04-17 16:05:31 -05006477
dea31012005-04-17 16:05:31 -05006478 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6479 lp = (uint32_t *) pcmd->virt;
6480
6481 cmd = *lp++;
6482 rn = (RNID *) lp;
6483
6484 /* RNID received */
6485
6486 switch (rn->Format) {
6487 case 0:
6488 case RNID_TOPOLOGY_DISC:
6489 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05006490 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05006491 break;
6492 default:
6493 /* Reject this request because format not supported */
6494 stat.un.b.lsRjtRsvd0 = 0;
6495 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6496 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6497 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05006498 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
6499 NULL);
dea31012005-04-17 16:05:31 -05006500 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006501 return 0;
dea31012005-04-17 16:05:31 -05006502}
6503
James Smarte59058c2008-08-24 21:49:00 -04006504/**
James Smart12265f62010-10-22 11:05:53 -04006505 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
6506 * @vport: pointer to a host virtual N_Port data structure.
6507 * @cmdiocb: pointer to lpfc command iocb data structure.
6508 * @ndlp: pointer to a node-list data structure.
6509 *
6510 * Return code
6511 * 0 - Successfully processed echo iocb (currently always return 0)
6512 **/
6513static int
6514lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6515 struct lpfc_nodelist *ndlp)
6516{
6517 uint8_t *pcmd;
6518
6519 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
6520
6521 /* skip over first word of echo command to find echo data */
6522 pcmd += sizeof(uint32_t);
6523
6524 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
6525 return 0;
6526}
6527
6528/**
James Smart3621a712009-04-06 18:47:14 -04006529 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04006530 * @vport: pointer to a host virtual N_Port data structure.
6531 * @cmdiocb: pointer to lpfc command iocb data structure.
6532 * @ndlp: pointer to a node-list data structure.
6533 *
6534 * This routine processes a Link Incident Report Registration(LIRR) IOCB
6535 * received as an ELS unsolicited event. Currently, this function just invokes
6536 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
6537 *
6538 * Return code
6539 * 0 - Successfully processed lirr iocb (currently always return 0)
6540 **/
dea31012005-04-17 16:05:31 -05006541static int
James Smart2e0fef82007-06-17 19:56:36 -05006542lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6543 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006544{
6545 struct ls_rjt stat;
6546
6547 /* For now, unconditionally reject this command */
6548 stat.un.b.lsRjtRsvd0 = 0;
6549 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6550 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6551 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05006552 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006553 return 0;
6554}
6555
James Smarte59058c2008-08-24 21:49:00 -04006556/**
James Smart5ffc2662009-11-18 15:39:44 -05006557 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
6558 * @vport: pointer to a host virtual N_Port data structure.
6559 * @cmdiocb: pointer to lpfc command iocb data structure.
6560 * @ndlp: pointer to a node-list data structure.
6561 *
6562 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
6563 * received as an ELS unsolicited event. A request to RRQ shall only
6564 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
6565 * Nx_Port N_Port_ID of the target Exchange is the same as the
6566 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
6567 * not accepted, an LS_RJT with reason code "Unable to perform
6568 * command request" and reason code explanation "Invalid Originator
6569 * S_ID" shall be returned. For now, we just unconditionally accept
6570 * RRQ from the target.
6571 **/
6572static void
6573lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6574 struct lpfc_nodelist *ndlp)
6575{
6576 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05006577 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6578 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05006579}
6580
6581/**
James Smart12265f62010-10-22 11:05:53 -04006582 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6583 * @phba: pointer to lpfc hba data structure.
6584 * @pmb: pointer to the driver internal queue element for mailbox command.
6585 *
6586 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6587 * mailbox command. This callback function is to actually send the Accept
6588 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6589 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6590 * mailbox command, constructs the RPS response with the link statistics
6591 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6592 * response to the RPS.
6593 *
6594 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6595 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6596 * will be stored into the context1 field of the IOCB for the completion
6597 * callback function to the RPS Accept Response ELS IOCB command.
6598 *
6599 **/
6600static void
6601lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6602{
6603 MAILBOX_t *mb;
6604 IOCB_t *icmd;
6605 struct RLS_RSP *rls_rsp;
6606 uint8_t *pcmd;
6607 struct lpfc_iocbq *elsiocb;
6608 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04006609 uint16_t oxid;
6610 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04006611 uint32_t cmdsize;
6612
6613 mb = &pmb->u.mb;
6614
6615 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04006616 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6617 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
James Smart12265f62010-10-22 11:05:53 -04006618 pmb->context1 = NULL;
6619 pmb->context2 = NULL;
6620
6621 if (mb->mbxStatus) {
6622 mempool_free(pmb, phba->mbox_mem_pool);
6623 return;
6624 }
6625
6626 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
James Smart12265f62010-10-22 11:05:53 -04006627 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6628 lpfc_max_els_tries, ndlp,
6629 ndlp->nlp_DID, ELS_CMD_ACC);
6630
6631 /* Decrement the ndlp reference count from previous mbox command */
6632 lpfc_nlp_put(ndlp);
6633
James Smart37db57e2012-05-09 21:17:16 -04006634 if (!elsiocb) {
6635 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04006636 return;
James Smart37db57e2012-05-09 21:17:16 -04006637 }
James Smart12265f62010-10-22 11:05:53 -04006638
6639 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04006640 icmd->ulpContext = rxid;
6641 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04006642
6643 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6644 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6645 pcmd += sizeof(uint32_t); /* Skip past command */
6646 rls_rsp = (struct RLS_RSP *)pcmd;
6647
6648 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6649 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6650 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6651 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6652 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6653 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
James Smart37db57e2012-05-09 21:17:16 -04006654 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04006655 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6656 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6657 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
6658 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6659 elsiocb->iotag, elsiocb->iocb.ulpContext,
6660 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6661 ndlp->nlp_rpi);
6662 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6663 phba->fc_stat.elsXmitACC++;
6664 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6665 lpfc_els_free_iocb(phba, elsiocb);
6666}
6667
6668/**
James Smart3621a712009-04-06 18:47:14 -04006669 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04006670 * @phba: pointer to lpfc hba data structure.
6671 * @pmb: pointer to the driver internal queue element for mailbox command.
6672 *
6673 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6674 * mailbox command. This callback function is to actually send the Accept
6675 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6676 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6677 * mailbox command, constructs the RPS response with the link statistics
6678 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6679 * response to the RPS.
6680 *
6681 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6682 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6683 * will be stored into the context1 field of the IOCB for the completion
6684 * callback function to the RPS Accept Response ELS IOCB command.
6685 *
6686 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05006687static void
James Smart329f9bc2007-04-25 09:53:01 -04006688lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006689{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006690 MAILBOX_t *mb;
6691 IOCB_t *icmd;
6692 RPS_RSP *rps_rsp;
6693 uint8_t *pcmd;
6694 struct lpfc_iocbq *elsiocb;
6695 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04006696 uint16_t status;
6697 uint16_t oxid;
6698 uint16_t rxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006699 uint32_t cmdsize;
6700
James Smart04c68492009-05-22 14:52:52 -04006701 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006702
6703 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04006704 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6705 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
Randy Dunlap041976f2006-06-25 01:58:51 -07006706 pmb->context1 = NULL;
6707 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006708
6709 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04006710 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006711 return;
6712 }
6713
6714 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04006715 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05006716 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6717 lpfc_max_els_tries, ndlp,
6718 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05006719
6720 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04006721 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05006722
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006723 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006724 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006725
6726 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04006727 icmd->ulpContext = rxid;
6728 icmd->unsli3.rcvsli3.ox_id = oxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006729
6730 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6731 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05006732 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006733 rps_rsp = (RPS_RSP *)pcmd;
6734
James Smart76a95d72010-11-20 23:11:48 -05006735 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006736 status = 0x10;
6737 else
6738 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05006739 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006740 status |= 0x4;
6741
6742 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05006743 rps_rsp->portStatus = cpu_to_be16(status);
6744 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6745 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6746 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6747 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6748 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6749 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006750 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04006751 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6752 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
6753 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6754 elsiocb->iotag, elsiocb->iocb.ulpContext,
6755 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6756 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05006757 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006758 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04006759 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006760 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006761 return;
6762}
6763
James Smarte59058c2008-08-24 21:49:00 -04006764/**
James Smart12265f62010-10-22 11:05:53 -04006765 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
6766 * @vport: pointer to a host virtual N_Port data structure.
6767 * @cmdiocb: pointer to lpfc command iocb data structure.
6768 * @ndlp: pointer to a node-list data structure.
6769 *
6770 * This routine processes Read Port Status (RPL) IOCB received as an
6771 * ELS unsolicited event. It first checks the remote port state. If the
6772 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6773 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6774 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6775 * for reading the HBA link statistics. It is for the callback function,
6776 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
6777 * to actually sending out RPL Accept (ACC) response.
6778 *
6779 * Return codes
6780 * 0 - Successfully processed rls iocb (currently always return 0)
6781 **/
6782static int
6783lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6784 struct lpfc_nodelist *ndlp)
6785{
6786 struct lpfc_hba *phba = vport->phba;
6787 LPFC_MBOXQ_t *mbox;
James Smart12265f62010-10-22 11:05:53 -04006788 struct ls_rjt stat;
6789
6790 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6791 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6792 /* reject the unsolicited RPS request and done with it */
6793 goto reject_out;
6794
James Smart12265f62010-10-22 11:05:53 -04006795 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6796 if (mbox) {
6797 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04006798 mbox->context1 = (void *)((unsigned long)
6799 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6800 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart12265f62010-10-22 11:05:53 -04006801 mbox->context2 = lpfc_nlp_get(ndlp);
6802 mbox->vport = vport;
6803 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
6804 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6805 != MBX_NOT_FINISHED)
6806 /* Mbox completion will send ELS Response */
6807 return 0;
6808 /* Decrement reference count used for the failed mbox
6809 * command.
6810 */
6811 lpfc_nlp_put(ndlp);
6812 mempool_free(mbox, phba->mbox_mem_pool);
6813 }
6814reject_out:
6815 /* issue rejection response */
6816 stat.un.b.lsRjtRsvd0 = 0;
6817 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6818 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6819 stat.un.b.vendorUnique = 0;
6820 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6821 return 0;
6822}
6823
6824/**
6825 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
6826 * @vport: pointer to a host virtual N_Port data structure.
6827 * @cmdiocb: pointer to lpfc command iocb data structure.
6828 * @ndlp: pointer to a node-list data structure.
6829 *
6830 * This routine processes Read Timout Value (RTV) IOCB received as an
6831 * ELS unsolicited event. It first checks the remote port state. If the
6832 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6833 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6834 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
6835 * Value (RTV) unsolicited IOCB event.
6836 *
6837 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6838 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6839 * will be stored into the context1 field of the IOCB for the completion
6840 * callback function to the RPS Accept Response ELS IOCB command.
6841 *
6842 * Return codes
6843 * 0 - Successfully processed rtv iocb (currently always return 0)
6844 **/
6845static int
6846lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6847 struct lpfc_nodelist *ndlp)
6848{
6849 struct lpfc_hba *phba = vport->phba;
6850 struct ls_rjt stat;
6851 struct RTV_RSP *rtv_rsp;
6852 uint8_t *pcmd;
6853 struct lpfc_iocbq *elsiocb;
6854 uint32_t cmdsize;
6855
6856
6857 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6858 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6859 /* reject the unsolicited RPS request and done with it */
6860 goto reject_out;
6861
6862 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
6863 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6864 lpfc_max_els_tries, ndlp,
6865 ndlp->nlp_DID, ELS_CMD_ACC);
6866
6867 if (!elsiocb)
6868 return 1;
6869
6870 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
Colin Ian King8fd03fd2017-12-22 00:39:36 +00006871 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart12265f62010-10-22 11:05:53 -04006872 pcmd += sizeof(uint32_t); /* Skip past command */
6873
6874 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04006875 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
6876 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04006877
6878 rtv_rsp = (struct RTV_RSP *)pcmd;
6879
6880 /* populate RTV payload */
6881 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
6882 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
6883 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
6884 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
6885 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
6886
6887 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6888 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6889 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
6890 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
6891 "Data: x%x x%x x%x\n",
6892 elsiocb->iotag, elsiocb->iocb.ulpContext,
6893 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6894 ndlp->nlp_rpi,
6895 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
6896 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6897 phba->fc_stat.elsXmitACC++;
6898 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6899 lpfc_els_free_iocb(phba, elsiocb);
6900 return 0;
6901
6902reject_out:
6903 /* issue rejection response */
6904 stat.un.b.lsRjtRsvd0 = 0;
6905 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6906 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6907 stat.un.b.vendorUnique = 0;
6908 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6909 return 0;
6910}
6911
6912/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04006913 * @vport: pointer to a host virtual N_Port data structure.
6914 * @cmdiocb: pointer to lpfc command iocb data structure.
6915 * @ndlp: pointer to a node-list data structure.
6916 *
6917 * This routine processes Read Port Status (RPS) IOCB received as an
6918 * ELS unsolicited event. It first checks the remote port state. If the
6919 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6920 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
6921 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6922 * for reading the HBA link statistics. It is for the callback function,
6923 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
6924 * to actually sending out RPS Accept (ACC) response.
6925 *
6926 * Return codes
6927 * 0 - Successfully processed rps iocb (currently always return 0)
6928 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006929static int
James Smart2e0fef82007-06-17 19:56:36 -05006930lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6931 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006932{
James Smart2e0fef82007-06-17 19:56:36 -05006933 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006934 uint32_t *lp;
6935 uint8_t flag;
6936 LPFC_MBOXQ_t *mbox;
6937 struct lpfc_dmabuf *pcmd;
6938 RPS *rps;
6939 struct ls_rjt stat;
6940
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05006941 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04006942 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6943 /* reject the unsolicited RPS request and done with it */
6944 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006945
6946 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6947 lp = (uint32_t *) pcmd->virt;
6948 flag = (be32_to_cpu(*lp++) & 0xf);
6949 rps = (RPS *) lp;
6950
6951 if ((flag == 0) ||
6952 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05006953 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05006954 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05006955
James Smart92d7f7b2007-06-17 19:56:38 -05006956 printk("Fix me....\n");
6957 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05006958 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6959 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006960 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04006961 mbox->context1 = (void *)((unsigned long)
6962 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6963 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart329f9bc2007-04-25 09:53:01 -04006964 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006965 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006966 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05006967 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04006968 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006969 /* Mbox completion will send ELS Response */
6970 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05006971 /* Decrement reference count used for the failed mbox
6972 * command.
6973 */
James Smart329f9bc2007-04-25 09:53:01 -04006974 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006975 mempool_free(mbox, phba->mbox_mem_pool);
6976 }
6977 }
James Smart90160e02008-08-24 21:49:45 -04006978
6979reject_out:
6980 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006981 stat.un.b.lsRjtRsvd0 = 0;
6982 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6983 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6984 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05006985 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006986 return 0;
6987}
6988
James Smart19ca7602010-11-20 23:11:55 -05006989/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
6990 * @vport: pointer to a host virtual N_Port data structure.
6991 * @ndlp: pointer to a node-list data structure.
6992 * @did: DID of the target.
6993 * @rrq: Pointer to the rrq struct.
6994 *
6995 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
6996 * Successful the the completion handler will clear the RRQ.
6997 *
6998 * Return codes
6999 * 0 - Successfully sent rrq els iocb.
7000 * 1 - Failed to send rrq els iocb.
7001 **/
7002static int
7003lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7004 uint32_t did, struct lpfc_node_rrq *rrq)
7005{
7006 struct lpfc_hba *phba = vport->phba;
7007 struct RRQ *els_rrq;
James Smart19ca7602010-11-20 23:11:55 -05007008 struct lpfc_iocbq *elsiocb;
7009 uint8_t *pcmd;
7010 uint16_t cmdsize;
7011 int ret;
7012
7013
7014 if (ndlp != rrq->ndlp)
7015 ndlp = rrq->ndlp;
7016 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7017 return 1;
7018
7019 /* If ndlp is not NULL, we will bump the reference count on it */
7020 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
7021 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
7022 ELS_CMD_RRQ);
7023 if (!elsiocb)
7024 return 1;
7025
James Smart19ca7602010-11-20 23:11:55 -05007026 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7027
7028 /* For RRQ request, remainder of payload is Exchange IDs */
7029 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
7030 pcmd += sizeof(uint32_t);
7031 els_rrq = (struct RRQ *) pcmd;
7032
James Smartee0f4fe2012-05-09 21:19:14 -04007033 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
James Smart19ca7602010-11-20 23:11:55 -05007034 bf_set(rrq_rxid, els_rrq, rrq->rxid);
7035 bf_set(rrq_did, els_rrq, vport->fc_myDID);
7036 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
7037 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
7038
7039
7040 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7041 "Issue RRQ: did:x%x",
7042 did, rrq->xritag, rrq->rxid);
7043 elsiocb->context_un.rrq = rrq;
7044 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
7045 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7046
7047 if (ret == IOCB_ERROR) {
7048 lpfc_els_free_iocb(phba, elsiocb);
7049 return 1;
7050 }
7051 return 0;
7052}
7053
7054/**
7055 * lpfc_send_rrq - Sends ELS RRQ if needed.
7056 * @phba: pointer to lpfc hba data structure.
7057 * @rrq: pointer to the active rrq.
7058 *
7059 * This routine will call the lpfc_issue_els_rrq if the rrq is
7060 * still active for the xri. If this function returns a failure then
7061 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
7062 *
7063 * Returns 0 Success.
7064 * 1 Failure.
7065 **/
7066int
7067lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
7068{
7069 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
7070 rrq->nlp_DID);
7071 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
7072 return lpfc_issue_els_rrq(rrq->vport, ndlp,
7073 rrq->nlp_DID, rrq);
7074 else
7075 return 1;
7076}
7077
James Smarte59058c2008-08-24 21:49:00 -04007078/**
James Smart3621a712009-04-06 18:47:14 -04007079 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04007080 * @vport: pointer to a host virtual N_Port data structure.
7081 * @cmdsize: size of the ELS command.
7082 * @oldiocb: pointer to the original lpfc command iocb data structure.
7083 * @ndlp: pointer to a node-list data structure.
7084 *
7085 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
7086 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
7087 *
7088 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7089 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7090 * will be stored into the context1 field of the IOCB for the completion
7091 * callback function to the RPL Accept Response ELS command.
7092 *
7093 * Return code
7094 * 0 - Successfully issued ACC RPL ELS command
7095 * 1 - Failed to issue ACC RPL ELS command
7096 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05007097static int
James Smart2e0fef82007-06-17 19:56:36 -05007098lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
7099 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007100{
James Smart2e0fef82007-06-17 19:56:36 -05007101 struct lpfc_hba *phba = vport->phba;
7102 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007103 RPL_RSP rpl_rsp;
7104 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007105 uint8_t *pcmd;
7106
James Smart2e0fef82007-06-17 19:56:36 -05007107 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
7108 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007109
James Smart488d1462006-03-07 15:02:37 -05007110 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007111 return 1;
James Smart488d1462006-03-07 15:02:37 -05007112
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007113 icmd = &elsiocb->iocb;
7114 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04007115 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
7116 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007117
7118 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7119 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05007120 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007121 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7122 pcmd += sizeof(uint16_t);
7123
7124 /* Setup the RPL ACC payload */
7125 rpl_rsp.listLen = be32_to_cpu(1);
7126 rpl_rsp.index = 0;
7127 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05007128 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7129 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007130 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007131 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007132 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04007133 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7134 "0120 Xmit ELS RPL ACC response tag x%x "
7135 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7136 "rpi x%x\n",
7137 elsiocb->iotag, elsiocb->iocb.ulpContext,
7138 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7139 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05007140 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007141 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04007142 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7143 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007144 lpfc_els_free_iocb(phba, elsiocb);
7145 return 1;
7146 }
7147 return 0;
7148}
7149
James Smarte59058c2008-08-24 21:49:00 -04007150/**
James Smart3621a712009-04-06 18:47:14 -04007151 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04007152 * @vport: pointer to a host virtual N_Port data structure.
7153 * @cmdiocb: pointer to lpfc command iocb data structure.
7154 * @ndlp: pointer to a node-list data structure.
7155 *
7156 * This routine processes Read Port List (RPL) IOCB received as an ELS
7157 * unsolicited event. It first checks the remote port state. If the remote
7158 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7159 * invokes the lpfc_els_rsp_reject() routine to send reject response.
7160 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7161 * to accept the RPL.
7162 *
7163 * Return code
7164 * 0 - Successfully processed rpl iocb (currently always return 0)
7165 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007166static int
James Smart2e0fef82007-06-17 19:56:36 -05007167lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7168 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007169{
7170 struct lpfc_dmabuf *pcmd;
7171 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007172 uint32_t maxsize;
7173 uint16_t cmdsize;
7174 RPL *rpl;
7175 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05007176
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05007177 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7178 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04007179 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007180 stat.un.b.lsRjtRsvd0 = 0;
7181 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7182 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7183 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05007184 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7185 NULL);
James Smart90160e02008-08-24 21:49:45 -04007186 /* rejected the unsolicited RPL request and done with it */
7187 return 0;
dea31012005-04-17 16:05:31 -05007188 }
7189
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007190 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7191 lp = (uint32_t *) pcmd->virt;
7192 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007193 maxsize = be32_to_cpu(rpl->maxsize);
7194
7195 /* We support only one port */
7196 if ((rpl->index == 0) &&
7197 ((maxsize == 0) ||
7198 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
7199 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05007200 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007201 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
7202 }
James Smart2e0fef82007-06-17 19:56:36 -05007203 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05007204
7205 return 0;
7206}
7207
James Smarte59058c2008-08-24 21:49:00 -04007208/**
James Smart3621a712009-04-06 18:47:14 -04007209 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04007210 * @vport: pointer to a virtual N_Port data structure.
7211 * @cmdiocb: pointer to lpfc command iocb data structure.
7212 * @ndlp: pointer to a node-list data structure.
7213 *
7214 * This routine processes Fibre Channel Address Resolution Protocol
7215 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
7216 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
7217 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
7218 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
7219 * remote PortName is compared against the FC PortName stored in the @vport
7220 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
7221 * compared against the FC NodeName stored in the @vport data structure.
7222 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
7223 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
7224 * invoked to send out FARP Response to the remote node. Before sending the
7225 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
7226 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
7227 * routine is invoked to log into the remote port first.
7228 *
7229 * Return code
7230 * 0 - Either the FARP Match Mode not supported or successfully processed
7231 **/
dea31012005-04-17 16:05:31 -05007232static int
James Smart2e0fef82007-06-17 19:56:36 -05007233lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7234 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007235{
7236 struct lpfc_dmabuf *pcmd;
7237 uint32_t *lp;
7238 IOCB_t *icmd;
7239 FARP *fp;
7240 uint32_t cmd, cnt, did;
7241
7242 icmd = &cmdiocb->iocb;
7243 did = icmd->un.elsreq64.remoteID;
7244 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7245 lp = (uint32_t *) pcmd->virt;
7246
7247 cmd = *lp++;
7248 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05007249 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04007250 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7251 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05007252 /* We will only support match on WWPN or WWNN */
7253 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007254 return 0;
dea31012005-04-17 16:05:31 -05007255 }
7256
7257 cnt = 0;
7258 /* If this FARP command is searching for my portname */
7259 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05007260 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05007261 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05007262 cnt = 1;
7263 }
7264
7265 /* If this FARP command is searching for my nodename */
7266 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05007267 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05007268 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05007269 cnt = 1;
7270 }
7271
7272 if (cnt) {
7273 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
7274 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7275 /* Log back into the node before sending the FARP. */
7276 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007277 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05007278 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04007279 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05007280 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05007281 }
7282
7283 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05007284 if (fp->Rflags & FARP_REQUEST_FARPR)
7285 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05007286 }
7287 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007288 return 0;
dea31012005-04-17 16:05:31 -05007289}
7290
James Smarte59058c2008-08-24 21:49:00 -04007291/**
James Smart3621a712009-04-06 18:47:14 -04007292 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04007293 * @vport: pointer to a host virtual N_Port data structure.
7294 * @cmdiocb: pointer to lpfc command iocb data structure.
7295 * @ndlp: pointer to a node-list data structure.
7296 *
7297 * This routine processes Fibre Channel Address Resolution Protocol
7298 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7299 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7300 * the FARP response request.
7301 *
7302 * Return code
7303 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7304 **/
dea31012005-04-17 16:05:31 -05007305static int
James Smart2e0fef82007-06-17 19:56:36 -05007306lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7307 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007308{
7309 struct lpfc_dmabuf *pcmd;
7310 uint32_t *lp;
7311 IOCB_t *icmd;
7312 uint32_t cmd, did;
7313
7314 icmd = &cmdiocb->iocb;
7315 did = icmd->un.elsreq64.remoteID;
7316 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7317 lp = (uint32_t *) pcmd->virt;
7318
7319 cmd = *lp++;
7320 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04007321 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7322 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05007323 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04007324 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05007325
7326 return 0;
7327}
7328
James Smarte59058c2008-08-24 21:49:00 -04007329/**
James Smart3621a712009-04-06 18:47:14 -04007330 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04007331 * @vport: pointer to a host virtual N_Port data structure.
7332 * @cmdiocb: pointer to lpfc command iocb data structure.
7333 * @fan_ndlp: pointer to a node-list data structure.
7334 *
7335 * This routine processes a Fabric Address Notification (FAN) IOCB
7336 * command received as an ELS unsolicited event. The FAN ELS command will
7337 * only be processed on a physical port (i.e., the @vport represents the
7338 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7339 * compared against those in the phba data structure. If any of those is
7340 * different, the lpfc_initial_flogi() routine is invoked to initialize
7341 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7342 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7343 * is invoked to register login to the fabric.
7344 *
7345 * Return code
7346 * 0 - Successfully processed fan iocb (currently always return 0).
7347 **/
dea31012005-04-17 16:05:31 -05007348static int
James Smart2e0fef82007-06-17 19:56:36 -05007349lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7350 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05007351{
James Smart2e0fef82007-06-17 19:56:36 -05007352 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04007353 uint32_t *lp;
7354 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007355
James Smart0d2b6b82008-06-14 22:52:47 -04007356 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7357 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7358 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007359 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04007360 if ((vport == phba->pport) &&
7361 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007362 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04007363 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007364 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04007365 sizeof(struct lpfc_name)))) {
7366 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05007367 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04007368 } else {
7369 /* FAN verified - skip FLOGI */
7370 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04007371 if (phba->sli_rev < LPFC_SLI_REV4)
7372 lpfc_issue_fabric_reglogin(vport);
James Smart1b511972011-12-13 13:23:09 -05007373 else {
7374 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7375 "3138 Need register VFI: (x%x/%x)\n",
7376 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -04007377 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -05007378 }
dea31012005-04-17 16:05:31 -05007379 }
dea31012005-04-17 16:05:31 -05007380 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007381 return 0;
dea31012005-04-17 16:05:31 -05007382}
7383
James Smarte59058c2008-08-24 21:49:00 -04007384/**
James Smart3621a712009-04-06 18:47:14 -04007385 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04007386 * @ptr: holder for the timer function associated data.
7387 *
7388 * This routine is invoked by the ELS timer after timeout. It posts the ELS
7389 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
7390 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
7391 * up the worker thread. It is for the worker thread to invoke the routine
7392 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
7393 **/
dea31012005-04-17 16:05:31 -05007394void
Kees Cookf22eb4d2017-09-06 20:24:26 -07007395lpfc_els_timeout(struct timer_list *t)
dea31012005-04-17 16:05:31 -05007396{
Kees Cookf22eb4d2017-09-06 20:24:26 -07007397 struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
James Smart2e0fef82007-06-17 19:56:36 -05007398 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04007399 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05007400 unsigned long iflag;
7401
James Smart2e0fef82007-06-17 19:56:36 -05007402 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04007403 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
James Smart06918ac2014-02-20 09:57:57 -05007404 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
James Smart2e0fef82007-06-17 19:56:36 -05007405 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04007406 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05007407
James Smart06918ac2014-02-20 09:57:57 -05007408 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
James Smart5e9d9b82008-06-14 22:52:53 -04007409 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05007410 return;
7411}
7412
James Smart2a9bf3d2010-06-07 15:24:45 -04007413
James Smarte59058c2008-08-24 21:49:00 -04007414/**
James Smart3621a712009-04-06 18:47:14 -04007415 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04007416 * @vport: pointer to a virtual N_Port data structure.
7417 *
7418 * This routine is the actual handler function that processes an ELS timeout
7419 * event. It walks the ELS ring to get and abort all the IOCBs (except the
7420 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
7421 * invoking the lpfc_sli_issue_abort_iotag() routine.
7422 **/
dea31012005-04-17 16:05:31 -05007423void
James Smart2e0fef82007-06-17 19:56:36 -05007424lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05007425{
James Smart2e0fef82007-06-17 19:56:36 -05007426 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05007427 struct lpfc_sli_ring *pring;
7428 struct lpfc_iocbq *tmp_iocb, *piocb;
7429 IOCB_t *cmd = NULL;
7430 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05007431 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05007432 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05007433 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04007434 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05007435
James Smart2a9bf3d2010-06-07 15:24:45 -04007436
dea31012005-04-17 16:05:31 -05007437 timeout = (uint32_t)(phba->fc_ratov << 1);
7438
James Smart895427b2017-02-12 13:52:30 -08007439 pring = lpfc_phba_elsring(phba);
Dick Kennedy1234a6d2017-09-29 17:34:29 -07007440 if (unlikely(!pring))
7441 return;
James Smart895427b2017-02-12 13:52:30 -08007442
James Smart06918ac2014-02-20 09:57:57 -05007443 if ((phba->pport->load_flag & FC_UNLOADING))
7444 return;
James Smart2a9bf3d2010-06-07 15:24:45 -04007445 spin_lock_irq(&phba->hbalock);
James Smart0976e1a2013-12-17 20:29:36 -05007446 if (phba->sli_rev == LPFC_SLI_REV4)
7447 spin_lock(&pring->ring_lock);
James Smart2a9bf3d2010-06-07 15:24:45 -04007448
James Smart06918ac2014-02-20 09:57:57 -05007449 if ((phba->pport->load_flag & FC_UNLOADING)) {
7450 if (phba->sli_rev == LPFC_SLI_REV4)
7451 spin_unlock(&pring->ring_lock);
7452 spin_unlock_irq(&phba->hbalock);
7453 return;
7454 }
7455
James Smart0976e1a2013-12-17 20:29:36 -05007456 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05007457 cmd = &piocb->iocb;
7458
James Smart2e0fef82007-06-17 19:56:36 -05007459 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
7460 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
7461 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05007462 continue;
James Smart2e0fef82007-06-17 19:56:36 -05007463
7464 if (piocb->vport != vport)
7465 continue;
7466
dea31012005-04-17 16:05:31 -05007467 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05007468 if (pcmd)
7469 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05007470
James Smart92d7f7b2007-06-17 19:56:38 -05007471 if (els_command == ELS_CMD_FARP ||
7472 els_command == ELS_CMD_FARPR ||
7473 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05007474 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05007475
dea31012005-04-17 16:05:31 -05007476 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05007477 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05007478 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05007479 else
dea31012005-04-17 16:05:31 -05007480 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05007481 continue;
7482 }
7483
James Smart2e0fef82007-06-17 19:56:36 -05007484 remote_ID = 0xffffffff;
7485 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05007486 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05007487 else {
7488 struct lpfc_nodelist *ndlp;
7489 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04007490 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05007491 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05007492 }
James Smart2a9bf3d2010-06-07 15:24:45 -04007493 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05007494 }
James Smart0976e1a2013-12-17 20:29:36 -05007495 if (phba->sli_rev == LPFC_SLI_REV4)
7496 spin_unlock(&pring->ring_lock);
James Smart2e0fef82007-06-17 19:56:36 -05007497 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04007498
James Smart2a9bf3d2010-06-07 15:24:45 -04007499 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
James Smart15026c92013-12-17 20:30:09 -05007500 cmd = &piocb->iocb;
James Smart2a9bf3d2010-06-07 15:24:45 -04007501 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7502 "0127 ELS timeout Data: x%x x%x x%x "
7503 "x%x\n", els_command,
7504 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
7505 spin_lock_irq(&phba->hbalock);
7506 list_del_init(&piocb->dlist);
7507 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7508 spin_unlock_irq(&phba->hbalock);
7509 }
7510
James Smart895427b2017-02-12 13:52:30 -08007511 if (!list_empty(&pring->txcmplq))
James Smart06918ac2014-02-20 09:57:57 -05007512 if (!(phba->pport->load_flag & FC_UNLOADING))
7513 mod_timer(&vport->els_tmofunc,
7514 jiffies + msecs_to_jiffies(1000 * timeout));
dea31012005-04-17 16:05:31 -05007515}
7516
James Smarte59058c2008-08-24 21:49:00 -04007517/**
James Smart3621a712009-04-06 18:47:14 -04007518 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04007519 * @vport: pointer to a host virtual N_Port data structure.
7520 *
7521 * This routine is used to clean up all the outstanding ELS commands on a
7522 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
7523 * routine. After that, it walks the ELS transmit queue to remove all the
7524 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
7525 * the IOCBs with a non-NULL completion callback function, the callback
7526 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7527 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
7528 * callback function, the IOCB will simply be released. Finally, it walks
7529 * the ELS transmit completion queue to issue an abort IOCB to any transmit
7530 * completion queue IOCB that is associated with the @vport and is not
7531 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
7532 * part of the discovery state machine) out to HBA by invoking the
7533 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
7534 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
7535 * the IOCBs are aborted when this function returns.
7536 **/
dea31012005-04-17 16:05:31 -05007537void
James Smart2e0fef82007-06-17 19:56:36 -05007538lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05007539{
James Smart0976e1a2013-12-17 20:29:36 -05007540 LIST_HEAD(abort_list);
James Smart2e0fef82007-06-17 19:56:36 -05007541 struct lpfc_hba *phba = vport->phba;
James Smart895427b2017-02-12 13:52:30 -08007542 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05007543 struct lpfc_iocbq *tmp_iocb, *piocb;
7544 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05007545
7546 lpfc_fabric_abort_vport(vport);
James Smart0976e1a2013-12-17 20:29:36 -05007547 /*
7548 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
7549 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
7550 * ultimately grabs the ring_lock, the driver must splice the list into
7551 * a working list and release the locks before calling the abort.
7552 */
7553 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08007554 pring = lpfc_phba_elsring(phba);
Guilherme G. Piccoli53cf29d2017-05-17 19:02:17 -03007555
7556 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
7557 if (unlikely(!pring)) {
7558 spin_unlock_irq(&phba->hbalock);
7559 return;
7560 }
7561
James Smart0976e1a2013-12-17 20:29:36 -05007562 if (phba->sli_rev == LPFC_SLI_REV4)
7563 spin_lock(&pring->ring_lock);
7564
7565 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7566 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
7567 continue;
7568
7569 if (piocb->vport != vport)
7570 continue;
7571 list_add_tail(&piocb->dlist, &abort_list);
7572 }
7573 if (phba->sli_rev == LPFC_SLI_REV4)
7574 spin_unlock(&pring->ring_lock);
7575 spin_unlock_irq(&phba->hbalock);
7576 /* Abort each iocb on the aborted list and remove the dlist links. */
7577 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7578 spin_lock_irq(&phba->hbalock);
7579 list_del_init(&piocb->dlist);
7580 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7581 spin_unlock_irq(&phba->hbalock);
7582 }
7583 if (!list_empty(&abort_list))
7584 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7585 "3387 abort list for txq not empty\n");
7586 INIT_LIST_HEAD(&abort_list);
dea31012005-04-17 16:05:31 -05007587
James Smart2e0fef82007-06-17 19:56:36 -05007588 spin_lock_irq(&phba->hbalock);
James Smart0976e1a2013-12-17 20:29:36 -05007589 if (phba->sli_rev == LPFC_SLI_REV4)
7590 spin_lock(&pring->ring_lock);
7591
dea31012005-04-17 16:05:31 -05007592 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
7593 cmd = &piocb->iocb;
7594
7595 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
7596 continue;
7597 }
7598
7599 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04007600 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
7601 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
7602 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
7603 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05007604 continue;
dea31012005-04-17 16:05:31 -05007605
James Smart2e0fef82007-06-17 19:56:36 -05007606 if (piocb->vport != vport)
7607 continue;
7608
James Smart0976e1a2013-12-17 20:29:36 -05007609 list_del_init(&piocb->list);
7610 list_add_tail(&piocb->list, &abort_list);
dea31012005-04-17 16:05:31 -05007611 }
James Smart0976e1a2013-12-17 20:29:36 -05007612 if (phba->sli_rev == LPFC_SLI_REV4)
7613 spin_unlock(&pring->ring_lock);
James Smart2e0fef82007-06-17 19:56:36 -05007614 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04007615
James Smarta257bf92009-04-06 18:48:10 -04007616 /* Cancell all the IOCBs from the completions list */
James Smart0976e1a2013-12-17 20:29:36 -05007617 lpfc_sli_cancel_iocbs(phba, &abort_list,
7618 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04007619
dea31012005-04-17 16:05:31 -05007620 return;
7621}
7622
James Smarte59058c2008-08-24 21:49:00 -04007623/**
James Smart3621a712009-04-06 18:47:14 -04007624 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04007625 * @phba: pointer to lpfc hba data structure.
7626 *
7627 * This routine is used to clean up all the outstanding ELS commands on a
7628 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
7629 * routine. After that, it walks the ELS transmit queue to remove all the
7630 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
7631 * the IOCBs with the completion callback function associated, the callback
7632 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7633 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
7634 * callback function associated, the IOCB will simply be released. Finally,
7635 * it walks the ELS transmit completion queue to issue an abort IOCB to any
7636 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
7637 * management plane IOCBs that are not part of the discovery state machine)
7638 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
7639 **/
James Smart549e55c2007-08-02 11:09:51 -04007640void
7641lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
7642{
James Smart0976e1a2013-12-17 20:29:36 -05007643 struct lpfc_vport *vport;
7644 list_for_each_entry(vport, &phba->port_list, listentry)
7645 lpfc_els_flush_cmd(vport);
James Smarta257bf92009-04-06 18:48:10 -04007646
James Smart549e55c2007-08-02 11:09:51 -04007647 return;
7648}
7649
James Smarte59058c2008-08-24 21:49:00 -04007650/**
James Smart3621a712009-04-06 18:47:14 -04007651 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04007652 * @phba: Pointer to hba context object.
7653 * @cmdiocbp: Pointer to command iocb which reported error.
7654 * @rspiocbp: Pointer to response iocb which reported error.
7655 *
7656 * This function sends an event when there is an ELS command
7657 * failure.
7658 **/
7659void
7660lpfc_send_els_failure_event(struct lpfc_hba *phba,
7661 struct lpfc_iocbq *cmdiocbp,
7662 struct lpfc_iocbq *rspiocbp)
7663{
7664 struct lpfc_vport *vport = cmdiocbp->vport;
7665 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7666 struct lpfc_lsrjt_event lsrjt_event;
7667 struct lpfc_fabric_event_header fabric_event;
7668 struct ls_rjt stat;
7669 struct lpfc_nodelist *ndlp;
7670 uint32_t *pcmd;
7671
7672 ndlp = cmdiocbp->context1;
7673 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7674 return;
7675
7676 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
7677 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
7678 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
7679 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
7680 sizeof(struct lpfc_name));
7681 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
7682 sizeof(struct lpfc_name));
7683 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
7684 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04007685 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04007686 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
7687 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
7688 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
7689 fc_host_post_vendor_event(shost,
7690 fc_get_event_number(),
7691 sizeof(lsrjt_event),
7692 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05007693 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04007694 return;
7695 }
7696 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
7697 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
7698 fabric_event.event_type = FC_REG_FABRIC_EVENT;
7699 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
7700 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
7701 else
7702 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
7703 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
7704 sizeof(struct lpfc_name));
7705 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
7706 sizeof(struct lpfc_name));
7707 fc_host_post_vendor_event(shost,
7708 fc_get_event_number(),
7709 sizeof(fabric_event),
7710 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05007711 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04007712 return;
7713 }
7714
7715}
7716
7717/**
James Smart3621a712009-04-06 18:47:14 -04007718 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04007719 * @vport: Pointer to vport object.
7720 * @ndlp: Pointer FC node object.
7721 * @cmd: ELS command code.
7722 *
7723 * This function posts an event when there is an incoming
7724 * unsolicited ELS command.
7725 **/
7726static void
7727lpfc_send_els_event(struct lpfc_vport *vport,
7728 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05007729 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04007730{
James Smartddcc50f2008-12-04 22:38:46 -05007731 struct lpfc_els_event_header *els_data = NULL;
7732 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04007733 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7734
James Smartddcc50f2008-12-04 22:38:46 -05007735 if (*payload == ELS_CMD_LOGO) {
7736 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
7737 if (!logo_data) {
7738 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7739 "0148 Failed to allocate memory "
7740 "for LOGO event\n");
7741 return;
7742 }
7743 els_data = &logo_data->header;
7744 } else {
7745 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
7746 GFP_KERNEL);
7747 if (!els_data) {
7748 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7749 "0149 Failed to allocate memory "
7750 "for ELS event\n");
7751 return;
7752 }
7753 }
7754 els_data->event_type = FC_REG_ELS_EVENT;
7755 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04007756 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05007757 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04007758 break;
7759 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05007760 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04007761 break;
7762 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05007763 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
7764 break;
7765 case ELS_CMD_LOGO:
7766 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
7767 /* Copy the WWPN in the LOGO payload */
7768 memcpy(logo_data->logo_wwpn, &payload[2],
7769 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04007770 break;
7771 default:
Julia Lawalle9161412009-02-08 22:43:19 +01007772 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04007773 return;
7774 }
James Smartddcc50f2008-12-04 22:38:46 -05007775 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
7776 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
7777 if (*payload == ELS_CMD_LOGO) {
7778 fc_host_post_vendor_event(shost,
7779 fc_get_event_number(),
7780 sizeof(struct lpfc_logo_event),
7781 (char *)logo_data,
7782 LPFC_NL_VENDOR_ID);
7783 kfree(logo_data);
7784 } else {
7785 fc_host_post_vendor_event(shost,
7786 fc_get_event_number(),
7787 sizeof(struct lpfc_els_event_header),
7788 (char *)els_data,
7789 LPFC_NL_VENDOR_ID);
7790 kfree(els_data);
7791 }
James Smartea2151b2008-09-07 11:52:10 -04007792
7793 return;
7794}
7795
7796
7797/**
James Smart3621a712009-04-06 18:47:14 -04007798 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04007799 * @phba: pointer to lpfc hba data structure.
7800 * @pring: pointer to a SLI ring.
7801 * @vport: pointer to a host virtual N_Port data structure.
7802 * @elsiocb: pointer to lpfc els command iocb data structure.
7803 *
7804 * This routine is used for processing the IOCB associated with a unsolicited
7805 * event. It first determines whether there is an existing ndlp that matches
7806 * the DID from the unsolicited IOCB. If not, it will create a new one with
7807 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
7808 * IOCB is then used to invoke the proper routine and to set up proper state
7809 * of the discovery state machine.
7810 **/
James Smarted957682007-06-17 19:56:37 -05007811static void
7812lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05007813 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05007814{
James Smart87af33f2007-10-27 13:37:43 -04007815 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05007816 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05007817 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05007818 uint32_t *payload;
James Smart303f2f92013-01-03 15:43:11 -05007819 uint32_t cmd, did, newnode;
7820 uint8_t rjt_exp, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05007821 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05007822
James Smarte47c9092008-02-08 18:49:26 -05007823 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05007824 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05007825
dea31012005-04-17 16:05:31 -05007826 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007827 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
7828 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05007829 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04007830 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05007831
James Smart858c9f62007-06-17 19:56:39 -05007832 did = icmd->un.rcvels.remoteID;
7833 if (icmd->ulpStatus) {
7834 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7835 "RCV Unsol ELS: status:x%x/x%x did:x%x",
7836 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05007837 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05007838 }
dea31012005-04-17 16:05:31 -05007839
7840 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05007841 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05007842 goto dropit;
dea31012005-04-17 16:05:31 -05007843
James Smartc8685952009-11-18 15:39:16 -05007844 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05007845 if (vport->load_flag & FC_UNLOADING)
7846 goto dropit;
7847
James Smart92494142011-02-16 12:39:44 -05007848 /* If NPort discovery is delayed drop incoming ELS */
7849 if ((vport->fc_flag & FC_DISC_DELAYED) &&
7850 (cmd != ELS_CMD_PLOGI))
7851 goto dropit;
7852
James Smart2e0fef82007-06-17 19:56:36 -05007853 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007854 if (!ndlp) {
dea31012005-04-17 16:05:31 -05007855 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07007856 ndlp = lpfc_nlp_init(vport, did);
James Smarted957682007-06-17 19:56:37 -05007857 if (!ndlp)
dea31012005-04-17 16:05:31 -05007858 goto dropit;
James Smart98c9ea52007-10-27 13:37:33 -04007859 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05007860 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05007861 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05007862 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04007863 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7864 ndlp = lpfc_enable_node(vport, ndlp,
7865 NLP_STE_UNUSED_NODE);
7866 if (!ndlp)
7867 goto dropit;
7868 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7869 newnode = 1;
7870 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7871 ndlp->nlp_type |= NLP_FABRIC;
7872 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
7873 /* This is similar to the new node path */
7874 ndlp = lpfc_nlp_get(ndlp);
7875 if (!ndlp)
7876 goto dropit;
7877 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7878 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04007879 }
dea31012005-04-17 16:05:31 -05007880
7881 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05007882
James Smart12838e72014-09-03 12:57:19 -04007883 /*
7884 * Do not process any unsolicited ELS commands
7885 * if the ndlp is in DEV_LOSS
7886 */
James Smart466e8402015-05-21 13:55:28 -04007887 shost = lpfc_shost_from_vport(vport);
7888 spin_lock_irq(shost->host_lock);
7889 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
7890 spin_unlock_irq(shost->host_lock);
James Smart12838e72014-09-03 12:57:19 -04007891 goto dropit;
James Smart466e8402015-05-21 13:55:28 -04007892 }
7893 spin_unlock_irq(shost->host_lock);
James Smart12838e72014-09-03 12:57:19 -04007894
James Smart329f9bc2007-04-25 09:53:01 -04007895 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05007896 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05007897
7898 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
7899 cmd &= ELS_CMD_MASK;
7900 }
7901 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04007902 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7903 "0112 ELS command x%x received from NPORT x%x "
James Smarte74c03c2013-04-17 20:15:19 -04007904 "Data: x%x x%x x%x x%x\n",
7905 cmd, did, vport->port_state, vport->fc_flag,
7906 vport->fc_myDID, vport->fc_prevDID);
James Smarteec3d312015-08-31 16:48:18 -04007907
7908 /* reject till our FLOGI completes */
7909 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
James Smartd6de08c2015-12-16 18:11:53 -05007910 (cmd != ELS_CMD_FLOGI)) {
James Smart401304c2016-10-13 15:06:14 -07007911 rjt_err = LSRJT_LOGICAL_BSY;
James Smarteec3d312015-08-31 16:48:18 -04007912 rjt_exp = LSEXP_NOTHING_MORE;
7913 goto lsrjt;
7914 }
7915
dea31012005-04-17 16:05:31 -05007916 switch (cmd) {
7917 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05007918 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7919 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
7920 did, vport->port_state, ndlp->nlp_flag);
7921
dea31012005-04-17 16:05:31 -05007922 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05007923 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
James Smarte74c03c2013-04-17 20:15:19 -04007924 if (phba->sli_rev == LPFC_SLI_REV4 &&
7925 (phba->pport->fc_flag & FC_PT2PT)) {
7926 vport->fc_prevDID = vport->fc_myDID;
7927 /* Our DID needs to be updated before registering
7928 * the vfi. This is done in lpfc_rcv_plogi but
7929 * that is called after the reg_vfi.
7930 */
7931 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
7932 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7933 "3312 Remote port assigned DID x%x "
7934 "%x\n", vport->fc_myDID,
7935 vport->fc_prevDID);
7936 }
James Smart858c9f62007-06-17 19:56:39 -05007937
James Smartddcc50f2008-12-04 22:38:46 -05007938 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05007939
7940 /* If Nport discovery is delayed, reject PLOGIs */
7941 if (vport->fc_flag & FC_DISC_DELAYED) {
7942 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007943 rjt_exp = LSEXP_NOTHING_MORE;
James Smart92494142011-02-16 12:39:44 -05007944 break;
7945 }
James Smartd6de08c2015-12-16 18:11:53 -05007946
James Smart858c9f62007-06-17 19:56:39 -05007947 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05007948 if (!(phba->pport->fc_flag & FC_PT2PT) ||
7949 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
7950 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007951 rjt_exp = LSEXP_NOTHING_MORE;
James Smart1b32f6a2008-02-08 18:49:39 -05007952 break;
7953 }
dea31012005-04-17 16:05:31 -05007954 }
James Smart87af33f2007-10-27 13:37:43 -04007955
James Smart87af33f2007-10-27 13:37:43 -04007956 spin_lock_irq(shost->host_lock);
7957 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
7958 spin_unlock_irq(shost->host_lock);
7959
James Smart2e0fef82007-06-17 19:56:36 -05007960 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7961 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05007962
dea31012005-04-17 16:05:31 -05007963 break;
7964 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05007965 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7966 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
7967 did, vport->port_state, ndlp->nlp_flag);
7968
dea31012005-04-17 16:05:31 -05007969 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04007970 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007971 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007972 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05007973 break;
7974 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05007975 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7976 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
7977 did, vport->port_state, ndlp->nlp_flag);
7978
dea31012005-04-17 16:05:31 -05007979 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05007980 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05007981 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007982 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007983 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007984 break;
7985 }
James Smart2e0fef82007-06-17 19:56:36 -05007986 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05007987 break;
7988 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05007989 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7990 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
7991 did, vport->port_state, ndlp->nlp_flag);
7992
dea31012005-04-17 16:05:31 -05007993 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05007994 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05007995 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007996 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007997 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007998 break;
7999 }
James Smart2e0fef82007-06-17 19:56:36 -05008000 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05008001 break;
James Smart8b017a32015-05-21 13:55:18 -04008002 case ELS_CMD_LCB:
8003 phba->fc_stat.elsRcvLCB++;
8004 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
8005 break;
James Smart86478872015-05-21 13:55:21 -04008006 case ELS_CMD_RDP:
8007 phba->fc_stat.elsRcvRDP++;
8008 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
8009 break;
dea31012005-04-17 16:05:31 -05008010 case ELS_CMD_RSCN:
8011 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04008012 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04008013 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008014 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05008015 break;
8016 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05008017 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8018 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
8019 did, vport->port_state, ndlp->nlp_flag);
8020
James Smartddcc50f2008-12-04 22:38:46 -05008021 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05008022 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05008023 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05008024 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008025 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008026 break;
8027 }
James Smart2e0fef82007-06-17 19:56:36 -05008028 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8029 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05008030 break;
8031 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05008032 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8033 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
8034 did, vport->port_state, ndlp->nlp_flag);
8035
dea31012005-04-17 16:05:31 -05008036 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05008037 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05008038 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008039 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008040 break;
8041 }
James Smart2e0fef82007-06-17 19:56:36 -05008042 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8043 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05008044 break;
8045 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05008046 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8047 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
8048 did, vport->port_state, ndlp->nlp_flag);
8049
dea31012005-04-17 16:05:31 -05008050 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05008051 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05008052 break;
8053 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05008054 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8055 "RCV FARP: did:x%x/ste:x%x flg:x%x",
8056 did, vport->port_state, ndlp->nlp_flag);
8057
dea31012005-04-17 16:05:31 -05008058 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05008059 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05008060 break;
8061 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05008062 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8063 "RCV FAN: did:x%x/ste:x%x flg:x%x",
8064 did, vport->port_state, ndlp->nlp_flag);
8065
dea31012005-04-17 16:05:31 -05008066 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05008067 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05008068 break;
dea31012005-04-17 16:05:31 -05008069 case ELS_CMD_PRLI:
James Smarta0f2d3e2017-02-12 13:52:31 -08008070 case ELS_CMD_NVMEPRLI:
James Smart858c9f62007-06-17 19:56:39 -05008071 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8072 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
8073 did, vport->port_state, ndlp->nlp_flag);
8074
dea31012005-04-17 16:05:31 -05008075 phba->fc_stat.elsRcvPRLI++;
Dick Kennedya71e3cd2017-03-23 08:47:18 -04008076 if ((vport->port_state < LPFC_DISC_AUTH) &&
8077 (vport->fc_flag & FC_FABRIC)) {
James Smart858c9f62007-06-17 19:56:39 -05008078 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008079 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008080 break;
8081 }
James Smart2e0fef82007-06-17 19:56:36 -05008082 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05008083 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008084 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05008085 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8086 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
8087 did, vport->port_state, ndlp->nlp_flag);
8088
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008089 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05008090 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04008091 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008092 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008093 break;
James Smart12265f62010-10-22 11:05:53 -04008094 case ELS_CMD_RLS:
8095 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8096 "RCV RLS: did:x%x/ste:x%x flg:x%x",
8097 did, vport->port_state, ndlp->nlp_flag);
8098
8099 phba->fc_stat.elsRcvRLS++;
8100 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
8101 if (newnode)
8102 lpfc_nlp_put(ndlp);
8103 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008104 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05008105 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8106 "RCV RPS: did:x%x/ste:x%x flg:x%x",
8107 did, vport->port_state, ndlp->nlp_flag);
8108
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008109 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05008110 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04008111 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008112 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008113 break;
8114 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05008115 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8116 "RCV RPL: did:x%x/ste:x%x flg:x%x",
8117 did, vport->port_state, ndlp->nlp_flag);
8118
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008119 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05008120 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04008121 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008122 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008123 break;
dea31012005-04-17 16:05:31 -05008124 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05008125 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8126 "RCV RNID: did:x%x/ste:x%x flg:x%x",
8127 did, vport->port_state, ndlp->nlp_flag);
8128
dea31012005-04-17 16:05:31 -05008129 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05008130 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04008131 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008132 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05008133 break;
James Smart12265f62010-10-22 11:05:53 -04008134 case ELS_CMD_RTV:
8135 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8136 "RCV RTV: did:x%x/ste:x%x flg:x%x",
8137 did, vport->port_state, ndlp->nlp_flag);
8138 phba->fc_stat.elsRcvRTV++;
8139 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
8140 if (newnode)
8141 lpfc_nlp_put(ndlp);
8142 break;
James Smart5ffc2662009-11-18 15:39:44 -05008143 case ELS_CMD_RRQ:
8144 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8145 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
8146 did, vport->port_state, ndlp->nlp_flag);
8147
8148 phba->fc_stat.elsRcvRRQ++;
8149 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
8150 if (newnode)
8151 lpfc_nlp_put(ndlp);
8152 break;
James Smart12265f62010-10-22 11:05:53 -04008153 case ELS_CMD_ECHO:
8154 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8155 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
8156 did, vport->port_state, ndlp->nlp_flag);
8157
8158 phba->fc_stat.elsRcvECHO++;
8159 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
8160 if (newnode)
8161 lpfc_nlp_put(ndlp);
8162 break;
James Smart303f2f92013-01-03 15:43:11 -05008163 case ELS_CMD_REC:
Colin Ian King8fd03fd2017-12-22 00:39:36 +00008164 /* receive this due to exchange closed */
8165 rjt_err = LSRJT_UNABLE_TPC;
8166 rjt_exp = LSEXP_INVALID_OX_RX;
James Smart303f2f92013-01-03 15:43:11 -05008167 break;
dea31012005-04-17 16:05:31 -05008168 default:
James Smart858c9f62007-06-17 19:56:39 -05008169 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8170 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
8171 cmd, did, vport->port_state);
8172
dea31012005-04-17 16:05:31 -05008173 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05008174 rjt_err = LSRJT_CMD_UNSUPPORTED;
James Smart303f2f92013-01-03 15:43:11 -05008175 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008176
8177 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04008178 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8179 "0115 Unknown ELS command x%x "
8180 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04008181 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008182 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05008183 break;
8184 }
8185
James Smarteec3d312015-08-31 16:48:18 -04008186lsrjt:
dea31012005-04-17 16:05:31 -05008187 /* check if need to LS_RJT received ELS cmd */
8188 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05008189 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05008190 stat.un.b.lsRjtRsnCode = rjt_err;
James Smart303f2f92013-01-03 15:43:11 -05008191 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
James Smart858c9f62007-06-17 19:56:39 -05008192 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
8193 NULL);
dea31012005-04-17 16:05:31 -05008194 }
8195
James Smartd7c255b2008-08-24 21:50:00 -04008196 lpfc_nlp_put(elsiocb->context1);
8197 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05008198 return;
8199
8200dropit:
James Smart98c9ea52007-10-27 13:37:33 -04008201 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04008202 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8203 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05008204 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04008205 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05008206 phba->fc_stat.elsRcvDrop++;
8207}
8208
James Smarte59058c2008-08-24 21:49:00 -04008209/**
James Smart3621a712009-04-06 18:47:14 -04008210 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04008211 * @phba: pointer to lpfc hba data structure.
8212 * @pring: pointer to a SLI ring.
8213 * @elsiocb: pointer to lpfc els iocb data structure.
8214 *
8215 * This routine is used to process an unsolicited event received from a SLI
8216 * (Service Level Interface) ring. The actual processing of the data buffer
8217 * associated with the unsolicited event is done by invoking the routine
8218 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
8219 * SLI ring on which the unsolicited event was received.
8220 **/
James Smarted957682007-06-17 19:56:37 -05008221void
8222lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8223 struct lpfc_iocbq *elsiocb)
8224{
8225 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05008226 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05008227 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05008228 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
8229 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05008230
James Smartd7c255b2008-08-24 21:50:00 -04008231 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05008232 elsiocb->context2 = NULL;
8233 elsiocb->context3 = NULL;
8234
8235 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
8236 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
8237 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
James Smarte3d2b802012-08-14 14:25:43 -04008238 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
8239 IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05008240 phba->fc_stat.NoRcvBuf++;
8241 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05008242 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04008243 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05008244 return;
8245 }
8246
James Smart92d7f7b2007-06-17 19:56:38 -05008247 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
8248 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
8249 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
8250 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
8251 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04008252 else
8253 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04008254 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05008255 }
James Smart6d368e52011-05-24 11:44:12 -04008256
James Smart7f5f3d02008-02-08 18:50:14 -05008257 /* If there are no BDEs associated
8258 * with this IOCB, there is nothing to do.
8259 */
James Smarted957682007-06-17 19:56:37 -05008260 if (icmd->ulpBdeCount == 0)
8261 return;
8262
James Smart7f5f3d02008-02-08 18:50:14 -05008263 /* type of ELS cmd is first 32bit word
8264 * in packet
8265 */
James Smarted957682007-06-17 19:56:37 -05008266 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05008267 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05008268 } else {
8269 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
8270 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05008271 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
8272 paddr);
James Smarted957682007-06-17 19:56:37 -05008273 }
8274
James Smart92d7f7b2007-06-17 19:56:38 -05008275 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8276 /*
8277 * The different unsolicited event handlers would tell us
8278 * if they are done with "mp" by setting context2 to NULL.
8279 */
dea31012005-04-17 16:05:31 -05008280 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05008281 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
8282 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05008283 }
James Smarted957682007-06-17 19:56:37 -05008284
8285 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05008286 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05008287 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05008288 elsiocb->context2 = bdeBuf2;
8289 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05008290 /* free mp if we are done with it */
8291 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05008292 lpfc_in_buf_free(phba, elsiocb->context2);
8293 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05008294 }
dea31012005-04-17 16:05:31 -05008295 }
dea31012005-04-17 16:05:31 -05008296}
James Smart92d7f7b2007-06-17 19:56:38 -05008297
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08008298static void
James Smart4258e982015-12-16 18:11:58 -05008299lpfc_start_fdmi(struct lpfc_vport *vport)
8300{
James Smart4258e982015-12-16 18:11:58 -05008301 struct lpfc_nodelist *ndlp;
8302
8303 /* If this is the first time, allocate an ndlp and initialize
8304 * it. Otherwise, make sure the node is enabled and then do the
8305 * login.
8306 */
8307 ndlp = lpfc_findnode_did(vport, FDMI_DID);
8308 if (!ndlp) {
James Smart9d3d3402017-04-21 16:05:00 -07008309 ndlp = lpfc_nlp_init(vport, FDMI_DID);
James Smart4258e982015-12-16 18:11:58 -05008310 if (ndlp) {
James Smart4258e982015-12-16 18:11:58 -05008311 ndlp->nlp_type |= NLP_FABRIC;
8312 } else {
8313 return;
8314 }
8315 }
8316 if (!NLP_CHK_NODE_ACT(ndlp))
8317 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
8318
8319 if (ndlp) {
8320 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8321 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
8322 }
8323}
8324
James Smarte59058c2008-08-24 21:49:00 -04008325/**
James Smart3621a712009-04-06 18:47:14 -04008326 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04008327 * @phba: pointer to lpfc hba data structure.
8328 * @vport: pointer to a virtual N_Port data structure.
8329 *
8330 * This routine issues a Port Login (PLOGI) to the Name Server with
8331 * State Change Request (SCR) for a @vport. This routine will create an
8332 * ndlp for the Name Server associated to the @vport if such node does
8333 * not already exist. The PLOGI to Name Server is issued by invoking the
8334 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
8335 * (FDMI) is configured to the @vport, a FDMI node will be created and
8336 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
8337 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008338void
8339lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
8340{
James Smart4258e982015-12-16 18:11:58 -05008341 struct lpfc_nodelist *ndlp;
James Smart92494142011-02-16 12:39:44 -05008342 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8343
8344 /*
8345 * If lpfc_delay_discovery parameter is set and the clean address
8346 * bit is cleared and fc fabric parameters chenged, delay FC NPort
8347 * discovery.
8348 */
8349 spin_lock_irq(shost->host_lock);
8350 if (vport->fc_flag & FC_DISC_DELAYED) {
8351 spin_unlock_irq(shost->host_lock);
James Smart18775702013-04-17 20:19:25 -04008352 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
8353 "3334 Delay fc port discovery for %d seconds\n",
8354 phba->fc_ratov);
James Smart92494142011-02-16 12:39:44 -05008355 mod_timer(&vport->delayed_disc_tmo,
James Smart256ec0d2013-04-17 20:14:58 -04008356 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
James Smart92494142011-02-16 12:39:44 -05008357 return;
8358 }
8359 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008360
8361 ndlp = lpfc_findnode_did(vport, NameServer_DID);
8362 if (!ndlp) {
James Smart9d3d3402017-04-21 16:05:00 -07008363 ndlp = lpfc_nlp_init(vport, NameServer_DID);
James Smart92d7f7b2007-06-17 19:56:38 -05008364 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05008365 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05008366 lpfc_disc_start(vport);
8367 return;
8368 }
8369 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04008370 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8371 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05008372 return;
8373 }
James Smarte47c9092008-02-08 18:49:26 -05008374 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
8375 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
8376 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05008377 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05008378 lpfc_disc_start(vport);
8379 return;
8380 }
8381 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8382 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8383 "0348 NameServer login: node freed\n");
8384 return;
8385 }
James Smart92d7f7b2007-06-17 19:56:38 -05008386 }
James Smart58da1ff2008-04-07 10:15:56 -04008387 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05008388
8389 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8390
8391 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
8392 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04008393 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8394 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05008395 return;
8396 }
8397
James Smart8663cbb2016-03-31 14:12:33 -07008398 if ((phba->cfg_enable_SmartSAN ||
8399 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
8400 (vport->load_flag & FC_ALLOW_FDMI))
James Smart4258e982015-12-16 18:11:58 -05008401 lpfc_start_fdmi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05008402}
8403
James Smarte59058c2008-08-24 21:49:00 -04008404/**
James Smart3621a712009-04-06 18:47:14 -04008405 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04008406 * @phba: pointer to lpfc hba data structure.
8407 * @pmb: pointer to the driver internal queue element for mailbox command.
8408 *
8409 * This routine is the completion callback function to register new vport
8410 * mailbox command. If the new vport mailbox command completes successfully,
8411 * the fabric registration login shall be performed on physical port (the
8412 * new vport created is actually a physical port, with VPI 0) or the port
8413 * login to Name Server for State Change Request (SCR) will be performed
8414 * on virtual port (real virtual port, with VPI greater than 0).
8415 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008416static void
8417lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
8418{
8419 struct lpfc_vport *vport = pmb->vport;
8420 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8421 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04008422 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05008423 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05008424
James Smart09372822008-01-11 01:52:54 -05008425 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008426 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05008427 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008428
8429 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04008430 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04008431 "0915 Register VPI failed : Status: x%x"
8432 " upd bit: x%x \n", mb->mbxStatus,
8433 mb->un.varRegVpi.upd);
8434 if (phba->sli_rev == LPFC_SLI_REV4 &&
8435 mb->un.varRegVpi.upd)
8436 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05008437
8438 switch (mb->mbxStatus) {
8439 case 0x11: /* unsupported feature */
8440 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05008441 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05008442 /* giving up on vport registration */
8443 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8444 spin_lock_irq(shost->host_lock);
8445 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
8446 spin_unlock_irq(shost->host_lock);
8447 lpfc_can_disctmo(vport);
8448 break;
James Smart695a8142010-01-26 23:08:03 -05008449 /* If reg_vpi fail with invalid VPI status, re-init VPI */
8450 case 0x20:
8451 spin_lock_irq(shost->host_lock);
8452 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8453 spin_unlock_irq(shost->host_lock);
8454 lpfc_init_vpi(phba, pmb, vport->vpi);
8455 pmb->vport = vport;
8456 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
8457 rc = lpfc_sli_issue_mbox(phba, pmb,
8458 MBX_NOWAIT);
8459 if (rc == MBX_NOT_FINISHED) {
8460 lpfc_printf_vlog(vport,
8461 KERN_ERR, LOG_MBOX,
8462 "2732 Failed to issue INIT_VPI"
8463 " mailbox command\n");
8464 } else {
8465 lpfc_nlp_put(ndlp);
8466 return;
8467 }
8468
James Smart92d7f7b2007-06-17 19:56:38 -05008469 default:
8470 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04008471 if (phba->sli_rev == LPFC_SLI_REV4)
8472 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05008473 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05008474 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008475 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05008476 spin_unlock_irq(shost->host_lock);
James Smart5d181532017-03-04 09:30:25 -08008477 if (mb->mbxStatus == MBX_NOT_FINISHED)
8478 break;
8479 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
8480 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
8481 if (phba->sli_rev == LPFC_SLI_REV4)
8482 lpfc_issue_init_vfi(vport);
8483 else
8484 lpfc_initial_flogi(vport);
8485 } else {
James Smart7f5f3d02008-02-08 18:50:14 -05008486 lpfc_initial_fdisc(vport);
James Smart5d181532017-03-04 09:30:25 -08008487 }
James Smart92d7f7b2007-06-17 19:56:38 -05008488 break;
8489 }
James Smart92d7f7b2007-06-17 19:56:38 -05008490 } else {
James Smart695a8142010-01-26 23:08:03 -05008491 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05008492 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05008493 spin_unlock_irq(shost->host_lock);
8494 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04008495 if (phba->sli_rev < LPFC_SLI_REV4)
8496 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05008497 else {
James Smartfc2b9892010-02-26 14:15:29 -05008498 /*
8499 * If the physical port is instantiated using
8500 * FDISC, do not start vport discovery.
8501 */
8502 if (vport->port_state != LPFC_FDISC)
8503 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05008504 lpfc_do_scr_ns_plogi(phba, vport);
8505 }
8506 } else
James Smart92d7f7b2007-06-17 19:56:38 -05008507 lpfc_do_scr_ns_plogi(phba, vport);
8508 }
James Smart38b92ef2010-08-04 16:11:39 -04008509mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05008510 /* Now, we decrement the ndlp reference count held for this
8511 * callback function
8512 */
8513 lpfc_nlp_put(ndlp);
8514
James Smart92d7f7b2007-06-17 19:56:38 -05008515 mempool_free(pmb, phba->mbox_mem_pool);
8516 return;
8517}
8518
James Smarte59058c2008-08-24 21:49:00 -04008519/**
James Smart3621a712009-04-06 18:47:14 -04008520 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04008521 * @phba: pointer to lpfc hba data structure.
8522 * @vport: pointer to a host virtual N_Port data structure.
8523 * @ndlp: pointer to a node-list data structure.
8524 *
8525 * This routine registers the @vport as a new virtual port with a HBA.
8526 * It is done through a registering vpi mailbox command.
8527 **/
James Smart695a8142010-01-26 23:08:03 -05008528void
James Smart92d7f7b2007-06-17 19:56:38 -05008529lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
8530 struct lpfc_nodelist *ndlp)
8531{
James Smart09372822008-01-11 01:52:54 -05008532 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05008533 LPFC_MBOXQ_t *mbox;
8534
8535 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8536 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04008537 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05008538 mbox->vport = vport;
8539 mbox->context2 = lpfc_nlp_get(ndlp);
8540 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04008541 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05008542 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05008543 /* mailbox command not success, decrement ndlp
8544 * reference count for this command
8545 */
8546 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05008547 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05008548
James Smarte8b62012007-08-02 11:10:09 -04008549 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8550 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05008551 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05008552 }
8553 } else {
James Smarte8b62012007-08-02 11:10:09 -04008554 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8555 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05008556 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05008557 }
James Smartfa4066b2008-01-11 01:53:27 -05008558 return;
8559
8560mbox_err_exit:
8561 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8562 spin_lock_irq(shost->host_lock);
8563 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
8564 spin_unlock_irq(shost->host_lock);
8565 return;
James Smart92d7f7b2007-06-17 19:56:38 -05008566}
8567
James Smarte59058c2008-08-24 21:49:00 -04008568/**
James Smart0c9ab6f2010-02-26 14:15:57 -05008569 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05008570 * @phba: pointer to lpfc hba data structure.
8571 *
James Smart0c9ab6f2010-02-26 14:15:57 -05008572 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05008573 **/
8574void
James Smart0c9ab6f2010-02-26 14:15:57 -05008575lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05008576{
8577 struct lpfc_vport **vports;
8578 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05008579 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05008580 int i;
James Smart695a8142010-01-26 23:08:03 -05008581
8582 /* Treat this failure as linkdown for all vports */
8583 link_state = phba->link_state;
8584 lpfc_linkdown(phba);
8585 phba->link_state = link_state;
8586
8587 vports = lpfc_create_vport_work_array(phba);
8588
8589 if (vports) {
8590 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
8591 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
8592 if (ndlp)
8593 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
8594 lpfc_els_flush_cmd(vports[i]);
8595 }
8596 lpfc_destroy_vport_work_array(phba, vports);
8597 }
James Smart0c9ab6f2010-02-26 14:15:57 -05008598}
8599
8600/**
8601 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
8602 * @phba: pointer to lpfc hba data structure.
8603 *
8604 * This routine abort all pending discovery commands and
8605 * start a timer to retry FLOGI for the physical port
8606 * discovery.
8607 **/
8608void
8609lpfc_retry_pport_discovery(struct lpfc_hba *phba)
8610{
8611 struct lpfc_nodelist *ndlp;
8612 struct Scsi_Host *shost;
8613
8614 /* Cancel the all vports retry delay retry timers */
8615 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05008616
8617 /* If fabric require FLOGI, then re-instantiate physical login */
8618 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
8619 if (!ndlp)
8620 return;
8621
James Smart695a8142010-01-26 23:08:03 -05008622 shost = lpfc_shost_from_vport(phba->pport);
James Smart256ec0d2013-04-17 20:14:58 -04008623 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
James Smart695a8142010-01-26 23:08:03 -05008624 spin_lock_irq(shost->host_lock);
8625 ndlp->nlp_flag |= NLP_DELAY_TMO;
8626 spin_unlock_irq(shost->host_lock);
8627 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
8628 phba->pport->port_state = LPFC_FLOGI;
8629 return;
8630}
8631
8632/**
8633 * lpfc_fabric_login_reqd - Check if FLOGI required.
8634 * @phba: pointer to lpfc hba data structure.
8635 * @cmdiocb: pointer to FDISC command iocb.
8636 * @rspiocb: pointer to FDISC response iocb.
8637 *
8638 * This routine checks if a FLOGI is reguired for FDISC
8639 * to succeed.
8640 **/
8641static int
8642lpfc_fabric_login_reqd(struct lpfc_hba *phba,
8643 struct lpfc_iocbq *cmdiocb,
8644 struct lpfc_iocbq *rspiocb)
8645{
8646
8647 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
8648 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
8649 return 0;
8650 else
8651 return 1;
8652}
8653
8654/**
James Smart3621a712009-04-06 18:47:14 -04008655 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04008656 * @phba: pointer to lpfc hba data structure.
8657 * @cmdiocb: pointer to lpfc command iocb data structure.
8658 * @rspiocb: pointer to lpfc response iocb data structure.
8659 *
8660 * This routine is the completion callback function to a Fabric Discover
8661 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
8662 * single threaded, each FDISC completion callback function will reset
8663 * the discovery timer for all vports such that the timers will not get
8664 * unnecessary timeout. The function checks the FDISC IOCB status. If error
8665 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
8666 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
8667 * assigned to the vport has been changed with the completion of the FDISC
8668 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
8669 * are unregistered from the HBA, and then the lpfc_register_new_vport()
8670 * routine is invoked to register new vport with the HBA. Otherwise, the
8671 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
8672 * Server for State Change Request (SCR).
8673 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008674static void
8675lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8676 struct lpfc_iocbq *rspiocb)
8677{
8678 struct lpfc_vport *vport = cmdiocb->vport;
8679 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8680 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
8681 struct lpfc_nodelist *np;
8682 struct lpfc_nodelist *next_np;
8683 IOCB_t *irsp = &rspiocb->iocb;
8684 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05008685 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
8686 struct serv_parm *sp;
8687 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05008688
James Smarte8b62012007-08-02 11:10:09 -04008689 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8690 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
8691 irsp->ulpStatus, irsp->un.ulpWord[4],
8692 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05008693 /* Since all FDISCs are being single threaded, we
8694 * must reset the discovery timer for ALL vports
8695 * waiting to send FDISC when one completes.
8696 */
8697 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
8698 lpfc_set_disctmo(piocb->vport);
8699 }
8700
James Smart858c9f62007-06-17 19:56:39 -05008701 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8702 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
8703 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
8704
James Smart92d7f7b2007-06-17 19:56:38 -05008705 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05008706
8707 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
8708 lpfc_retry_pport_discovery(phba);
8709 goto out;
8710 }
8711
James Smart92d7f7b2007-06-17 19:56:38 -05008712 /* Check for retry */
8713 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
8714 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05008715 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04008716 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart6b5151f2012-01-18 16:24:06 -05008717 "0126 FDISC failed. (x%x/x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04008718 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04008719 goto fdisc_failed;
8720 }
James Smartd7c255b2008-08-24 21:50:00 -04008721 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05008722 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04008723 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04008724 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05008725 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04008726 vport->fc_flag |= FC_PUBLIC_LOOP;
8727 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008728
James Smartd7c255b2008-08-24 21:50:00 -04008729 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
8730 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05008731 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04008732 if (!prsp)
8733 goto out;
James Smart92494142011-02-16 12:39:44 -05008734 sp = prsp->virt + sizeof(uint32_t);
8735 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
8736 memcpy(&vport->fabric_portname, &sp->portName,
8737 sizeof(struct lpfc_name));
8738 memcpy(&vport->fabric_nodename, &sp->nodeName,
8739 sizeof(struct lpfc_name));
8740 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04008741 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8742 /* If our NportID changed, we need to ensure all
8743 * remaining NPORTs get unreg_login'ed so we can
8744 * issue unreg_vpi.
8745 */
8746 list_for_each_entry_safe(np, next_np,
8747 &vport->fc_nodes, nlp_listp) {
8748 if (!NLP_CHK_NODE_ACT(ndlp) ||
8749 (np->nlp_state != NLP_STE_NPR_NODE) ||
8750 !(np->nlp_flag & NLP_NPR_ADISC))
8751 continue;
James Smart09372822008-01-11 01:52:54 -05008752 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04008753 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05008754 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04008755 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05008756 }
James Smart78730cf2010-04-06 15:06:30 -04008757 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04008758
8759 if (phba->sli_rev == LPFC_SLI_REV4)
8760 lpfc_sli4_unreg_all_rpis(vport);
8761
James Smartd7c255b2008-08-24 21:50:00 -04008762 lpfc_mbx_unreg_vpi(vport);
8763 spin_lock_irq(shost->host_lock);
8764 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05008765 if (phba->sli_rev == LPFC_SLI_REV4)
8766 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04008767 else
8768 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04008769 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04008770 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
8771 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8772 /*
8773 * Driver needs to re-reg VPI in order for f/w
8774 * to update the MAC address.
8775 */
8776 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04008777 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05008778 }
8779
James Smartecfd03c2010-02-12 14:41:27 -05008780 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
8781 lpfc_issue_init_vpi(vport);
8782 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04008783 lpfc_register_new_vport(phba, vport, ndlp);
8784 else
8785 lpfc_do_scr_ns_plogi(phba, vport);
8786 goto out;
8787fdisc_failed:
James Smart845d9e82017-05-15 15:20:38 -07008788 if (vport->fc_vport &&
8789 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
James Smartc84163d2015-05-21 13:55:22 -04008790 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smartd7c255b2008-08-24 21:50:00 -04008791 /* Cancel discovery timer */
8792 lpfc_can_disctmo(vport);
8793 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05008794out:
8795 lpfc_els_free_iocb(phba, cmdiocb);
8796}
8797
James Smarte59058c2008-08-24 21:49:00 -04008798/**
James Smart3621a712009-04-06 18:47:14 -04008799 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04008800 * @vport: pointer to a virtual N_Port data structure.
8801 * @ndlp: pointer to a node-list data structure.
8802 * @retry: number of retries to the command IOCB.
8803 *
8804 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
8805 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
8806 * routine to issue the IOCB, which makes sure only one outstanding fabric
8807 * IOCB will be sent off HBA at any given time.
8808 *
8809 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8810 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8811 * will be stored into the context1 field of the IOCB for the completion
8812 * callback function to the FDISC ELS command.
8813 *
8814 * Return code
8815 * 0 - Successfully issued fdisc iocb command
8816 * 1 - Failed to issue fdisc iocb command
8817 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01008818static int
James Smart92d7f7b2007-06-17 19:56:38 -05008819lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
8820 uint8_t retry)
8821{
8822 struct lpfc_hba *phba = vport->phba;
8823 IOCB_t *icmd;
8824 struct lpfc_iocbq *elsiocb;
8825 struct serv_parm *sp;
8826 uint8_t *pcmd;
8827 uint16_t cmdsize;
8828 int did = ndlp->nlp_DID;
8829 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05008830
James Smart5ffc2662009-11-18 15:39:44 -05008831 vport->port_state = LPFC_FDISC;
James Smart6b5151f2012-01-18 16:24:06 -05008832 vport->fc_myDID = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05008833 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
8834 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
8835 ELS_CMD_FDISC);
8836 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05008837 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04008838 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8839 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05008840 return 1;
8841 }
8842
8843 icmd = &elsiocb->iocb;
8844 icmd->un.elsreq64.myID = 0;
8845 icmd->un.elsreq64.fl = 1;
8846
James Smart73d91e52011-10-10 21:32:10 -04008847 /*
8848 * SLI3 ports require a different context type value than SLI4.
8849 * Catch SLI3 ports here and override the prep.
8850 */
8851 if (phba->sli_rev == LPFC_SLI_REV3) {
James Smartf1126682009-06-10 17:22:44 -04008852 icmd->ulpCt_h = 1;
8853 icmd->ulpCt_l = 0;
8854 }
James Smart92d7f7b2007-06-17 19:56:38 -05008855
8856 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8857 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
8858 pcmd += sizeof(uint32_t); /* CSP Word 1 */
8859 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
8860 sp = (struct serv_parm *) pcmd;
8861 /* Setup CSPs accordingly for Fabric */
8862 sp->cmn.e_d_tov = 0;
8863 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05008864 sp->cmn.virtual_fabric_support = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05008865 sp->cls1.classValid = 0;
8866 sp->cls2.seqDelivery = 1;
8867 sp->cls3.seqDelivery = 1;
8868
8869 pcmd += sizeof(uint32_t); /* CSP Word 2 */
8870 pcmd += sizeof(uint32_t); /* CSP Word 3 */
8871 pcmd += sizeof(uint32_t); /* CSP Word 4 */
8872 pcmd += sizeof(uint32_t); /* Port Name */
8873 memcpy(pcmd, &vport->fc_portname, 8);
8874 pcmd += sizeof(uint32_t); /* Node Name */
8875 pcmd += sizeof(uint32_t); /* Node Name */
8876 memcpy(pcmd, &vport->fc_nodename, 8);
Dick Kennedy176de5b2017-08-23 16:55:40 -07008877 sp->cmn.valid_vendor_ver_level = 0;
James Smartaeb3c812017-04-21 16:05:02 -07008878 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
James Smart92d7f7b2007-06-17 19:56:38 -05008879 lpfc_set_disctmo(vport);
8880
8881 phba->fc_stat.elsXmitFDISC++;
8882 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
8883
James Smart858c9f62007-06-17 19:56:39 -05008884 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8885 "Issue FDISC: did:x%x",
8886 did, 0, 0);
8887
James Smart92d7f7b2007-06-17 19:56:38 -05008888 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
8889 if (rc == IOCB_ERROR) {
8890 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05008891 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04008892 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8893 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05008894 return 1;
8895 }
8896 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05008897 return 0;
8898}
8899
James Smarte59058c2008-08-24 21:49:00 -04008900/**
James Smart3621a712009-04-06 18:47:14 -04008901 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04008902 * @phba: pointer to lpfc hba data structure.
8903 * @cmdiocb: pointer to lpfc command iocb data structure.
8904 * @rspiocb: pointer to lpfc response iocb data structure.
8905 *
8906 * This routine is the completion callback function to the issuing of a LOGO
8907 * ELS command off a vport. It frees the command IOCB and then decrement the
8908 * reference count held on ndlp for this completion function, indicating that
8909 * the reference to the ndlp is no long needed. Note that the
8910 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
8911 * callback function and an additional explicit ndlp reference decrementation
8912 * will trigger the actual release of the ndlp.
8913 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008914static void
8915lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8916 struct lpfc_iocbq *rspiocb)
8917{
8918 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05008919 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05008920 struct lpfc_nodelist *ndlp;
James Smart9589b0622011-04-16 11:03:17 -04008921 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05008922
James Smart9589b0622011-04-16 11:03:17 -04008923 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05008924 irsp = &rspiocb->iocb;
8925 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8926 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
8927 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05008928
8929 lpfc_els_free_iocb(phba, cmdiocb);
8930 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05008931
8932 /* Trigger the release of the ndlp after logo */
8933 lpfc_nlp_put(ndlp);
James Smart9589b0622011-04-16 11:03:17 -04008934
8935 /* NPIV LOGO completes to NPort <nlp_DID> */
8936 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8937 "2928 NPIV LOGO completes to NPort x%x "
8938 "Data: x%x x%x x%x x%x\n",
8939 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
8940 irsp->ulpTimeout, vport->num_disc_nodes);
8941
8942 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
8943 spin_lock_irq(shost->host_lock);
James Smart73dc0db2015-05-22 10:42:36 -04008944 vport->fc_flag &= ~FC_NDISC_ACTIVE;
James Smart9589b0622011-04-16 11:03:17 -04008945 vport->fc_flag &= ~FC_FABRIC;
8946 spin_unlock_irq(shost->host_lock);
James Smart73dc0db2015-05-22 10:42:36 -04008947 lpfc_can_disctmo(vport);
James Smart9589b0622011-04-16 11:03:17 -04008948 }
James Smart92d7f7b2007-06-17 19:56:38 -05008949}
8950
James Smarte59058c2008-08-24 21:49:00 -04008951/**
James Smart3621a712009-04-06 18:47:14 -04008952 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04008953 * @vport: pointer to a virtual N_Port data structure.
8954 * @ndlp: pointer to a node-list data structure.
8955 *
8956 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
8957 *
8958 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8959 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8960 * will be stored into the context1 field of the IOCB for the completion
8961 * callback function to the LOGO ELS command.
8962 *
8963 * Return codes
8964 * 0 - Successfully issued logo off the @vport
8965 * 1 - Failed to issue logo off the @vport
8966 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008967int
8968lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
8969{
8970 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8971 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05008972 struct lpfc_iocbq *elsiocb;
8973 uint8_t *pcmd;
8974 uint16_t cmdsize;
8975
8976 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
8977 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
8978 ELS_CMD_LOGO);
8979 if (!elsiocb)
8980 return 1;
8981
James Smart92d7f7b2007-06-17 19:56:38 -05008982 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8983 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
8984 pcmd += sizeof(uint32_t);
8985
8986 /* Fill in LOGO payload */
8987 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
8988 pcmd += sizeof(uint32_t);
8989 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
8990
James Smart858c9f62007-06-17 19:56:39 -05008991 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8992 "Issue LOGO npiv did:x%x flg:x%x",
8993 ndlp->nlp_DID, ndlp->nlp_flag, 0);
8994
James Smart92d7f7b2007-06-17 19:56:38 -05008995 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
8996 spin_lock_irq(shost->host_lock);
8997 ndlp->nlp_flag |= NLP_LOGO_SND;
8998 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04008999 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
9000 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05009001 spin_lock_irq(shost->host_lock);
9002 ndlp->nlp_flag &= ~NLP_LOGO_SND;
9003 spin_unlock_irq(shost->host_lock);
9004 lpfc_els_free_iocb(phba, elsiocb);
9005 return 1;
9006 }
9007 return 0;
9008}
9009
James Smarte59058c2008-08-24 21:49:00 -04009010/**
James Smart3621a712009-04-06 18:47:14 -04009011 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04009012 * @ptr: holder for the timer function associated data.
9013 *
9014 * This routine is invoked by the fabric iocb block timer after
9015 * timeout. It posts the fabric iocb block timeout event by setting the
9016 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
9017 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
9018 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
9019 * posted event WORKER_FABRIC_BLOCK_TMO.
9020 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009021void
Kees Cookf22eb4d2017-09-06 20:24:26 -07009022lpfc_fabric_block_timeout(struct timer_list *t)
James Smart92d7f7b2007-06-17 19:56:38 -05009023{
Kees Cookf22eb4d2017-09-06 20:24:26 -07009024 struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer);
James Smart92d7f7b2007-06-17 19:56:38 -05009025 unsigned long iflags;
9026 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04009027
James Smart92d7f7b2007-06-17 19:56:38 -05009028 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
9029 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
9030 if (!tmo_posted)
9031 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
9032 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
9033
James Smart5e9d9b82008-06-14 22:52:53 -04009034 if (!tmo_posted)
9035 lpfc_worker_wake_up(phba);
9036 return;
James Smart92d7f7b2007-06-17 19:56:38 -05009037}
9038
James Smarte59058c2008-08-24 21:49:00 -04009039/**
James Smart3621a712009-04-06 18:47:14 -04009040 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04009041 * @phba: pointer to lpfc hba data structure.
9042 *
9043 * This routine issues one fabric iocb from the driver internal list to
9044 * the HBA. It first checks whether it's ready to issue one fabric iocb to
9045 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
9046 * remove one pending fabric iocb from the driver internal list and invokes
9047 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
9048 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009049static void
9050lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
9051{
9052 struct lpfc_iocbq *iocb;
9053 unsigned long iflags;
9054 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05009055 IOCB_t *cmd;
9056
9057repeat:
9058 iocb = NULL;
9059 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05009060 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05009061 if (atomic_read(&phba->fabric_iocb_count) == 0) {
9062 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
9063 list);
9064 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05009065 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05009066 atomic_inc(&phba->fabric_iocb_count);
9067 }
9068 spin_unlock_irqrestore(&phba->hbalock, iflags);
9069 if (iocb) {
9070 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9071 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9072 iocb->iocb_flag |= LPFC_IO_FABRIC;
9073
James Smart858c9f62007-06-17 19:56:39 -05009074 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9075 "Fabric sched1: ste:x%x",
9076 iocb->vport->port_state, 0, 0);
9077
James Smart3772a992009-05-22 14:50:54 -04009078 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05009079
9080 if (ret == IOCB_ERROR) {
9081 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9082 iocb->fabric_iocb_cmpl = NULL;
9083 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9084 cmd = &iocb->iocb;
9085 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
9086 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
9087 iocb->iocb_cmpl(phba, iocb, iocb);
9088
9089 atomic_dec(&phba->fabric_iocb_count);
9090 goto repeat;
9091 }
9092 }
9093
9094 return;
9095}
9096
James Smarte59058c2008-08-24 21:49:00 -04009097/**
James Smart3621a712009-04-06 18:47:14 -04009098 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04009099 * @phba: pointer to lpfc hba data structure.
9100 *
9101 * This routine unblocks the issuing fabric iocb command. The function
9102 * will clear the fabric iocb block bit and then invoke the routine
9103 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
9104 * from the driver internal fabric iocb list.
9105 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009106void
9107lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
9108{
9109 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9110
9111 lpfc_resume_fabric_iocbs(phba);
9112 return;
9113}
9114
James Smarte59058c2008-08-24 21:49:00 -04009115/**
James Smart3621a712009-04-06 18:47:14 -04009116 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04009117 * @phba: pointer to lpfc hba data structure.
9118 *
9119 * This routine blocks the issuing fabric iocb for a specified amount of
9120 * time (currently 100 ms). This is done by set the fabric iocb block bit
9121 * and set up a timeout timer for 100ms. When the block bit is set, no more
9122 * fabric iocb will be issued out of the HBA.
9123 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009124static void
9125lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
9126{
9127 int blocked;
9128
9129 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05009130 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05009131 if (!blocked)
James Smart256ec0d2013-04-17 20:14:58 -04009132 mod_timer(&phba->fabric_block_timer,
9133 jiffies + msecs_to_jiffies(100));
James Smart92d7f7b2007-06-17 19:56:38 -05009134
9135 return;
9136}
9137
James Smarte59058c2008-08-24 21:49:00 -04009138/**
James Smart3621a712009-04-06 18:47:14 -04009139 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04009140 * @phba: pointer to lpfc hba data structure.
9141 * @cmdiocb: pointer to lpfc command iocb data structure.
9142 * @rspiocb: pointer to lpfc response iocb data structure.
9143 *
9144 * This routine is the callback function that is put to the fabric iocb's
9145 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
9146 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
9147 * function first restores and invokes the original iocb's callback function
9148 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
9149 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
9150 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009151static void
9152lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9153 struct lpfc_iocbq *rspiocb)
9154{
9155 struct ls_rjt stat;
9156
Shyam Sainie01ea5e2016-12-24 16:21:07 +05309157 BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
James Smart92d7f7b2007-06-17 19:56:38 -05009158
9159 switch (rspiocb->iocb.ulpStatus) {
9160 case IOSTAT_NPORT_RJT:
9161 case IOSTAT_FABRIC_RJT:
9162 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
9163 lpfc_block_fabric_iocbs(phba);
9164 }
9165 break;
9166
9167 case IOSTAT_NPORT_BSY:
9168 case IOSTAT_FABRIC_BSY:
9169 lpfc_block_fabric_iocbs(phba);
9170 break;
9171
9172 case IOSTAT_LS_RJT:
9173 stat.un.lsRjtError =
9174 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
9175 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
9176 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
9177 lpfc_block_fabric_iocbs(phba);
9178 break;
9179 }
9180
James Smarta0f2d3e2017-02-12 13:52:31 -08009181 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
James Smart92d7f7b2007-06-17 19:56:38 -05009182
9183 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
9184 cmdiocb->fabric_iocb_cmpl = NULL;
9185 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
9186 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
9187
9188 atomic_dec(&phba->fabric_iocb_count);
9189 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05009190 /* Post any pending iocbs to HBA */
9191 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05009192 }
9193}
9194
James Smarte59058c2008-08-24 21:49:00 -04009195/**
James Smart3621a712009-04-06 18:47:14 -04009196 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04009197 * @phba: pointer to lpfc hba data structure.
9198 * @iocb: pointer to lpfc command iocb data structure.
9199 *
9200 * This routine is used as the top-level API for issuing a fabric iocb command
9201 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
9202 * function makes sure that only one fabric bound iocb will be outstanding at
9203 * any given time. As such, this function will first check to see whether there
9204 * is already an outstanding fabric iocb on the wire. If so, it will put the
9205 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
9206 * issued later. Otherwise, it will issue the iocb on the wire and update the
9207 * fabric iocb count it indicate that there is one fabric iocb on the wire.
9208 *
9209 * Note, this implementation has a potential sending out fabric IOCBs out of
9210 * order. The problem is caused by the construction of the "ready" boolen does
9211 * not include the condition that the internal fabric IOCB list is empty. As
9212 * such, it is possible a fabric IOCB issued by this routine might be "jump"
9213 * ahead of the fabric IOCBs in the internal list.
9214 *
9215 * Return code
9216 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
9217 * IOCB_ERROR - failed to issue fabric iocb
9218 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01009219static int
James Smart92d7f7b2007-06-17 19:56:38 -05009220lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
9221{
9222 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05009223 int ready;
9224 int ret;
9225
James Smarta0f2d3e2017-02-12 13:52:31 -08009226 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
James Smart92d7f7b2007-06-17 19:56:38 -05009227
9228 spin_lock_irqsave(&phba->hbalock, iflags);
9229 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
9230 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9231
James Smart7f5f3d02008-02-08 18:50:14 -05009232 if (ready)
9233 /* Increment fabric iocb count to hold the position */
9234 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05009235 spin_unlock_irqrestore(&phba->hbalock, iflags);
9236 if (ready) {
9237 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9238 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9239 iocb->iocb_flag |= LPFC_IO_FABRIC;
9240
James Smart858c9f62007-06-17 19:56:39 -05009241 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9242 "Fabric sched2: ste:x%x",
9243 iocb->vport->port_state, 0, 0);
9244
James Smart3772a992009-05-22 14:50:54 -04009245 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05009246
9247 if (ret == IOCB_ERROR) {
9248 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9249 iocb->fabric_iocb_cmpl = NULL;
9250 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9251 atomic_dec(&phba->fabric_iocb_count);
9252 }
9253 } else {
9254 spin_lock_irqsave(&phba->hbalock, iflags);
9255 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
9256 spin_unlock_irqrestore(&phba->hbalock, iflags);
9257 ret = IOCB_SUCCESS;
9258 }
9259 return ret;
9260}
9261
James Smarte59058c2008-08-24 21:49:00 -04009262/**
James Smart3621a712009-04-06 18:47:14 -04009263 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04009264 * @vport: pointer to a virtual N_Port data structure.
9265 *
9266 * This routine aborts all the IOCBs associated with a @vport from the
9267 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9268 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9269 * list, removes each IOCB associated with the @vport off the list, set the
9270 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9271 * associated with the IOCB.
9272 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01009273static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05009274{
9275 LIST_HEAD(completions);
9276 struct lpfc_hba *phba = vport->phba;
9277 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05009278
9279 spin_lock_irq(&phba->hbalock);
9280 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9281 list) {
9282
9283 if (piocb->vport != vport)
9284 continue;
9285
9286 list_move_tail(&piocb->list, &completions);
9287 }
9288 spin_unlock_irq(&phba->hbalock);
9289
James Smarta257bf92009-04-06 18:48:10 -04009290 /* Cancel all the IOCBs from the completions list */
9291 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9292 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05009293}
9294
James Smarte59058c2008-08-24 21:49:00 -04009295/**
James Smart3621a712009-04-06 18:47:14 -04009296 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04009297 * @ndlp: pointer to a node-list data structure.
9298 *
9299 * This routine aborts all the IOCBs associated with an @ndlp from the
9300 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9301 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9302 * list, removes each IOCB associated with the @ndlp off the list, set the
9303 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9304 * associated with the IOCB.
9305 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009306void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
9307{
9308 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04009309 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05009310 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart895427b2017-02-12 13:52:30 -08009311 struct lpfc_sli_ring *pring;
9312
9313 pring = lpfc_phba_elsring(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05009314
Dick Kennedy1234a6d2017-09-29 17:34:29 -07009315 if (unlikely(!pring))
9316 return;
9317
James Smart92d7f7b2007-06-17 19:56:38 -05009318 spin_lock_irq(&phba->hbalock);
9319 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9320 list) {
9321 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
9322
9323 list_move_tail(&piocb->list, &completions);
9324 }
9325 }
9326 spin_unlock_irq(&phba->hbalock);
9327
James Smarta257bf92009-04-06 18:48:10 -04009328 /* Cancel all the IOCBs from the completions list */
9329 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9330 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05009331}
9332
James Smarte59058c2008-08-24 21:49:00 -04009333/**
James Smart3621a712009-04-06 18:47:14 -04009334 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04009335 * @phba: pointer to lpfc hba data structure.
9336 *
9337 * This routine aborts all the IOCBs currently on the driver internal
9338 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
9339 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
9340 * list, removes IOCBs off the list, set the status feild to
9341 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
9342 * the IOCB.
9343 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009344void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
9345{
9346 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05009347
9348 spin_lock_irq(&phba->hbalock);
9349 list_splice_init(&phba->fabric_iocb_list, &completions);
9350 spin_unlock_irq(&phba->hbalock);
9351
James Smarta257bf92009-04-06 18:48:10 -04009352 /* Cancel all the IOCBs from the completions list */
9353 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9354 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05009355}
James Smart6fb120a2009-05-22 14:52:59 -04009356
9357/**
James Smart1151e3e2011-02-16 12:39:35 -05009358 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
9359 * @vport: pointer to lpfc vport data structure.
9360 *
9361 * This routine is invoked by the vport cleanup for deletions and the cleanup
9362 * for an ndlp on removal.
9363 **/
9364void
9365lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
9366{
9367 struct lpfc_hba *phba = vport->phba;
9368 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9369 unsigned long iflag = 0;
9370
9371 spin_lock_irqsave(&phba->hbalock, iflag);
James Smart895427b2017-02-12 13:52:30 -08009372 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart1151e3e2011-02-16 12:39:35 -05009373 list_for_each_entry_safe(sglq_entry, sglq_next,
9374 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9375 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
9376 sglq_entry->ndlp = NULL;
9377 }
James Smart895427b2017-02-12 13:52:30 -08009378 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart1151e3e2011-02-16 12:39:35 -05009379 spin_unlock_irqrestore(&phba->hbalock, iflag);
9380 return;
9381}
9382
9383/**
James Smart6fb120a2009-05-22 14:52:59 -04009384 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
9385 * @phba: pointer to lpfc hba data structure.
9386 * @axri: pointer to the els xri abort wcqe structure.
9387 *
9388 * This routine is invoked by the worker thread to process a SLI4 slow-path
9389 * ELS aborted xri.
9390 **/
9391void
9392lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
9393 struct sli4_wcqe_xri_aborted *axri)
9394{
9395 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05009396 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -04009397 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -05009398
James Smart6fb120a2009-05-22 14:52:59 -04009399 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9400 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05009401 struct lpfc_nodelist *ndlp;
James Smart895427b2017-02-12 13:52:30 -08009402 struct lpfc_sli_ring *pring;
9403
9404 pring = lpfc_phba_elsring(phba);
James Smart6fb120a2009-05-22 14:52:59 -04009405
James Smart0f65ff62010-02-26 14:14:23 -05009406 spin_lock_irqsave(&phba->hbalock, iflag);
James Smart895427b2017-02-12 13:52:30 -08009407 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04009408 list_for_each_entry_safe(sglq_entry, sglq_next,
9409 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9410 if (sglq_entry->sli4_xritag == xri) {
9411 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05009412 ndlp = sglq_entry->ndlp;
9413 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -04009414 list_add_tail(&sglq_entry->list,
James Smart895427b2017-02-12 13:52:30 -08009415 &phba->sli4_hba.lpfc_els_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05009416 sglq_entry->state = SGL_FREED;
James Smart895427b2017-02-12 13:52:30 -08009417 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04009418 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smartee0f4fe2012-05-09 21:19:14 -04009419 lpfc_set_rrq_active(phba, ndlp,
9420 sglq_entry->sli4_lxritag,
9421 rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04009422
9423 /* Check if TXQ queue needs to be serviced */
Dick Kennedy1234a6d2017-09-29 17:34:29 -07009424 if (pring && !list_empty(&pring->txq))
James Smart589a52d2010-07-14 15:30:54 -04009425 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04009426 return;
9427 }
9428 }
James Smart895427b2017-02-12 13:52:30 -08009429 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -04009430 lxri = lpfc_sli4_xri_inrange(phba, xri);
9431 if (lxri == NO_XRI) {
9432 spin_unlock_irqrestore(&phba->hbalock, iflag);
9433 return;
9434 }
James Smart895427b2017-02-12 13:52:30 -08009435 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -04009436 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -05009437 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
James Smart895427b2017-02-12 13:52:30 -08009438 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -05009439 spin_unlock_irqrestore(&phba->hbalock, iflag);
9440 return;
9441 }
9442 sglq_entry->state = SGL_XRI_ABORTED;
James Smart895427b2017-02-12 13:52:30 -08009443 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -05009444 spin_unlock_irqrestore(&phba->hbalock, iflag);
9445 return;
James Smart6fb120a2009-05-22 14:52:59 -04009446}
James Smart086a3452012-08-14 14:25:21 -04009447
9448/* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
9449 * @vport: pointer to virtual port object.
9450 * @ndlp: nodelist pointer for the impacted node.
9451 *
9452 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
9453 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
9454 * the driver is required to send a LOGO to the remote node before it
9455 * attempts to recover its login to the remote node.
9456 */
9457void
9458lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
9459 struct lpfc_nodelist *ndlp)
9460{
9461 struct Scsi_Host *shost;
9462 struct lpfc_hba *phba;
9463 unsigned long flags = 0;
9464
9465 shost = lpfc_shost_from_vport(vport);
9466 phba = vport->phba;
9467 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
9468 lpfc_printf_log(phba, KERN_INFO,
9469 LOG_SLI, "3093 No rport recovery needed. "
9470 "rport in state 0x%x\n", ndlp->nlp_state);
9471 return;
9472 }
9473 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9474 "3094 Start rport recovery on shost id 0x%x "
9475 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
9476 "flags 0x%x\n",
9477 shost->host_no, ndlp->nlp_DID,
9478 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
9479 ndlp->nlp_flag);
9480 /*
9481 * The rport is not responding. Remove the FCP-2 flag to prevent
9482 * an ADISC in the follow-up recovery code.
9483 */
9484 spin_lock_irqsave(shost->host_lock, flags);
9485 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
9486 spin_unlock_irqrestore(shost->host_lock, flags);
9487 lpfc_issue_els_logo(vport, ndlp, 0);
9488 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
9489}
9490